/// <summary>
 /// Add an element to banlist.
 /// </summary>
 /// <param name="content">To content to be banned.</param>
 public void Add(string content)
 {
     if (!_values.ContainsKey(content))
     {
         _values.Add(content, content);
     }
 }
        public MainPage()
        {
            this.InitializeComponent();

            //DisplayProperties.AutoRotationPreferences = DisplayProperties.NativeOrientation;
            DisplayInformation.AutoRotationPreferences = DisplayInformation.GetForCurrentView().NativeOrientation;
            Loaded      += OnMainPageLoaded;
            SizeChanged += OnMainPageSizeChanged;

            // Get application settings (and later save them)
            IPropertySet propertySet = ApplicationData.Current.LocalSettings.Values;

            if (propertySet.ContainsKey("ZoomLevel"))
            {
                zoomLevel = (int)propertySet["ZoomLevel"];
            }

            if (propertySet.ContainsKey("MapStyle"))
            {
                mapStyle = (MapStyle)(int)propertySet["MapStyle"];
            }

            Application.Current.Suspending += (sender, args) =>
            {
                propertySet["ZoomLevel"] = zoomLevel;
                propertySet["MapStyle"]  = (int)mapStyle;
            };
        }
Exemple #3
0
        /// <summary>
        /// Run all required provision tasks asynchronously.
        /// </summary>
        /// <returns>Task that represents the asynchronous provision operation.</returns>
        public async Task RunProvisionTasksAsync()
        {
            foreach (var def in m_provDef)
            {
                var required = true;
                if (m_provisionHistory.ContainsKey(def.TaskName))
                {
                    var currentVersion = Version.Parse((string)m_provisionHistory[def.TaskName]);
                    required = currentVersion >= def.RequiredVersion;
                }

                if (required)
                {
                    await RunSingleProvisionTaskAsync(def);
                }
            }

            foreach (var task in m_podQueue)
            {
                var pTask = (IProvisionTask)Activator.CreateInstance(Type.GetType((string)task.Value));
                await pTask.ProvisionAsync();
            }

            m_podQueue.Clear();
        }
Exemple #4
0
        void OnMainPageLoaded(object sender, RoutedEventArgs args)
        {
            // Load application settings
            IPropertySet appData = ApplicationData.Current.LocalSettings.Values;

            // Get the page count
            int pageCount = 1;

            if (appData.ContainsKey("PageCount"))
            {
                pageCount = (int)appData["PageCount"];
            }

            // Create that many InkFileManager objects
            for (int i = 0; i < pageCount; i++)
            {
                inkFileManagers.Add(new InkFileManager(i.ToString()));
            }

            // Set the collection to the FlipView
            flipView.ItemsSource = inkFileManagers;

            // Set the SelectedIndex of the PageView
            if (appData.ContainsKey("PageIndex"))
            {
                flipView.SelectedIndex = (int)appData["PageIndex"];
            }
        }
        // A pointer back to the main page.  This is needed if you want to call methods in MainPage such
        // as NotifyUser()
        // MainPage rootPage = MainPage.Current;
        #region Constructors and Destructors

        /// <summary>
        ///     Initializes a new instance of the <see cref="SettingsFlyout" /> class.
        /// </summary>
        public SettingsFlyout()
        {
            InitializeComponent();
            FlyoutContent.Transitions = new TransitionCollection();
            FlyoutContent.Transitions.Add(
                new EntranceThemeTransition
            {
                FromHorizontalOffset =
                    (SettingsPane.Edge == SettingsEdgeLocation.Right)
                                ? ContentAnimationOffset
                                : (ContentAnimationOffset * -1)
            });

            IPropertySet settings = ApplicationData.Current.RoamingSettings.Values;

            if (settings.ContainsKey("user"))
            {
                UsernameTextBox.Text = (string)settings["user"];
            }

            if (settings.ContainsKey("pass"))
            {
                PasswordBox.Password = (string)settings["pass"];
            }

            MidThreshold        = (int)settings["MidThreshold"];
            LowThreshold        = (int)settings["LowThreshold"];
            MidRateTextBox.Text = ((int)settings["MidRate"]).ToString();
            LowRateTextBox.Text = ((int)settings["LowRate"]).ToString();
            HighestPercentDiscountTextBox.Text = ((int)settings["PctDiscount"]).ToString();
        }
