Beispiel #1
0
 public NessDefinition(string name)
 {
     Condition.Requires(name).IsNotNullOrEmpty();
     this.Name           = name;
     this.ConditionStore = NaturalInMemoryStore.New().IsOf <INessCondition>();
     this.OperationStore = NaturalInMemoryStore.New().IsOf <INessOperation>();
 }
Beispiel #2
0
        /// <summary>
        /// deserializes text to a Node Store.  The node values are unhydrated.
        /// </summary>
        /// <param name="storeText"></param>
        /// <returns></returns>
        public static IStoreOf <GraphNode> HydrateNodeStore(string storeText)
        {
            var nodeStore = NaturalInMemoryStore.New().IsOf <GraphNode>();
            var list      = HydrateNodeList(storeText);

            nodeStore.SaveItems(list.ConvertListTo <IHasId, GraphNode>());
            return(nodeStore);
        }
Beispiel #3
0
 public FactoriedEvictingInMemoryStore(LogicOfTo <IStoredObjectId, IHasId> factory,
                                       LogicOfTo <IHasId, ICondition> defaultItemEvictionConditionFactory,
                                       double backgroundIntervalMSecs = 30000)
     : base(NaturalInMemoryStore.New()
            .DecorateWithEviction(NaturalInMemoryStore.New(),
                                  defaultItemEvictionConditionFactory, backgroundIntervalMSecs)
            .DecorateWithFactory(factory))
 {
 }
 public RoutingTokenizerDecoration(IForwardMovingTokenizer <T> decorated,
                                   bool overridesTokenizerRouting = true,
                                   bool tokenizeUnrecognized      = true)
     : base(decorated)
 {
     this.TokenizerStore            = NaturalInMemoryStore.New().IsOf <TokenizerItem>();
     this.OverridesTokenizerRouting = overridesTokenizerRouting;
     this.TokenizeUnrecognized      = tokenizeUnrecognized;
 }
Beispiel #5
0
        public StringStateMachineGraph(string initialState)
        {
            if (initialState == null)
            {
                throw new ArgumentNullException("initialState");
            }
            this.InitialState = initialState;
            this.CurrentState = initialState;

            this.Store = NaturalInMemoryStore.New().IsOf <StringStateTransition>();
        }
Beispiel #6
0
        public static ILogger GetFileLogger(string path)
        {
            var logger = StoreLogger.New(NaturalInMemoryStore.New().Polls());

            logger.Store.GetPoll().SetBackgroundAction(LogicOf <IStore> .New((store) =>
            {
                var dat = StoreSerializer.SerializeStore(store, ValueManagerChainOfResponsibility.NewDefault());
                Debug.WriteLine(dat);
                dat.MakeStringable().Fileable().Filing(path).Write();
            }), 100);
            return(logger);
        }
Beispiel #7
0
        protected StringStateMachineGraph(SerializationInfo info, StreamingContext context)
        {
            this.InitialState = info.GetString("InitialState");
            this.CurrentState = info.GetString("CurrentState");

            List <StringStateTransition> list = (List <StringStateTransition>)info.GetValue("list", typeof(List <StringStateTransition>));

            this.Store = NaturalInMemoryStore.New().IsOf <StringStateTransition>();
            var newList = list.ConvertListTo <IHasId, StringStateTransition>();

            this.Store.SaveItems(newList);
        }
Beispiel #8
0
 public TokenLexer(NessManager nessManager, IStoreOf <NamedNaturalInMemoryStore> storeOfStores = null)
 {
     if (storeOfStores == null)
     {
         this.StoreOfStores = NaturalInMemoryStore.New().IsOf <NamedNaturalInMemoryStore>();
     }
     else
     {
         this.StoreOfStores = storeOfStores;
     }
     this.NessManager = nessManager;
 }
        private string HandleStoreProtocolRequest(string request)
        {
            //decode the request store
            var requestStore = StoreSerializer.DeserializeStore(request, this.ValueManager);

            Condition.Requires(requestStore).IsNotNull();

            var responseStore          = NaturalInMemoryStore.New();
            Tuple <IStore, IStore> uow = new Tuple <IStore, IStore>(requestStore, responseStore);

            this.StoreProtocolLogic.Perform(uow);

            //encode the response
            var responseText = StoreSerializer.SerializeStore(uow.Item2, this.ValueManager);

            return(responseText);
        }
Beispiel #10
0
        public static IStore DeserializeStore(string data, ValueManagerChainOfResponsibility managerSet)
        {
            if (string.IsNullOrEmpty(data))
            {
                return(null);
            }

            var list  = LengthEncoder.LengthDecodeList(data);
            var store = NaturalInMemoryStore.New();

            list.WithEach(each =>
            {
                var item   = DeserializeItem(each, managerSet);
                IHasId obj = item as IHasId;
                store.SaveItem(obj);
            });
            return(store);
        }
Beispiel #11
0
        /// <summary>
        /// given the object to graph, builds a graph
        /// </summary>
        /// <param name="obj"></param>
        private void BuildGraph(object obj, Func <object, GraphPath, bool> skipFilter = null)
        {
            /*
             *  We walk each object in the graph and convert that into a GraphNode (ie. GraphPath + ManagedValue + Sequence)
             *
             */

            Condition.Requires(obj).IsNotNull();

            this.NodeStore  = NaturalInMemoryStore.New().IsOf <GraphNode>();
            this.Counter    = new Counter();
            this.SkipFilter = skipFilter;

            var rootPath = GraphPath.New();

            //build the node and recurse, maybe
            BuildNode(obj, rootPath);
        }
Beispiel #12
0
 public CLConfig(NessManager nessManager = null, IStoreOf <NamedNaturalInMemoryStore> storeOfStores = null)
 {
     if (storeOfStores == null)
     {
         this.StoreOfStores = NaturalInMemoryStore.New().IsOf <NamedNaturalInMemoryStore>();
     }
     else
     {
         this.StoreOfStores = storeOfStores;
     }
     if (nessManager == null)
     {
         this.NessManager = NessManager.New();
     }
     else
     {
         this.NessManager = nessManager;
     }
 }
Beispiel #13
0
        public static void RunTest(this ITestable testable)
        {
            Condition.Requires(testable).IsNotNull();

            var    tests            = testable.GetTests();
            var    testStore        = testable.GenerateTestInput();
            IStore testResultsStore = NaturalInMemoryStore.New();

            tests.HandleOperations(testStore, testResultsStore);

            var errors = tests.GetErrors(testResultsStore);

            if (errors != null && errors.Count > 0)
            {
                //output the stores
                testResultsStore.JoinStore(testStore);
                var dump = StoreSerializer.SerializeStore(testResultsStore, ValueManagerChainOfResponsibility.NewDefault());
                Debug.WriteLine(dump);
                throw new InvalidOperationException("test failure");
            }
        }
 public EvictingInMemoryStore(Func <IHasId, ICondition> defaultItemEvictionConditionFactory,
                              double backgroundIntervalMSecs = 30000)
     : base(NaturalInMemoryStore.New().DecorateWithEviction(
                NaturalInMemoryStore.New(), defaultItemEvictionConditionFactory.MakeLogicOfTo(), backgroundIntervalMSecs))
 {
 }
 public EventingInMemoryStore()
     : base(NaturalInMemoryStore.New().DecorateWithEvents())
 {
 }
Beispiel #16
0
 public TaskStoreDecoration(IStore store, LogicOfTo <IHasId, IExpirable> evictionPolicy)
     : base(store.IsOf <ITask>().IsOfUniqueId().Evicting(NaturalInMemoryStore.New(), evictionPolicy, 1000))
 {
 }
Beispiel #17
0
 public TaskStore(LogicOfTo <IHasId, IExpirable> evictionPolicy)
     : base(NaturalInMemoryStore.New(), evictionPolicy)
 {
 }
Beispiel #18
0
 public OperationManager()
 {
     this.Operations = NaturalInMemoryStore.New().IsOf <IOperation>();
 }
