Пример #1
0
        private static string SaveObjectToStorage(object tree, IObjectStorage storage)
        {
            var    jsonRepresentation = JsonConvert.SerializeObject(tree, Formatting.Indented);
            var    bytes      = Encoding.UTF8.GetBytes(jsonRepresentation);
            string hashString = Hash(bytes);

            storage.Set(hashString, new MemoryStream(bytes));
            return(hashString);
        }
 public void Intercept(Castle.DynamicProxy.IInvocation invocation)
 {
     if (setters.ContainsKey(invocation.Method))
     {
         var prop = setters[invocation.Method];
         storage.Set(prop.Name, invocation.Arguments[0]);
         obs.OnNext(prop.Name);
     }
     else if (getters.ContainsKey(invocation.Method))
     {
         invocation.ReturnValue = storage.Get(getters[invocation.Method].Name);
     }
     else
     {
         invocation.Proceed(); //DataStorageInterceptor only implements properties, not methods
     }
 }