Example #1
0
        public async override void Start()
        {
            // initialize API & authenticate if necessary
            var isAuthenticated = await Office365Api.GetInstance().Authenticate();

            // disable tracker if authentication was without success
            if (!isAuthenticated)
            {
                IsRunning = false;

                var msg = string.Format(CultureInfo.InvariantCulture, "The {0} was disabled as the authentication with Office 365 failed. Maybe you don't have an internet connection or the Office 365 credentials were wrong.\n\nThe tool will prompt the Office 365 login again with the next start of the application. You can also disable the {0} in the settings.\n\nIf the problem persists, please contact us via " + Shared.Settings.EmailAddress1 + " and attach the logfile.", Name);
                MessageBox.Show(msg, Dict.ToolName + ": Error", MessageBoxButton.OK); //todo: use toast message
                return;
            }
            else
            {
                IsRunning = true;
            }

            // Start Email Count Timer
            if (_timer != null)
            {
                Stop();
            }

            // initialize a new timer
            var interval = (int)TimeSpan.FromMinutes(Settings.SaveEmailCountsIntervalInMinutes).TotalMilliseconds;

            _timer = new Timer(new TimerCallback(TimerTick), // callback
                               null,                         // no idea
                               60000,                        // start immediately after 1 minute
                               interval);                    // interval
        }
Example #2
0
        public async void NextClicked()
        {
            if (Enable.IsChecked.HasValue)
            {
                if (Enable.IsChecked.Value)
                {
                    bool success = await Office365Api.GetInstance().Authenticate();

                    if (!success)
                    {
                        NotifyIcon notification = new NotifyIcon();
                        notification.Visible         = true;
                        notification.BalloonTipTitle = "PersonalAnalytics";
                        notification.BalloonTipText  = Settings.TrackerName + " was disabled as the authentication failed.";
                        notification.Icon            = SystemIcons.Exclamation;
                        notification.Text            = Settings.TrackerName + " was disabled as the authentication failed.";
                        notification.ShowBalloonTip(60 * 1000);
                    }

                    Leave(success);
                }
                else
                {
                    Leave(false);
                }
            }
            else
            {
                Leave(false);
            }
        }
Example #3
0
        /// <summary>
        /// Regularly runs and saves some email counts
        /// </summary>
        private static void SaveMeetingsCount(DateTimeOffset date)
        {
            try
            {
                // don't do it if already done for the date; always check for the current date
                if (date.Date != DateTime.Now.Date && // always do it for current day
                    Queries.HasMeetingEntriesForDate(date))    // only do it for past day, if there are no entries
                {
                    return;
                }

                // get meetings for the date
                var meetingsResult = Office365Api.GetInstance().LoadMeetings(date);
                meetingsResult.Wait();
                var meetings = meetingsResult.Result;

                if (meetings.Count <= 0)
                {
                    return;
                }

                // delete old entries (to add updated meetings)
                Queries.RemoveMeetingsForDate(date);

                // save new meetings into the database
                foreach (var meeting in meetings)
                {
                    var start    = DateTime.Parse(meeting.Start.DateTime).ToLocalTime();
                    var end      = DateTime.Parse(meeting.End.DateTime).ToLocalTime();
                    var duration = (int)Math.Round(Math.Abs((start - end).TotalMinutes), 0);
                    if ((meeting.IsAllDay.HasValue && meeting.IsAllDay.Value) || duration > 24 * 60)
                    {
                        continue;                                                                              // only store if not all-day/multiple-day meeting
                    }
                    if (date.Date != start.Date)
                    {
                        continue;                          // only store if the start of the meeting is the same day
                    }
                    if (meeting.ShowAs == FreeBusyStatus.Tentative)
                    {
                        continue;                                             // only store if meeting was accepted
                    }
                    var numAttendees = meeting.Attendees.Count(a => a.EmailAddress.Address != meeting.Organizer.EmailAddress.Address);
                    Queries.SaveMeetingsSnapshot(start, meeting.Subject, duration, numAttendees);
                }
            }
            catch (Exception e)
            {
                Logger.WriteToLogFile(e);
            }
        }
