Example #1
0
        public override DateTime ComputeNextDate(DateTime fromDate)
        {
            if (!this.IsValidValue)
            {
                TrackingManagerHelper.Trace("Unable to compute next date of days of week frequency because it's not valid");
                return(fromDate);
            }

            DateTime currentDate = fromDate;
            bool     dateOk      = false;

            while (!dateOk)
            {
                currentDate = currentDate.AddDays(1);
                // Not very elegant... but working
                if ((currentDate.DayOfWeek == DayOfWeek.Monday && this.isMonday) ||
                    (currentDate.DayOfWeek == DayOfWeek.Tuesday && this.isTuesday) ||
                    (currentDate.DayOfWeek == DayOfWeek.Wednesday && this.isWednesday) ||
                    (currentDate.DayOfWeek == DayOfWeek.Thursday && this.isThursday) ||
                    (currentDate.DayOfWeek == DayOfWeek.Friday && this.isFriday) ||
                    (currentDate.DayOfWeek == DayOfWeek.Saturday && this.isSaturday) ||
                    (currentDate.DayOfWeek == DayOfWeek.Sunday && this.isSunday))
                {
                    dateOk = true;
                }
            }
            return(currentDate);
        }
Example #2
0
        public ToodleDoApiCallResult(string api, string error, int errorId = -1)
            : this()
        {
            TrackingManagerHelper.Trace($"ToodleDoService - Error while calling api: {api} error: {error} id: {errorId}");

            this.Error    = error;
            this.ErrorId  = errorId;
            this.HasError = true;
        }
