Created
May 26, 2016 19:57
-
-
Save ATLPhenx/f8e280c7212fba14659ef90b76b4d600 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#region Variables | |
public string path { get; set; } | |
public string searchTerm { get; set; } | |
public int lineNumberCount { get; set; } | |
public List<string> FileList { get; set; } | |
#endregion | |
public GetFile() | |
{ | |
//get path and searchterm and lineNumberCount | |
} | |
public GetFile(string path, string searchTerm, string LineNumberCount, SearchResultsbyLine searchresultsbyline) | |
{ | |
//get path and searchterm and lineNumberCount | |
} | |
public void DoWork() | |
{ | |
// Queue a task. | |
System.Threading.ThreadPool.QueueUserWorkItem( | |
new System.Threading.WaitCallback(SomeLongTask)); | |
// Queue another task. | |
System.Threading.ThreadPool.QueueUserWorkItem( | |
new System.Threading.WaitCallback(AnotherLongTask)); | |
} | |
private void SomeLongTask(Object state) | |
{ | |
// Insert code to perform a long task. | |
} | |
private void AnotherLongTask(Object state) | |
{ | |
// Insert code to perform a long task. | |
} | |
#region ReplaceFileFunctions | |
public void makeReplacementFile(List<SearchResultsString> replaceContent, string path)//, string savepath | |
{ | |
var getFileLines = readFileLinesArray(path); | |
foreach (var result in replaceContent) | |
{ | |
getFileLines[result.lineNumber - 1] = result.returnString; | |
} | |
using (StreamWriter newTask = new StreamWriter(path, false)) | |
{ | |
foreach (var line in getFileLines) | |
{ | |
newTask.WriteLine(line.ToString()); | |
} | |
} | |
} | |
public List<string> getReplacementFile(List<SearchResultsString> replaceContent, string path) | |
{ | |
var getFileLines = readFileLinesArray(path); | |
foreach (var result in replaceContent) | |
{ | |
getFileLines[result.lineNumber - 1] = result.returnString; | |
} | |
return getFileLines; | |
} | |
public List<SearchResultsString> getReplaceString(string replaceTerm, string searchTerm, string filePath) | |
{ | |
List<SearchResultsString> resultContent = new List<SearchResultsString>(); | |
var fileContent = readFileLinesArray(filePath); | |
int index = 1; | |
foreach (var line in fileContent) | |
{ | |
if (line.Contains(searchTerm)) | |
{ | |
SearchResultsString searchStr = new SearchResultsString(); | |
searchStr.lineNumber = index; | |
searchStr.returnLineString = line; | |
searchStr.returnString = line.Replace(searchTerm, replaceTerm); | |
resultContent.Add(searchStr); | |
} | |
index++; | |
} | |
return resultContent; | |
} | |
public List<SearchResultsbyLine> getSearchTermResultLines(string searchTerm, string filePath) | |
{ | |
List<SearchResultsbyLine> resultContent = new List<SearchResultsbyLine>(); | |
SearchResults searchresults = new SearchResults(); | |
List<string> fileContent = readFileLinesArray(filePath); | |
int index = 1; | |
foreach (var line in fileContent) | |
{ | |
if (line.Contains(searchTerm)) | |
{ | |
SearchResultsbyLine searchLines = new SearchResultsbyLine(); | |
searchLines.LineString = line.ToString(); | |
searchLines.lineNumber = index; | |
resultContent.Add(searchLines); | |
} | |
index++; | |
} | |
return resultContent; | |
} | |
public List<string> readFileLinesArray(string filePath) | |
{ | |
List<string> returnStringLines = new List<string>(); | |
string text = File.ReadAllText(filePath); | |
int lineCount = 1; | |
string[] lines = File.ReadAllLines(filePath); | |
foreach (string line in lines) | |
{ | |
lineCount++; | |
returnStringLines.Add(line); | |
} | |
lineNumberCount = lineCount; | |
return returnStringLines; | |
} | |
#endregion |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment