예제 #1
0
 /// <summary>
 /// Copies the contents of one state accessor to another
 /// </summary>
 /// <param name="This"></param>
 /// <param name="destination"></param>
 public static void CopyFrom(this IStateAccessor This, IStateAccessor source)
 {
     for (int i = 0; i < source.InputParameters.Length; i++)
     {
         This[i] = source[i];
     }
 }
예제 #2
0
 public InstructionExecutor(IStateAccessor stateAccessor, bool littleEndian = false) : this()
 {
     StateAccessor = stateAccessor;
     if (littleEndian)
     {
         DataConverterUInt32 = (x) => x;
         DataConverterUInt16 = (x) => x;
     }
     else
     {
         DataConverterUInt32 = Utils.ReverseUInt32;
         DataConverterUInt16 = Utils.ReverseUInt16;
     }
 }
 public InstructionExecutor(IStateAccessor stateAccessor, bool littleEndian = false)
     : this()
 {
     StateAccessor = stateAccessor;
     if (littleEndian)
     {
         DataConverterUInt32 = (x) => x;
         DataConverterUInt16 = (x) => x;
     }
     else
     {
         DataConverterUInt32 = Utils.ReverseUInt32;
         DataConverterUInt16 = Utils.ReverseUInt16;
     }
 }
 public MinionEventHandlerFLow(IStateAccessor stateAccessor,
                               IStateHolder stateHolder,
                               IEventHandlerFactory eventHandlerFactory,
                               IStateRestorer stateRestorer,
                               IStateSavingFlow stateSavingFlow,
                               StateRecoveryOptions stateRecoveryOptions,
                               EventLoadingOptions eventLoadingOptions,
                               IEventLoader eventLoader,
                               ILogger <MinionEventHandlerFLow> logger) : base(stateAccessor,
                                                                               stateHolder,
                                                                               eventHandlerFactory,
                                                                               stateRestorer,
                                                                               stateSavingFlow,
                                                                               stateRecoveryOptions,
                                                                               logger)
 {
     _eventLoadingOptions = eventLoadingOptions;
     _eventLoader         = eventLoader;
 }
예제 #5
0
 public MasterEventHandlerFLow(IStateAccessor stateAccessor,
                               IStateHolder stateHolder,
                               IEventHandlerFactory eventHandlerFactory,
                               IStateRestorer stateRestorer,
                               IStateSavingFlow stateSavingFlow,
                               StateRecoveryOptions stateRecoveryOptions,
                               IEventSaver eventSaver,
                               IEventHandledNotificationFlow eventHandledNotificationFlow,
                               ILogger <MasterEventHandlerFLow> logger) : base(stateAccessor,
                                                                               stateHolder,
                                                                               eventHandlerFactory,
                                                                               stateRestorer,
                                                                               stateSavingFlow,
                                                                               stateRecoveryOptions,
                                                                               logger)
 {
     _eventSaver = eventSaver;
     _eventHandledNotificationFlow = eventHandledNotificationFlow;
     _logger = logger;
 }
예제 #6
0
        /// <summary>
        /// Copy only changed items into the SA
        /// </summary>
        /// <param name="sa"></param>
        /// <param name="getSourceViaKey"></param>
        /// <remarks>TODO: Move this out of the IWorkflow area, it's more reusable than that</remarks>
        public static void CopyFrom(this IStateAccessor sa,
                                    Func <string, object> getSourceViaKey)
        {
            foreach (var p in sa.InputParameters)
            {
                var original = sa[p];
                var source   = getSourceViaKey(p.Name);

                if (!Utility.Equal(source, original))
                {
                    sa[p] = source;

                    /*
                     * if (wrapper == null)
                     *  sa[p] = source;
                     * else
                     *  wrapper(() => sa[p] = source);*/
                }
            }
        }