Exemple #6
0
        private static void InitializeOrValidateSettings()
        {
            if (!roamingValues.ContainsKey("UserId"))
            {
                // Generate a random user id.
                roamingValues["UserId"] = Guid.NewGuid().ToString();
            }

            // Roaming websites.

            roamingWebsites = null;
            if (roamingValues.ContainsKey(WebsitesKey))
            {
                string jsonString = roamingValues[WebsitesKey].ToString();
                if (!JsonObject.TryParse(jsonString, out roamingWebsites))
                {
                    roamingWebsites = null;
                }
            }

            if (roamingWebsites == null)
            {
                roamingWebsites            = new JsonObject();
                roamingValues[WebsitesKey] = roamingWebsites.Stringify();
            }

            if (roamingWebsites == null)
            {
                // This should not be null.
                Debugger.Break();
            }

            // Local websites.

            localWebsites = null;
            if (localValues.ContainsKey(WebsitesKey))
            {
                string jsonString = localValues[WebsitesKey].ToString();
                Debug.WriteLine("Loading: {0}", jsonString);
                if (!JsonObject.TryParse(jsonString, out localWebsites))
                {
                    localWebsites = null;
                }
            }

            if (localWebsites == null)
            {
                localWebsites            = new JsonObject();
                localValues[WebsitesKey] = localWebsites.Stringify();
            }

            if (localWebsites == null)
            {
                // This should not be null.
                Debugger.Break();
            }

            SyncWebsites();
        }
Exemple #7
0
 protected override string GetUniqueVisitorId()
 {
     if (!_settings.ContainsKey(StorageKeyUniqueId))
     {
         _settings.Add(StorageKeyUniqueId, base.GetUniqueVisitorId());
     }
     return((string)_settings[StorageKeyUniqueId]);
 }
Exemple #8
0
        /// <summary>
        /// Invoked when the application is launched normally by the end user.  Other entry points
        ///     will be used when the application is launched to open a specific file, to display
        ///     search results, and so forth.
        /// </summary>
        /// <param name="args">
        /// Details about the launch request and process.
        /// </param>
        protected override async void OnLaunched(LaunchActivatedEventArgs args)
        {
            var rootFrame = Window.Current.Content as Frame;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();

                // Associate the frame with a SuspensionManager key
                SuspensionManager.RegisterFrame(rootFrame, "AppFrame");

                if (args.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    // Restore the saved session state only when appropriate
                    try
                    {
                        await SuspensionManager.RestoreAsync();
                    }
                    catch (SuspensionManagerException)
                    {
                        // Something went wrong restoring state.
                        // Assume there is no state and continue
                    }
                }

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }

            if (rootFrame.Content == null)
            {
                IPropertySet settings = ApplicationData.Current.RoamingSettings.Values;
                if (settings.ContainsKey("user"))
                {
                    // no first-time setup required
                    if (!rootFrame.Navigate(typeof(MainPage)))
                    {
                        throw new Exception("Failed to create initial page");
                    }
                }

                if (!settings.ContainsKey("MidThreshold"))
                {
                    AddDefaultSettings(settings);
                }

                if (!rootFrame.Navigate(typeof(MainPage)))
                {
                    throw new Exception("Failed to create initial page");
                }
            }

            // Ensure the current window is active
            Window.Current.Activate();
        }
        public async Task LoadAsync()
        {
            if (isLoaded)
            {
                return;
            }

            // Load previously saved ink
            StorageFolder storageFolder = ApplicationData.Current.LocalFolder;

            try
            {
                StorageFile storageFile =
                    await storageFolder.GetFileAsync("Page" + id + ".ink");

                using (IRandomAccessStream stream =
                           await storageFile.OpenAsync(FileAccessMode.Read))
                {
                    await this.InkManager.LoadAsync(stream.GetInputStreamAt(0));
                }
            }
            catch
            {
                // Do nothing if an exception occurs
            }

            // Load saved settings
            IPropertySet appData = ApplicationData.Current.LocalSettings.Values;

            // Pen size setting
            double penSize = 4;

            if (appData.ContainsKey("PenSize" + id))
            {
                penSize = (double)appData["PenSize" + id];
            }

            this.InkDrawingAttributes.Size = new Size(penSize, penSize);

            // Color setting
            if (appData.ContainsKey("Color" + id))
            {
                byte[] argb = (byte[])appData["Color" + id];
                this.InkDrawingAttributes.Color =
                    Color.FromArgb(argb[0], argb[1], argb[2], argb[3]);
            }

            // Set default drawing attributes
            UpdateAttributes();
            isLoaded = true;
        }
