Inheritance: ViewModelBase
 public static void SaveSettingsData(Settings latestSettingsData)
 {
     using (var userIsoStorage = IsolatedStorageFile.GetUserStoreForApplication())
     {
         if (userIsoStorage.FileExists("settingsData.dat"))
         {
             userIsoStorage.DeleteFile("settingsData.dat");
         }
         using (var iss = userIsoStorage.CreateFile("settingsData.dat"))
         {
             SilverlightSerializer.Serialize(latestSettingsData, iss);
         }
     }
 }
 public static void SaveImplementedSettings(Settings latestImplementedSettings)
 {
     using (var userIsoStorage = IsolatedStorageFile.GetUserStoreForApplication())
     {
         if (userIsoStorage.FileExists("LastImplementedSettings.dat"))
         {
             userIsoStorage.DeleteFile("LastImplementedSettings.dat");
         }
         using (var iss = userIsoStorage.CreateFile("LastImplementedSettings.dat"))
         {
             SilverlightSerializer.Serialize(latestImplementedSettings, iss);
         }
     }
 }
        public static Settings GetSettingsData()
        {
            using (var userIsoStore = IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (userIsoStore.FileExists("settingsData.dat"))
                {
                    using (var iss = userIsoStore.OpenFile("settingsData.dat", System.IO.FileMode.Open))
                    {
                        return SilverlightSerializer.Deserialize(iss) as Settings;
                    }
                }
                else
                {
                    Settings newSettingsData = new Settings();

                    return newSettingsData;
                }
            }
        }
        /// <summary>
        /// Initializes a new instance of the MainViewModel class.
        /// </summary>
        public MainViewModel()
        {
            if (IsInDesignMode)
            {
                // Code runs in Blend --> create design time data.
            }
            else
            {
                // Code runs "for real"
            }

            _appSettings = SettingsService.GetSettingsData();
            // Set everything
            IsUsingToast = _appSettings.IsUsingToast;
            IsUsingSimpleTile = _appSettings.IsUsingSimpleTile;
            IsUsingLiveTile = _appSettings.IsUsingLiveTile;

            _pushNotificationService = new PushNotificationService();
            _pushNotificationService.GotPushUri += new System.EventHandler<GotPushUriEventArgs>(_pushNotificationService_GotPushUri);
        }
        public void GetPushSubscription(Settings _latestSettings)
        {
            _appSettings = _latestSettings;

            try
            {
                //Step 1: See if we already have a valid HttpNotificationChannel
                _notificationChannel = HttpNotificationChannel.Find(_pushChannelName);
            } catch { }

            // If we have already implemented the channel && if nothing has
            //      changed in the settings since last time
            if (_notificationChannel != null && DoSettingsMatch(_appSettings, _previousSettings))
            {
                // Step 2: Make sure we got the channel Uri appropriately
                if (_notificationChannel.ChannelUri != null)
                {
                    // Success!
                    RaiseGotPushUri(_notificationChannel.ChannelUri);
                }
                else
                {
                    // If we never got the Uri back, unbind and reset everything...
                    this.UnbindAndResetPush();
                    // Step 3: ... and re-register the event handlers
                    _notificationChannel = new HttpNotificationChannel(_pushChannelName);
                    _notificationChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(_notificationChannel_ChannelUriUpdated);
                    _notificationChannel.HttpNotificationReceived += new EventHandler<HttpNotificationEventArgs>(_notificationChannel_HttpNotificationReceived);
                    _notificationChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(_notificationChannel_ErrorOccurred);
                    // Step 4: Ask for a new Uri
                    _notificationChannel.Open();
                    // Step 5: Set the HttpNotificationChannel to handle
                    //      the appropriate push notifications
                    BindNotifications(_notificationChannel);
                }
            }
            else
            {
            // Step 3: Register the event handlers so we can handle when we get
            //      the channel information (or errors) back.
            _notificationChannel = new HttpNotificationChannel(_pushChannelName);
            _notificationChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(_notificationChannel_ChannelUriUpdated);
            _notificationChannel.HttpNotificationReceived += new EventHandler<HttpNotificationEventArgs>(_notificationChannel_HttpNotificationReceived);
            _notificationChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(_notificationChannel_ErrorOccurred);

            try
            {
            // Step 4: Ask for a new Uri
            _notificationChannel.Open();
            // Step 5: Set the HttpNotificationChannel to handle
            //      the appropriate push notifications
            BindNotifications(_notificationChannel);
            // Now that we've implememted the settings, let's save them so we can remember
            //  them next time.
            SettingsService.SaveImplementedSettings(_appSettings);
            _previousSettings = _appSettings;
            }
            catch (Exception err)
            {
            // Oops! Something went wrong, null out the channel.
            _notificationChannel = null;
            }
            }
        }
 private bool DoSettingsMatch(Settings _newSettings, Settings _oldSettings)
 {
     if ((_newSettings.IsUsingSimpleTile == _oldSettings.IsUsingSimpleTile) &&
         (_newSettings.IsUsingLiveTile == _oldSettings.IsUsingLiveTile) &&
         (_newSettings.IsUsingToast == _oldSettings.IsUsingToast))
     {
         return true;
     }
     else
     {
         return false;
     }
 }