Пример #1
0
        public void Sample()
        {
            NuclearStorage storage  = null;
            var            customer = new Customer()
            {
                Name    = "My first customer",
                Address = "The address"
            };

            storage.AddEntity("cust-123", customer);
            storage.UpdateEntity <Customer>("cust-123", c =>
            {
                c.Address = "Customer Moved";
            });

            var result = storage.GetEntity <Customer>("cust-123").Value;

            Console.WriteLine("{0}: {1}", result.Name, result.Address);
        }
Пример #2
0
        void VerifyNonAtomic(NuclearStorage storage)
        {
            storage.AddOrUpdateEntity(1, new Entity());
            storage.GetEntity <Entity>(1);
            storage.UpdateEntity <Entity>(1, e => e.Do());
            storage.TryDeleteEntity <Entity>(1);


            storage.AddOrUpdateSingleton(() => new Entity(), e => e.Do());
            storage.UpdateSingletonEnforcingNew <Entity>(e => e.Do());
            storage.GetSingleton <Entity>();
            storage.TryDeleteSingleton <Entity>();
            storage.UpdateSingleton <Entity>(e => e.Do());


            //storage.UpdateOrAddEntity<Entity>(1, e => e.Do());
            //storage.TryDelete<Entity>(1);

            //storage.SaveSingleton(new Entity());
            //storage.GetSingleton<Entity>();
            //storage.UpdateSingleton<Entity>(e => e.Do());
            //storage.TryDeleteSingleton<Entity>();
        }
 public static TSingleton UpdateSingleton <TSingleton>(this NuclearStorage storage, Action <TSingleton> update)
     where TSingleton : new()
 {
     return(storage.Factory.GetSingletonWriter <TSingleton>().UpdateEnforcingNew(update));
 }
Пример #4
0
        protected static void HandleNuclear(NuclearMessage msg, SimpleMessageSender sender, NuclearStorage storage)
        {
            var count = storage.AddOrUpdateSingleton(() => 1, i => i + 1);

            if (count >= 2)
            {
                sender.SendBatch(new object[] {}, e => e.AddString("ok"));
                return;
            }
            sender.SendOne(new NuclearMessage());
        }
 public Handler(NuclearStorage storage, ViewUpdater <int, CustomDomainViewWithTypedKey> view, IMessageSender sender)
 {
     _storage = storage;
     _sender  = sender;
     _view    = view;
 }
Пример #6
0
 public NuclearHandler(IMessageSender sender, NuclearStorage storage)
 {
     _sender  = sender;
     _storage = storage;
 }
Пример #7
0
 private static void AssertContents(NuclearStorage setup)
 {
     Assert.AreEqual("test", setup.GetEntity <string>(1).Value);
     Assert.AreEqual(1, setup.GetSingleton <int>().Value);
 }