Example #1
0
        void SyncTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            ServiceEventLog.WriteEntry("Syncing Schoology Attendances.", EventLogEntryType.Information);
            long   ticks  = DateTime.Now.Ticks;
            String report = "";

            //this.CanStop = false;
            try
            {
                report = AttendanceControl.PullFromSchoology();
            }
            catch (SchoologyAPICall.SchoologyAPIException apiex)
            {
                String    Message = apiex.Message;
                Exception inner   = apiex.InnerException;
                while (inner != null)
                {
                    Message += Environment.NewLine + "________________________________________" + Environment.NewLine + inner.Message;
                }
                ServiceEventLog.WriteEntry(String.Format("API Call failed:{0}{1}", Environment.NewLine, Message), EventLogEntryType.Error);
                MailControler.MailToWebmaster("Schoology Sync Service Error", String.Format("Schoology Sync Service Failed with the following error:{0}{0}{1}", Environment.NewLine, Message));
            }
            catch (Exception ex)
            {
                String Message = ex.Message;
                while (ex.InnerException != null)
                {
                    ex       = ex.InnerException;
                    Message += Environment.NewLine + "________________________________________" + Environment.NewLine + ex.Message;
                }
                MailControler.MailToWebmaster("Schoology Sync Service Error", String.Format("Schoology Sync Service Failed with the following error:{0}{0}{1}", Environment.NewLine, Message));
                ServiceEventLog.WriteEntry(String.Format(Message), EventLogEntryType.Error);
            }
            //this.CanStop = true;
            ServiceEventLog.WriteEntry(report, EventLogEntryType.Information);
            ticks = DateTime.Now.Ticks - ticks;
            TimeSpan ts = new TimeSpan(ticks);

            ServiceEventLog.WriteEntry(String.Format("Syncronization Complete.  This Sync took {0}.", ts), EventLogEntryType.Information);
        }