예제 #7
0
 public StateRestorer(
     IClaptrapIdentity claptrapIdentity,
     EventLoadingOptions eventLoadingOptions,
     IStateAccessor stateAccessor,
     IInitialStateDataFactory initialStateDataFactory,
     IStateLoader stateLoader,
     IEventLoader eventLoader,
     IEventHandlerFactory eventHandlerFactory,
     IL l,
     ILogger <StateRestorer> logger)
 {
     _claptrapIdentity        = claptrapIdentity;
     _eventLoadingOptions     = eventLoadingOptions;
     _stateAccessor           = stateAccessor;
     _initialStateDataFactory = initialStateDataFactory;
     _stateLoader             = stateLoader;
     _eventLoader             = eventLoader;
     _eventHandlerFactory     = eventHandlerFactory;
     _l      = l;
     _logger = logger;
 }
예제 #8
0
 public ClaptrapActor(
     IClaptrapIdentity claptrapIdentity,
     ILogger <ClaptrapActor> logger,
     StateSavingOptions stateSavingOptions,
     IStateAccessor stateAccessor,
     IStateRestorer stateRestorer,
     IEventHandlerFLow eventHandlerFLow,
     IStateSavingFlow stateSavingFlow,
     IEventHandledNotificationFlow eventHandledNotificationFlow,
     IL l)
 {
     _claptrapIdentity             = claptrapIdentity;
     _logger                       = logger;
     _stateSavingOptions           = stateSavingOptions;
     _stateAccessor                = stateAccessor;
     _stateRestorer                = stateRestorer;
     _eventHandlerFLow             = eventHandlerFLow;
     _stateSavingFlow              = stateSavingFlow;
     _eventHandledNotificationFlow = eventHandledNotificationFlow;
     _l = l;
 }
예제 #9
0
        void SaveState(
            IDictionary <string, object> stateDictionary,
            Dictionary <string, IStateAccessor> accessors,
            object propertiesLock)
        {
            lock (propertiesLock)
            {
                foreach (KeyValuePair <string, IStateAccessor> pair in accessors)
                {
                    string         stateKey = pair.Key;
                    IStateAccessor accessor = pair.Value;

                    object accessorValue = accessor.Value;

                    if (accessorValue == null)
                    {
                        stateDictionary.Remove(stateKey);
                        continue;
                    }

                    byte[] bytes;
                    try
                    {
                        bytes = Serialize(accessorValue);
                    }
                    catch (Exception ex)
                    {
                        stateDictionary[pair.Key] = null;
                        Debug.Assert(false, "Unable to serialize state value. " + ex);
                        continue;
                    }

                    stateDictionary[stateKey] = bytes;
                }
            }
        }
예제 #10
0
 public void Execute(IStateAccessor state)
 {
     Executor(this, state);
 }
 public void Execute(IStateAccessor state)
 {
     Executor(this, state);
 }
예제 #12
0
 public void Execute(IStateAccessor state)
 {
 }
예제 #13
0
        void LoadState(
            IDictionary <string, object> stateDictionary,
            Dictionary <string, IStateAccessor> accessors,
            object propertiesLock)
        {
            lock (propertiesLock)
            {
                foreach (KeyValuePair <string, IStateAccessor> pair in accessors)
                {
                    object         stateValue;
                    string         stateKey = pair.Key;
                    IStateAccessor accessor = pair.Value;

                    if (!stateDictionary.TryGetValue(stateKey, out stateValue))
                    {
                        continue;
                    }

                    byte[] bytes = stateValue as byte[];

                    if (bytes == null)
                    {
                        Debug.Assert(false, "state value is not a byte[]");
                        continue;
                    }

                    object deserializedValue;

                    try
                    {
                        deserializedValue = Deserialize(bytes);
                    }
                    catch (Exception ex)
                    {
                        string message = "Unable to deserialize bytes. " + ex;
                        var    log     = Dependency.Resolve <ILog>();
                        log.Error(message);
                        Debug.Assert(false, message);
                        continue;
                    }

                    if (deserializedValue == null)
                    {
                        const string message = "Deserialized object should not be null.";
                        var          log     = Dependency.Resolve <ILog>();
                        log.Error(message);
                        Debug.Assert(false, message);
                        continue;
                    }

                    try
                    {
                        accessor.Value = deserializedValue;
                    }
                    catch (Exception ex)
                    {
                        var log = Dependency.Resolve <ILog>();
                        log.Error("Unable to set state value. ", ex);
                    }
                }
            }
        }
 public void Execute(IStateAccessor state)
 {
 }