CreateContainer() public method

public CreateContainer ( [ name, [ disposition ) : ApplicationDataContainer
name [
disposition [
return ApplicationDataContainer
        public SettingsManager(ref MapControl MapMain)
        {
            // Check is the instance doesnt already exist.
            if (Current != null)
            {
                //if there is an instance in the app already present then simply throw an error.
                throw new Exception("Only one settings manager can exist in a App.");
            }

            // Setting the instance to the static instance field.
            Current = this;

            this.MapMain = MapMain;

            ApplicationData.Current.DataChanged += new TypedEventHandler<ApplicationData, object>(DataChangeHandler);

            // Roaming Settings
            RoamingSettings = ApplicationData.Current.RoamingSettings;

            RoamingSettings.CreateContainer("Map", ApplicationDataCreateDisposition.Always);
            RoamingSettings.CreateContainer("Appearance", ApplicationDataCreateDisposition.Always);
            

            // Local Settings
            LocalSettings = ApplicationData.Current.LocalSettings;

            LocalSettings.CreateContainer("Location", ApplicationDataCreateDisposition.Always);
        }
示例#2
0
        public void RemoveSite(string key)
        {
            Windows.Storage.ApplicationDataContainer roamingSettings = Windows.Storage.ApplicationData.Current.RoamingSettings;
            Windows.Storage.ApplicationDataContainer container       = roamingSettings.CreateContainer("hapSites", Windows.Storage.ApplicationDataCreateDisposition.Always);

            if (key != "site0")
            {
                PasswordVault vault = new PasswordVault();
                if (vault.FindAllByResource("HAP+ Credentials").Count(c => c.UserName.EndsWith(Settings[key].Address.DnsSafeHost)) == 1)
                {
                    vault.Remove(vault.FindAllByResource("HAP+ Credentials").Single(c => c.UserName.EndsWith(Settings[key].Address.DnsSafeHost)));
                }
            }

            roamingSettings.Containers["hapSites"].Values.Remove(key);
            List <string> s = new List <string>();

            s.AddRange((string[])roamingSettings.Values["sites"]);
            s.Remove(key);
            if (s.Count == 0)
            {
                roamingSettings.Containers["hapSites"].Values["site0"] = new string[] { "site0", "" };
                roamingSettings.Values["sites"] = new string[] { "site0" };
            }
            else
            {
                roamingSettings.Values["sites"] = s.ToArray();
            }
        }
示例#3
0
        async void startTimeCalculation()
        {
            while (true)
            {
                timeSpent += 5;
                if (timeSpent > 2)
                {
                    if (!localSettings.Containers.ContainsKey("userInfo"))
                    {
                        MessageDialog msgbox = new MessageDialog("Please log-in first. Go to settings from the main menu.");
                        await msgbox.ShowAsync();

                        Frame.Navigate(typeof(Views.Settings));
                        return;
                    }
                    else
                    {
                        localSettings.CreateContainer("userInfo", Windows.Storage.ApplicationDataCreateDisposition.Always);
                        double oldVal = (double)localSettings.Containers["userInfo"].Values["timeSpent"];
                        localSettings.Containers["userInfo"].Values["timeSpent"] = ((double)timeSpent) / 60 + oldVal;
                        Debug.WriteLine("Time Spent in Code updated to " + ((double)timeSpent) / 60 + oldVal);
                    }
                    timeSpent = 0;
                }
                await Task.Delay(5000);
            }
        }
示例#4
0
 //-------------------------------------------------------------------------------------
 // Class constructor
 /// <summary>
 /// Class constructor. Scope is internal so external code cannot create instances.
 /// </summary>
 static SettingsManager()
 {
     #if !WINDOWS_PHONE
     // Initialise the _settings object
     _settings = ApplicationData.Current.LocalSettings;
     _settings.CreateContainer("main", ApplicationDataCreateDisposition.Always);
     #endif
 }
示例#5
0
 internal void CreateEmailProxiesSettings(ApplicationDataContainer localRootContainer)
 {
     if (!localRootContainer.Containers.ContainsKey(projectContainerName))
     {
         localRootContainer.CreateContainer(projectContainerName, ApplicationDataCreateDisposition.Always);
     }
     var emailProxiesSettings = localRootContainer.Containers[projectContainerName];
     CreateIpSettings(emailProxiesSettings);
 }
示例#6
0
 public void InitHandlers()
 {
     Windows.Storage.ApplicationData.Current.DataChanged += new TypedEventHandler <ApplicationData, object>(DataChangeHandler);
     Windows.Storage.ApplicationDataContainer roamingSettings = Windows.Storage.ApplicationData.Current.RoamingSettings;
     //roamingSettings.DeleteContainer("hapSites");
     Windows.Storage.ApplicationDataContainer container = roamingSettings.CreateContainer("hapSites", Windows.Storage.ApplicationDataCreateDisposition.Always);
     if (roamingSettings.Containers.ContainsKey("hapSites") && roamingSettings.Containers["hapSites"].Values.Count == 0)
     {
         roamingSettings.Containers["hapSites"].Values["site0"] = new string[] { "site0", "" };
         roamingSettings.Values["sites"] = new string[] { "site0" };
     }
 }
示例#7
0
 private void CreateIpSettings(ApplicationDataContainer emailProxiesContainer)
 {
     if (!emailProxiesContainer.Containers.ContainsKey(ipContainerName))
     {
         emailProxiesContainer.CreateContainer(ipContainerName, ApplicationDataCreateDisposition.Always);
     }
     var ipSettings = emailProxiesContainer.Containers[ipContainerName].Values;
     ipSettings["MinBufferSize"] = (uint)1024;
     ipSettings["MaxBufferSize"] = (uint)65536;
     ipSettings["LogResponse"] = (bool)true;  //TODO this mist be set to false!!!!
     ipSettings["Timeout"] = (uint)1000;
     }
示例#8
0
        public void AddSite(HAPSetting value)
        {
            Windows.Storage.ApplicationDataContainer roamingSettings = Windows.Storage.ApplicationData.Current.RoamingSettings;
            Windows.Storage.ApplicationDataContainer container       = roamingSettings.CreateContainer("hapSites", Windows.Storage.ApplicationDataCreateDisposition.Always);
            roamingSettings.Containers["hapSites"].Values[value.Name] = value.ToString();
            List <string> s = new List <string>();

            s.AddRange((string[])roamingSettings.Values["sites"]);
            if (!s.Contains(value.Name))
            {
                s.Add(value.Name);
            }
            roamingSettings.Values["sites"] = s.ToArray();
        }
        private void DemoDataPersistenceCodeThroughSettings()
        {
            // Persisting simple Application Settings.
            localSettings.Values["CurrentReadingBook"]          = "Migrating to Windows Phone";
            roamingSettings.Values["LastPageReadOnCurrentBook"] = 20;

            // Organizing settings in containers.
            Windows.Storage.ApplicationDataContainer container = localSettings.CreateContainer("FavoriteBooks", Windows.Storage.ApplicationDataCreateDisposition.Always);
            if (localSettings.Containers.ContainsKey("FavoriteBooks"))
            {
                localSettings.Containers["FavoriteBooks"].Values["FavoriteWindowsPhoneBook"] = "Windows Phone Recipes";
            }


            // Reading settings back.
            string currentBook = string.Empty;
            int    lastPageReadOnCurrentBook;

            if (localSettings.Values["CurrentReadingBook"] != null)
            {
                currentBook = localSettings.Values["CurrentReadingBook"].ToString();
            }

            if (roamingSettings.Values["LastPageReadOnCurrentBook"] != null)
            {
                lastPageReadOnCurrentBook = Convert.ToInt16(roamingSettings.Values["LastPageReadOnCurrentBook"]);
            }

            bool   hasFavoritesContainer    = localSettings.Containers.ContainsKey("FavoriteBooks");
            string favoriteWindowsPhoneBook = string.Empty;

            if (hasFavoritesContainer)
            {
                if (localSettings.Containers["FavoriteBooks"].Values.ContainsKey("FavoriteWindowsPhoneBook"))
                {
                    favoriteWindowsPhoneBook = localSettings.Containers["FavoriteBooks"].Values["FavoriteWindowsPhoneBook"].ToString();
                }
            }


            // Deleting Settings from Storage.
            localSettings.Values.Remove("CurrentReadingBook");
            roamingSettings.Values.Remove("LastPageReadOnCurrentBook");
            localSettings.DeleteContainer("FavoriteBooks");
        }
示例#10
0
 /// <summary>
 /// 创建容器
 /// </summary>
 /// <param name="ContainerName">容器的名字</param>
 /// <returns></returns>
 Windows.Storage.ApplicationDataContainer CreatContainer(object ContainerName)
 {
     return(localSetting.CreateContainer(ContainerName.ToString(), Windows.Storage.ApplicationDataCreateDisposition.Always));
 }
示例#11
0
		private static void WriteSetting(ApplicationDataContainer container, string containerName, string name, string value)
		{
			var selectedcontainer = !container.Containers.ContainsKey(containerName)
				? container.CreateContainer(containerName, ApplicationDataCreateDisposition.Always)
				: container.Containers[containerName];

			if (selectedcontainer.Values.ContainsKey(name))
				selectedcontainer.Values[name] = value;
			else
				selectedcontainer.Values.Add(name, value);
		}
示例#12
0
 /// <summary>
 /// 创建设置容器
 /// </summary>
 /// <param name="containerName"></param>
 /// <returns></returns>
 private static Windows.Storage.ApplicationDataContainer CreateContainer(string containerName)
 {
     return(localSettings.CreateContainer(containerName, Windows.Storage.ApplicationDataCreateDisposition.Always));
 }
示例#13
0
        private void SaveConnection(ApplicationDataContainer store, ConnectionOptions conn)
        {
            ApplicationDataContainer connStore;
            if (!store.Containers.TryGetValue("connection", out connStore))
            {
                connStore = store.CreateContainer("connection", ApplicationDataCreateDisposition.Always);
            }

            connStore.Values["scheme"] = conn.Scheme;
            connStore.Values["host"] = conn.Host;
            connStore.Values["port"] = conn.Port;
            connStore.Values["base"] = conn.Base;
            connStore.Values["username"] = conn.Username;
            connStore.Values["password"] = conn.Password;
        }
示例#14
0
        private async void Login(object sender, RoutedEventArgs e)
        {
            LoadingBar.IsEnabled  = true;
            LoadingBar.Visibility = Visibility.Visible;

            if (username.Text == "" & email.Text == "")
            {
                MessageDialog messageDialog = new MessageDialog("Please fill atleast one of email/username fields");
                await messageDialog.ShowAsync();

                return;
            }
            if (passwordbox.Password == "")
            {
                MessageDialog messageDialog = new MessageDialog("Please enter your password");
                await messageDialog.ShowAsync();

                return;
            }

            var client = new Windows.Web.Http.HttpClient();
            HttpStringContent content = new HttpStringContent(
                "{ \"Username\": \"" + username.Text + "\", \"Password\": \"" + passwordbox.Password + "\" }",
                UnicodeEncoding.Utf8,
                "application/json");

            Debug.WriteLine(content);

            var uri = new Uri("http://codeinn-acecoders.rhcloud.com:8000/users/login");

            var response = await client.PostAsync(uri, content);

            var result = await response.Content.ReadAsStringAsync();

            if (response.StatusCode == HttpStatusCode.Ok)
            {
                Debug.WriteLine("Accepted");
                MessageDialog messageDialog = new MessageDialog(result);
                messageDialog.ShowAsync();
            }
            else
            {
                Debug.WriteLine("Rejected " + response.StatusCode);
                MessageDialog messageDialog = new MessageDialog(result);
                await messageDialog.ShowAsync();

                LoadingBar.IsEnabled  = false;
                LoadingBar.Visibility = Visibility.Collapsed;
                return;
            }

            // Query online database first to check if the user is valid.
            recreateTables <Problems>();
            recreateTables <Examples>();
            recreateTables <Tips>();
            recreateTables <Lessons>();

            Windows.Storage.ApplicationDataContainer container =
                localSettings.CreateContainer("userInfo", Windows.Storage.ApplicationDataCreateDisposition.Always);

            if (localSettings.Containers.ContainsKey("userInfo"))
            {
                localSettings.Containers["userInfo"].Values["userName"]          = username.Text;
                localSettings.Containers["userInfo"].Values["userEmail"]         = email.Text;
                localSettings.Containers["userInfo"].Values["userPass"]          = passwordbox.Password;
                localSettings.Containers["userInfo"].Values["lastcheckexamples"] = "2014-01-01T01:01:01Z";
                localSettings.Containers["userInfo"].Values["lastcheckproblems"] = "2014-01-01T01:01:01Z";
                localSettings.Containers["userInfo"].Values["lastchecklessons"]  = "2014-01-01T01:01:01Z";
                localSettings.Containers["userInfo"].Values["lastchecktips"]     = "2014-01-01T01:01:01Z";
                double timeSpent = 0;
                localSettings.Containers["userInfo"].Values["timeSpent"] = ((double)timeSpent) / 60;
            }

            await populateSolvedData();

            LoadingBar.IsEnabled  = false;
            LoadingBar.Visibility = Visibility.Collapsed;
        }