public bool PrintAllDataFromDB(int _inIISQueue, Dictionary <string, List <string> > _allWebChecked) { bool printAllData = true; foreach (var item in _allWebChecked) { if (item.Value.Count > 0) { printAllData = false; break; } } if (_inIISQueue > 0) { printAllData = false; } if (printAllData) { SQLRequests SQLReq = new SQLRequests(); List <WebPageClass> AllDBData = SQLReq.GetAllDataFromDB(); Console.WriteLine(Environment.NewLine + "DB Contant:" + Environment.NewLine); foreach (WebPageClass item in AllDBData) { Console.WriteLine(item.WebPageName + Environment.NewLine + "Number of links = " + item.AllLinks + " Working links = " + item.WorkinkLinks + " Broken links = " + item.BrokenLinks + " Time out links = " + item.TimeoutLinks + " Total check time = " + ConvertSecondsToMinutes(item.TotalCheckTime) + Environment.NewLine); } } return(printAllData); }
private void InitialDefaultDBTables() { // Display tables initialize DisplayInvestigationTable = new ObservableCollection <InvestigationClass>(); DisplayProductTable = new ObservableCollection <ProductClass>(); SQLRequests SQLReq = new SQLRequests(); DisplayInvestigationTable = SQLReq.GetInvestigations(); DisplayInvestigationTable.Insert(0, new InvestigationClass { ID = 0, Name = "All Products", CreationDate = new DateTime() }); InvestigationChooser.DataSource = DisplayInvestigationTable; InvestigationChooser.DisplayMember = "Name"; InvestigationChooser.ValueMember = "Name"; }
private void InvestigationChooser_SelectedIndexChanged(object sender, EventArgs e) { ComboBox cmb = (ComboBox)sender; InvestigationClass SelectedInvestigation = (InvestigationClass)cmb.SelectedItem; SQLRequests SQLReq = new SQLRequests(); DisplayProductTable.Clear(); DisplayProductTable = SQLReq.GetProducts(SelectedInvestigation.ID); ProductList.DataSource = new BindingSource { DataSource = DisplayProductTable }; ProductList.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells; ProductList.Columns[1].Visible = false; ProductList.Columns[2].HeaderText = "Type"; ProductList.Columns[3].HeaderText = "Creation Date"; ProductList.Columns[6].Visible = false; }
private void DelItemThread(ItemToDelete _itemToDelete, int _itemID, int _productType) { Dictionary <ItemToDelete, string[]> valuesDictionaryByDeleteItemType = new Dictionary <ItemToDelete, string[]>(); valuesDictionaryByDeleteItemType.Add(ItemToDelete.Investigation, new string[2] { "Investigation deleted successfully", "Failed to delete investigation\nor its products" }); valuesDictionaryByDeleteItemType.Add(ItemToDelete.Product, new string[2] { "Product deleted successfully", "Failed to delete product" }); SQLRequests SQLReq = new SQLRequests(); bool isActionFinished = false; switch (_itemToDelete) { case ItemToDelete.Investigation: if (SQLReq.DeleteInvestigation(_itemID)) { isActionFinished = true; } break; case ItemToDelete.Product: if (SQLReq.DeleteProduct(_itemID, _productType)) { isActionFinished = true; } break; } if (isActionFinished) { MessageBox.Show(valuesDictionaryByDeleteItemType[_itemToDelete][0]); BeginInvoke((Action) delegate //Invoke at UI thread { LoadOrRefresh(); }); } else { MessageBox.Show(valuesDictionaryByDeleteItemType[_itemToDelete][1]); } }
private void btnSaveInvestigation_Click(object sender, EventArgs e) { if (tbInestigationToAdd.Text == "") { MessageBox.Show("Investigation name must have a value"); } else if (tbInestigationToAdd.Text == "All Products") { MessageBox.Show("Investigation name is invalid"); } else { SQLRequests SQLReq = new SQLRequests(); Tuple <string, int> msgForAdd = SQLReq.AddInvestigation(tbInestigationToAdd.Text); MessageBox.Show(msgForAdd.Item1); if (msgForAdd.Item2 == 1) { this.Close(); } } }
static void CheckWebPageLinks() { string _currentWebPage = String.Empty; while (true) //Never stop (for virtualizing IIS socket) { GeneralUtils generalUtils = new GeneralUtils(); if (String.IsNullOrEmpty(_currentWebPage)) { lock (_objectLockWebPagesList) { _currentWebPage = WebPagesToCheck.FirstOrDefault(); //Get web page from IIS queue WebPagesToCheck.Remove(_currentWebPage); } } if ((_currentWebPage != null) && (_currentWebPage != "")) { WebPageClass CurrentWebPage = new WebPageClass(_currentWebPage); Settings settingsValues = new Settings(); SQLRequests SQLReq = new SQLRequests(); CurrentWebPage = SQLReq.GetWebPageCheckResults(CurrentWebPage.WebPageName, settingsValues.TimePeriodForValidCheckResultsInMinutes); if (CurrentWebPage.AllLinks > 0) //Results from last x minutes exist in the DB and will return to the request { Console.WriteLine("Results from DB - " + CurrentWebPage.WebPageName + Environment.NewLine + "Number of links = " + CurrentWebPage.AllLinks + " Working links = " + CurrentWebPage.WorkinkLinks + " Broken links = " + CurrentWebPage.BrokenLinks + " Time out links = " + CurrentWebPage.TimeoutLinks + " Total check time = " + generalUtils.ConvertSecondsToMinutes(CurrentWebPage.TotalCheckTime) + Environment.NewLine); _currentWebPage = ""; } else //No results exist in the DB { bool addToCheckWebList = false; lock (_objectLockWebPagesDictionary) { if ((WebPagesLinksToCheck.ContainsKey(CurrentWebPage.WebPageName)) && (WebPagesLinksToCheck[CurrentWebPage.WebPageName].Count > 0)) //Web page links currently being checked { addToCheckWebList = false; Thread.Sleep(60000); //Sleep 1 minutes to wait for the check results } else //Add a check web page to dictionary { addToCheckWebList = true; if (!WebPagesLinksToCheck.ContainsKey(CurrentWebPage.WebPageName)) { WebPagesLinksToCheck.Add(CurrentWebPage.WebPageName, new List <string>()); } } } if (addToCheckWebList) //Check web page links { DateTime StartTime = new DateTime(); DateTime EndTime = new DateTime(); StartTime = DateTime.Now; //Get all links from http WebUtils webUtils = new WebUtils(); List <string> LinksFromWebPage = webUtils.GetAllLinksFromWebPage(CurrentWebPage.WebPageName); lock (_objectLockWebPagesDictionary) { foreach (string item in LinksFromWebPage) { WebPagesLinksToCheck[CurrentWebPage.WebPageName].Add(item); } CurrentWebPage.AllLinks = WebPagesLinksToCheck[CurrentWebPage.WebPageName].Count; } if (CurrentWebPage.AllLinks > 0) //Address is valid and internet connection works { int numberOfLinksCheckTasks = settingsValues.DeterminNumberOfSockets(CurrentWebPage.AllLinks); Task[] AllTasks = new Task[numberOfLinksCheckTasks]; for (int i = 0; i < numberOfLinksCheckTasks; i++) { AllTasks[i] = Task.Factory.StartNew(() => CheckNextLink(CurrentWebPage)); } //All unchecked links after timeout time will considered as timeout links if (!Task.WaitAll(AllTasks, settingsValues.WebPageCheckTimeoutInMilliseconds)) { int allUncheckLinks = CurrentWebPage.AllLinks - CurrentWebPage.WorkinkLinks - CurrentWebPage.BrokenLinks - CurrentWebPage.TimeoutLinks; lock (_objectLockWebPageClass) { CurrentWebPage.TimeoutLinks = CurrentWebPage.TimeoutLinks + allUncheckLinks; } } EndTime = DateTime.Now; TimeSpan ts = EndTime - StartTime; CurrentWebPage.TotalCheckTime = (int)ts.TotalSeconds; //Add result to the DB and print a message if (SQLReq.AddWebCheckResult(CurrentWebPage.WebPageName, CurrentWebPage.AllLinks, CurrentWebPage.WorkinkLinks, CurrentWebPage.BrokenLinks, CurrentWebPage.TimeoutLinks, CurrentWebPage.TotalCheckTime)) { Console.WriteLine("INSERTED - " + CurrentWebPage.WebPageName + Environment.NewLine + "Number of links = " + CurrentWebPage.AllLinks + " Working links = " + CurrentWebPage.WorkinkLinks + " Broken links = " + CurrentWebPage.BrokenLinks + " Time out links = " + CurrentWebPage.TimeoutLinks + " Total check time = " + generalUtils.ConvertSecondsToMinutes(CurrentWebPage.TotalCheckTime) + Environment.NewLine); } else { Console.WriteLine("NOT INSERTED - " + CurrentWebPage.WebPageName + Environment.NewLine); } _currentWebPage = String.Empty; } else //Address is not valid or no internet connection - set web page as timeout page { EndTime = DateTime.Now; TimeSpan ts = EndTime - StartTime; CurrentWebPage.TotalCheckTime = (int)ts.TotalSeconds; //Add result to the DB (name and all counts are 0) and print a message if (SQLReq.AddWebCheckResult(CurrentWebPage.WebPageName, 0, 0, 0, 0, CurrentWebPage.TotalCheckTime)) { Console.WriteLine("ERROR - Error reading web page links " + Environment.NewLine + "INSERTED - " + CurrentWebPage.WebPageName + Environment.NewLine + "Number of links = " + CurrentWebPage.AllLinks + " Working links = " + CurrentWebPage.WorkinkLinks + " Broken links = " + CurrentWebPage.BrokenLinks + " Time out links = " + CurrentWebPage.TimeoutLinks + " Total check time = " + generalUtils.ConvertSecondsToMinutes(CurrentWebPage.TotalCheckTime) + Environment.NewLine); } else { Console.WriteLine("ERROR - Error reading web page links and DB insertion failed " + Environment.NewLine + "NOT INSERTED - " + CurrentWebPage.WebPageName + Environment.NewLine); } _currentWebPage = String.Empty; } } } } Thread.Sleep(3000); //Sleep 3 seconds for reducing actions while queue is empty } }
private void btnSaveProduct_Click(object sender, EventArgs e) { long CallLengthConverter = -1; bool IsAllFieldsHasVal = true; if ((tbSource.Text == "") || (tbDestination.Text == "") || (cbProductType.SelectedItem == null) || (cbProductType.SelectedItem.ToString() == "")) { IsAllFieldsHasVal = false; } if (cbProductType.SelectedItem == null) { IsAllFieldsHasVal = false; } else { if (cbProductType.SelectedItem.ToString() == "SMS") { if (tbTextForSMS.Text == "") { IsAllFieldsHasVal = false; } } if (cbProductType.SelectedItem.ToString() == "Call") { if ((tbLengthForCall.Text == "") || (tbPathForCall.Text == "")) { IsAllFieldsHasVal = false; } else { try { String[] arr = tbLengthForCall.Text.Split(':'); if (arr.Length != 2) { IsAllFieldsHasVal = false; } else { CallLengthConverter = ((long.Parse(arr[0].Trim()) * 60) + long.Parse(arr[1].Trim())) * 1000; } } catch { IsAllFieldsHasVal = false; } } } } if (!IsAllFieldsHasVal) { MessageBox.Show("Not all fields has values\nor not all values are valid"); } else { SQLRequests SQLReq = new SQLRequests(); if (SQLReq.AddProduct(tbSource.Text, tbDestination.Text, cbProductType.SelectedItem.ToString(), tbTextForSMS.Text, CallLengthConverter, tbPathForCall.Text, InvestigationID)) { MessageBox.Show("Product inserted successfully"); this.Close(); } else { MessageBox.Show("Product failed to insert"); } } }