Exemple #10
0
 /// <summary>
 /// Saves a setting with the given key
 /// </summary>
 /// <typeparam name="T">The type of the settisg to save</typeparam>
 /// <param name="key">The key of the setting to save</param>
 /// <param name="value">The value of the new setting</param>
 /// <param name="overwrite">Indicates wheter or not to overwrite an already existing setting</param>
 public static void Save <T>([NotNull] String key, T value, bool overwrite = true)
 {
     if (Settings.ContainsKey(key))
     {
         if (overwrite)
         {
             Settings[key] = value;
         }
     }
     else
     {
         Settings.Add(key, value);
     }
 }
        private void LoadState()
        {
            IPropertySet state = ApplicationData.Current.LocalSettings.Values;

            if (state.ContainsKey(AngleKey))
            {
                //_rotationY = ((IPropertyValue)state[AngleKey]).GetSingle();
            }

            if (state.ContainsKey(TrackingKey))
            {
                //_tracking = ((IPropertyValue)state[TrackingKey]).GetBoolean();
                //state.Remove(TrackingKey);
            }
        }
        public void SaveState()
        {
            IPropertySet state = ApplicationData.Current.LocalSettings.Values;

            if (state.ContainsKey(AngleKey))
            {
                state.Remove(AngleKey);
            }
            if (state.ContainsKey(TrackingKey))
            {
                state.Remove(TrackingKey);
            }

            state.Add(AngleKey, PropertyValue.CreateSingle(_rotationY));
            state.Add(TrackingKey, PropertyValue.CreateBoolean(_tracking));
        }
Exemple #13
0
        protected override Task OnLaunchApplicationAsync(LaunchActivatedEventArgs args)
        {
            IPropertySet roamingProperties = ApplicationData.Current.RoamingSettings.Values;

            if (roamingProperties.ContainsKey("HasBeenHereBefore"))
            {
                // The normal case
                return(LaunchApplicationAsync(PageTokens.WebViewPage, null));
            }
            else
            {
                // The first-time case -- Go to the aria2c-rpc service download page
                // The URI to launch
                string uriToLaunch = @"http://www.trevalim.fr/download/aria2c-rpc-service-installer/";

                // Create a Uri object from a URI string
                var uri = new Uri(uriToLaunch);

                // Launch the URI
                async void LaunchDownload()
                {
                    // Launch the URI
                    var success = await Windows.System.Launcher.LaunchUriAsync(uri);
                }

                LaunchDownload();
                roamingProperties["HasBeenHereBefore"] = bool.TrueString; // Doesn't really matter what
                return(LaunchApplicationAsync(PageTokens.WebViewPage, null));
            }
        }
        internal static byte[] GetCacheValue(IPropertySet containerValues)
        {
            if (!containerValues.ContainsKey(CacheValueLength))
            {
                return null;
            }

            int encyptedValueLength = (int)containerValues[CacheValueLength];
            int segmentCount = (int)containerValues[CacheValueSegmentCount];

            byte[] encryptedValue = new byte[encyptedValueLength];
            if (segmentCount == 1)
            {
                encryptedValue = (byte[])containerValues[CacheValue + 0];
            }
            else
            {
                for (int i = 0; i < segmentCount - 1; i++)
                {
                    Array.Copy((byte[])containerValues[CacheValue + i], 0, encryptedValue, i * MaxCompositeValueLength, MaxCompositeValueLength); 
                }
            }

            Array.Copy((byte[])containerValues[CacheValue + (segmentCount - 1)], 0, encryptedValue, (segmentCount - 1) * MaxCompositeValueLength, encyptedValueLength - (segmentCount - 1) * MaxCompositeValueLength);
            return CryptographyHelper.Decrypt(encryptedValue);
        }
Exemple #15
0
        /// <inheritdoc/>
        public void SetValue <T>(string key, T value, bool overwrite = true)
        {
            // Convert the value
            object serializable;

            if (typeof(T).IsEnum)
            {
                Type type = Enum.GetUnderlyingType(typeof(T));
                serializable = Convert.ChangeType(value, type);
            }
            else if (typeof(T).IsPrimitive || typeof(T) == typeof(string))
            {
                serializable = value;
            }
            else if (typeof(T) == typeof(DateTime))
            {
                serializable = Unsafe.As <T, DateTime>(ref value).ToBinary();
            }
            else
            {
                ThrowHelper.ThrowArgumentException("Invalid setting type.");

                return;
            }

            // Store the new value
            if (!SettingsStorage.ContainsKey(key))
            {
                SettingsStorage.Add(key, serializable);
            }
            else if (overwrite)
            {
                SettingsStorage[key] = serializable;
            }
        }
 internal static void RemoveValue(this IPropertySet self, String key)
 {
     if (self.ContainsKey(key))
     {
         self.Remove(key);
     }
 }
        internal byte[] GetCacheValue(IPropertySet containerValues)
        {
            if (!containerValues.ContainsKey(CacheValueLength))
            {
                return(null);
            }

            int encyptedValueLength = (int)containerValues[CacheValueLength];
            int segmentCount        = (int)containerValues[CacheValueSegmentCount];

            byte[] encryptedValue = new byte[encyptedValueLength];
            if (segmentCount == 1)
            {
                encryptedValue = (byte[])containerValues[CacheValue + 0];
            }
            else
            {
                for (int i = 0; i < segmentCount - 1; i++)
                {
                    Array.Copy((byte[])containerValues[CacheValue + i], 0, encryptedValue, i * MaxCompositeValueLength, MaxCompositeValueLength);
                }
            }

            Array.Copy((byte[])containerValues[CacheValue + (segmentCount - 1)], 0, encryptedValue, (segmentCount - 1) * MaxCompositeValueLength, encyptedValueLength - (segmentCount - 1) * MaxCompositeValueLength);
            return(_cryptographyManager.Decrypt(encryptedValue));
        }
 internal static string GetValue(this IPropertySet self, String key)
 {
     if (self.ContainsKey(key))
     {
         return(self[key] as String);
     }
     return(null);
 }
