void findEvents() { Microsoft.Office.Interop.Outlook.Items objEvents; objEvents = null; History objHistory; try { objHistory = new History(); } catch (Exception ex) { System.IO.File.AppendAllText(LOGPATH, DateTime.Now.ToString() + " Error Loading History: " + ex.Message + Environment.NewLine); return; } // retrieve all events from Calendar objEvents = objCalendar.Items; // objFolder.Items; // retrict events to specified days. Restrict by <= current date + number of days and > that calculation - 1 day. // Since will run every day on a schedualer, do not want to send events already sent in previouse days emails. // this way will only look for events after date searched previouse day up to number of days to search. DateTime restrictDate = DateTime.Now.AddDays(_Days); // Date is trestricted from between current date and date provided in params. // Original: String Filter = "[Start] <= '" + restrictDate.ToString("MM/dd/yyyy") + "' AND [Start] > '" + DateTime.Now.ToString("MM/dd/yyyy") + "'"; //ISO8601: String Filter = "[Start] <= '" + String.Format("{0:yyyy/MM/dd h:m tt}", restrictDate) + "' AND [Start] > '" + String.Format("{0:M/d/yy h:m tt}", DateTime.Now) + "'" // suggested format for Outlook restrict function: String Filter = "[Start] <= '" + String.Format("{0:M/d/yyyy h:m tt}", restrictDate) + "' AND [Start] > '" + String.Format("{0:M/d/yyyy h:m tt}", DateTime.Now) + "'"; // initial test just filtering for any event <= specified number of days // String Filter = "[Start] <= '" + restrictDate.ToString("MM/dd/yyyy hh:mm tt") + "'"; objEvents = objEvents.Restrict(Filter); // iterate restricted event items, instantiate EmailEvent class and add to list for (int i = 1; i <= objEvents.Count; i++) { #if Debug try { #endif Microsoft.Office.Interop.Outlook.AppointmentItem objEvent; objEvent = (Microsoft.Office.Interop.Outlook.AppointmentItem)objEvents[i]; // double check since does not always filtering correctly apparently if (objEvent.Start <= restrictDate) { //*** 02/03/12 check if already sent // tests if history id already exists. if (objHistory.FindByID(objEvent.EntryID) != true) { if (sendEmail == false) { sendEmail = true; } EmailEvent objEmailEvent = new EmailEvent(); objEmailEvent.EndDate = objEvent.End; objEmailEvent.StartDate = objEvent.Start; objEmailEvent.Subject = objEvent.Subject; EmailEvents.Add(objEmailEvent); // save event id objHistory.AddEvent(objEvent.EntryID, objEvent.Start.ToString(@"yyyy-MM-dd"), objEvent.End.ToString(@"yyyy-MM-dd")); } } #if Debug } catch (Exception ex) { //ToDo: // add exception handling for retrieving events // continue loop for now System.IO.File.AppendAllText(LOGPATH, DateTime.Now.ToString() + " Error retrieving Event: " + ex.Message + Environment.NewLine); continue; } #endif } // persist data. SaveIDs(objHistory); if (sendEmail == true) { sendEmails(); } }
internal HistoryCollection(History objTemp) { objHistory = objTemp; }
void SaveIDs(History objTemp) { System.Xml.Serialization.XmlSerializer objXML = new System.Xml.Serialization.XmlSerializer(typeof(History)); System.IO.StreamWriter objWriter = new System.IO.StreamWriter("History.xml"); objXML.Serialize(objWriter, objTemp); objWriter.Close(); }