//Button Open Preview private void Button_OpenPreview(object sender, RoutedEventArgs e) { string FilePath = null; string Source = null; double PercResults = 0; Encoding encoding = Encoding.Default; //Return IDText Parent string MyIDTextParent = DesignUtils.ReturnCurrentFileIDText(); //Get Encoding encoding = DesignUtils.GetEncodingIDText(MyIDTextParent); //Get the Current File FilePath = Directory.GetCurrentDirectory() + "/StorageTextToolbox/CurrentFile.txt"; Source = System.IO.File.ReadAllText(FilePath); string inputText = System.IO.File.ReadAllText(Source, encoding); //Get File Path FilePath = Directory.GetCurrentDirectory() + "/StorageTextToolbox/Infos/" + MyIDText + ".txt"; Source = System.IO.File.ReadAllText(FilePath, encoding); //Check if all Parameters are in the File string[] searchWords = { "Search Words" + Utils.DefaultSeparator() }; PercResults = Utils.FindWordsInString(Source, searchWords, false); //Case it is found if (PercResults == 1) { //Split the Line string[] MyArray = Strings.Split(Source, Utils.DefaultSeparator()); //Fill in the Variables string MyArgument = MyArray[0]; string MyValue = MyArray[1]; //'Convert' Array to String string[] SearchWords = DesignUtils.ConvertStringToArray(MyValue, false); //Find Words in String PercResults = Utils.FindWordsInString(inputText, SearchWords, false); //Display Result MessageBox.Show($"Percentage: {PercResults.ToString("P", CultureInfo.InvariantCulture)}", "Count Words in String"); } else { //Delete Argument in case it is null MyArgument = "Search Words"; DesignUtils.DeleteTextFileRowArgument(FilePath, MyArgument, encoding); //Error Message MessageBox.Show("Please fill in all arguments", "Validation Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
//Run Extraction private void RunExtraction(string Label) { string Source = null; string inputText = null; //Read Data from IDTextFile //string FilePath = Directory.GetCurrentDirectory() + "/StorageTextToolbox/CurrentFile.txt"; string FilePath = DicArgumentsParent["FileName"]; if (File.Exists(FilePath) == true) { //Source = System.IO.File.ReadAllText(FilePath); //Get Data from the Text File inputText = System.IO.File.ReadAllText(FilePath, encoding); //Display Result this.DisplaySource.Text = inputText; //Add Dummy last line to InputText inputText += Environment.NewLine; } #region Variable Declarations string[] begWords = null; string[] endWords = null; string regexParameterText = null; string ArrayText = null; string[] anchorText = null; string[] anchorWords = null; string anchorTextParamText = null; string[] OutputResults = null; int LinesAbove = 0; int LinesBelow = 0; int NumLines = 0; string MyOccurenceParameter = null; int MyOccurencePosition = 0; string FilePathforPreview = null; string TextResult = null; string[] inputArray = null; #endregion #region Run Extraction switch (Label) { #region Extract Text Between Two Anchor Words case "Extract Text Between Two Anchor Words": //Load Arguments from Dictionary //Beg Words ArrayText = DicArguments["Beg Words"]; begWords = DesignUtils.ConvertStringToArray(ArrayText, false); //End Words if (DicArguments.ContainsKey("End Words") == true) { ArrayText = DicArguments["End Words"]; //DicArguments.TryGetValue("End Words", out ArrayText); endWords = DesignUtils.ConvertStringToArray(ArrayText, false); } else { //Null Array endWords = null; } //Regex Parameter regexParameterText = DicArguments["Regex Parameter"]; //Run Extraction OutputResults = CallExtractions.CallExtractTextBetweenTwoAnchorWords(inputText, begWords, endWords, regexParameterText, false, false); break; #endregion #region Extract All Lines Below Anchor Words case "Extract All Lines Below Anchor Words": //Load Arguments from Dictionary anchorTextParamText = DicArguments["Anchor Words Parameter"]; ArrayText = DicArguments["Anchor Words"]; //Split the Items anchorText = DesignUtils.ConvertStringToArray(ArrayText, false); //Run Extraction OutputResults = CallExtractions.CallExtractAllLinesBelowAnchorText(inputText, anchorText, anchorTextParamText, false, false); break; #endregion #region Extract Text Above Anchor Words case "Extract Text Above Anchor Words": //Load Arguments from Dictionary anchorTextParamText = DicArguments["Anchor Words Parameter"]; ArrayText = DicArguments["Anchor Words"]; //Split the Items anchorWords = DesignUtils.ConvertStringToArray(ArrayText, false); LinesAbove = Convert.ToInt32(DicArguments["Lines Above"]); NumLines = Convert.ToInt32(DicArguments["Number of Lines"]); //Run Extraction OutputResults = CallExtractions.CallExtractTextAboveAnchorWords(inputText, anchorWords, anchorTextParamText, LinesAbove, NumLines, false, false); break; #endregion #region Extract Text Below Anchor Words case "Extract Text Below Anchor Words": //Load Arguments from Dictionary anchorTextParamText = DicArguments["Anchor Words Parameter"]; ArrayText = DicArguments["Anchor Words"]; //Split the Items anchorWords = DesignUtils.ConvertStringToArray(ArrayText, false); LinesBelow = Convert.ToInt32(DicArguments["Lines Below"]); NumLines = Convert.ToInt32(DicArguments["Number of Lines"]); //Run Extraction OutputResults = CallExtractions.CallExtractTextBelowAnchorWords(inputText, anchorWords, anchorTextParamText, LinesBelow, NumLines, true, true); break; #endregion #region Extract Text Until White Space case "Extract Text Until White Space": //Load Arguments from Dictionary ArrayText = DicArguments["Anchor Words"]; //Split the Items anchorWords = DesignUtils.ConvertStringToArray(ArrayText, false); //Run Extraction OutputResults = CallExtractions.CallExtractAllCharactersUntilWhiteSpace(inputText, anchorWords, false, false); break; #endregion #region Extract Text Until Next Letter case "Extract Text Until Next Letter": //Load Arguments from Dictionary ArrayText = DicArguments["Anchor Words"]; //Split the Items anchorWords = DesignUtils.ConvertStringToArray(ArrayText, false); //Run Extraction OutputResults = CallExtractions.CallExtractAllCharactersUntilLetterCharacter(inputText, anchorWords, false); break; #endregion #region Remove Words case "Remove Words": //Load Arguments from Dictionary ArrayText = DicArguments["Words"]; //Split the Items anchorWords = DesignUtils.ConvertStringToArray(ArrayText, false); //Occurence Parameter MyOccurenceParameter = DicArguments["Occurence Parameter"]; //Occurence Position if (DicArguments.ContainsKey("Occurence Position") == true) { MyOccurencePosition = Convert.ToInt32(DicArguments["Occurence Position"]); } //Run Extraction TextResult = Utils.RemoveWordsFromText(inputText, anchorWords, MyOccurenceParameter, MyOccurencePosition, false); //Display Result this.DisplayResult.Text = TextResult; //Hide Controls ResultsMatches_Label.Visible = false; ResultsMatches.Visible = false; SelectResult_Label.Visible = false; SelectResult.Visible = false; break; #endregion #region Replace Words case "Replace Words": //Load Arguments from Dictionary ArrayText = DicArguments["Search Words"]; //Split the Items anchorWords = DesignUtils.ConvertStringToArray(ArrayText, false); string ReplacedWords = DicArguments["Replaced Word"]; //Occurence Parameter MyOccurenceParameter = DicArguments["Occurence Parameter"]; //Occurence Position if (DicArguments.ContainsKey("Occurence Position") == true) { MyOccurencePosition = Convert.ToInt32(DicArguments["Occurence Position"]); } //Run Extraction TextResult = Utils.ReplaceWordsFromText(inputText, anchorWords, ReplacedWords, MyOccurenceParameter, MyOccurencePosition, false); //Display Result this.DisplayResult.Text = TextResult; //Hide Controls ResultsMatches_Label.Visible = false; ResultsMatches.Visible = false; SelectResult_Label.Visible = false; SelectResult.Visible = false; break; #endregion #region Split Text Uneven Blank Spaces case "Split text Uneven Blank Spaces": //Load Arguments from Dictionary FilePathforPreview = DicArguments["FileName"]; inputText = System.IO.File.ReadAllText(FilePathforPreview, encoding); //Null Limit int nullLimit = Convert.ToInt32(DicArguments["Null Limit"]); //Suppress Null Values string SuppressNullValues = DicArguments["Suppress Null Values"]; bool bSuppressNullValues = false; if (SuppressNullValues == "True") { bSuppressNullValues = true; } else if (SuppressNullValues == "False") { bSuppressNullValues = false; } //Run Extraction OutputResults = Utils.SplitTextBigSpaces(inputText, nullLimit, bSuppressNullValues, false); break; #endregion #region Remove Empty Rows case "Remove Empty Rows": FilePathforPreview = DicArguments["FileName"]; inputText = System.IO.File.ReadAllText(FilePathforPreview, encoding); //Run Extraction TextResult = Utils.TextRemoveEmptyRows(inputText); //Display Result this.DisplayResult.Text = TextResult; //Hide Controls ResultsMatches_Label.Visible = false; ResultsMatches.Visible = false; SelectResult_Label.Visible = false; SelectResult.Visible = false; break; #endregion #region Read Text File Encoding case "Read Text File Encoding": case "Text Application Scope": ////File Name //FilePath = DicArguments["FileName"]; ////Encoding //string strEncoding = DicArguments["Encoding"]; ////Run Extraction //TextResult = Utils.ReadTextFileEncoding(FilePath, strEncoding,false); ////Display Result //this.DisplayResult.Text = TextResult; //Remove TAG Source this.tabText.TabPages.Remove(tabResults); //Hide Controls ResultsMatches_Label.Visible = false; ResultsMatches.Visible = false; SelectResult_Label.Visible = false; SelectResult.Visible = false; break; #endregion #region Extract Text until Blank Line case "Extract Text until Blank Line": //Anchor Words ArrayText = DicArguments["Anchor Words"]; anchorWords = DesignUtils.ConvertStringToArray(ArrayText, false); //Anchor Words Parameter anchorTextParamText = DicArguments["Anchor Words Parameter"]; //Direction string Direction = DicArguments["Direction"]; string IncludeAnchorWordsParameter = DicArguments["Include Anchor Words Parameter"]; bool bIncludeAnchorWordsParameter = false; if (IncludeAnchorWordsParameter == "True") { bIncludeAnchorWordsParameter = true; } else if (IncludeAnchorWordsParameter == "False") { bIncludeAnchorWordsParameter = false; } //Run Extraction OutputResults = CallExtractions.CallExtractTextUntilBlankLine(inputText, anchorWords, anchorTextParamText, Direction, bIncludeAnchorWordsParameter, false, false); break; #endregion #region Split Text New Lines case "Split Text New Lines": //Run Extraction OutputResults = Utils.SplitTextNewLine(inputText); break; #endregion #region Split Text By Blank Lines case "Split Text By Blank Lines": //Run Extraction OutputResults = Utils.SplitTextByBlankLines(inputText); break; #endregion #region Find Array Items case "Find Array Items": //File Path for Preview FilePath = DicArguments["FileName"]; inputText = System.IO.File.ReadAllText(FilePath, encoding); //Input Array inputArray = Utils.SplitTextByBlankLines(inputText); //Anchor Words ArrayText = DicArguments["Filter Words"]; string [] filterWords = DesignUtils.ConvertStringToArray(ArrayText, false); //Anchor Words Parameter anchorTextParamText = DicArguments["Anchor Words Parameter"]; //Run Extraction OutputResults = CallExtractions.CallFindArrayItems(inputArray, filterWords, anchorTextParamText, false); break; #endregion #region Match Item in Array case "Match Item in Array": //File Path for Preview FilePath = DicArguments["FileName"]; inputText = System.IO.File.ReadAllText(FilePath, encoding); //Input Array inputArray = Utils.SplitTextNewLine(inputText); ArrayText = DicArguments["SearchWord"]; string[] searchWords = DesignUtils.ConvertStringToArray(ArrayText, false); bool isFound = Utils.MatchItemInArrayOfStrings(inputArray, searchWords, false); //Display Result this.DisplayResult.Text = isFound.ToString(); //Hide Controls ResultsMatches_Label.Visible = false; ResultsMatches.Visible = false; SelectResult_Label.Visible = false; SelectResult.Visible = false; break; #endregion } #endregion #region Display Results if (OutputResults != null) { //Get Results Counter int ResultsCounter = OutputResults.Length; //Case Items are found if (ResultsCounter > 0) { //Results Counter this.ResultsMatches.Text = ResultsCounter.ToString(); //Load the ComboBox for (int i = 0; i < ResultsCounter; i++) { //Add to the ComboBox SelectResult.Items.Add(i + 1); //Add to the Dic Results DicResults.Add((i + 1), OutputResults[i]); } //Set Default value case item is found this.SelectResult.SelectedItem = 1; } //Case items are not found else { //Matches this.ResultsMatches.Text = "0"; //Hide Select Result SelectResult_Label.Visible = false; SelectResult.Visible = false; } } #endregion }