Example #4
0
        /// <summary>
        /// Class calls the API to determine the inbox size, number of emails sent and received.
        /// (inbox size: is only collected for date = DateTime.Now)
        /// </summary>
        /// <param name="date"></param>
        /// <param name="isFromTimer"></param>
        internal static Tuple <long, long, int, int, int> CreateEmailsSnapshot(DateTime date, bool isFromTimer)
        {
            try
            {
                // get inbox size (can only be done today)
                var unreadInbox = -1;
                var inbox       = -1;
                if (date.Date == DateTime.Now.Date)
                {
                    // unread inbox size
                    var unreadInboxSizeResponse = Office365Api.GetInstance().GetNumberOfUnreadEmailsInInbox();
                    unreadInboxSizeResponse.Wait();
                    unreadInbox = (int)unreadInboxSizeResponse.Result;

                    // total inbox size
                    var inboxSizeResponse = Office365Api.GetInstance().GetTotalNumberOfEmailsInInbox();
                    inboxSizeResponse.Wait();
                    inbox = (int)inboxSizeResponse.Result;
                }

                // get emails sent count
                var sentResult = Office365Api.GetInstance().GetNumberOfEmailsSent(date.Date);
                sentResult.Wait();
                var sent = sentResult.Result;

                // get total emails received count
                var receivedResult = Office365Api.GetInstance().GetTotalNumberOfEmailsReceived(date.Date);
                receivedResult.Wait();
                var received          = receivedResult.Result;
                var receivedCorrected = received - sent; // TODO: due to a bug which will show sent items in the received list, we subtract it (03.01.17)

                // get unread emails received count
                var unreadReceivedResult = Office365Api.GetInstance().GetNumberOfUnreadEmailsReceived(date.Date);
                unreadReceivedResult.Wait();
                var unreadReceived = unreadReceivedResult.Result;

                // save into the database
                SaveEmailsSnapshot(date, inbox, unreadInbox, sent, receivedCorrected, unreadReceived, isFromTimer);

                // return for immediate use
                return(new Tuple <long, long, int, int, int>(inbox, unreadInbox, sent, receivedCorrected, unreadReceived));
            }
            catch (Exception e)
            {
                Logger.WriteToLogFile(e);
                return(new Tuple <long, long, int, int, int>(-1, -1, -1, -1, -1));
            }
        }
Example #5
0
        /// <summary>
        /// Class calls the API to determine the inbox size, number of emails sent and received.
        /// (inbox size: is only collected for date = DateTime.Now)
        /// </summary>
        /// <param name="date"></param>
        /// <param name="isFromTimer"></param>
        internal static Tuple <long, long, long, long, int> CreateEmailsSnapshot(DateTime date, bool isFromTimer)
        {
            try
            {
                // get inbox size (can only be done today)
                var unreadInbox    = Settings.NoValueDefault;
                var inbox          = Settings.NoValueDefault;
                var unreadReceived = Settings.NoValueDefault;
                if (date.Date == DateTime.Now.Date)
                {
                    // unread inbox size
                    var unreadInboxSizeResponse = Office365Api.GetInstance().GetNumberOfUnreadEmailsInInbox();
                    unreadInboxSizeResponse.Wait();
                    unreadInbox = (int)unreadInboxSizeResponse.Result;

                    // total inbox size
                    var inboxSizeResponse = Office365Api.GetInstance().GetTotalNumberOfEmailsInInbox();
                    inboxSizeResponse.Wait();
                    inbox = (int)inboxSizeResponse.Result;

                    // get unread emails received count
                    var unreadReceivedResult = Office365Api.GetInstance().GetNumberOfUnreadEmailsReceived(date.Date);
                    unreadReceivedResult.Wait();
                    unreadReceived = unreadReceivedResult.Result;
                }

                // get emails sent count
                var sentResult = Office365Api.GetInstance().GetNumberOfEmailsSent(date.Date);
                sentResult.Wait();
                var sent = sentResult.Result;

                // get total emails received count
                var receivedResult = Office365Api.GetInstance().GetTotalNumberOfEmailsReceived(date.Date);
                receivedResult.Wait();
                var received = receivedResult.Result;

                // save into the database
                SaveEmailsSnapshot(date, inbox, unreadInbox, sent, received, unreadReceived, isFromTimer);

                // return for immediate use
                return(new Tuple <long, long, long, long, int>(inbox, unreadInbox, sent, received, unreadReceived));
            }
            catch (Exception e)
            {
                Logger.WriteToLogFile(e);
                return(new Tuple <long, long, long, long, int>(Settings.NoValueDefault, Settings.NoValueDefault, Settings.NoValueDefault, Settings.NoValueDefault, Settings.NoValueDefault));
            }
        }
Example #6
0
        /// <summary>
        /// Regularly runs and saves some email counts
        /// </summary>
        private void SaveMeetingsCount(DateTimeOffset date)
        {
            try
            {
                // don't do it if already done for the date; always check for the current date
                if (date.Date != DateTime.Now.Date && // always do it for current day
                    Queries.HasMeetingEntriesForDate(date))    // only do it for past day, if there are no entries
                {
                    return;
                }

                // get meetings for the date
                var meetingsResult = Office365Api.GetInstance().LoadMeetings(date);
                meetingsResult.Wait();
                var meetings = meetingsResult.Result;

                if (meetings.Count > 0)
                {
                    // delete old entries (to add updated meetings)
                    Queries.RemoveMeetingsForDate(date);

                    // save new meetings into the database
                    foreach (var meeting in meetings)
                    {
                        var duration = (int)Math.Round(Math.Abs((meeting.End - meeting.Start).TotalMinutes), 0);
                        if (duration >= 24 * 60)
                        {
                            continue;                      // only store if not multiple-day meeting
                        }
                        var start = meeting.Start.ToLocalTime();
                        Queries.SaveMeetingsSnapshot(start, meeting.Subject, duration);
                    }
                }
            }
            catch (Exception e)
            {
                Logger.WriteToLogFile(e);
            }
        }