Ejemplo n.º 1
0
        /// <summary>
        /// A method that deserializes a file on disk into
        /// the Dictionary object it was originally
        /// serialized from, and returns it.
        /// </summary>
        /// <param name="path">The filepath to the Dictionary you want
        /// to deserialize.</param>
        /// <returns>The deserialized dictionary.</returns>
        public static BinarySerializableDictionary <TKey, TValue> Deserialize(string path)
        {
            BinarySerializableDictionary <TKey, TValue> dict = new BinarySerializableDictionary <TKey, TValue>();

            using (FileStream stream = new FileStream(path, FileMode.Open))
            {
                dict = Serializer.Deserialize <BinarySerializableDictionary <TKey, TValue> >(stream);
            }
            return(dict);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// A method that takes the name of a file on disk,
        /// and deserialises that into the KeyValueStore
        /// member variable.
        /// </summary>
        /// <param name="name">The name of the dictionary.</param>
        /// <returns>
        /// A queryresult on whether the operation succeeded or not.
        /// </returns>
        public QueryResult LoadStore(string name)
        {
            string filePath = ConfigurationManager.AppSettings["DataStoreFilePath"] + name;

            try
            {
                KeyValueStore = BinarySerializableDictionary <string, string> .Deserialize(filePath);

                return(new QueryResult("Success", null, null));
            }
            catch (Exception e)
            {
                return(new QueryResult("Failed", e, null));
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// A constructor that initialises the KeyValueStore member variable with
 ///a default capacity.
 /// </summary>
 public DataService()
 {
     KeyValueStore = new BinarySerializableDictionary <string, string>();
 }