示例#1
0
        /// <summary>
        /// Save the specified <see cref="Entity"/> and remove it from Ram.
        /// </summary>
        /// <param name="id">Identifier.</param>
        /// <param name="removeFromRam">If set to <c>true</c> remove from ram.</param>
        public void Save(EntityId id, bool removeFromRam = false)
        {
            //ValuesController.SetValue
            var data = references[id];
            //MessagePack.MessagePackSerializer.ser
            var bytes = MessagePack.MessagePackSerializer.Typeless.Serialize(data);

            var h = new PersistHelper()
            {
                reference = data,
                data      = data.Resource
            };

            //var rr = new RedundantReference<CoflnetUser>((CoflnetUser)data, ((CoflnetUser)data).Id, new CoflnetServer(11111, "", 12, new byte[16]));

            FileController.WriteAllBytes($"res/{id.ToString()}-a", MessagePack.MessagePackSerializer.Typeless.Serialize(h));
            DataController.Instance.SaveData($"{RelativeStorageFolder}/{id.ToString()}", bytes);

            if (!removeFromRam)
            {
                return;
            }

            InnerReference <Entity> reference;

            references.TryRemove(id, out reference);
        }
示例#2
0
 public static void Save()
 {
     FileController.WriteAllBytes("userSettings", MessagePackSerializer.Serialize(UserSettings));
     ValuesController.SetValue <EntityId>("currentUserIdentifier", ActiveUserId);
     ValuesController.SetValue <EntityId>("deviceId", DeviceId);
     ValuesController.SetValue <EntityId>("installationId", InstallationId);
 }
示例#3
0
 /// <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));
 }
示例#4
0
 /// <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));
 }
示例#5
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));
 }