Ejemplo n.º 1
0
 /// <summary>
 /// </summary>
 /// <returns>
 /// </returns>
 public static Settings GetDefaultSettings()
 {
     var settings = new Settings
     {
         IsFirstSave = true,
         SettingsVersion = ApplicationInfo.Version,
         AppSettings = new AppSettings
         {
             MinimizeToSystemTray = true,
             CheckForUpdates = true,
             PeriodicSyncOn = true,
             RunApplicationAtSystemStartup = true,
             ProxySettings = new ProxySetting
             {
                 ProxyType = ProxyType.Auto
             }
         },
         SyncProfiles = new ObservableCollection<CalendarSyncProfile>
         {
             CalendarSyncProfile.GetDefaultSyncProfile()
         },
         GoogleAccounts = new ObservableCollection<GoogleAccount>()
     };
     return settings;
 }
        private void SerializeSettingsBackgroundTask(Settings syncProfile)
        {
            if (!Directory.Exists(ApplicationDataDirectory))
            {
                Directory.CreateDirectory(ApplicationDataDirectory);
            }

            var serializer = new XmlSerializer<Settings>();
            serializer.SerializeToFile(syncProfile, SettingsFilePath);
        }
 public bool SerializeSettings(Settings syncProfile)
 {
     SerializeSettingsBackgroundTask(syncProfile);
     return true;
 }
        private void ValidateSettings(Settings result)
        {
            if (result.SyncProfiles == null)
            {
                result.SyncProfiles = new ObservableCollection<CalendarSyncProfile>();
            }

            if (result.SyncProfiles.Count == 0)
            {
                result.SyncProfiles.Add(CalendarSyncProfile.GetDefaultSyncProfile());
            }

            foreach (var syncProfile in result.SyncProfiles)
            {
                syncProfile.SetCalendarTypes();
                if (syncProfile.SyncSettings == null || syncProfile.SyncSettings.SyncFrequency == null)
                {
                    syncProfile.SyncSettings = SyncSettings.GetDefault();
                }
                else if (syncProfile.SyncSettings.SyncRangeType == SyncRangeTypeEnum.SyncEntireCalendar)
                {
                    syncProfile.SyncSettings.SyncRangeType = SyncRangeTypeEnum.SyncRangeInDays;
                    syncProfile.SyncSettings.DaysInPast = 120;
                    syncProfile.SyncSettings.DaysInFuture = 120;
                }
            }

            if (result.AppSettings == null)
            {
                result.AppSettings = new AppSettings();
            }

            if (result.AppSettings.ProxySettings == null)
            {
                result.AppSettings.ProxySettings = new ProxySetting
                {
                    ProxyType = ProxyType.Auto
                };
            }
        }
 public async Task<bool> SerializeSettingsAsync(Settings syncProfile)
 {
     await TaskEx.Run(() => SerializeSettingsBackgroundTask(syncProfile));
     return true;
 }