bool testing = false;//false true public override object CreateCalendarItem(string content) { //workApp = new Microsoft.Office.Interop.Word.Application(); //abc: string reservationsNumber = "ReservationsNumber not found"; //<div><strong>Reservation #:</strong> 1322312<br> string pattern = "<strong>Reservation #:</strong> (.*)<br>"; Regex regex = new Regex(pattern); Match match = regex.Match(content); if ((match.Success) && (match.Groups.Count > 1)) { reservationsNumber = match.Groups[1].Value; //Items appts = GetAppointmentsByReservationNumber( reservationsNumber ); //if( !testing ) // if( ( appts != null ) && ( appts.Count > 0 ) ) // return null; } /* if using the Body this alternative is not thoroughly implemented through this code * if( !match.Success ) * { * pattern = "(Reservation #: (\\d+))"; * regex = new Regex( pattern ); * match = regex.Match( content ); * if( ( match.Success ) && ( match.Groups.Count > 1 ) ) * { * reservationsNumber = match.Groups[2].Value; * } * // * } */ ConEx.Log("CreateCalendarItem: reservationsNumber={0}", reservationsNumber); Items appts = GetAppointmentsByReservationNumber(reservationsNumber); ConEx.Log("is this already present? " + ((appts != null) && (appts.Count > 0))); if (!testing) { if ((appts != null) && (appts.Count > 0)) { return(null); } } //This email was sent to [email protected] string footer = "An email address was not found"; //<strong>Spot Name:</strong> Lafayette Tennis Court #2</div> pattern = "(This email was sent to (.*))"; regex = new Regex(pattern); match = regex.Match(content); string categoryStr = tennisCat1; if ((match.Success) && (match.Groups.Count > 1)) { footer = match.Groups[1].Value; if (footer.Contains("greenflashtennis")) { categoryStr = tennisCat2; } else if (footer.Contains("gslockwood")) { categoryStr = tennisCat3; } // } footer = "<div><div><div>" + footer.TrimEnd('\r').Trim() + "</div></div></div>"; string location = "Location not found"; //<strong>Spot Name:</strong> Lafayette Tennis Court #2</div> pattern = "<strong>Spot Name:</strong> (.*)</div>"; regex = new Regex(pattern); match = regex.Match(content); if ((match.Success) && (match.Groups.Count > 1)) { location = match.Groups[1].Value; } string body = "Body not found"; string temp = content; //<div>Dear int start = temp.IndexOf("<div>Dear ");// - "<div>Dear ".Length; int end = temp.IndexOf("</td>", start) + "</td>".Length; int length = end - start; temp = temp.Substring(start, length); temp = temp.Replace("\r\n", ""); temp = temp.Replace("\t", ""); pattern = "(<div>Dear (.*))</td>"; regex = new Regex(pattern); match = regex.Match(temp); if ((match.Success) && (match.Groups.Count > 1)) { body = match.Groups[1].Value + "</div></div></div></div></div>"; } AppointmentItem newAppointment = (AppointmentItem)app.CreateItem(OlItemType.olAppointmentItem); pattern = "<strong>Activity Date:</strong> (.*)</div>"; regex = new Regex(pattern); match = regex.Match(content); if ((match.Success) && (match.Groups.Count > 1)) { string value = match.Groups[1].Value; var array = value.Split(new string[] { " to " }, StringSplitOptions.None); try { newAppointment.Start = DateTime.Parse(array[0]); newAppointment.End = DateTime.Parse(newAppointment.Start.ToShortDateString() + " " + array[1]); } catch (System.Exception) { //throw ex; } // } //GetAppointmentsInRange( newAppointment.Start.Date, newAppointment.Start.AddDays( 1 ).Date ); body += footer; newAppointment.Subject = string.Format("{0} #{1} ({2} minutes)", location, reservationsNumber, newAppointment.Duration); ItemProperty MeetingNameProperty = newAppointment.ItemProperties.Add(ReservationUserPropertyTitle, OlUserPropertyType.olText, true); MeetingNameProperty.Value = ReservationUserPropertyValue + reservationsNumber; ConEx.Log("MeetingNameProperty.Value ={0}", MeetingNameProperty.Value); newAppointment.Categories = categoryStr; body += "<div>"; ////[SpoteryReservation]='Reservation: #1364009' //body += "<strong>["+ ReservationUserPropertyTitle + "]='" + MeetingNameProperty.Value + "'</strong>"; body += "Seachable"; body += "</div>"; HTML2RTFConverter html2RTFConverter = new HTML2RTFConverter(); string newTemp = html2RTFConverter.Convert(body); newAppointment.RTFBody = Encoding.ASCII.GetBytes(newTemp); newAppointment.Save(); Items items = GetAppointmentsByReservationNumber(reservationsNumber); ConEx.Log("after save is this Now present? " + ((items != null) && (items.Count > 0))); //if( ( items != null ) && ( items.Count > 0 ) ) //{ // System.Diagnostics.Debug.WriteLine( "created and found!" ); //} /* * UserProperties userProperties = newAppointment.UserProperties; * if( userProperties != null ) * { * Console.WriteLine( userProperties.Count ); * foreach( UserProperty prop in userProperties ) * { * new System.Threading.Thread( () => * { * System.Windows.Forms.MessageBox.Show( prop.Name + " " + prop.Value ); * * } ).Start(); * * } * //Console.WriteLine( prop.Name + " " + prop.Value ); * * } */ return(newAppointment); // }
bool testing = false;//false true public override object CreateCalendarItem(string content) { ReservationParser reservationParser = new ReservationParser(content); /* * ConEx.Log(reservationParser.Reservation); * ConEx.Log(reservationParser.Location); * ConEx.Log(reservationParser.ActivityDateStart); * ConEx.Log(reservationParser.ActivityDateEnd); */ ConEx.Log("CreateCalendarItem: reservationsNumber={0}", reservationParser.Reservation); Items appts = GetAppointmentsByReservationNumber(reservationParser.Reservation); ConEx.Log("is this already present? " + ((appts != null) && (appts.Count > 0))); if (!testing) { if ((appts != null) && (appts.Count > 0)) { return(null); } } //string footer = "An email address was not found"; string footer = "<div><div><div>" + "N/A" + "</div></div></div>"; if (reservationParser.PrincipalPlayer != null) { footer = "<div><div><div>" + reservationParser.PrincipalPlayer.TrimEnd('\r').Trim() + "</div></div></div>"; } string categoryStr = tennisCat1; if (reservationParser.PrincipalPlayer.Contains("greenflashtennis")) { categoryStr = tennisCat2; } else if (reservationParser.PrincipalPlayer.Contains("gslockwood")) { categoryStr = tennisCat3; } AppointmentItem newAppointment = (AppointmentItem)app.CreateItem(OlItemType.olAppointmentItem); newAppointment.Start = reservationParser.ActivityDateStart; newAppointment.End = reservationParser.ActivityDateEnd; string body = reservationParser.Body + footer; newAppointment.Subject = string.Format("{0} #{1} ({2} minutes)", reservationParser.Location, reservationParser.Reservation, newAppointment.Duration); ItemProperty MeetingNameProperty = newAppointment.ItemProperties.Add(ReservationUserPropertyTitle, OlUserPropertyType.olText, true); MeetingNameProperty.Value = ReservationUserPropertyValue + reservationParser.Reservation; ConEx.Log("MeetingNameProperty.Value ={0}", MeetingNameProperty.Value); newAppointment.Categories = categoryStr; body += "<div>"; ////[SpoteryReservation]='Reservation: #1364009' //body += "<strong>["+ ReservationUserPropertyTitle + "]='" + MeetingNameProperty.Value + "'</strong>"; body += "Seachable"; body += "</div>"; HTML2RTFConverter html2RTFConverter = new HTML2RTFConverter(); string newTemp = html2RTFConverter.Convert(body); newAppointment.RTFBody = Encoding.ASCII.GetBytes(newTemp); if (testing) { newAppointment.Display(true); } else { newAppointment.Save(); } appts = GetAppointmentsByReservationNumber(reservationParser.Reservation); ConEx.Log("after save is this Now present? " + ((appts != null) && (appts.Count > 0))); return(newAppointment); // }