public void funcUpdateCombobox1(string strNewHostName, object sender) { List <ComboBoxPair> alHosts = ((ComboBox)sender).ItemsSource.Cast <ComboBoxPair>().ToList(); List <ComboBoxPair> alHostsNew = new List <ComboBoxPair>(); ComboBoxPair myCbp = new ComboBoxPair(strNewHostName, strNewHostName); bool boolNewItem = false; alHostsNew.Add(myCbp); foreach (ComboBoxPair item in alHosts) { if (strNewHostName != item._Key) { boolNewItem = true; alHostsNew.Add(item); } } if (alHostsNew.Count > 14) { for (int i = alHostsNew.Count - 1; i > 0; i--) { if (alHostsNew[i]._Key.Trim() != "--Select Item ---") { alHostsNew.RemoveAt(i); break; } } } string fileName = ((ComboBox)sender).Name + ".txt"; Methods myActions = new Methods(); string strScriptName = System.Diagnostics.Process.GetCurrentProcess().ProcessName; string strApplicationBinDebug = System.Windows.Forms.Application.StartupPath; string myNewProjectSourcePath = strApplicationBinDebug.Replace("\\bin\\Debug", ""); string settingsDirectory = GetAppDirectoryForScript(myActions.ConvertFullFileNameToScriptPath(myNewProjectSourcePath)); string settingsPath = System.IO.Path.Combine(settingsDirectory, fileName); using (StreamWriter objSWFile = File.CreateText(settingsPath)) { foreach (ComboBoxPair item in alHostsNew) { if (item._Key != "") { objSWFile.WriteLine(item._Key + '^' + item._Value); } } objSWFile.Close(); } // alHosts = alHostsNew; if (boolNewItem) { ((ComboBox)sender).ItemsSource = alHostsNew; } }
private string GetAppDirectoryForScript() { Methods myActions = new Methods(); string directory = AppDomain.CurrentDomain.BaseDirectory; directory = directory.Replace("\\bin\\Debug\\", ""); string settingsDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\IdealAutomate\\" + myActions.ConvertFullFileNameToScriptPath(directory); if (!Directory.Exists(settingsDirectory)) { Directory.CreateDirectory(settingsDirectory); } return(settingsDirectory); }
public WindowMultipleControls(ref List <ControlEntity> myListControlEntity, int intWindowHeight, int intWindowWidth, int intTop, int intLeft, WindowState windowState) { _Top = intTop; _Left = intLeft; this.Top = _Top; this.Left = _Left; if (intTop < 0 || intLeft < 0) { this.WindowStartupLocation = WindowStartupLocation.CenterScreen; } if (windowState == WindowState.Minimized) { this.WindowState = WindowState.Minimized; } InitializeComponent(); if (intWindowHeight > 0) { myWindow.Height = intWindowHeight; MainBorder.Height = intWindowHeight; } else { myWindow.Height = 391; } if (intWindowWidth > 0) { myWindow.Width = intWindowWidth; MainBorder.Width = intWindowWidth; } else { myWindow.Width = 487; } _ListControlEntity = myListControlEntity; //// Create a button. //Button myButton = new Button(); //// Set properties. //myButton.Content = "Click Me!"; //// Add created button to a previously created container. //myStackPanel.Children.Add(myButton); int intMaxRows = 0; int intMaxColumns = 0; foreach (ControlEntity item in myListControlEntity) { if (item.RowNumber > intMaxRows) { intMaxRows = item.RowNumber; } int intNumSpanSum = 0; intNumSpanSum = item.ColumnNumber + item.ColumnSpan; if (item.ColumnSpan > 0) { intNumSpanSum--; } if (intNumSpanSum > intMaxColumns) { intMaxColumns = intNumSpanSum; } } for (int i = 0; i < intMaxRows + 1; i++) { myGrid.RowDefinitions.Add(new RowDefinition()); } for (int i = 0; i < intMaxColumns + 1; i++) { myGrid.ColumnDefinitions.Add(new ColumnDefinition()); } foreach (ControlEntity item in myListControlEntity) { switch (item.ControlType) { case ControlType.Heading: Label1.Text = item.Text; if (item.Width > 0) { Label1.Width = item.Width; } break; case ControlType.Label: Label myLabel = new Label(); if (item.ToolTipx != null && item.ToolTipx.ToString().Trim() != "") { myLabel.ToolTip = item.ToolTipx; } myLabel.FontFamily = item.FontFamilyx; myLabel.FontSize = item.FontSize; myLabel.FontStretch = item.FontStretchx; myLabel.FontStyle = item.FontStyle; myLabel.FontWeight = FontWeights.Normal; myLabel.Margin = new Thickness(1, 1, 1, 1); myLabel.Name = item.ID; myLabel.Content = item.Text; if (item.BackgroundColor != null) { myLabel.Background = new SolidColorBrush(item.BackgroundColor ?? Color.FromRgb(00, 00, 00)); } if (item.ForegroundColor != null) { myLabel.Foreground = new SolidColorBrush(item.ForegroundColor ?? Color.FromRgb(00, 00, 00)); } Grid.SetRow(myLabel, item.RowNumber); Grid.SetColumn(myLabel, item.ColumnNumber); if (item.ColumnSpan < 1) { item.ColumnSpan = 1; } Grid.SetColumnSpan(myLabel, item.ColumnSpan); if (item.Width > 0) { myLabel.Width = item.Width; } myGrid.Children.Add(myLabel); break; case ControlType.Button: Button button = new Button(); if (item.ToolTipx != null && item.ToolTipx.ToString().Trim() != "") { button.ToolTip = item.ToolTipx; } button.Click += new System.Windows.RoutedEventHandler(button_Click); button.Name = item.ID; button.Content = item.Text; if (item.BackgroundColor != null) { button.Background = new SolidColorBrush(item.BackgroundColor ?? Color.FromRgb(00, 00, 00)); } if (item.ForegroundColor != null) { button.Foreground = new SolidColorBrush(item.ForegroundColor ?? Color.FromRgb(00, 00, 00)); } Grid.SetRow(button, item.RowNumber); Grid.SetColumn(button, item.ColumnNumber); if (item.ColumnSpan < 1) { item.ColumnSpan = 1; } Grid.SetColumnSpan(button, item.ColumnSpan); if (item.Width > 0) { button.Width = item.Width; } button.Margin = new Thickness(1, 1, 1, 1); myGrid.Children.Add(button); break; case ControlType.TextBox: TextBox myTextBox = new TextBox(); myTextBox.Text = item.Text; if (item.ToolTipx != null && item.ToolTipx.ToString().Trim() != "") { myTextBox.ToolTip = item.ToolTipx; } myTextBox.Name = item.ID; if (item.Width > 0) { myTextBox.Width = item.Width; } if (item.Multiline == true) { // AcceptsReturn = "True" TextWrapping = "Wrap" VerticalScrollBarVisibility="Auto" myTextBox.AcceptsReturn = true; myTextBox.TextWrapping = System.Windows.TextWrapping.Wrap; myTextBox.VerticalScrollBarVisibility = ScrollBarVisibility.Auto; myTextBox.Height = 50; } if (item.Height > 0) { myTextBox.Height = item.Height; } Grid.SetRow(myTextBox, item.RowNumber); Grid.SetColumn(myTextBox, item.ColumnNumber); if (item.ColumnSpan < 1) { item.ColumnSpan = 1; } Grid.SetColumnSpan(myTextBox, item.ColumnSpan); myGrid.Children.Add(myTextBox); break; case ControlType.PasswordBox: PasswordBox myPasswordBox = new PasswordBox(); myPasswordBox.Password = item.Text; if (item.ToolTipx != null && item.ToolTipx.ToString().Trim() != "") { myPasswordBox.ToolTip = item.ToolTipx; } myPasswordBox.Name = item.ID; if (item.Width > 0) { myPasswordBox.Width = item.Width; } if (item.Height > 0) { myPasswordBox.Height = item.Height; } Grid.SetRow(myPasswordBox, item.RowNumber); Grid.SetColumn(myPasswordBox, item.ColumnNumber); if (item.ColumnSpan < 1) { item.ColumnSpan = 1; } Grid.SetColumnSpan(myPasswordBox, item.ColumnSpan); myGrid.Children.Add(myPasswordBox); break; case ControlType.ComboBox: Methods myActions = new Methods(); string strScriptName = System.Diagnostics.Process.GetCurrentProcess().ProcessName; string strApplicationBinDebug = System.Windows.Forms.Application.StartupPath; string myNewProjectSourcePath = strApplicationBinDebug.Replace("\\bin\\Debug", ""); string settingsDirectory = GetAppDirectoryForScript(myActions.ConvertFullFileNameToScriptPath(myNewProjectSourcePath)); string fileName = item.ID + ".txt"; string settingsPath = System.IO.Path.Combine(settingsDirectory, fileName); ArrayList alHosts = new ArrayList(); List <ComboBoxPair> cbp = new List <ComboBoxPair>(); cbp.Clear(); cbp.Add(new ComboBoxPair("--Select Item ---", "--Select Item ---")); ComboBox myComboBox = new ComboBox(); if (item.ComboBoxIsEditable) { myComboBox.IsEditable = true; myComboBox.DropDownOpened += comboBoxDropDownOpened; myComboBox.LostFocus += comboBoxLostFocus; myComboBox.SelectionChanged += comboBoxSelectionChanged; if (!File.Exists(settingsPath)) { using (StreamWriter objSWFile = File.CreateText(settingsPath)) { objSWFile.Close(); } } using (StreamReader objSRFile = File.OpenText(settingsPath)) { string strReadLine = ""; while ((strReadLine = objSRFile.ReadLine()) != null) { string[] keyvalue = strReadLine.Split('^'); if (keyvalue[0] != "--Select Item ---") { cbp.Add(new ComboBoxPair(keyvalue[0], keyvalue[1])); } } objSRFile.Close(); } item.ListOfKeyValuePairs = cbp; } if (item.ToolTipx != null && item.ToolTipx.ToString().Trim() != "") { myComboBox.ToolTip = item.ToolTipx; } myComboBox.Name = item.ID; if (item.ListOfKeyValuePairs.Count == 0) { cbp = new List <ComboBoxPair>(); cbp.Clear(); cbp.Add(new ComboBoxPair("--Select Item ---", "--Select Item ---")); SqlConnection con = new SqlConnection("Server=(local)\\SQLEXPRESS;Initial Catalog=IdealAutomateDB;Integrated Security=SSPI"); SqlCommand cmd = new SqlCommand(); cmd.CommandText = "SELECT lk.inc, i.listItemKey, i.ListItemValue FROM LkDDLNamesItems lk " + "join DDLNames n on n.inc = lk.DDLNamesInc " + "join DDLItems i on i.inc = lk.ddlItemsInc " + "where n.ID = @ID "; if (item.ParentLkDDLNamesItemsInc > -1) { cmd.CommandText += " and lk.ParentLkDDLNamesItemsInc = @ParentLkDDLNamesItemsInc"; cmd.Parameters.Add("@ParentLkDDLNamesItemsInc", SqlDbType.VarChar, -1); cmd.Parameters["@ParentLkDDLNamesItemsInc"].Value = item.ParentLkDDLNamesItemsInc; } cmd.Parameters.Add("@ID", SqlDbType.VarChar, -1); cmd.Parameters["@ID"].Value = item.ID; if (item.DDLName != null && item.DDLName != "") { cmd.Parameters["@ID"].Value = item.DDLName; } cmd.Connection = con; try { con.Open(); SqlDataReader reader = cmd.ExecuteReader(); //(CommandBehavior.SingleRow) while (reader.Read()) { int intInc = reader.GetInt32(0); string strIDx = reader.GetString(1); cbp.Add(new ComboBoxPair(strIDx, intInc.ToString())); } reader.Close(); item.ListOfKeyValuePairs = cbp; if (item.SelectedValue == "" || item.SelectedValue == null) { cmd.CommandText = "SELECT Top 1 DefaultValue from DDLNames where ID = @ID "; var strDefaultValue = cmd.ExecuteScalar(); if (strDefaultValue == null) { item.SelectedValue = ""; } else { item.SelectedValue = strDefaultValue.ToString(); } } } finally { con.Close(); } } myComboBox.ItemsSource = item.ListOfKeyValuePairs; Grid.SetRow(myComboBox, item.RowNumber); Grid.SetColumn(myComboBox, item.ColumnNumber); if (item.ColumnSpan < 1) { item.ColumnSpan = 1; } Grid.SetColumnSpan(myComboBox, item.ColumnSpan); myComboBox.SelectedValue = item.SelectedValue; myComboBox.DisplayMemberPath = "_Key"; myComboBox.SelectedValuePath = "_Value"; if (item.Width > 0) { myComboBox.Width = item.Width; } myGrid.Children.Add(myComboBox); break; case ControlType.CheckBox: CheckBox myCheckBox = new CheckBox(); if (item.ToolTipx != null && item.ToolTipx.ToString().Trim() != "") { myCheckBox.ToolTip = item.ToolTipx; } myCheckBox.Name = item.ID; myCheckBox.Content = item.Text; myCheckBox.IsChecked = item.Checked; Grid.SetRow(myCheckBox, item.RowNumber); Grid.SetColumn(myCheckBox, item.ColumnNumber); if (item.ColumnSpan < 1) { item.ColumnSpan = 1; } Grid.SetColumnSpan(myCheckBox, item.ColumnSpan); if (item.Width > 0) { myCheckBox.Width = item.Width; } myGrid.Children.Add(myCheckBox); break; case ControlType.Image: Image myImage = new Image(); if (item.ToolTipx != null && item.ToolTipx.ToString().Trim() != "") { myImage.ToolTip = item.ToolTipx; } myImage.Name = item.ID; Grid.SetRow(myImage, item.RowNumber); Grid.SetColumn(myImage, item.ColumnNumber); if (item.ColumnSpan < 1) { item.ColumnSpan = 1; } Grid.SetColumnSpan(myImage, item.ColumnSpan); if (item.Width > 0) { myImage.Width = item.Width; } if (item.Height > 0) { myImage.Height = item.Height; } myImage.Source = item.Source; myGrid.Children.Add(myImage); break; default: break; } } }
public MainWindow() { bool boolRunningFromHome = false; var window = new Window() //make sure the window is invisible { Width = 0, Height = 0, Left = -2000, WindowStyle = WindowStyle.None, ShowInTaskbar = false, ShowActivated = false, }; window.Show(); myActions = new Methods(); myActions.ScriptStartedUpdateStats(); string strSavedDomainName = myActions.GetValueByKey("DomainName"); if (strSavedDomainName == "") { strSavedDomainName = System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties().DomainName; } InitializeComponent(); this.Hide(); listHotKeyRecords = new List <HotKeyRecord>(); HotKeyRecord myHotKeyRecord = new HotKeyRecord(); string strHotKey = "Ctrl+Alt+N"; myHotKeyRecord.HotKeys = strHotKey.Split('+'); myHotKeyRecord.Executable = @"OpenLineInNotepad"; myHotKeyRecord.ExecuteContent = null; myHotKeyRecord.ScriptID = 0; bool boolHotKeysGood = true; foreach (string myHotKey in myHotKeyRecord.HotKeys) { if (dictVirtualKeyCodes.ContainsKey(myHotKey)) { MessageBox.Show("Invalid hotkey: " + myHotKey); boolHotKeysGood = false; } } if (boolHotKeysGood) { listHotKeyRecords.Add(myHotKeyRecord); } dictVirtualKeyCodes.Add("Ctrl", VirtualKeyCode.CONTROL); dictVirtualKeyCodes.Add("Alt", VirtualKeyCode.MENU); dictVirtualKeyCodes.Add("Shift", VirtualKeyCode.SHIFT); dictVirtualKeyCodes.Add("Space", VirtualKeyCode.SPACE); dictVirtualKeyCodes.Add("Up", VirtualKeyCode.UP); dictVirtualKeyCodes.Add("Down", VirtualKeyCode.DOWN); dictVirtualKeyCodes.Add("Left", VirtualKeyCode.LEFT); dictVirtualKeyCodes.Add("Right", VirtualKeyCode.RIGHT); dictVirtualKeyCodes.Add("A", VirtualKeyCode.VK_A); dictVirtualKeyCodes.Add("B", VirtualKeyCode.VK_B); dictVirtualKeyCodes.Add("C", VirtualKeyCode.VK_C); dictVirtualKeyCodes.Add("D", VirtualKeyCode.VK_D); dictVirtualKeyCodes.Add("E", VirtualKeyCode.VK_E); dictVirtualKeyCodes.Add("F", VirtualKeyCode.VK_F); dictVirtualKeyCodes.Add("G", VirtualKeyCode.VK_G); dictVirtualKeyCodes.Add("H", VirtualKeyCode.VK_H); dictVirtualKeyCodes.Add("I", VirtualKeyCode.VK_I); dictVirtualKeyCodes.Add("J", VirtualKeyCode.VK_J); dictVirtualKeyCodes.Add("K", VirtualKeyCode.VK_K); dictVirtualKeyCodes.Add("L", VirtualKeyCode.VK_L); dictVirtualKeyCodes.Add("M", VirtualKeyCode.VK_M); dictVirtualKeyCodes.Add("N", VirtualKeyCode.VK_N); dictVirtualKeyCodes.Add("O", VirtualKeyCode.VK_O); dictVirtualKeyCodes.Add("P", VirtualKeyCode.VK_P); dictVirtualKeyCodes.Add("Q", VirtualKeyCode.VK_Q); dictVirtualKeyCodes.Add("R", VirtualKeyCode.VK_R); dictVirtualKeyCodes.Add("S", VirtualKeyCode.VK_S); dictVirtualKeyCodes.Add("T", VirtualKeyCode.VK_T); dictVirtualKeyCodes.Add("U", VirtualKeyCode.VK_U); dictVirtualKeyCodes.Add("V", VirtualKeyCode.VK_V); dictVirtualKeyCodes.Add("W", VirtualKeyCode.VK_W); dictVirtualKeyCodes.Add("X", VirtualKeyCode.VK_X); dictVirtualKeyCodes.Add("Y", VirtualKeyCode.VK_Y); dictVirtualKeyCodes.Add("Z", VirtualKeyCode.VK_Z); // Create a timer and set a two millisecond interval. System.Timers.Timer aTimer = new System.Timers.Timer(); aTimer.Interval = 2; // Alternate method: create a Timer with an interval argument to the constructor. //aTimer = new System.Timers.Timer(2000); // Create a timer with a two millisecond interval. aTimer = new System.Timers.Timer(2); // Hook up the Elapsed event for the timer. aTimer.Elapsed += OnTimedEvent; // Have the timer fire repeated events (true is the default) aTimer.AutoReset = true; // Start the timer aTimer.Enabled = true; DisplayFindTextInFilesWindow: int intRowCtr = 0; ControlEntity myControlEntity = new ControlEntity(); List <ControlEntity> myListControlEntity = new List <ControlEntity>(); List <ComboBoxPair> cbp = new List <ComboBoxPair>(); List <ComboBoxPair> cbp1 = new List <ComboBoxPair>(); List <ComboBoxPair> cbp2 = new List <ComboBoxPair>(); List <ComboBoxPair> cbp3 = new List <ComboBoxPair>(); myControlEntity.ControlEntitySetDefaults(); myControlEntity.ControlType = ControlType.Heading; myControlEntity.ID = "lbl"; myControlEntity.Text = "Find Text In Files"; myControlEntity.RowNumber = intRowCtr; myControlEntity.ColumnNumber = 0; myListControlEntity.Add(myControlEntity.CreateControlEntity()); intRowCtr++; myControlEntity.ControlEntitySetDefaults(); myControlEntity.ControlType = ControlType.Label; myControlEntity.ID = "lblFindWhat"; myControlEntity.Text = "FindWhat"; myControlEntity.RowNumber = intRowCtr; myControlEntity.Width = 150; myControlEntity.ColumnNumber = 0; myControlEntity.ColumnSpan = 1; myListControlEntity.Add(myControlEntity.CreateControlEntity()); myControlEntity.ControlEntitySetDefaults(); myControlEntity.ControlType = ControlType.ComboBox; myControlEntity.SelectedValue = myActions.GetValueByKey("cbxFindWhatSelectedValue"); myControlEntity.ID = "cbxFindWhat"; myControlEntity.RowNumber = intRowCtr; myControlEntity.ToolTipx = ""; //foreach (var item in alcbxFindWhat) { // cbp.Add(new ComboBoxPair(item.ToString(), item.ToString())); //} //myControlEntity.ListOfKeyValuePairs = cbp; myControlEntity.ComboBoxIsEditable = true; myControlEntity.ColumnNumber = 1; myControlEntity.ColumnSpan = 2; myListControlEntity.Add(myControlEntity.CreateControlEntity()); intRowCtr++; myControlEntity.ControlEntitySetDefaults(); myControlEntity.ControlType = ControlType.Label; myControlEntity.ID = "lblFileType"; myControlEntity.Text = "FileType"; myControlEntity.RowNumber = intRowCtr; myControlEntity.Width = 150; myControlEntity.ColumnNumber = 0; myControlEntity.ColumnSpan = 1; myListControlEntity.Add(myControlEntity.CreateControlEntity()); myControlEntity.ControlEntitySetDefaults(); myControlEntity.ControlType = ControlType.ComboBox; myControlEntity.SelectedValue = myActions.GetValueByKey("cbxFileTypeSelectedValue"); myControlEntity.ID = "cbxFileType"; myControlEntity.RowNumber = intRowCtr; myControlEntity.ToolTipx = "Here is an example: *.*"; //foreach (var item in alcbxFileType) { // cbp1.Add(new ComboBoxPair(item.ToString(), item.ToString())); //} //myControlEntity.ListOfKeyValuePairs = cbp1; myControlEntity.ComboBoxIsEditable = true; myControlEntity.ColumnNumber = 1; myControlEntity.ColumnSpan = 2; myListControlEntity.Add(myControlEntity.CreateControlEntity()); intRowCtr++; myControlEntity.ControlEntitySetDefaults(); myControlEntity.ControlType = ControlType.Label; myControlEntity.ID = "lblExclude"; myControlEntity.Text = "Exclude"; myControlEntity.Width = 150; myControlEntity.RowNumber = intRowCtr; myControlEntity.ColumnNumber = 0; myControlEntity.ColumnSpan = 1; myListControlEntity.Add(myControlEntity.CreateControlEntity()); myControlEntity.ControlEntitySetDefaults(); myControlEntity.ControlType = ControlType.ComboBox; myControlEntity.SelectedValue = myActions.GetValueByKey("cbxExcludeSelectedValue"); myControlEntity.ID = "cbxExclude"; myControlEntity.RowNumber = intRowCtr; myControlEntity.ToolTipx = "Here is an example: *.dll;*.exe;*.png;*.xml;*.cache;*.sln;*.suo;*.pdb;*.csproj;*.deploy"; myControlEntity.ComboBoxIsEditable = true; myControlEntity.ColumnNumber = 1; myControlEntity.ColumnSpan = 2; myListControlEntity.Add(myControlEntity.CreateControlEntity()); intRowCtr++; myControlEntity.ControlEntitySetDefaults(); myControlEntity.ControlType = ControlType.Label; myControlEntity.ID = "lblFolder"; myControlEntity.Text = "Folder"; myControlEntity.Width = 150; myControlEntity.RowNumber = intRowCtr; myControlEntity.ColumnNumber = 0; myControlEntity.ColumnSpan = 1; myListControlEntity.Add(myControlEntity.CreateControlEntity()); myControlEntity.ControlEntitySetDefaults(); myControlEntity.ControlType = ControlType.ComboBox; myControlEntity.SelectedValue = myActions.GetValueByKey("cbxFolderSelectedValue"); myControlEntity.ID = "cbxFolder"; myControlEntity.RowNumber = intRowCtr; myControlEntity.ToolTipx = @"Here is an example: C:\Users\harve\Documents\GitHub"; myControlEntity.ComboBoxIsEditable = true; myControlEntity.ColumnNumber = 1; myControlEntity.ColumnSpan = 2; myListControlEntity.Add(myControlEntity.CreateControlEntity()); myControlEntity.ControlEntitySetDefaults(); myControlEntity.ControlType = ControlType.Button; myControlEntity.ID = "btnSelectFolder"; myControlEntity.Text = "Select Folder..."; myControlEntity.RowNumber = intRowCtr; myControlEntity.ColumnNumber = 3; myListControlEntity.Add(myControlEntity.CreateControlEntity()); intRowCtr++; myControlEntity.ControlEntitySetDefaults(); myControlEntity.ControlType = ControlType.CheckBox; myControlEntity.ID = "chkMatchCase"; myControlEntity.Text = "Match Case"; myControlEntity.Width = 150; myControlEntity.RowNumber = intRowCtr; myControlEntity.ColumnNumber = 0; myControlEntity.ColumnSpan = 1; string strMatchCase = myActions.GetValueByKey("chkMatchCase"); if (strMatchCase.ToLower() == "true") { myControlEntity.Checked = true; } else { myControlEntity.Checked = false; } myListControlEntity.Add(myControlEntity.CreateControlEntity()); intRowCtr++; myControlEntity.ControlEntitySetDefaults(); myControlEntity.ControlType = ControlType.CheckBox; myControlEntity.ID = "chkUseRegularExpression"; myControlEntity.Text = "UseRegularExpression"; myControlEntity.Width = 150; myControlEntity.RowNumber = intRowCtr; myControlEntity.ColumnNumber = 0; myControlEntity.ColumnSpan = 1; string strUseRegularExpression = myActions.GetValueByKey("chkUseRegularExpression"); if (strUseRegularExpression.ToLower() == "true") { myControlEntity.Checked = true; } else { myControlEntity.Checked = false; } myListControlEntity.Add(myControlEntity.CreateControlEntity()); DisplayWindowAgain: string strButtonPressed = myActions.WindowMultipleControls(ref myListControlEntity, 300, 1200, 100, 100); LineAfterDisplayWindow: if (strButtonPressed == "btnCancel") { myActions.MessageBoxShow("Okay button not pressed - Script Cancelled"); goto myExit; } boolMatchCase = myListControlEntity.Find(x => x.ID == "chkMatchCase").Checked; boolUseRegularExpression = myListControlEntity.Find(x => x.ID == "chkUseRegularExpression").Checked; strFindWhat = myListControlEntity.Find(x => x.ID == "cbxFindWhat").SelectedValue; // string strFindWhatKey = myListControlEntity.Find(x => x.ID == "cbxFindWhat").SelectedKey; string strFileType = myListControlEntity.Find(x => x.ID == "cbxFileType").SelectedValue; // string strFileTypeKey = myListControlEntity.Find(x => x.ID == "cbxFileType").SelectedKey; string strExclude = myListControlEntity.Find(x => x.ID == "cbxExclude").SelectedValue; // string strExcludeKey = myListControlEntity.Find(x => x.ID == "cbxExclude").SelectedKey; string strFolder = myListControlEntity.Find(x => x.ID == "cbxFolder").SelectedValue; // string strFolderKey = myListControlEntity.Find(x => x.ID == "cbxFolder").SelectedKey; myActions.SetValueByKey("chkMatchCase", boolMatchCase.ToString()); myActions.SetValueByKey("chkUseRegularExpression", boolUseRegularExpression.ToString()); myActions.SetValueByKey("cbxFindWhatSelectedValue", strFindWhat); myActions.SetValueByKey("cbxFileTypeSelectedValue", strFileType); myActions.SetValueByKey("cbxExcludeSelectedValue", strExclude); myActions.SetValueByKey("cbxFolderSelectedValue", strFolder); string settingsDirectory = ""; if (strButtonPressed == "btnSelectFolder") { var dialog = new System.Windows.Forms.FolderBrowserDialog(); dialog.SelectedPath = myActions.GetValueByKey("LastSearchFolder"); string str = "LastSearchFolder"; System.Windows.Forms.DialogResult result = dialog.ShowDialog(); if (result == System.Windows.Forms.DialogResult.OK && Directory.Exists(dialog.SelectedPath)) { myListControlEntity.Find(x => x.ID == "cbxFolder").SelectedValue = dialog.SelectedPath; myListControlEntity.Find(x => x.ID == "cbxFolder").SelectedKey = dialog.SelectedPath; myListControlEntity.Find(x => x.ID == "cbxFolder").Text = dialog.SelectedPath; myActions.SetValueByKey("LastSearchFolder", dialog.SelectedPath); strFolder = dialog.SelectedPath; myActions.SetValueByKey("cbxFolderSelectedValue", strFolder); string strScriptName = System.Diagnostics.Process.GetCurrentProcess().ProcessName; string fileName = "cbxFolder.txt"; string strApplicationBinDebug = System.Windows.Forms.Application.StartupPath; string myNewProjectSourcePath = strApplicationBinDebug.Replace("\\bin\\Debug", ""); settingsDirectory = GetAppDirectoryForScript(myActions.ConvertFullFileNameToScriptPath(myNewProjectSourcePath)); string settingsPath = System.IO.Path.Combine(settingsDirectory, fileName); ArrayList alHosts = new ArrayList(); cbp = new List <ComboBoxPair>(); cbp.Clear(); cbp.Add(new ComboBoxPair("--Select Item ---", "--Select Item ---")); ComboBox myComboBox = new ComboBox(); if (!File.Exists(settingsPath)) { using (StreamWriter objSWFile = File.CreateText(settingsPath)) { objSWFile.Close(); } } using (StreamReader objSRFile = File.OpenText(settingsPath)) { string strReadLine = ""; while ((strReadLine = objSRFile.ReadLine()) != null) { string[] keyvalue = strReadLine.Split('^'); if (keyvalue[0] != "--Select Item ---") { cbp.Add(new ComboBoxPair(keyvalue[0], keyvalue[1])); } } objSRFile.Close(); } string strNewHostName = dialog.SelectedPath; List <ComboBoxPair> alHostx = cbp; List <ComboBoxPair> alHostsNew = new List <ComboBoxPair>(); ComboBoxPair myCbp = new ComboBoxPair(strNewHostName, strNewHostName); bool boolNewItem = false; alHostsNew.Add(myCbp); if (alHostx.Count > 14) { for (int i = alHostx.Count - 1; i > 0; i--) { if (alHostx[i]._Key.Trim() != "--Select Item ---") { alHostx.RemoveAt(i); break; } } } foreach (ComboBoxPair item in alHostx) { if (strNewHostName != item._Key && item._Key != "--Select Item ---") { boolNewItem = true; alHostsNew.Add(item); } } using (StreamWriter objSWFile = File.CreateText(settingsPath)) { foreach (ComboBoxPair item in alHostsNew) { if (item._Key != "") { objSWFile.WriteLine(item._Key + '^' + item._Value); } } objSWFile.Close(); } goto DisplayWindowAgain; } } string strFindWhatToUse = ""; string strFileTypeToUse = ""; string strExcludeToUse = ""; string strFolderToUse = ""; if (strButtonPressed == "btnOkay") { if ((strFindWhat == "--Select Item ---" || strFindWhat == "")) { myActions.MessageBoxShow("Please enter Find What or select Find What from ComboBox; else press Cancel to Exit"); goto DisplayFindTextInFilesWindow; } if ((strFileType == "--Select Item ---" || strFileType == "")) { myActions.MessageBoxShow("Please enter File Type or select File Type from ComboBox; else press Cancel to Exit"); goto DisplayFindTextInFilesWindow; } if ((strExclude == "--Select Item ---" || strExclude == "")) { myActions.MessageBoxShow("Please enter Exclude or select Exclude from ComboBox; else press Cancel to Exit"); goto DisplayFindTextInFilesWindow; } if ((strFolder == "--Select Item ---" || strFolder == "")) { myActions.MessageBoxShow("Please enter Folder or select Folder from ComboBox; else press Cancel to Exit"); goto DisplayFindTextInFilesWindow; } strFindWhatToUse = strFindWhat; if (boolUseRegularExpression) { strFindWhatToUse = strFindWhatToUse.Replace(")", "\\)").Replace("(", "\\("); } strFileTypeToUse = strFileType; strExcludeToUse = strExclude; strFolderToUse = strFolder; } strPathToSearch = strFolderToUse; strSearchPattern = strFileTypeToUse; strSearchExcludePattern = strExcludeToUse; strSearchText = strFindWhatToUse; strLowerCaseSearchText = strFindWhatToUse.ToLower(); myActions.SetValueByKey("FindWhatToUse", strFindWhatToUse); System.Diagnostics.Stopwatch st = new System.Diagnostics.Stopwatch(); st.Start(); intHits = 0; int intLineCtr; List <FileInfo> myFileList = TraverseTree(strSearchPattern, strPathToSearch); int intFiles = 0; matchInfoList = new List <MatchInfo>(); // myFileList = myFileList.OrderBy(fi => fi.FullName).ToList(); Parallel.ForEach(myFileList, myFileInfo => { intLineCtr = 0; boolStringFoundInFile = false; ReadFileToString(myFileInfo.FullName, intLineCtr, matchInfoList); if (boolStringFoundInFile) { intFiles++; } }); matchInfoList = matchInfoList.Where(mi => mi != null).OrderBy(mi => mi.FullName).ThenBy(mi => mi.LineNumber).ToList(); List <string> lines = new List <string>(); foreach (var item in matchInfoList) { lines.Add("\"" + item.FullName + "\"(" + item.LineNumber + "," + item.LinePosition + "): " + item.LineText.Length.ToString() + " " + item.LineText.Substring(0, item.LineText.Length > 5000 ? 5000 : item.LineText.Length)); } string strApplicationBinDebug1 = System.Windows.Forms.Application.StartupPath; string myNewProjectSourcePath1 = strApplicationBinDebug1.Replace("\\bin\\Debug", ""); settingsDirectory = GetAppDirectoryForScript(myActions.ConvertFullFileNameToScriptPath(myNewProjectSourcePath1)); using (FileStream fs = new FileStream(settingsDirectory + @"\MatchInfo.txt", FileMode.Create)) { StreamWriter file = new System.IO.StreamWriter(fs, Encoding.Default); file.WriteLine(@"-- " + strSearchText + " in " + strPathToSearch + " from " + strSearchPattern + " excl " + strSearchExcludePattern + " --"); foreach (var item in matchInfoList) { file.WriteLine("\"" + item.FullName + "\"(" + item.LineNumber + "," + item.LinePosition + "): " + item.LineText.Substring(0, item.LineText.Length > 5000 ? 5000 : item.LineText.Length)); } int intUniqueFiles = matchInfoList.Select(x => x.FullName).Distinct().Count(); st.Stop(); // Get the elapsed time as a TimeSpan value. TimeSpan ts = st.Elapsed; // Format and display the TimeSpan value. string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10); file.WriteLine("RunTime " + elapsedTime); file.WriteLine(intHits.ToString() + " hits"); // file.WriteLine(myFileList.Count().ToString() + " files"); file.WriteLine(intUniqueFiles.ToString() + " files with hits"); file.Close(); // Get the elapsed time as a TimeSpan value. ts = st.Elapsed; // Format and display the TimeSpan value. elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10); Console.WriteLine("RunTime " + elapsedTime); Console.WriteLine(intHits.ToString() + " hits"); // Console.WriteLine(myFileList.Count().ToString() + " files"); Console.WriteLine(intUniqueFiles.ToString() + " files with hits"); Console.ReadLine(); string strExecutable = @"C:\Program Files (x86)\Notepad++\notepad++.exe"; string strContent = settingsDirectory + @"\MatchInfo.txt"; Process.Start(strExecutable, string.Concat("", strContent, "")); myActions.ScriptEndedSuccessfullyUpdateStats(); myActions.MessageBoxShow("RunTime: " + elapsedTime + "\n\r\n\rHits: " + intHits.ToString() + "\n\r\n\rFiles with hits: " + intUniqueFiles.ToString() + "\n\r\n\rPut Cursor on line and\n\r press Ctrl+Alt+N\n\rto view detail page. "); } if (strButtonPressed == "btnOkay") { strButtonPressed = myActions.WindowMultipleControlsMinimized(ref myListControlEntity, 300, 1200, 100, 100); myActions.ScriptStartedUpdateStats(); goto LineAfterDisplayWindow; } myExit: int myExecCount = myActions.GetValueByKeyAsInt("ScriptTotalExecutions"); myExecCount--; myActions.SetValueByKey("ScriptTotalExecutions", myExecCount.ToString()); Application.Current.Shutdown(); }