/// Version 1.0.0 /// Last modified 24.5.2014 /// /// Copyright (C) 2014 Atte Söderlund /// /// Halyri-system is a prototype emergency call system. Its purpose is to /// demonstrate the use of the advanced capabilities available in the current /// generation smartphones in facilitating the emergency service dispatcher's /// capability to determine the nature of the emergency and to dispatch help. /// /// For more information, see the README file of this package. /// /// The MIT License (MIT) /// /// Permission is hereby granted, free of charge, to any person obtaining a copy /// of this software and associated documentation files (the "Software"), to /// deal in the Software without restriction, including without limitation the /// rights to use, copy, modify, merge, publish, distribute, sublicense, /// and/or sell copies of the Software, and to permit persons to whom the /// Software is furnished to do so, subject to the following conditions: /// /// The above copyright notice and this permission notice shall be included in /// all copies or substantial portions of the Software. /// /// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR /// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, /// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE /// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER /// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING /// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS /// IN THE SOFTWARE. /// using System; using System.Collections.Generic; using System.IO; using System.IO.IsolatedStorage; using System.Runtime.Serialization.Formatters.Binary; namespace Hake_WPF { /// Atte Söderlund /// /// The class is used to store a object specified with key. A user can add, update, get and remove the objects using the key. /// class Settings { private IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForAssembly(); private BinaryFormatter formatter = new BinaryFormatter(); private Dictionary settings = new Dictionary(); // These should be used always as keys. /// /// The key for a object that contains the endpoint address. /// public const String ENDPOINTADDRESS = "endpointAddress"; /// /// The key for a object that contains the color for an assignment that is new and urgent. /// public const String NEWURGENTSTATECOLOR = "newUrgentStateColor"; /// /// The key for a object that contains the color of the graph line. /// public const String GRAPHLINECOLOR = "graphLineColor"; /// /// The key for a object that contains the background color of the graph. /// public const String GRAPHBACKGROUNDCOLOR = "graphBackgroundColor"; /// /// The function initializes settings by reading them from settings.cfg. /// public Settings() { try { using (var stream = store.OpenFile("settings.cfg", FileMode.OpenOrCreate, FileAccess.Read)) { settings = (Dictionary)formatter.Deserialize(stream); } } catch(Exception) { } } /// /// The function adds or updates a object with the given key. /// /// The key that specifies the object. /// The object to store. public void AddOrUpdate(String key, object obj) { if (settings.ContainsKey(key)) settings.Remove(key); settings.Add(key,obj); } /// /// The function removes a object with the given key. /// /// The key that is used to remove a object. public void Remove(String key) { if (settings.ContainsKey(key)) settings.Remove(key); } /// /// The function returns object from settings that is stored using given key. /// /// Key string. /// The stored object corresponding to the key. public object Get(String key) { if (settings.ContainsKey(key)) return settings[key]; return null; } /// /// The function saves the settings to the file settings.cfg if its not in use. /// /// True if no exceptions catched and false otherwise. public bool Save() { try { using (var stream = store.OpenFile("settings.cfg", FileMode.OpenOrCreate, FileAccess.Write)) { formatter.Serialize(stream, settings); } } catch(Exception) { return false; } return true; } } }