//void SetupCalendarForSubsription() //{ // try // { // scopes.Add(CalendarService.Scope.Calendar); // UserCredential credential = default(UserCredential); // FileDataStore _fdsToken = new FileDataStore("CT"); // credential = GoogleWebAuthorizationBroker.AuthorizeAsync( // new ClientSecrets // { // ClientId = "532982290458-u189keaaki44sskvtki6p28rq5crjl6d.apps.googleusercontent.com", // ClientSecret = "DDO62gcKn5nYWm4XCXlJkngo", // }, scopes, // "Z", // CancellationToken.None, _fdsToken).Result; // credential.Token.ExpiresInSeconds = 500000; // String token = credential.Token.RefreshToken; // credential.Token.RefreshToken = "1/wU76ItFh-n64iqZLjIiXER0Vx4u-MxEnHtHFLgQpa7E"; // credential.Token.ExpiresInSeconds = 500000; // // Create the calendar service using an initializer instance // BaseClientService.Initializer initializer = new BaseClientService.Initializer(); // initializer.HttpClientInitializer = credential; // initializer.ApplicationName = "DPI Google Calendar"; // service = new CalendarService(initializer); // } // catch (Exception ex) // { // } //} public void CheckAllCalendarEvents(int orgId) { SetCalendar(orgId); bool IsAllDay = false; var list = service.CalendarList.List().Execute().Items; try { foreach (var cal in list) { InsertGoogleSyncTime(cal.Id, DateTime.Now); var itemlistreq = service.Events.List(cal.Id); // itemlistreq.PageToken = token; itemlistreq.MaxResults = 100000; itemlistreq.ShowDeleted = true; itemlistreq.ShowHiddenInvitations = true; var itemlistex = itemlistreq.Execute(); //itemlistex.Items[0]. var token = itemlistex.NextPageToken; string[] Descs = null; for (int i = 0; i < itemlistex.Items.Count; i++) { IsAllDay = false; string Calendar = cal.Id; string EventId = itemlistex.Items[i].Id; string RecurringEventId = itemlistex.Items[i].RecurringEventId; if (RecurringEventId == null) { RecurringEventId = ""; }; var Attendees = itemlistex.Items[i].Attendees; string Attendes = ""; if (Attendees != null) { for (int j = 0; j < Attendees.Count; j++) { Attendes = Attendes + "~" + Attendees[j]; }; } string ColorId = itemlistex.Items[i].ColorId; if (ColorId == null) { ColorId = ""; }; bool? AttendeesOmitted = itemlistex.Items[i].AttendeesOmitted; if (AttendeesOmitted == null) { AttendeesOmitted = false; }; bool? AnyoneCanAddSelf = itemlistex.Items[i].AnyoneCanAddSelf; if (AnyoneCanAddSelf == null) { AnyoneCanAddSelf = false; }; string Title = itemlistex.Items[i].Summary; if (Title == null) { Title = ""; } string Location = itemlistex.Items[i].Location; if (Location == null) { Location = ""; } string Description = itemlistex.Items[i].Description; if (Description == null) { Description = ""; } string Kind = itemlistex.Items[i].Kind; if (Kind == null) { Kind = ""; } DateTime StartDate = Convert.ToDateTime("01/01/1900"); if (itemlistex.Items[i].Start != null) { if (itemlistex.Items[i].Start.Date != null) { StartDate = Convert.ToDateTime(itemlistex.Items[i].Start.Date); } if (StartDate == null || StartDate == Convert.ToDateTime("01/01/1900")) { { StartDate = Convert.ToDateTime(itemlistex.Items[i].Start.DateTime); } if (StartDate != null && StartDate.ToString().Contains("0001")) { StartDate = Convert.ToDateTime("01/01/1900"); } } } DateTime EndDate = Convert.ToDateTime("01/01/1900"); if (itemlistex.Items[i].End != null) { if (itemlistex.Items[i].End.Date != null) { EndDate = Convert.ToDateTime(itemlistex.Items[i].End.Date); IsAllDay = true;// here this is all day event EndDate = EndDate.AddDays(-1); //text = File.ReadAllText("C://Google.txt"); //text = text + Environment.NewLine + " End Date- " + EndDate.ToString(); //File.WriteAllText("C://Google.txt", text); } if (EndDate == null || EndDate == Convert.ToDateTime("01/01/1900")) { { EndDate = Convert.ToDateTime(itemlistex.Items[i].End.DateTime); } if (EndDate != null && EndDate.ToString().Contains("0001")) { EndDate = Convert.ToDateTime("01/01/1900"); } } } DateTime MovedOn = Convert.ToDateTime("01/01/1900"); if (itemlistex.Items[i].Created != null) { MovedOn = Convert.ToDateTime(itemlistex.Items[i].Created); } if (MovedOn != null && MovedOn.ToString().Contains("0001")) { MovedOn = Convert.ToDateTime("01/01/1900"); } string Status = itemlistex.Items[i].Status; var Recurrence = itemlistex.Items[i].Recurrence; string Recurrences = ""; if (Recurrence != null) { for (int j = 0; j < Recurrence.Count; j++) { Recurrences = Recurrences + "~" + Recurrence[j]; }; } string Organizer = ""; if (itemlistex.Items[i].Organizer != null) { Organizer = itemlistex.Items[i].Organizer.DisplayName; } if (Organizer == null) { Organizer = ""; } string Creator = ""; if (itemlistex.Items[i].Creator != null) { Creator = itemlistex.Items[i].Creator.DisplayName; } if (Creator == null) { Creator = ""; } bool? Locked = false; try { Locked = itemlistex.Items[i].Locked; } catch { }; Locked = false; //if (Locked == null) { Locked = false; }; int Sequence = 0; if (itemlistex.Items[i].Sequence != null) { Sequence = (int)itemlistex.Items[i].Sequence; } string Transperancy = itemlistex.Items[i].Transparency; if (Transperancy == null) { Transperancy = ""; } DateTime Updated = Convert.ToDateTime("01/01/1900"); if (itemlistex.Items[i].Updated != null) { Updated = Convert.ToDateTime(itemlistex.Items[i].Updated); } if (Updated != null && Updated.ToString().Contains("0001")) { Updated = Convert.ToDateTime("01/01/1900"); } string Visibility = itemlistex.Items[i].Visibility; if (Visibility == null) { Visibility = ""; } InsertOtherEvents(Calendar, EventId, RecurringEventId, ColorId, Attendes, AttendeesOmitted, AnyoneCanAddSelf, Locked, Title, Location, Description, Kind, StartDate, EndDate, MovedOn, Status, Recurrences, Organizer, Creator, Sequence, Transperancy, Updated, Visibility, IsAllDay); } } } catch (Exception ex) { Email.Email eml = new Email.Email(); string strLog = ex.StackTrace.ToString() + "~~~~~~~~~~~~Error~~~~~~~~~~~:" + ex.Message.ToString(); eml.SendMail("Error syncing google calendar", "Error :- " + strLog, "*****@*****.**", "", false); }; }
public void SyncGoogleCalendars(int orgId) { SetCalendar(orgId); //CheckCalendarEvents(); string a; var list = service.CalendarList.List().Execute().Items; try { foreach (var cal in list) { // if (cal.Id != "*****@*****.**") { continue; } int result = InsertCalendars(cal.Id, 825, cal.TimeZone, cal.Kind, cal.ETag, int.Parse(cal.ColorId), cal.BackgroundColor, cal.ForegroundColor, cal.AccessRole, cal.Selected ?? false); if (result == 2) { Subscribe(cal, orgId); } var itemlistreq = service.Events.List(cal.Id); // itemlistreq.PageToken = token; itemlistreq.MaxResults = 100000; itemlistreq.ShowDeleted = true; itemlistreq.ShowHiddenInvitations = true; try { var itemlistex = itemlistreq.Execute(); //itemlistex.Items[0]. var token = itemlistex.NextPageToken; for (int i = 0; i < itemlistex.Items.Count; i++) { if (itemlistex.Items[i].Description != null) { if (Convert.ToDateTime(itemlistex.Items[i].Created).Date == DateTime.Now.Date || Convert.ToDateTime(itemlistex.Items[i].Created).Date == DateTime.Now.Date.AddDays(-1) || Convert.ToDateTime(itemlistex.Items[i].Created).Date == DateTime.Now.Date.AddDays(-2)) { if (itemlistex.Items[i].Description.Contains("Order Item (Please donot delete or update OrderItemId) :") == true) { string Desc = itemlistex.Items[i].Description; string[] Descs = Desc.Split(new string[] { "Order Item (Please donot delete or update OrderItemId) :" }, StringSplitOptions.None); string OrderItemId = Descs[1]; string Title = itemlistex.Items[i].Summary; string Calendar = cal.Id; DateTime StartDate = Convert.ToDateTime(itemlistex.Items[i].Start.DateTime); DateTime EndDate = Convert.ToDateTime(itemlistex.Items[i].End.DateTime); DateTime MovedOn = Convert.ToDateTime(itemlistex.Items[i].Created); string Status = itemlistex.Items[i].Status; InsertCalendarEvents(Calendar, OrderItemId, Title, StartDate, EndDate, MovedOn, Status); } } } } } catch { } //Here, itemlistreq.PageToken == null; } } catch (Exception ex) { Email.Email eml = new Email.Email(); string strLog = ex.StackTrace.ToString() + "~~~~~~~~~~~~Error~~~~~~~~~~~:" + ex.Message.ToString(); eml.SendMail("Error syncing google calendars Only (Inserting newly added calendar in db)", "Error :- " + strLog, "*****@*****.**", "", false); }; }
public void CheckCalendarMovements(string calendar, int orgId) { SetCalendar(orgId); //CheckCalendarEvents(calendar); string a; var list = service.CalendarList.List().Execute().Items;//.Where(x=>x.Id==calendar); try { foreach (var cal in list) { // if (cal.Id != "*****@*****.**") { continue; } int res = InsertCalendars(cal.Id, 1, cal.TimeZone); //Subscribe(cal); //var itemlistreq = service.Events.List(cal.Id); //// itemlistreq.PageToken = token; //itemlistreq.MaxResults = 100000; //itemlistreq.ShowDeleted = true; //itemlistreq.ShowHiddenInvitations = true; //var itemlistex = itemlistreq.Execute(); ////itemlistex.Items[0]. //var token = itemlistex.NextPageToken; //for (int i = 0; i < itemlistex.Items.Count; i++) //{ // if (itemlistex.Items[i].Description != null) // { // if (Convert.ToDateTime(itemlistex.Items[i].Created).Date == DateTime.Now.Date || Convert.ToDateTime(itemlistex.Items[i].Created).Date == DateTime.Now.Date.AddDays(-1) || Convert.ToDateTime(itemlistex.Items[i].Created).Date == DateTime.Now.Date.AddDays(-2)) // { // if (itemlistex.Items[i].Description.Contains("Order Item (Please donot delete or update OrderItemId) :") == true) // { // string Desc = itemlistex.Items[i].Description; // string[] Descs = Desc.Split(new string[] { "Order Item (Please donot delete or update OrderItemId) :" }, StringSplitOptions.None); // string OrderItemId = Descs[1]; // string Title = itemlistex.Items[i].Summary; // string Calendar = cal.Id; // DateTime StartDate = Convert.ToDateTime(itemlistex.Items[i].Start.DateTime); // DateTime EndDate = Convert.ToDateTime(itemlistex.Items[i].End.DateTime); // DateTime MovedOn = Convert.ToDateTime(itemlistex.Items[i].Created); // string Status = itemlistex.Items[i].Status; // //InsertCalendarEvents(Calendar, OrderItemId, Title, StartDate, EndDate, MovedOn, Status); // } // } // } //} //Here, itemlistreq.PageToken == null; } //UpdateCalendar(); } catch (Exception ex) { Email.Email eml = new Email.Email(); string strLog = ex.StackTrace.ToString() + "~~~~~~~~~~~~Error~~~~~~~~~~~:" + ex.Message.ToString(); eml.SendMail("Error syncing google calendar", "Error :- " + strLog, "*****@*****.**", "", false); }; }
public string ProcessData() { string strLog = ""; XmlDocument xmlDoc = new XmlDocument(); IOAuthSession session; DateTime DueDate = DateTime.Now; string strd; string Subject; string jpgfilename; Email.Email eml = new Email.Email(); try { session = XeroAPI(); Repository repository = new Repository(session); //OpreateData opftp = new OpreateData(); //string strLogs = opftp.GetDataFromServer(ref connectionSuccess);//, ref index); HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument(); DataSet dsProductNotification = new DataSet(); String[] OrderId = null; foreach (string file in Directory.EnumerateFiles(FullPath, "*.htm")) { filename = Path.GetFileName(file); // filename = "201404161759591372889.htm"; htmlDoc.Load(file); StartBrowser(htmlDoc.DocumentNode.OuterHtml); } // } foreach (string file in Directory.EnumerateFiles(FullPath, "*.htm")) { int propertyId = 0; string location=string.Empty; filename = Path.GetFileName(file); jpgfilename = filename.Replace("htm", "jpg"); // filename = "201404161759591372889.htm"; XmlNode rootElement = xmlDoc.CreateElement("Root"); xmlDoc.AppendChild(rootElement); htmlDoc.Load(file); htmlDoc.OptionWriteEmptyNodes = true; htmlDoc.OptionOutputAsXml = true; string value = ""; HtmlNodeCollection nodesitemheading = htmlDoc.DocumentNode.SelectNodes(".//b"); /*This is an order notification from Robin Parker at Marshall White Brighton<br /> <i>Relating to campaign: 11 Lagnicourt Street, Hampton</i> */ String[] SplitValues = new String[1000]; XmlElement Element = xmlDoc.CreateElement("PrimaryContact"); try { SplitValues = Splits(sep(nodesitemheading[0].InnerText, "from "), new char[] { ' ' }); } catch { File.Move(file, System.Configuration.ConfigurationSettings.AppSettings["Error"] + "\\" + filename); File.Move(file.Replace("htm", "txt"), System.Configuration.ConfigurationSettings.AppSettings["Error"] + "\\" + filename.Replace("htm", "txt")); xmlDoc.RemoveAll(); continue; }; string cncl1 = "", cncl2 = "", cncl3 = ""; if (nodesitemheading[0].InnerText.Contains("The order listed below was cancelled by")) { IList<string> arrayAsList = (IList<string>)SplitValues; int index; index = arrayAsList.IndexOf("campaign:"); if (index == -1) index = arrayAsList.IndexOf("\r\ncampaign:"); for (int i = index + 1; i < SplitValues.Length; i++) { if (SplitValues[i].Contains("of")) { break; }; cncl1 = cncl1 + " " + SplitValues[i];//email body subject cncl1 = cncl1.Replace("Description", "").Replace("\r\n", ""); } IList<string> arrayAsList1 = (IList<string>)SplitValues; int index1 = arrayAsList.IndexOf("being"); for (int i = index1 + 2; i < SplitValues.Length; i++) { if (SplitValues[i].Contains("on")) { break; }; cncl2 = cncl2 + " " + SplitValues[i];//email body subject cncl2 = cncl2.Replace("Required", "").Replace("\r\n", ""); } IList<string> arrayAsList2 = (IList<string>)SplitValues; int index2 = arrayAsList.IndexOf("on"); cncl3 = SplitValues[index2 + 1].Replace("Product", ""); InsertCancelledOrders(cncl1, cncl2, cncl3, filename); File.Move(file, System.Configuration.ConfigurationSettings.AppSettings["Cancelled"] + "\\" + filename); File.Move(file.Replace("htm", "txt"), System.Configuration.ConfigurationSettings.AppSettings["Cancelled"] + "\\" + filename.Replace("htm", "txt")); xmlDoc.RemoveAll(); continue; } string str11 = "", str22 = "", str33 = ""; try { #region Fixed on 9 Oct 2014 if (SplitValues[3] == "at") { var midleName = SplitValues[1]; SplitValues = SplitValues.Where(x => x != midleName).ToArray(); var lastName = SplitValues[1]; SplitValues[1] = midleName + " " + lastName; } #endregion str11 = SplitValues[0] + " " + SplitValues[1];//primary contact str22 = SplitValues[3] + " " + SplitValues[4] + " " + SplitValues[5];//company name str22 = str22.Replace("Relating", ""); //if (SplitValues[7].Contains("to")) //{ // str33 = ""; // for (int i = 8; i < SplitValues.Length; i++) // { // str33 = str33 + " " + SplitValues[i];//email body subject // } //} //else // str33 = SplitValues[7] + " " + SplitValues[8] + " " + SplitValues[9] + " " + SplitValues[10] + SplitValues[11];//email body subject IList<string> arrayAsList = (IList<string>)SplitValues; int index; index = arrayAsList.IndexOf("Relating".Replace("\r\n", "")); if (index == -1) index = arrayAsList.IndexOf("\r\ncampaign:");//campaign: if (index == -1) index = arrayAsList.IndexOf("campaign:");//campaign: for (int i = index + 1; i < SplitValues.Length; i++) { if (SplitValues[i].Contains("of")) { break; }; str33 = str33 + " " + SplitValues[i];//email body subject str33 = str33.Replace("Description", "").Replace("\r\n", ""); } //if (SplitValues[7].Contains("Relating")) //{ // str33 = ""; // for (int i = 10; i < SplitValues.Length; i++) // { // str33 = str33 + " " + SplitValues[i];//email body subject // } //} } catch { File.Move(file, System.Configuration.ConfigurationSettings.AppSettings["Error"] + "\\" + filename); File.Move(file.Replace("htm", "txt"), System.Configuration.ConfigurationSettings.AppSettings["Error"] + "\\" + filename.Replace("htm", "txt")); xmlDoc.RemoveAll(); continue; }; XmlElement PrimaryContactElement = xmlDoc.CreateElement("PrimaryContact"); PrimaryContactElement.InnerText = str11; rootElement.AppendChild(PrimaryContactElement); XmlElement CompanyNameElement = xmlDoc.CreateElement("CompanyName"); CompanyNameElement.InnerText = str22; rootElement.AppendChild(CompanyNameElement); XmlElement EmailBodySubjectElement = xmlDoc.CreateElement("EmailBodySubject"); EmailBodySubjectElement.InnerText = nodesitemheading[0].InnerText; rootElement.AppendChild(EmailBodySubjectElement); XmlElement PropertyNameElement = xmlDoc.CreateElement("PropertyName"); str33 = str33.Replace("campaign:", ""); PropertyNameElement.InnerText = str33; rootElement.AppendChild(PropertyNameElement); location = str33; XmlElement FileNameElement = xmlDoc.CreateElement("FileName"); FileNameElement.InnerText = Path.GetFileName(file); rootElement.AppendChild(FileNameElement); string strfile = file.Replace("htm", "txt"); string[] lines = File.ReadAllLines(strfile); string From = lines[0].ToString().Replace("From:", ""); XmlElement FromElement = xmlDoc.CreateElement("From"); FromElement.InnerText = From; rootElement.AppendChild(FromElement); string SentDate = lines[1].ToString().Replace("SentDate:", ""); XmlElement SentDateElement = xmlDoc.CreateElement("SentDate"); //DateTime objSentDate = Convert.ToDateTime(SentDate,CultureInfo.CreateSpecificCulture("en-US")); DateTime objSentDate = DateTime.Parse(SentDate, CultureInfo.GetCultureInfo("en-gb")); SentDateElement.InnerText = objSentDate.Month.ToString().PadLeft(2, '0') + "/" + objSentDate.Day.ToString().PadLeft(2, '0') + "/" + objSentDate.Year + " " + objSentDate.ToLongTimeString(); rootElement.AppendChild(SentDateElement); Subject = lines[2].ToString().Replace("Subject:", ""); XmlElement SubjectElement = xmlDoc.CreateElement("Subject"); SubjectElement.InnerText = Subject; rootElement.AppendChild(SubjectElement); HtmlNodeCollection nodesitemcontacts = htmlDoc.DocumentNode.SelectNodes(".//td[@class='content']"); //htmlDoc.DocumentNode.SelectNodes(".//td[@class='content']")[0].ChildNodes foreach (HtmlNode childNode in nodesitemcontacts) { if (childNode.ChildNodes.Count > 0) { foreach (HtmlNode childOfChildNode in childNode.ChildNodes) { if (childOfChildNode.Name == "#text") { if (childOfChildNode.ChildNodes.Count == 0) { if (childOfChildNode.InnerText.Trim().Contains("Property ID") || childOfChildNode.InnerText.Trim().Contains("Property")) { //MessageBox.Show(childOfChildofChildNode.InnerText.Trim().Replace("Property ID:", ""));//Property Id XmlElement PropertyIdElement = xmlDoc.CreateElement("PropertyId"); PropertyIdElement.InnerText = childOfChildNode.InnerText.Trim().Replace("Property ID:", "").Replace("\r\n", "").Replace("Property ID:", ""); rootElement.AppendChild(PropertyIdElement); try { propertyId = int.Parse(PropertyIdElement.InnerText); } catch { } } if (childOfChildNode.InnerText.Trim().Contains("OrderItem")) { // MessageBox.Show(childOfChildofChildNode.InnerText.Trim().Replace("OrderItem:", "")); String[] SplitValue = Splits(childOfChildNode.InnerText.Trim().Replace("OrderItem:", ""), new char[] { ',' });//Order Item Id OrderId = SplitValue; SplitValueOrderItemId = Splits(childOfChildNode.InnerText.Trim().Replace("OrderItem:", ""), new char[] { ',' }); XmlElement OrderItemIdElement = xmlDoc.CreateElement("OrderItemId"); for (int i = 0; i < SplitValue.Length; i++) { string str = SplitValue[i]; XmlElement IdElement = xmlDoc.CreateElement("Id"); IdElement.InnerText = str.Trim(); OrderItemIdElement.AppendChild(IdElement); } rootElement.AppendChild(OrderItemIdElement); } if (childOfChildNode.InnerText.Trim().Contains("Sales contacts")) { // MessageBox.Show(childOfChildofChildNode.InnerText.Trim().Replace("Sales contacts:", ""), "8"); String[] SplitValue = Splits(childOfChildNode.InnerText.Trim().Replace("Sales contacts:", ""), new char[] { ',' }); for (int i = 0; i < SplitValue.Length; i++) { string str = (SplitValue[i].Replace(" on ", ",").Replace("\r\non", ",")); String[] strValue = Splits(str, new char[] { ',' }); string str1 = strValue[0];//Sales contact name string str2 = strValue[1].Replace("or", "");//Sales contact phone number XmlElement SalesContactElement = xmlDoc.CreateElement("SalesContact"); SalesContactElement.InnerText = str1.Trim(); ; rootElement.AppendChild(SalesContactElement); XmlElement SalesContactNumberElement = xmlDoc.CreateElement("SalesContactNumber"); SalesContactNumberElement.InnerText = str2.Trim(); rootElement.AppendChild(SalesContactNumberElement); } HtmlNodeCollection adminemail = htmlDoc.DocumentNode.SelectNodes(".//a[@href]"); string stradmin = adminemail[1].InnerText;//Admin email address } if (childOfChildNode.InnerText.Trim().Contains("Admin contact")) { // MessageBox.Show(childOfChildofChildNode.InnerText.Trim(), "9"); // String[] SplitValue = Splits(childOfChildNode.InnerText.Trim().Replace("Admin contact:", "").Replace(" on", ","), new char[] { ',' }); String[] SplitValue = Splits(childOfChildNode.InnerText.Trim().Replace("Admin contact:", "").Replace(" on", ","), "or".ToCharArray()); string admindetails = childOfChildNode.InnerText.Trim().Replace("Admin contact:", "");//Admin contact name string str1; try { // bool string1Matched = Regex.IsMatch(string1, @"\bthe\b", RegexOptions.IgnoreCase); str1 = admindetails.Substring(0, admindetails.IndexOf(" or ")); str1 = str1.Substring(0, str1.IndexOf(" on "));//Admin name string str2; str2 = admindetails.Substring(0, admindetails.IndexOf(" or ")); str2 = str2.Substring(str2.LastIndexOf(" on ") + 3);//Admin Phone string str3 = ""; str3 = admindetails.Substring(admindetails.IndexOf(" or ") + 4); XmlElement AdminContactElement = xmlDoc.CreateElement("AdminContact"); AdminContactElement.InnerText = str1.Trim(); rootElement.AppendChild(AdminContactElement); XmlElement AdminContactNumberElement = xmlDoc.CreateElement("AdminContactNumber"); AdminContactNumberElement.InnerText = str2.Trim(); rootElement.AppendChild(AdminContactNumberElement); XmlElement AdminContactEmailElement = xmlDoc.CreateElement("AdminContactEmail"); AdminContactEmailElement.InnerText = str3.Trim(); rootElement.AppendChild(AdminContactEmailElement); } catch (Exception ex) { strLog = ex.StackTrace.ToString(); WriteLog(strLog + " " + filename); } } if (childOfChildNode.InnerText.Trim().Contains("Supplier:")) { //MessageBox.Show(childOfChildofChildNode.InnerText.Trim(), "10"); string str1 = childOfChildNode.InnerText.Replace("Supplier:", "");//Product XmlElement SupplierElement = xmlDoc.CreateElement("Supplier"); SupplierElement.InnerText = str1.Trim(); rootElement.AppendChild(SupplierElement); } if (childOfChildNode.InnerText.Trim().Contains("Description of product/service being ordered:")) { value = "Description of product"; continue; } if (value == "Description of product") { //MessageBox.Show(childOfChildofChildNode.InnerText.Trim(), "11"); string str = childOfChildNode.InnerText.Replace("Description of product/service being ordered: ", "");//Product Description value = ""; XmlElement DescriptionElement = xmlDoc.CreateElement("Description"); DescriptionElement.InnerText = str.Trim(); rootElement.AppendChild(DescriptionElement); } if (childOfChildNode.InnerText.Trim().Contains("Required")) { // MessageBox.Show(childOfChildofChildNode.InnerText.Trim(), "12"); string RequiredDate = childOfChildNode.InnerText.Replace("Required on", "").Replace("Required \r\non", "").Replace("\r\n", "");//Required Date DateTime objRequiredDate = DateTime.Parse(RequiredDate, CultureInfo.GetCultureInfo("en-gb")); XmlElement RequiredDateElement = xmlDoc.CreateElement("RequiredDate"); // RequiredDateElement.InnerText = objRequiredDate.Month.ToString().PadLeft(2, '0') + "-" + objRequiredDate.Day.ToString().PadLeft(2, '0') + "-" + objRequiredDate.Year; RequiredDateElement.InnerText = objRequiredDate.ToShortDateString(); rootElement.AppendChild(RequiredDateElement); DueDate = Convert.ToDateTime(objRequiredDate.ToShortDateString()); //DueDate = DateTime.Parse(RequiredDate, "dd/MM/yyyy").ToString("MM/dd/yyyy"); } if (value == "PROPERTY") { // MessageBox.Show(childOfChildofChildNode.InnerText, "2");//Property Comments XmlElement PropertyDetailsElement = xmlDoc.CreateElement("PropertyDetails"); PropertyDetailsElement.InnerText = childOfChildNode.InnerText; rootElement.AppendChild(PropertyDetailsElement); HtmlNodeCollection propertycomments = htmlDoc.DocumentNode.SelectNodes(".//i"); string str = propertycomments[1].InnerText;//Property Comments value = ""; XmlElement PropertyCommentsElement = xmlDoc.CreateElement("PropertyComments"); PropertyCommentsElement.InnerText = str.Trim(); rootElement.AppendChild(PropertyCommentsElement); } if (childOfChildNode.InnerText.Trim() == "PROPERTY") { value = "PROPERTY"; continue; } //} // } } } } } } HtmlNodeCollection Nds = htmlDoc.DocumentNode.SelectNodes(".//table[@cellpadding='3']"); int cnt = 1; if (Nds == null) { if (Subject.Contains("cancellation")) { File.Move(file, System.Configuration.ConfigurationSettings.AppSettings["Cancelled"] + "\\" + filename); File.Move(file.Replace("htm", "txt"), System.Configuration.ConfigurationSettings.AppSettings["Cancelled"] + "\\" + filename.Replace("htm", "txt")); } }; if (Nds != null) { foreach (HtmlNode childNds in Nds) { if (childNds.ChildNodes.Count > 0) { if (childNds.InnerText.Contains("This is an order")) { continue; } else { if (childNds.ChildNodes.Count > 0) { foreach (HtmlNode childofChildNds in childNds.ChildNodes) { XmlElement OrderItemDetailsElement = xmlDoc.CreateElement("OrderItemDetails"); if (childofChildNds.InnerText.Trim() != "" && childofChildNds.InnerText.Contains("Client PriceCost") == false && childofChildNds.InnerText.Contains("Client \r\nPriceCost") == false && childofChildNds.InnerText.Trim() != "campaigntrack.com.auhelpdesk") { string str = childofChildNds.InnerText; str = str.Replace("$", "|"); String[] SplitValue = Splits(str, new char[] { '|' }); string str1 = SplitValue[0].ToString().Trim(); string str2 = SplitValue[1].ToString().Trim(); string str3 = SplitValue[2].ToString().Trim(); //MessageBox.Show(str1 + ' ' + str2 + ' ' + str3); //for (int i = 1; i < SplitValue.Length; i++) //{ // if (i != 4 && i != 10 && i != 16) { continue; } // if (str1 == " " || str2 == " " || str3 == " ") { continue; } // string str = SplitValue[i]; // XmlElement IdElement = xmlDoc.CreateElement("n"); // //cnt = cnt + 1; // IdElement.InnerText = cnt.ToString() + "_" + str1 + "|" + str2 + "|" + str3; // OrderItemDetailsElement.AppendChild(IdElement); //} if (str1 != "" || str2 != "" || str3 != "") { XmlElement IdElement = xmlDoc.CreateElement("n"); IdElement.InnerText = cnt.ToString() + "_" + str1 + "|" + str2 + "|" + str3; OrderItemDetailsElement.AppendChild(IdElement); rootElement.AppendChild(OrderItemDetailsElement); } //dsProductNotification = ProductEmailNotification(str1); //if (dsProductNotification.Tables[0].Rows.Count > 0) //{ // //(String subject,String Message,string To,string CC, bool hasattachment) // // eml.SendMail("", "", dsProductNotification.Tables[0].Rows[0]["EmailTo"].ToString(), dsProductNotification.Tables[0].Rows[0]["EmailCC"].ToString(), false); //} } } { cnt = cnt + 1; } } } } } } strd = xmlDoc.InnerXml.ToString(); strd = strd.Replace("&", "and").Replace("andamp;", " and "); strd = strd.Replace("'", "''"); DataSet ds = new DataSet(); strd = strd.Replace("\r\n",string.Empty); strd = strd.Replace(";", string.Empty); ds = ExecuteProcess(strd); xmlDoc.RemoveAll(); if (propertyId != 0 && !string.IsNullOrEmpty(location)) { ProprtyCoordinates(propertyId, location); } if (ds.Tables[0].Rows.Count > 0) { for (int j = 0; j < ds.Tables[1].Rows.Count; j++) { dsProductNotification = ProductSchedule((int)ds.Tables[1].Rows[j]["Xero_Id"]); if (dsProductNotification.Tables[0].Rows.Count > 0) { string productGroupName = string.Empty; string productGroupId = string.Empty; try { if (dsProductNotification.Tables[0].Rows[dsProductNotification.Tables[0].Rows.Count - 1]["ProductGroupId"] != null) { productGroupId = dsProductNotification.Tables[0].Rows[dsProductNotification.Tables[0].Rows.Count - 1]["ProductGroupId"].ToString(); } if (dsProductNotification.Tables[0].Rows[dsProductNotification.Tables[0].Rows.Count - 1]["ProductGroupName"] != null) { productGroupName = dsProductNotification.Tables[0].Rows[dsProductNotification.Tables[0].Rows.Count - 1]["ProductGroupName"].ToString(); } } catch { productGroupId = string.Empty; productGroupName = string.Empty; } //(String subject,String Message,string To,string CC, bool hasattachment) // eml.SendMail("", "", dsProductNotification.Tables[0].Rows[0]["EmailTo"].ToString(), dsProductNotification.Tables[0].Rows[0]["EmailCC"].ToString(), false); if (dsProductNotification.Tables[0].Rows[dsProductNotification.Tables[0].Rows.Count - 1]["Value"].ToString().Contains("@")) { // eml.SendMail(Subject, htmlDoc.DocumentNode.OuterHtml, dsProductNotification.Tables[0].Rows[0]["EmailTo"].ToString(), "", false); eml.SendMail(Subject, htmlDoc.DocumentNode.OuterHtml, "*****@*****.**", "", false); } else { DataSet dsRecordtoProcess = new DataSet(); DataTable dtRecordtoProcess = new DataTable(); dsRecordtoProcess = ReturnDataforCalenderEntry(ds.Tables[1].Rows[j]["OrderId"].ToString()); dtRecordtoProcess = dsRecordtoProcess.Tables[0]; CampaignTrack_MailScarapper.GoogleService.IGoogleNotificationService client = (CampaignTrack_MailScarapper.GoogleService.IGoogleNotificationService)new CampaignTrack_MailScarapper.GoogleService.GoogleNotificationServiceClient(); //GoogleCalSvc s = new GoogleCalSvc(); if (dtRecordtoProcess.Rows.Count > 0) { for (int i = 0; i < dtRecordtoProcess.Rows.Count; i++) { //s.CreateEvent(dtRecordtoProcess.Rows[i]["Title"].ToString(), dtRecordtoProcess.Rows[i]["Location"].ToString(), dtRecordtoProcess.Rows[i]["SalesContact"].ToString(), dtRecordtoProcess.Rows[i]["Startdate"].ToString(), dtRecordtoProcess.Rows[i]["Enddate"].ToString(), dtRecordtoProcess.Rows[i]["Comments"].ToString(), dtRecordtoProcess.Rows[i]["ProductDescription"].ToString(), dtRecordtoProcess.Rows[i]["OrderId"].ToString(), dtRecordtoProcess.Rows[i]["RequiredDate"].ToString(), dtRecordtoProcess.Rows[i]["ColorId"].ToString()); string orderItemDetails = string.Empty; if (!string.IsNullOrEmpty(productGroupId)) { orderItemDetails = "Order Item (Please do not delete or update Order Item Id) :" + dtRecordtoProcess.Rows[i]["OrderId"].ToString() + ", " + productGroupId + "-" + productGroupName; } else { orderItemDetails = "Order Item (Please do not delete or update Order Item Id) :" + dtRecordtoProcess.Rows[i]["OrderId"].ToString(); } //string description = "SalesContact : " + dtRecordtoProcess.Rows[i]["SalesContact"].ToString() + Environment.NewLine + Environment.NewLine + "Required On :" + Convert.ToDateTime(dtRecordtoProcess.Rows[i]["RequiredDate"].ToString()).ToShortDateString() + Environment.NewLine + Environment.NewLine + "Product Description :" + dtRecordtoProcess.Rows[i]["ProductDescription"].ToString() + Environment.NewLine + Environment.NewLine + "Supplier Instructions :" + dtRecordtoProcess.Rows[i]["Comments"].ToString().Replace("Supplier Instructions", "") + Environment.NewLine + Environment.NewLine + "Order Item (Please do not delete or update Order Item Id) :" + dtRecordtoProcess.Rows[i]["OrderId"].ToString() + ", " + productGroupId + "-" + productGroupName; string description = "SalesContact : " + dtRecordtoProcess.Rows[i]["SalesContact"].ToString() + Environment.NewLine + Environment.NewLine + "Required On :" + Convert.ToDateTime(dtRecordtoProcess.Rows[i]["RequiredDate"].ToString()).ToShortDateString() + Environment.NewLine + Environment.NewLine + "Product Description :" + dtRecordtoProcess.Rows[i]["ProductDescription"].ToString() + Environment.NewLine + Environment.NewLine + "Supplier Instructions :" + dtRecordtoProcess.Rows[i]["Comments"].ToString().Replace("Supplier Instructions", "") + Environment.NewLine + Environment.NewLine + orderItemDetails; //client.CreateEvent(dtRecordtoProcess.Rows[i]["Title"].ToString(), dtRecordtoProcess.Rows[i]["Location"].ToString(), dtRecordtoProcess.Rows[i]["SalesContact"].ToString(), Convert.ToDateTime(dtRecordtoProcess.Rows[i]["Startdate"].ToString()), Convert.ToDateTime(dtRecordtoProcess.Rows[i]["Enddate"].ToString()), dtRecordtoProcess.Rows[i]["Comments"].ToString(), dtRecordtoProcess.Rows[i]["ProductDescription"].ToString(), dtRecordtoProcess.Rows[i]["OrderId"].ToString(), dtRecordtoProcess.Rows[i]["RequiredDate"].ToString(), dtRecordtoProcess.Rows[i]["ColorId"].ToString(), "*****@*****.**", description, string.Empty, false); // if (s.CheckedCalendarEvent == 0) { s.CheckedCalendarEvent = 1; } //UpdateOrderEvent((int)ds.Tables[1].Rows[j]["row_id1"]);//OrderId // s.A1CreateEvent("*****@*****.**", "abc", "05-12-2013", "06-12-2013", "Test", "def", "ghi"); } } } } UpdateOrderEvent((int)ds.Tables[1].Rows[j]["row_id1"]);//OrderId } Invoice invoice = new Invoice(); invoice.Type = "ACCREC"; invoice.Contact = new Contact { Name = ds.Tables[0].Rows[0]["XeroName"].ToString() }; invoice.Date = DateTime.Today; invoice.DueDate = DateTime.Today.AddDays(30); invoice.Status = "DRAFT"; invoice.TotalTax = 0; invoice.HasAttachments = true; invoice.LineAmountTypes = XeroApi.Model.LineAmountType.Inclusive; invoice.Reference = ds.Tables[0].Rows[0]["Property"].ToString(); LineItems lineitems = new LineItems(); invoice.LineItems = new XeroApi.Model.LineItems(); for (int j = 0; j < ds.Tables[0].Rows.Count; j++) { if (ds.Tables[0].Rows[j]["CreateInvoice"].ToString() == "True") { ds.Tables[1].DefaultView.RowFilter = "OrderId='" + ds.Tables[0].Rows[j]["OrderId"].ToString() + "'"; for (int i = 0; i < ds.Tables[1].DefaultView.Count; i++) { LineItem lineItem = new LineItem(); lineItem.ItemCode = ds.Tables[1].DefaultView[i]["XeroCode"].ToString(); lineItem.Description = ds.Tables[1].DefaultView[i]["XeroItemDescription"].ToString(); lineItem.Quantity = 1; lineItem.UnitAmount = Convert.ToDecimal(ds.Tables[1].DefaultView[i]["Cost1"]); lineItem.TaxType = ds.Tables[1].DefaultView[i]["SalesTaxType"].ToString().Replace("GST on Income", "OUTPUT"); lineItem.AccountCode = ds.Tables[1].DefaultView[i]["SalesAccountCode"].ToString(); invoice.LineItems.Add(lineItem); } } } var inv = repository.Create<XeroApi.Model.Invoice>(invoice); if (invoice.ValidationStatus == ValidationStatus.ERROR) { foreach (var message in invoice.ValidationErrors) { } } try { Guid invoiceId = inv.InvoiceID; string invoiceNo = inv.InvoiceNumber; // System.Threading.Thread.Sleep(5000); string AnyAttachmentFilename = FullPath + "\\" + jpgfilename; var SalesInvoice = repository.Invoices.FirstOrDefault(it => it.InvoiceID == invoiceId); var newAttachment = repository.Attachments.Create(SalesInvoice, new FileInfo(AnyAttachmentFilename)); InsertPropertyInvoice((int)ds.Tables[1].Rows[0]["Property_Id"], invoiceNo); ds.Tables[1].DefaultView.RowFilter = string.Empty; System.Threading.Thread.Sleep(5000); } catch (Exception ex) { strLog = ex.StackTrace.ToString() + "~~~~~~~~~~~~Error~~~~~~~~~~~:" + ex.Message.ToString(); WriteLog(strLog + "For Filename :" + filename); File.Move(System.Configuration.ConfigurationSettings.AppSettings["MailPath"] + filename, System.Configuration.ConfigurationSettings.AppSettings["Error"] + filename); filename = filename.Replace("htm", "txt"); File.Move(System.Configuration.ConfigurationSettings.AppSettings["MailPath"] + filename, System.Configuration.ConfigurationSettings.AppSettings["Error"] + filename); } System.Threading.Thread.Sleep(5000); System.IO.File.Move(System.Configuration.ConfigurationSettings.AppSettings["MailPath"] + filename, System.Configuration.ConfigurationSettings.AppSettings["Archive"] + filename); //System.IO.File.Delete(System.Configuration.ConfigurationSettings.AppSettings["MailPath"] + "\\" + filename); filename = filename.Replace("htm", "txt"); //if (System.IO.File.Exists(System.Configuration.ConfigurationSettings.AppSettings["MailPath"] + "\\" + filename)) //{ System.IO.File.Delete(System.Configuration.ConfigurationSettings.AppSettings["MailPath"] + "\\" + filename); } //filename = filename.Replace("txt", "jpg"); //System.IO.File.Move(System.Configuration.ConfigurationSettings.AppSettings["MailPath"] + "\\" + filename, System.Configuration.ConfigurationSettings.AppSettings["MailPath"] + "\\Archive\\" + filename); } else { eml.SendMail("No Product Match..", "The file name is " + filename, "*****@*****.**", "", false); File.Move(System.Configuration.ConfigurationSettings.AppSettings["MailPath"] + filename, System.Configuration.ConfigurationSettings.AppSettings["NoMatch"] + filename); filename = filename.Replace("htm", "txt"); File.Move(System.Configuration.ConfigurationSettings.AppSettings["MailPath"] + filename, System.Configuration.ConfigurationSettings.AppSettings["NoMatch"] + filename); }; } } catch (Exception ex) { strLog = ex.StackTrace.ToString() + "~~~~~~~~~~~~Error~~~~~~~~~~~:" + ex.Message.ToString(); //if (strLog.Contains("at Google.Apis.Requests.ClientServiceRequest") == false) //{ eml.SendMail("Error in parsing file..", "The file name is " + filename + ". Error :- " + strLog, "*****@*****.**", "", false); WriteLog(strLog + "For Filename :" + filename); File.Move(System.Configuration.ConfigurationSettings.AppSettings["MailPath"] + filename, System.Configuration.ConfigurationSettings.AppSettings["Error"] + filename); filename = filename.Replace("htm", "txt"); File.Move(System.Configuration.ConfigurationSettings.AppSettings["MailPath"] + filename, System.Configuration.ConfigurationSettings.AppSettings["Error"] + filename); //} } return strLog; }