コード例 #1
0
ファイル: ValuesController.cs プロジェクト: Coflnet/cloud
 /// <summary>
 /// Gets the string.
 /// </summary>
 /// <returns>The string found under that key.</returns>
 /// <param name="key">Key.</param>
 public static string GetString(string key)
 {
     try
     {
         return(Encoding.UTF8.GetString(FileController.ReadAllBytes(SaveKeyWithPrefix(key))));
     }
     catch (FileNotFoundException)
     {
         return(null);
     }
 }
コード例 #2
0
ファイル: ValuesController.cs プロジェクト: Coflnet/cloud
 /// <summary>
 /// Gets an int.
 /// </summary>
 /// <returns>The int if found or -1 if an error occured.</returns>
 /// <param name="key">Key.</param>
 public static int GetInt(string key)
 {
     try
     {
         return(BitConverter.ToInt32(FileController.ReadAllBytes("data" + key), 0));
     }
     catch (FileNotFoundException)
     {
         return(-1);
     }
 }
コード例 #3
0
 /// <summary>
 /// Loads data from disc and tries to decrypt and deserialize it.
 /// </summary>
 /// <returns>The loaded object.</returns>
 /// <param name="relativePath">Path relative to the data folder.</param>
 /// <param name="createNew">Function to create a new instance of the object when not found on disc.</param>
 /// <typeparam name="T">Type to deserialize to.</typeparam>
 public T LoadObject <T>(string relativePath, Func <T> createNew = null)
 {
     if (!FileController.Exists(relativePath))
     {
         if (createNew != null)
         {
             return(createNew());
         }
         else
         {
             return((T)Activator.CreateInstance(typeof(T)));
         }
     }
     return(MessagePackSerializer.Deserialize <T>(LoadData(relativePath)));
 }
コード例 #4
0
ファイル: ReferenceManager.cs プロジェクト: Coflnet/cloud
        /// <summary>
        /// Tries to load the  reference from disc.
        /// </summary>
        /// <returns><c>true</c>, if load resource was tryed, <c>false</c> otherwise.</returns>
        /// <param name="id">Identifier.</param>
        /// <param name="data">Data.</param>
        /// <typeparam name="T">The 1st type parameter.</typeparam>
        public bool TryLoadReference(EntityId id, out InnerReference <Entity> data, bool cache = true)
        {
            var path = $"res/{id.ToString()}";

            if (!FileController.Exists(path))
            {
                data = null;
                return(false);
            }
            var bytes  = DataController.Instance.LoadData(path);
            var result = MessagePack.MessagePackSerializer.Typeless.Deserialize(bytes)
                         as InnerReference <Entity>;

            if (cache)
            {
                references[id] = result;
            }
            data = result;
            return(true);
        }
コード例 #5
0
ファイル: KeyPairManager.cs プロジェクト: Coflnet/cloud
 public void Save()
 {
     FileController.SaveAs("coflnet_keyPairs", keys);
     FileController.SaveAs("signingKeys", signingKeyPairs);
 }
コード例 #6
0
ファイル: ValuesController.cs プロジェクト: Coflnet/cloud
 /// <summary>
 /// Sets the value.
 /// Objects save this way have to have DataContract or <see cref="MessagePack.MessagePackObjectAttribute"/> attribute
 /// </summary>
 /// <param name="key">Key.</param>
 /// <param name="value">Value.</param>
 /// <typeparam name="T">The 1st type parameter.</typeparam>
 public static void SetValue <T>(string key, T value)
 {
     FileController.SaveAs(SaveKeyWithPrefix(key), value);
 }
コード例 #7
0
ファイル: ValuesController.cs プロジェクト: Coflnet/cloud
 /// <summary>
 /// Deletes the key.
 /// </summary>
 /// <param name="key">Key.</param>
 public static void DeleteKey(string key)
 {
     FileController.Delete(SaveKeyWithPrefix(key));
 }
コード例 #8
0
ファイル: ValuesController.cs プロジェクト: Coflnet/cloud
 /// <summary>
 /// Sets an int.
 /// </summary>
 /// <param name="key">Key under which to save the int.</param>
 /// <param name="value">The int which to save.</param>
 public static void SetInt(string key, int value)
 {
     FileController.WriteAllBytes(SaveKeyWithPrefix(key), BitConverter.GetBytes(value));
 }
コード例 #9
0
ファイル: ValuesController.cs プロジェクト: Coflnet/cloud
 /// <summary>
 /// Saves a string to disc
 /// </summary>
 /// <param name="key">Key under which to save the string.</param>
 /// <param name="value">Value.</param>
 public static void SetString(string key, string value)
 {
     FileController.WriteAllBytes(SaveKeyWithPrefix(key), Encoding.UTF8.GetBytes(value));
 }
コード例 #10
0
ファイル: ValuesController.cs プロジェクト: Coflnet/cloud
 /// <summary>
 /// Hases the key.
 /// </summary>
 /// <returns><c>true</c>, if key exists, <c>false</c> otherwise.</returns>
 /// <param name="key">Key to search for.</param>
 public static bool HasKey(string key)
 {
     return(FileController.Exists(SaveKeyWithPrefix(key)));
 }
コード例 #11
0
ファイル: ValuesController.cs プロジェクト: Coflnet/cloud
 /// <summary>
 /// Gets the value.
 /// </summary>
 /// <returns>The value.</returns>
 /// <param name="key">Key.</param>
 /// <typeparam name="T">The 1st type parameter.</typeparam>
 public static T GetValue <T>(string key)
 {
     return(FileController.LoadAs <T>(SaveKeyWithPrefix(key)));
 }
コード例 #12
0
 /// <summary>
 /// Saves the data after encryption
 /// </summary>
 /// <param name="path">Path relative to the data folder.</param>
 /// <param name="data">Data.</param>
 public void SaveData(string path, byte[] data)
 {
     FileController.WriteAllBytes(path, Encrypt(data));
 }
コード例 #13
0
 /// <summary>
 /// Loads data from disc and tries to decrypt it.
 /// </summary>
 /// <returns>The decrypted data.</returns>
 /// <param name="relativePath">Relative path.</param>
 public byte[] LoadData(string relativePath)
 {
     return(Decrypt(FileController.ReadAllBytes(relativePath)));
 }