예제 #1
0
        internal static bool Execution(SandboxDataValue value)
        {
            Logger.Trace("Start Execution(SandboxDataValue ", value, ")");
            var ret = _plugin.Execution(value.Value);

            Logger.Trace("End IsRestart()");
            return(ret);
        }
예제 #2
0
        internal static bool AddAction(SandboxDataValue value)
        {
            Logger.Trace("Start AddAction(SandboxData action)");
            Logger.Debug("Action is", value.ToJson());
            if (value != null)
            {
                ExchangeData.Enqueue(value);
            }
            Logger.Debug("Start ActionsStart()");


            actionsStart();
            Logger.Trace("End AddAction(SandboxData action)");
            return(true);
        }
        private static SandboxDataValue createOnAction(ISubstance value, Guid self, string eventName)
        {
            SandboxDataValue data = null;

            Logger.Trace($"Start createOnAction {self}.{eventName}");
            if (value is ISubstance)
            {
                data = new SandboxDataValue()
                {
                    From = self, EventName = eventName, TheType = value?.GetType(), Value = value
                };
            }
            else
            {
                Logger.Error("value is not ISubstance", value.ToJson());
            }
            Logger.Trace("End createOnAction");
            return(data);
        }
        internal static void Action(SandboxDataValue value)
        {
            Logger.Trace("Start  Action(SandboxDataValue ", value, ")");
            var data = value;

            if (ActionConnections.TryGetValue($"{data.From}.{data.EventName}", out ActionConfig info))
            {
                data.To        = info.Events;
                data.Controled = info.Controled;
            }
            try
            {
                Logger.Trace("Start  Action invoke", data.ToJson());

                Task.Run(() => OnAction?.Invoke(data));
            }
            catch (Exception ex)
            {
                Logger.Fatal(ex);
            }

            Logger.Trace("End  Action(SandboxDataValue value, string eventName)");
        }
        internal static bool Action(SandboxDataValue data)
        {
            var ret = false;

            Logger.Trace("Start  Action<T>(T action)");

            var val = data.Value;

            foreach (var item in data.To)
            {
                if (_plugins.TryGetValue(item.Key, out IConfiguration pl))
                {
                    if (!_methods.TryGetValue(pl, out ConcurrentDictionary <Type, MethodInfo> mt))
                    {
                        mt           = new ConcurrentDictionary <Type, MethodInfo>();
                        _methods[pl] = mt;
                    }

                    if (!mt.TryGetValue(data.TheType, out MethodInfo method))
                    {
                        method           = pl.GetType().GetMethod("Action").MakeGenericMethod(new Type[] { data.TheType });
                        mt[data.TheType] = method;
                    }
                    Logger.Debug("run action", data.TheType);
                    var exec = new object[] { val, item.Value };
                    try
                    {
                        ret = (bool)method.Invoke(pl, exec);
                    }
                    catch (Exception ex)
                    {
                        Logger.Error(ex);
                        ret = false;
                    }
                    val = exec[0] as ISubstance;
                }
            }
            data.Value = val;
            if (!data.Controled)
            {
                if (_currentDeligate.TryGetValue(data, out EventDelegate onDelegate))
                {
                    onDelegate?.Invoke(val);
                }
                else if (_currentWait.TryGetValue(data, out ManualResetEvent onEvent))
                {
                    try
                    {
                        onEvent?.Set();
                    }
                    catch (Exception ex)
                    {
                        Logger.Error(ex);
                    }
                }
            }


            Logger.Trace("End  Action<T>(T action)");
            return(ret);
        }
예제 #6
0
 private static void actionDispetcherClass_OnAction(SandboxDataValue ssd)
 {
     Logger.Trace("Start actionDispetcherClass_OnAction(SandboxDataValue ", ssd, ")");
     PluginDispetcherClass.Action(ssd);
     Logger.Trace("End actionDispetcherClass_OnAction(SandboxDataValue ssd)");
 }