public List <String> checkStringSimilarity(List <String> emails) { try { for (int i = 0; i < emails.Count; i++) { for (int j = i + 1; j < emails.Count; j++) { percentage = similarity(emails[i], emails[j]); Debug.WriteLine("------> checkStringSimilarity() <------ PERCENTAGE: " + percentage + " DISTANCE: " + distance); //TERAZ CAŁA LOGIKA if else if oraz else if (emails[i].StartsWith("https") || emails[j].StartsWith("https")) { if (percentage == 1.0) { emails.RemoveAt(j); j--; } else { //NIC } } else if ((emails[i].Length < 35 || emails[j].Length < 35) && distance <= 4 && percentage >= 0.87) { emails.RemoveAt(j); j--; } else if ((emails[i].Length > 35 || emails[j].Length > 35) && distance <= 3 && percentage >= 0.92) { emails.RemoveAt(j); j--; } else if ((emails[i].Length > 35 || emails[j].Length > 35) && distance <= 4 && percentage >= 0.95) { emails.RemoveAt(j); j--; } else { //NIC } } } return(emails); } catch (Exception ex) { OurDebug.AppendInfo("!!!!!!!!************ERROR***********!!!!!!!!!!\n", "DataObject.cs line:176. Blad w usuwaniu duplikatow; Sprawdzanie poprawnosci procentowej.\n", ex.Message, "\n", ex.StackTrace); Debug.WriteLine("Blad w usuwaniu duplikatow; Sprawdzanie poprawnosci procentowej "); return(emails); } }
private void CreateDocument(string path, Debuger OurDebug) { try { /********************************************************************************************/ //Create an instance for word app Application winword = new Application(); //Set animation status for word application //winword.ShowAnimation = false; //Set status for word application is to be visible or not. winword.Visible = false; //Create a missing variable for missing value object missing = System.Reflection.Missing.Value; //Create a new document Document document = winword.Documents.Add(ref missing, ref missing, ref missing, ref missing); /********************************************************************************************/ string header = "NCMAILBOX tasks (week "; header += CurrentWeek(); header += "):"; WriteMainHeader(header, document); string tym11 = "Inflow: "; tym11 += Loading.OurData.inflowAmount.ToString(); WriteSecondHeader(tym11, document); WriteMails(document, Loading.OurData.inflow); string tym22 = "In-hands: "; tym22 += Loading.OurData.inhandsAmount.ToString(); WriteSecondHeader(tym22, document); WriteMails(document, Loading.OurData.inhands); string tym33 = "Outflow: "; tym33 += Loading.OurData.outflowAmount.ToString(); WriteSecondHeader(tym33, document); WriteMails(document, Loading.OurData.outflow); /**********************************************************************************************/ //Save the document object filename = path; document.SaveAs(ref filename, WdSaveFormat.wdFormatDocumentDefault); document.Close(true); winword.Quit(); Marshal.ReleaseComObject(winword); } catch (Exception ex) { OurDebug.AppendInfo("!!!!!!!!************ERROR***********!!!!!!!!!!\n", "Problem with createDocument Word. \n", ex.StackTrace, "\n", ex.Message); } }
private void saveToExcel(string OutputRaportFileName, Debuger ourDebug) { try { var rowInHands = 4; var rowInflow = 4; var rowOutflow = 4; foreach (string s in Loading.OurData.inflow) { rowInflow++; oSheet.Cells[rowInflow, 1] = s; } foreach (string s in Loading.OurData.outflow) { rowOutflow++; oSheet.Cells[rowOutflow, 2] = s; } foreach (string s in Loading.OurData.inhands) { rowInHands++; oSheet.Cells[rowInHands, 3] = s; } oSheet.Columns.AutoFit(); oSheet.Cells[4, 1].EntireRow.Font.Bold = true; createCenterTables(oSheet, rowInHands, rowInflow, rowOutflow); createExcelSumCategories(oSheet, rowInHands, rowInflow, rowOutflow); oWB.SaveAs(OutputRaportFileName, Excel.XlFileFormat.xlOpenXMLStrictWorkbook); oWB.Close(true); oXL.Quit(); killExcel(getExcelIDProcess()); } catch (Exception ex) { ourDebug.AppendInfo("!!!!!!!!************ERROR***********!!!!!!!!!!\n", "Problem with saveToExcel function. \n", ex.StackTrace, ex.Message); } }
private void pb_DoWork(object sender, DoWorkEventArgs e) { EmailFunctions functions = new EmailFunctions(OurDebug, Settings.boxMailName, DateTime.Parse(Settings.raportDate)); List <MailItem> emails = new List <MailItem>(); MailItem email1 = null; int DebugCorrectEmailsCounter = 0; functions.choiceOfFileFormat(Settings.checkList); //Initialize outlook app Outlook.Application oApp = new Outlook.Application(); NameSpace oNS = oApp.GetNamespace("mapi"); MAPIFolder oInbox2 = oApp.ActiveExplorer().CurrentFolder as MAPIFolder; OurDebug.AppendInfo("Wybrany folder ", oInbox2.Name); Items oItems = oInbox2.Items; OurDebug.AppendInfo("Email's amount", oItems.Count.ToString()); //Sort all items oItems.Sort("[ReceivedTime]", true); //Debug info for mails OurDebug.AppendInfo("\n\n ************************MAILS*******************\n\n"); //Get only mails from two weeks ago DebugForEachCounter = functions.getOnlyEmailsForTwoWeeksAgo(DebugForEachCounter, email1, oItems, DebugCorrectEmailsCounter, emails); //Show how many times foreach is performed OurDebug.AppendInfo("\n\n", "Ile razy foreach: ", DebugForEachCounter.ToString(), "Maile brane pod uwage po wstepnej selekcji: ", "\n\n"); //Delete duplicates from email in the same name or the same thread try { emails = functions.emailsWithoutDuplicates(emails); emails = functions.removeDuplicateOneMoreTime(emails); } catch (Exception ex) { OurDebug.AppendInfo("!!!!!!!!************ERROR***********!!!!!!!!!!\n", "Usuwanie duplikatow nie dziala", ex.StackTrace, "\n", ex.Message); } int counterForAllEmails = 0; //Iterate all emails foreach (MailItem newEmail in emails) { try { List <bool> categoryList; //Divide on category if (functions.isMultipleCategoriesAndAnyOfTheireInterestedUs(newEmail.Categories)) { //Get inflow date and set to category DateTime friday = functions.getInflowDate(); categoryList = functions.selectCorrectEmailType(newEmail); OurData.addNewItem(newEmail.Subject, categoryList); } } catch (Exception ex) { OurDebug.AppendInfo("!!!!!!!!************ERROR***********!!!!!!!!!!\n", "Ribbon1.cs line:96. Problem in ID message.", ex.Message, "\n", ex.StackTrace); } counterForAllEmails++; backgroundWorker1.ReportProgress(counterForAllEmails / emails.Count * 60); } OurData.lastTuning(); //Start create excel raport if (checkExcel) { fullInfoBox += "\n\nYour report (Excel) is saved: " + Settings.OutputRaportFileName + ".xlsx"; ExcelSheet raport = new ExcelSheet(); raport.SaveExcel(Settings.OutputRaportFileName, OurDebug); } backgroundWorker1.ReportProgress(80); //Save to txt file and word if (checkWord) { fullInfoBox += "\n\nYour report(Word) is saved: " + Settings.OutputRaportFileName + ".docx"; string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\" + Settings.OutputRaportFileName + ".docx"; toBeSavedWord.WriteToWord(path, OurDebug, DateTime.Parse(Settings.raportDate)); } backgroundWorker1.ReportProgress(100); Thread.Sleep(1000); //Raport is saved OurDebug.AppendInfo("Your report is SAVED :D"); }
void EnumerateConversation(object item, Outlook.Conversation conversation, int i, List <bool> categoryList, ref bool correctCategory) { SimpleItems items = conversation.GetChildren(item); if (items.Count > 0) { foreach (object myItem in items) { if (myItem is Outlook.MailItem) { MailItem mailItem = myItem as MailItem; Folder inFolder = mailItem.Parent as Folder; string msg = mailItem.Subject + " in folder " + inFolder.Name + " Sender: " + mailItem.SenderName + " Date: " + mailItem.ReceivedTime; if (i == 0) { if (mailItem.ReceivedTime > getInflowDate().AddDays(-7) && mailItem.SenderName.Equals(adminMail)) { msg += " ++correctCategory++"; correctCategory = true; } if (mailItem.ReceivedTime > getInflowDate()) { msg += " TYP: INFLOW"; categoryList[0] = true; } } else { if (mailItem.ReceivedTime > getInflowDate().AddDays(-7) && mailItem.SenderName.Equals(adminMail)) { msg += " ++correctCategory++"; correctCategory = true; } if (mailItem.SenderName.Equals(adminMail) && mailItem.ReceivedTime > getInflowDate()) { msg += " TYP: IN HANDS"; categoryList[1] = true; } } Debug.WriteLine(msg); OurDebug.AppendInfo(msg); i++; } EnumerateConversation(myItem, conversation, i, categoryList, ref correctCategory); } } }