public ApplicationContext()
        {
            //is null in design time mode
            if (PhoneApplicationService.Current != null)
            {
                PhoneApplicationService.Current.Launching += Current_Launching;
                PhoneApplicationService.Current.Activated += Current_Activated;
                PhoneApplicationService.Current.Deactivated += Current_Deactivated;
                PhoneApplicationService.Current.Closing += Current_Closing;
            }

            //create required objects
            _dataAcquirer = new DataSource();
            ControllerClient = new PhoneControllerClient(_dataAcquirer);
            Settings = new Settings();
        }
        void Current_Launching(object sender, LaunchingEventArgs e)
        {
            //set the property value so the app can offer convenient features for the user
            if (IsolatedStorageSettings.ApplicationSettings.Contains(LastServerAddressKey))
            {
                LastServerAddress =
                    IPAddress.Parse(IsolatedStorageSettings.ApplicationSettings[LastServerAddressKey].ToString());
            }

            //restore settings
            if (IsolatedStorageSettings.ApplicationSettings.Contains(ApplicationSettingsKey))
            {
                try
                {
                    Settings = (Settings)IsolatedStorageSettings.ApplicationSettings[ApplicationSettingsKey];
                }
                catch (Exception)
                {
                    _logger.Trace("Restore of application settings from isolated storage failed.");
                    Settings = new Settings();
                }
            }
        }
        void Current_Activated(object sender, ActivatedEventArgs e)
        {
            _logger.Trace("Application activating");

            try
            {
                //try to restore some values
                if (IsolatedStorageSettings.ApplicationSettings.Contains(LastServerAddressKey))
                {
                    LastServerAddress =
                        IPAddress.Parse(IsolatedStorageSettings.ApplicationSettings[LastServerAddressKey].ToString());
                }

                if (IsolatedStorageSettings.ApplicationSettings.Contains(ControllerConfigurationKey))
                {
                    var configuration =
                        (ControllerConfiguration)
                        IsolatedStorageSettings.ApplicationSettings[ControllerConfigurationKey];
                    ControllerClient.Configure(configuration);
                }
            }
            catch (Exception ex)
            {
                _logger.Trace("Reading isolated storage communication settings failed: {0}", ex);
            }

            //only restore application settings if we were tombstoned
            if (!e.IsApplicationInstancePreserved)
            {
                if (IsolatedStorageSettings.ApplicationSettings.Contains(ApplicationSettingsKey))
                {
                    try
                    {
                        Settings = (Settings)IsolatedStorageSettings.ApplicationSettings[ApplicationSettingsKey];

                        //restore options service
                        OptionsService.Current.RestoreAfterTombstoning(Settings);
                    }
                    catch (Exception)
                    {
                        _logger.Trace("Restore of application settings from isolated storage failed.");
                        Settings = new Settings();
                    }
                }
            }
        }