Exemple #19
0
 private static void Save <T>(string key, T value, IPropertySet values)
 {
     if (values.ContainsKey(key))
     {
         values.Remove(key);
     }
     values.Add(key, value);
 }
Exemple #20
0
        private static string ReadContent(IPropertySet set, string key)
        {
            if (set.ContainsKey(key))
            {
                return(set[key] as string);
            }

            return(string.Empty);
        }
        public void SetProperties(IPropertySet configuration)
        {
            this.propertySet = configuration;

            if (propertySet.ContainsKey("compositionPropertySet"))
            {
                compositionPropertySet = (CompositionPropertySet)propertySet["compositionPropertySet"];
            }
        }
Exemple #22
0
        /// <summary>
        /// Returns stored user wallet address
        /// </summary>
        /// <returns>User wallet address</returns>
        public string GetStoredUserWalletKey()
        {
            if (_settings.ContainsKey(UserWalletSettingsKey))
            {
                return(_settings[UserWalletSettingsKey] as string);
            }

            return(null);
        }
        public static string GetError()
        {
            if (Values.ContainsKey("error"))
            {
                return(Values["error"] as string);
            }

            return(null);
        }
Exemple #24
0
        public static T GetValue <T>(this IPropertySet set, string key, T defaul)
        {
            if (!set.ContainsKey(key))
            {
                return(defaul);
            }

            return((T)set[key]);
        }
 /// <summary>Get an object of type T from settings using the specified key</summary>
 /// <typeparam name="T">The type of the value specified by the key</typeparam>
 /// <param name="key">The key for the settings value</param>
 /// <returns>Returns a value from settings</returns>
 public T Get <T>(string key)
 {
     // If the setting doesn't exist, create it with a default value
     if (!_settingsStore.ContainsKey(key))
     {
         _settingsStore[key] = default(T);
     }
     return((T)State[key]);
 }
Exemple #26
0
 private static void SetContent(IPropertySet set, string key, string value)
 {
     if (set.ContainsKey(key))
     {
         set[key] = value;
     }
     else
     {
         set.Add(key, value);
     }
 }
 public void SetValue <T>(string key, T value)
 {
     if (!SettingsStorage.ContainsKey(key))
     {
         SettingsStorage.Add(key, value);
     }
     else
     {
         SettingsStorage[key] = value;
     }
 }
 public static void AddOrUpdate(this IPropertySet propertySet, string key, object value)
 {
     if (propertySet.ContainsKey(key))
     {
         propertySet[key] = value;
     }
     else
     {
         propertySet.Add(key, value);
     }
 }
 public void Remove(string key, IPropertySet values, ApplicationDataContainer container)
 {
     if (values.ContainsKey(key))
     {
         values.Remove(key);
     }
     if (container.Containers.ContainsKey(key))
     {
         container.DeleteContainer(key);
     }
 }
        private void LoadIterationNumber()
        {
            IPropertySet localValues = ApplicationData.Current.LocalSettings.Values;

            if (localValues.ContainsKey(taskIdString))
            {
                iteration = (int)localValues[taskIdString] + 1;
            }

            iteration = 1;
        }
 public void PutSetting <T>(string property, T value)
 {
     if (_values.ContainsKey(property))
     {
         _values[property] = value;
     }
     else
     {
         _values.Add(property, value);
     }
 }
        private static string ReadContent(IPropertySet set, string key)
        {
            if (set.ContainsKey(key))
            {
                return set[key] as string;
            }

            return string.Empty;
        }
 private static void SetContent(IPropertySet set, string key, string value)
 {
     if (set.ContainsKey(key))
     {
         set[key] = value;
     }
     else
     {
         set.Add(key, value);
     }
 }