//Funkcja która wydobywa plik excel i nadaje mu nazwę, po czym wrzuca ją do zmiennej publicznej excelname. private string ExcelFile() { LoginDSV login = new LoginDSV(); ExtractResource resource = new ExtractResource(); DateTime thisDay = DateTime.Today; DateTimeOffset theTime = new DateTimeOffset(2008, 3, 1, 14, 15, 00, DateTimeOffset.Now.Offset); string time = thisDay.ToString("ddMMyyyy") + "_" + theTime.Hour + theTime.Minute + theTime.Second; string excelname = "LW_ErrorAnalyze_" + login.Login() + "_" + time + ".xlsx"; //Wydobywam plik resource.Extract("myProactive", @"C:\EDI", "Resources", "LW_ErrorAnalyze.xlsx"); //Zmieniam nazwę pliku if (File.Exists(@"C:\EDI\LW_ErrorAnalyze.xlsx")) { File.Copy(@"C:\EDI\LW_ErrorAnalyze.xlsx", @"C:\EDI\" + excelname, true); File.Delete(@"C:\EDI\LW_ErrorAnalyze.xlsx"); } //przypisuje nowo utworzony jako plik docelowy excelPath = @"C:\EDI\" + excelname; richTextBox_savepath.Text = excelPath; return(excelname); }
public void LogToFTP() //Metoda zapisujaca logi do pliku log.txt na serwerze FTP { LoginDSV login = new LoginDSV(); string date = DateTime.Today.ToString("dd-MM-yyyy"); string time = DateTime.Now.ToString("HH:mm:ss"); string who = login.Login(); string name = SystemInformation.UserName; string ver = "v" + Application.ProductVersion; string input = "[" + date + "][" + time + "][" + name + "][" + who + "][" + ver + "]\n"; byte[] data = Encoding.ASCII.GetBytes(input); try { FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://files.000webhost.com/myproactive/log.txt"); request.Credentials = new NetworkCredential("ediapp", "w8EtQdvNMJ8vXbt"); request.Method = WebRequestMethods.Ftp.AppendFile; Stream requestStream = request.GetRequestStream(); requestStream.Write(data, 0, data.Length); requestStream.Close(); FtpWebResponse response = (FtpWebResponse)request.GetResponse(); response.Close(); } catch { } }
public MyProactive() { InitializeComponent(); LoginDSV login = new LoginDSV(); Resources resource = new Resources(); groupBox1.Paint += GroupBox_Paint; groupBox2.Paint += GroupBox_Paint; string userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name; ListBox("[" + DateTime.Now.ToString("HH:mm:ss") + "] " + "Logged as: " + userName + " " + "(" + login.Login() + ")"); ListBox("[" + DateTime.Now.ToString("HH:mm:ss") + "] " + "App is ready to use."); ver.Text = "v" + Application.ProductVersion; Task.Delay(3000).ContinueWith(t => resource.LogToFTP()); //zapisz log na serwerze z opoźnieniem latest_ver.Text = resource.CheckVersion(); //kontrola wersji programu textBox1.Enabled = false; }
public void ReadMailItems(object sender, DoWorkEventArgs e) { OutlookApp.Application outlookApplication = null; OutlookApp.NameSpace outlookNamespace = null; OutlookApp.MAPIFolder inboxFolder = null; OutlookApp.Items mailItems = null; workerThread = Thread.CurrentThread; // Obiek + numer zakladki Excel excel = new Excel(excelPath, 1); // Wykorzystam to do nazwy kategorii w outlooku LoginDSV login = new LoginDSV(); // Licznik maili (wszystkie) int i = 0; // Licznik maili zapisanych (uwzglednionych) int l = 0; int k1 = 1; int k2 = 1; int k3 = 1; int k4 = 1; int k5 = 1; int k6 = 1; int k7 = 1; int k8 = 1; int k9 = 1; string content = string.Empty; string content2 = string.Empty; string inc = "waiting to be created"; string mailCategory = "[myProactive] handled by " + login.Login(); excel.WriteToCell(2, 0, ""); excel.WriteToCell(2, 1, "DATE"); excel.WriteToCell(2, 2, "WFID"); excel.WriteToCell(2, 3, "BP"); excel.WriteToCell(2, 4, "SourceID"); excel.WriteToCell(2, 5, "DestinationID"); excel.WriteToCell(2, 6, "Error Description"); excel.WriteToCell(2, 7, "Taken action"); excel.WriteToCell(2, 8, "INC"); excel.ReadCell(0, 0); try { outlookApplication = new OutlookApp.Application(); outlookNamespace = outlookApplication.GetNamespace("MAPI"); inboxFolder = outlookNamespace.Folders.Session.PickFolder(); mailItems = inboxFolder.Items; OutlookApp.Items restrictedItems = mailItems.Restrict(filter); for (int j = 0; j <= restrictedItems.Count; j++) { foreach (OutlookApp.MailItem item in mailItems) { // Licznik maili, zwiększam o 1 za każdym razem gdy obliczam kolejną pozycję mailową i += 1; // Licznik maili uwzblędnionych, zwiększam o 1 za każdym razem gdy pochodzę do kolejnego rekordu l += 1; //Start date string startDate = item.CreationTime.ToString(); if ((i <= number)) //wczytaj tyle maili, ile zostalo wybranych w klasie Form1.cs { Invoke( //odpowiedź na: Nieprawidłowa operacja między wątkami. new Action(() => { // Wywołanie metody ReportProgress() wywołuje zdarzenie ProgressChanged // Do tej metody należy przekazać procent przetwarzania, które zostało zakończone backgroundWorker1.ReportProgress(i); // Przypisuje kategorie do obsłużonego maila if (checkBoxTagYes.Checked) { string existingCategories = item.Categories; if (string.IsNullOrEmpty(existingCategories)) { item.Categories = mailCategory; } else { if (item.Categories.Contains(mailCategory) == false) { item.Categories = mailCategory; } } // Zapisuje maila po dodaniu kategorii item.Save(); } var stringBuilder = new StringBuilder(); string CreationTime = item.CreationTime.ToString(); stringBuilder.AppendLine("Subject: " + item.Subject); stringBuilder.AppendLine("Body: " + item.Body); string body = item.Body.ToString(); Marshal.ReleaseComObject(item); string sPattern = "LOCK"; if (Regex.IsMatch(body, sPattern, RegexOptions.IgnoreCase)) { listBox1.Items.Add("Item: " + i + " || " + "Skipping, found: Error description 'LOCK: Lock exists'"); // Odejmuje z licznika pozycje z LOCK w opisie bledu, w dalszej czesci nie zapisuje i przechodze dalej. l -= 1; } else { //////////// extract WFID content = stringBuilder.ToString(); int first = content.IndexOf(" = ") + " : ".Length; int last = content.LastIndexOf(" : "); string str2 = content.Substring(first, last - first); string wfid = string.Empty; Regex wyrazenie_wfid = new Regex(@"\d+"); Match wfidTry = wyrazenie_wfid.Match(str2); if (wfidTry.Success) { wfid = wfidTry.Value; } else { wfid = "myProactive_error"; } //////////// extract BP string content_BP = stringBuilder.ToString(); int first_bp = content_BP.IndexOf(" : ") + ": ".Length; int last_bp = content_BP.LastIndexOf("Body"); string bp_part1 = content_BP.Substring(first_bp, last_bp - first_bp); int first_bp1 = bp_part1.IndexOf(" "); int last_bp1 = bp_part1.LastIndexOf(" :"); string bp = bp_part1.Substring(first_bp1, last_bp1 - first_bp1); //////////// extract SOURCE ID string content_sourceID = stringBuilder.ToString(); int first2 = content_sourceID.IndexOf("(Name)"); //+ " : ".Length; int last2 = content_sourceID.LastIndexOf("(Name)"); string source_id = content_sourceID.Substring(first2 + 7, last2 - 26 - first2); string sourceIDpattern = "()"; if (source_id.Length > 100) { source_id = "()"; } else // jezeli wystpuje w stringu () to utnij spacje { if (Regex.IsMatch(source_id, sourceIDpattern, RegexOptions.IgnoreCase)) { source_id = source_id.Trim(); } } //////////// extract DESTINATION ID string content_destID = stringBuilder.ToString(); int first_destID = content_destID.IndexOf("Destination"); //+ " : ".Length; int last_destID = content_destID.LastIndexOf("Type"); string source_destID = content_destID.Substring(first_destID + 22, last_destID - 35 - first_destID); string destIDpattern = "()"; if (source_destID.Length > 100) { source_destID = "()"; } else //jezeli wystepuje w stringu () to utnij spacje { if (Regex.IsMatch(source_destID, destIDpattern, RegexOptions.IgnoreCase)) { source_destID = source_destID.Trim(); } } //////////// extract ERROR string content_error = stringBuilder.ToString(); int first_error = content_error.IndexOf(" : ") + " : ".Length; int last_error = content_error.LastIndexOf("Body:"); string error_part1 = content_error.Substring(first_error, last_error - first_error); int error_first1 = error_part1.IndexOf(": ") + " ".Length + 1; int error_last1 = error_part1.LastIndexOf(""); string source_error = error_part1.Substring(error_first1, error_last1 - error_first1); excel.ReadCell(1, 1); excel.WriteToCell(k1++, 0, l.ToString()); excel.WriteToCell(k2++, 1, CreationTime); excel.WriteToCell(k3++, 2, wfid); excel.WriteToCell(k4++, 3, bp); excel.WriteToCell(k5++, 4, source_id); excel.WriteToCell(k6++, 5, source_destID); excel.WriteToCell(k7++, 6, source_error); excel.WriteToCell(k8++, 7, "no"); excel.WriteToCell(k9++, 8, inc); ListBox("Item: " + i + " || " + "Date: " + CreationTime + " || " + "WFID: " + wfid + " || " + "BP: " + bp + " || " + "SourceID: " + source_id + " || " + "DestinationID: " + source_destID + " || " + source_error); // AktualizujProgres(i, number); CustomizeVerticalScroll(); // Przewijam wraz z dodana pozycja listBox1.TopIndex = listBox1.Items.Count - 1; // Sprawdź, czy zażądano anulowania if (backgroundWorker1.CancellationPending) { // Ustaw właściwość Cancel obiektu DoWorkEventArgs na true e.Cancel = true; // Zresetuj procent postępu do ZERA backgroundWorker1.ReportProgress(0); return; } } })); } } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); //excel.Close(); label5.Text = "Completed."; //Zapobiega propagacji ThreadAbortException //Thread.ResetAbort(); } finally { ReleaseComObject(mailItems); ReleaseComObject(inboxFolder); ReleaseComObject(outlookNamespace); ReleaseComObject(outlookApplication); } if (workerThread != null) { e.Result = i; excel.Save(); excel.Close(); excel.KillSpecificExcelFileProcess("EXCEL.EXE"); } return; }