Beispiel #19
0
 public IndexFactory()
 {
     this.StoreOfBitLogic = NaturalInMemoryStore.New().IsOf <IndexingBitLogic>();
 }
Beispiel #20
0
 public InMemoryStoreOf()
     : base(NaturalInMemoryStore.New().DecorateWithIsOf <T>())
 {
 }
Beispiel #21
0
        /// <summary>
        /// provide store (with defined eviction strategies)
        /// </summary>
        /// <param name="store"></param>
        public Job(string id, LogicOfTo <IHasId, IExpirable> evictionPolicy)
            : base(StrategizedTask.NewBlank(id))
        {
            /*Overall process:
             * -create a managing task (this guy) to manage and store all of the subtasks.
             *  -the core of this managing task is a blank strategized core which is decorated
             *  with a bunch of behaviours that help accomplish the managing task's purpose.
             *
             * The layers are described below:
             * -Core
             *      -PerformLogic - on perform, injects polling strategy checkTriggers() that moves the tasks along
             *      -CancelLogic - cancels all cancellable tasks
             * -Async
             *       -Complete trigger: When all tasks complete
             *       -Error trigger:When any tasks go wrong
             * -Events
             *       -OnCancelled, release waithandle
             *       -OnComplete, release waithandle
             *       -OnError, release waithandle
             * -Polling
             *       -run checkTriggers as injected above
             *
             * The job task also contains the TaskStore which all contains all of the tasks to manage.
             *
             * RunToCompletion() kicks the job off and waits until it is complete.
             */

            //create new in memory store for the tasks to live in
            var taskStore = NaturalInMemoryStore.New().MakeTaskStore(evictionPolicy);

            this.TaskStore = taskStore;

            //get the core task (is also the Decorated property as we're a 2-layer cake at this point)
            StrategizedTask coreTask = this.Core as StrategizedTask;

            //define the Perform and Cancel Logic
            coreTask.Performs(Logic.New(
                                  () =>
            {
                //the perform task is to turn on the polling process
                this.As <IPollingDecoration>(false)
                .SetBackgroundAction(LogicOf <ITask> .New(
                                         (x) =>
                {
                    this.checkTriggers();
                })
                                     );
            }));
            coreTask.Cancels(Logic.New(() => { this.CancelTasks(); }));

            //define the action to flip the waithandle that is waited on in RunToCompletion
            Action flipWaitHandle = () =>
            {
                lock (_stateLock)
                {
                    if (this.Status == DecoratidTaskStatusEnum.Cancelled ||
                        this.Status == DecoratidTaskStatusEnum.Complete ||
                        this.Status == DecoratidTaskStatusEnum.Errored)
                    {
                        Monitor.Pulse(_stateLock);
                    }
                }
            };

            //now decorate this core task with the layers described above

            //decorate as asynch (under the hood this will decorate with Trigger Conditions). Also implies that we need a polling process to check the conditions
            ITask decoratedTask = coreTask.IsAsynchronous(
                StrategizedCondition.New(() => { return(this.AreTasksComplete()); }),
                StrategizedCondition.New(() => { return(this.HaveTasksErrored()); }));

            //decorate with event handlers to flip the wait handle
            decoratedTask = decoratedTask.Eventing().DoOnTaskCancelled(flipWaitHandle).DoOnTaskCompleted(flipWaitHandle).DoOnTaskErrored(flipWaitHandle);
            //decorate with polling without a polling strategy
            decoratedTask = decoratedTask.DecorateWithPolling();

            //set the task store
            decoratedTask.TaskStore = this.TaskStore;
            decoratedTask.Save();

            //inject decoration that we've just built
            this.ReplaceDecorated((decorated) =>
            {
                return(decoratedTask);
            });

            //subscribe to eviction event where we initiate a cancel if it happens
            this.TaskStore.ItemEvicted += Job_ItemEvicted;
        }
Beispiel #22
0
 public OperationProtocolClientDecoration(IEndPointClient decorated, ValueManagerChainOfResponsibility valueManager = null)
     : base(decorated.StoreProtocoling(valueManager))
 {
     this.RequestStore = NaturalInMemoryStore.New();
 }