Example #3
0
        private string ComputeDeviceId()
        {
            if (Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.System.Profile.HardwareIdentification"))
            {
                HardwareToken token      = HardwareIdentification.GetPackageSpecificToken(null);
                var           hardwareId = token.Id;
                var           dataReader = DataReader.FromBuffer(hardwareId);

                byte[] bytes = new byte[hardwareId.Length];
                dataReader.ReadBytes(bytes);

                return(BitConverter.ToString(bytes).Replace("-", string.Empty));
            }
            else
            {
                TrackingManagerHelper.Trace("Could not find HardwareIdentification to have device id");
            }

            return("NA");
        }
        public async Task InitializeAsync()
        {
            try
            {
                this.metadata = await this.platformService.LoadFileAsync <SynchronizationMetadata>(SynchronizationMetadata.Filename);

                if (this.metadata == null)
                {
                    // do not use this.Workbook as it's null at this point because AttachWorkbook wasn't called yet
                    int launchCount = this.platformService.GetSettingValue <int>(CoreSettings.LaunchCount);
                    if (launchCount > 5)
                    {
                        TrackingManagerHelper.Trace("SynchronizationManager.InitializeAsync: null metadata while launch count is " + launchCount);
                    }
                    this.metadata = new SynchronizationMetadata();
                }
            }
            catch (Exception)
            {
                this.metadata = new SynchronizationMetadata();
            }
        }
        private async Task <bool> PrepareSync()
        {
            this.isRunning = true;

            if (this.metadata.ActiveProvider == SynchronizationService.None || this.provider == null)
            {
                return(false);
            }

            // if this is the first sync, clear the metada
            if (this.metadata.LastSync == DateTime.MinValue)
            {
                this.metadata.Reset();
            }

            this.metadata.ClearIgnoreList();

            // check if we have task in the Edited list with no sync id
            // in this case, move those tasks in the Added list instead
            foreach (var taskId in this.metadata.EditedTasks.Select(t => t.Key).ToList())
            {
                var task = this.workbook.Tasks.FirstOrDefault(t => t.Id == taskId);
                if (task != null && task.SyncId == null)
                {
                    TrackingManagerHelper.Trace(string.Format("SyncManagerBase - Task '{0}' in the edited task list without id, adding as new task", task.Title));
                    this.metadata.EditedTasks.Remove(taskId);
                    this.metadata.AddedTasks.Add(taskId);
                }
            }

            this.provider.OperationProgressChanged += this.OnProviderProgressChanged;
            this.provider.OperationCompleted       += this.OnProviderSynchronizationCompleted;
            this.provider.OperationFailed          += this.OnCurrentProviderSynchronizationFailed;

            return(true);
        }
Example #6
0
        public static void UpdateFromExchange(this ITask task, ExchangeTask exchangeTask)
        {
            task.Title     = exchangeTask.Subject;
            task.Priority  = exchangeTask.Importance.GetPriority();
            task.Completed = exchangeTask.Completed;
            task.Due       = exchangeTask.Due;
            task.Start     = exchangeTask.Start;

            task.SyncId = exchangeTask.Id;
            task.Note   = exchangeTask.Note;
            task.Alarm  = exchangeTask.Alarm;

            // set the progress in the task if the value is exchange is more than 0 (ie, the user has set a value - 0 being the default value for all tasks)
            // or if the task has a value which is different from the value in exchange
            if (exchangeTask.ProgressPercent > 0 || (task.Progress.HasValue && task.Progress.Value != exchangeTask.ProgressPercent))
            {
                // Progress is between 0.0 and 1.0
                task.Progress = exchangeTask.ProgressPercent / 100;
            }

            task.Modified = DateTime.Now;
            // Remove recurring if task is completed
            if (!exchangeTask.IsRecurring || exchangeTask.Completed.HasValue)
            {
                task.FrequencyType = FrequencyType.Once;
            }
            else
            {
                task.UseFixedDate = true;

                switch (exchangeTask.RecurrenceType)
                {
                case ExchangeRecurrencePattern.None:

                    break;

                case ExchangeRecurrencePattern.Daily:
                case ExchangeRecurrencePattern.DailyRegeneration:

                    if (exchangeTask.Interval == 1)
                    {
                        task.CustomFrequency = FrequencyFactory.GetCustomFrequency(FrequencyType.Daily);
                    }
                    else
                    {
                        var frequency = FrequencyFactory.GetCustomFrequency <EveryXPeriodFrequency>(FrequencyType.EveryXPeriod);
                        frequency.Scale = CustomFrequencyScale.Day;
                        frequency.Rate  = exchangeTask.Interval;

                        task.CustomFrequency = frequency;
                    }

                    task.UseFixedDate = exchangeTask.RecurrenceType == ExchangeRecurrencePattern.Daily;

                    break;

                case ExchangeRecurrencePattern.Weekly:
                case ExchangeRecurrencePattern.WeeklyRegeneration:

                    if (exchangeTask.Interval < 2)
                    {
                        int daysCount = 0;
                        var frequency = FrequencyFactory.GetCustomFrequency <DaysOfWeekFrequency>(FrequencyType.DaysOfWeek);

                        if ((exchangeTask.DaysOfWeek & ExchangeDayOfWeek.Monday) == ExchangeDayOfWeek.Monday)
                        {
                            daysCount++;
                            frequency.IsMonday = true;
                        }
                        if ((exchangeTask.DaysOfWeek & ExchangeDayOfWeek.Tuesday) == ExchangeDayOfWeek.Tuesday)
                        {
                            daysCount++;
                            frequency.IsTuesday = true;
                        }
                        if ((exchangeTask.DaysOfWeek & ExchangeDayOfWeek.Wednesday) == ExchangeDayOfWeek.Wednesday)
                        {
                            daysCount++;
                            frequency.IsWednesday = true;
                        }
                        if ((exchangeTask.DaysOfWeek & ExchangeDayOfWeek.Thursday) == ExchangeDayOfWeek.Thursday)
                        {
                            daysCount++;
                            frequency.IsThursday = true;
                        }
                        if ((exchangeTask.DaysOfWeek & ExchangeDayOfWeek.Friday) == ExchangeDayOfWeek.Friday)
                        {
                            daysCount++;
                            frequency.IsFriday = true;
                        }
                        if ((exchangeTask.DaysOfWeek & ExchangeDayOfWeek.Saturday) == ExchangeDayOfWeek.Saturday)
                        {
                            daysCount++;
                            frequency.IsSaturday = true;
                        }
                        if ((exchangeTask.DaysOfWeek & ExchangeDayOfWeek.Sunday) == ExchangeDayOfWeek.Sunday)
                        {
                            daysCount++;
                            frequency.IsSunday = true;
                        }

                        // if the weekly frequency repeat on a single day that match the due date or the start date
                        // use the WeeklyFrequency instead of DaysOfWeek
                        bool matchDaysOfWeek = (!exchangeTask.Start.HasValue && exchangeTask.Due.HasValue && exchangeTask.DaysOfWeek.ToDayOfWeek() == exchangeTask.Due.Value.DayOfWeek) ||
                                               (exchangeTask.Start.HasValue && exchangeTask.DaysOfWeek.ToDayOfWeek() == exchangeTask.Start.Value.DayOfWeek);
                        if (daysCount == 0 || (daysCount == 1 && matchDaysOfWeek))
                        {
                            task.CustomFrequency = FrequencyFactory.GetCustomFrequency(FrequencyType.Weekly);
                        }
                        else if (daysCount > 0)
                        {
                            task.CustomFrequency = frequency;
                        }
                        else
                        {
                            TrackingManagerHelper.Trace("Exchange update task weekly frequency without days");
                        }
                    }
                    else
                    {
                        var frequency = FrequencyFactory.GetCustomFrequency <EveryXPeriodFrequency>(FrequencyType.EveryXPeriod);
                        frequency.Scale = CustomFrequencyScale.Week;
                        frequency.Rate  = exchangeTask.Interval;

                        task.CustomFrequency = frequency;
                    }

                    task.UseFixedDate = exchangeTask.RecurrenceType == ExchangeRecurrencePattern.Weekly;

                    break;

                case ExchangeRecurrencePattern.Monthly:
                case ExchangeRecurrencePattern.MonthlyRegeneration:

                    if (exchangeTask.Interval < 2)
                    {
                        task.CustomFrequency = FrequencyFactory.GetCustomFrequency(FrequencyType.Monthly);
                    }
                    else
                    {
                        var frequency = FrequencyFactory.GetCustomFrequency <EveryXPeriodFrequency>(FrequencyType.EveryXPeriod);
                        frequency.Scale = CustomFrequencyScale.Month;
                        frequency.Rate  = exchangeTask.Interval;

                        task.CustomFrequency = frequency;
                    }

                    task.UseFixedDate = exchangeTask.RecurrenceType == ExchangeRecurrencePattern.Monthly;

                    break;

                case ExchangeRecurrencePattern.MonthlyRelative:
                {
                    if (exchangeTask.Interval == 1)
                    {
                        var frequency = FrequencyFactory.GetCustomFrequency <OnXDayFrequency>(FrequencyType.OnXDayOfEachMonth);
                        frequency.RankingPosition = exchangeTask.DayOfWeekIndex.ToRankingPosition();
                        frequency.DayOfWeek       = exchangeTask.DaysOfWeek.ToDayOfWeek();

                        task.CustomFrequency = frequency;
                    }
                    else if (exchangeTask.Interval > 1)
                    {
                        if (exchangeTask.Due.HasValue && exchangeTask.Due.Value.DayOfWeek == exchangeTask.DaysOfWeek.ToDayOfWeek())
                        {
                            // repeat every N month, day of the week match due date => use EveryXPeriod
                            var frequency = FrequencyFactory.GetCustomFrequency <EveryXPeriodFrequency>(FrequencyType.EveryXPeriod);
                            frequency.Rate  = exchangeTask.Interval;
                            frequency.Scale = CustomFrequencyScale.Month;

                            task.CustomFrequency = frequency;
                        }
                    }
                }

                break;

                case ExchangeRecurrencePattern.Yearly:
                case ExchangeRecurrencePattern.YearlyRegeneration:

                    if (exchangeTask.Interval < 2)
                    {
                        task.CustomFrequency = FrequencyFactory.GetCustomFrequency(FrequencyType.Yearly);
                    }
                    else
                    {
                        var frequency = FrequencyFactory.GetCustomFrequency <EveryXPeriodFrequency>(FrequencyType.EveryXPeriod);
                        frequency.Scale = CustomFrequencyScale.Year;
                        frequency.Rate  = exchangeTask.Interval;

                        task.CustomFrequency = frequency;
                    }
                    task.UseFixedDate = exchangeTask.RecurrenceType == ExchangeRecurrencePattern.Yearly;

                    break;

                default:
                    TrackingManagerHelper.Trace("ExchangeHelper - Unknown recurrence type: " + exchangeTask.RecurrenceType);
                    break;
                }
            }
        }