示例#1
0
 // 在此初始化参数
 protected override void OnCreate()
 {
     varname  = Utility.ToVarname(parameters["var"]);
     varscope = (EScope)Utility.ToEnumInt(parameters["scope"]);
     func     = Utility.ToFunc(parameters["func"]);
     value    = Utility.ToVar(missionVars, parameters["value"]);
 }
示例#2
0
        public override EVariable Solve(EScope scope)
        {
            EVariable firstS  = first.Solve(scope);
            EVariable secondS = second.Solve(scope);

            return(op.Solve(firstS, secondS));
        }
示例#3
0
        public override EVariable Exec(EScope scope)
        {
            EVariable toUpdate = scope.Get(variable.ToString());

            toUpdate.Assign(value.Solve(scope));
            return(toUpdate);
        }
示例#4
0
        public override EVariable Solve(EScope scope)
        {
            EFunction toRun = scope.GetFunction(callFunc.ToString());

            EVariable output = toRun.Exec(scope, arguments);

            return(output);
        }
示例#5
0
        public override void LoadConfig(FXmlNode config)
        {
            // Id
            _id = config[PTY_ID];
            // Face
            _faceName = config[PTY_FACE];
            // Type
            _typeName = config[PTY_TYPE];
            // Scope
            string scope = config[PTY_SCOPE];

            if (!RString.IsEmpty(scope))
            {
                _scope = REnum.ToValue <EScope>(scope);
            }
            // Load config
            if (config.HasNode())
            {
                foreach (FXmlNode node in config.Nodes)
                {
                    if (node.IsName(XAopConstructor.TAG))
                    {
                        // Constructor
                        if (_constructor != null)
                        {
                            throw new FFatalException("Constructor can't be duplicate.\n{1}", config.Dump());
                        }
                        _constructor = new XAopConstructor();
                        _constructor.LoadConfig(node);
                    }
                    else if (node.IsName(XAopProperty.TAG))
                    {
                        // Properties
                        XAopProperty property = new XAopProperty();
                        property.LoadConfig(node);
                        _properties.Push(property);
                    }
                    else if (node.IsName(XAopInitialize.TAG))
                    {
                        // Initializes
                        XAopInitialize method = new XAopInitialize();
                        method.LoadConfig(node);
                        _initializes.Push(method);
                    }
                    else if (node.IsName(XAopRelease.TAG))
                    {
                        // Releases
                        XAopRelease method = new XAopRelease();
                        method.LoadConfig(node);
                        _releases.Push(method);
                    }
                }
            }
        }
示例#6
0
 public override EVariable Solve(EScope scope)
 {
     if (IsInteger())
     {
         return(new EVInt().Set((int)number));
     }
     else
     {
         return(new EVDouble().Set(number));
     }
 }
示例#7
0
        // Run a program
        public static EVariable Run(EProgram program, EScope scope)
        {
            // Create a variable to assign the output to
            EVariable output = new EVVoid();

            // Loop over every instruction and return the last value
            EOperation[] operations = program.GetOperations();
            foreach (EOperation operation in operations)
            {
                output = operation.Exec(scope);
            }
            return(output);
        }
示例#8
0
        public override EVariable Exec(EScope scope)
        {
            EVBoolean solved = (EVBoolean)check.Solve(scope).Convert(EType.Boolean);

            if (solved.Get())
            {
                EScope subScope = scope.GetChild();
                return(Interpreter.Run(program, subScope));
            }
            if (elseProgram != null)
            {
                EScope subScope = scope.GetChild();
                return(Interpreter.Run(elseProgram, subScope));
            }
            return(new EVVoid());
        }
示例#9
0
        public void SetKeyValue(string key, object content, EScope scope = EScope.Hidden, string userLocator = null, string appLocator = null)
        {
            if (userLocator == null)
            {
                userLocator = Current.Orchestrator?.Person?.Locator;
            }
            if (appLocator == null)
            {
                appLocator = Current.Orchestrator?.Application?.Code;
            }

            var obj = JObject.Parse(new Entry {
                Key = key, Scope = scope, Proposed = null, Value = content
            }.ToJson());

            Put(obj, userLocator, appLocator);
        }
示例#10
0
        public override EVariable Exec(EScope scope)
        {
            Func <bool> checkVar = () => (
                (EVBoolean)
                check.Solve(scope)
                .Convert(EType.Boolean)
                ).Get();

            EVariable output = new EVVoid();

            while (checkVar())
            {
                EScope subScope = scope.GetChild();
                output = Interpreter.Run(program, subScope);
            }

            return(output);
        }
示例#11
0
        public override EVariable Exec(EScope scope)
        {
            EVariable newVar = new EVVoid();

            foreach (EWord variable in variables)
            {
                newVar = EVariable.New(type);
                scope.Set(variable.ToString(), newVar);
            }

            if (assignOperations != null)
            {
                foreach (EAssignOperation assignOp in assignOperations)
                {
                    assignOp.Exec(scope);
                }
            }

            return(newVar);
        }
示例#12
0
 public static void Add(EScope scope)
 {
     scope.SetFunction("log",
                       new EGlobalFunction(
                           "log",
                           EType.Void,
                           (EScope subScope, ESolvable[] args) => {
         EVariable[] variables = args.Select(arg => arg.Solve(subScope)).ToArray();
         string toLog          = variables.Aggregate("", (prev, next) => {
             if (prev.Length == 0)
             {
                 return(prev + next);
             }
             return(prev + " " + next);
         });
         Console.WriteLine(toLog);
         return(new EVVoid());
     }
                           )
                       );
 }
示例#13
0
        public override EVariable Exec(EScope scope, ESolvable[] args)
        {
            // TODO: output type casting
            if (args.Length != arguments.Length)
            {
                throw new ELangException("Wrong amount of args for function " + name);
            }

            EScope lowerScope = scope.GetChild();

            for (int i = 0; i < arguments.Length; i++)
            {
                string    argname = arguments[i].GetVariable().ToString();
                ETypeWord argtype = arguments[i].GetEType();

                EVariable solved = EVariable.New(argtype).Assign(args[i].Solve(lowerScope));
                lowerScope.Set(argname, solved);
            }

            return(Interpreter.Run(program, lowerScope));
        }
示例#14
0
 public virtual EVariable Exec(EScope scope)
 {
     return(new EVVoid());
 }
示例#15
0
 public override EVariable Solve(EScope scope)
 {
     return(new EVBoolean().Set(boolean));
 }
示例#16
0
 public override EVariable Solve(EScope scope)
 {
     return(EVariable.New(type));
 }
示例#17
0
 public ScopeAttribute(EScope scope)
 {
     Scope = scope;
 }
示例#18
0
 public override EVariable Exec(EScope scope)
 {
     scope.SetFunction(name.ToString(), ToEFunction());
     return(new EVVoid());
 }
示例#19
0
 public override EVariable Exec(EScope scope)
 {
     return(expression.Solve(scope));
 }
示例#20
0
 public virtual EVariable Solve(EScope scope)
 {
     return(new EVVoid());
 }
示例#21
0
        public override EVariable Exec(EScope scope, ESolvable[] args)
        {
            EScope lowerScope = scope.GetChild();

            return(func(lowerScope, args));
        }
示例#22
0
 public override EVariable Exec(EScope scope)
 {
     return(new EVVoid());
 }
示例#23
0
 public virtual EVariable Exec(EScope scope, ESolvable[] args)
 {
     return(new EVVoid());
 }
示例#24
0
        public static void RunMaintenance(EScope scope = EScope.Distributed)
        {
            if (!Monitor.TryEnter(LockObject))
            {
                return;
            }

            var taskSet = scope == EScope.Distributed ? DistributedMaintenanceTasks : LocalInstanceMaintenanceTasks;

            var taskMap = taskSet.ToDictionary(i => i, i =>
            {
                var trackId = i.Id;
                if (i.Setup.LocalInstance)
                {
                    trackId = $"{Environment.MachineName.ToLower()}.{Host.ApplicationAssemblyName}.{trackId}";
                }

                var trackItem = Tracking.Get(trackId) ?? new Tracking {
                    Id = trackId, Description = i.Description
                };

                trackItem.InstanceIdentifier = Environment.MachineName;

                return(trackItem);
            });

            try
            {
                var runnableTaskMap = taskMap.Where(i => i.Value.CanRun()).ToList();

                if (!runnableTaskMap.Any())
                {
                    return;
                }

                Log.Divider();
                Log.Maintenance <MaintenanceService>($"Running {taskSet.Count} {scope} maintenance task(s)");
                foreach (var(key, value) in runnableTaskMap)
                {
                    Log.KeyValuePair(key.Type.FullName, value.ToString(), Message.EContentType.Maintenance);
                }
                Log.Divider();

                foreach (var(item, tracking) in runnableTaskMap)
                {
                    Task <Result> task = null;
                    var           sw   = new Stopwatch();
                    Ticket        distributedTaskHandler = null;

                    sw.Start();

                    try
                    {
                        if (item.Setup.Orchestrated)
                        {
                            distributedTaskHandler = Factory.GetTicket(item.Description);
                            if (!distributedTaskHandler.CanRun())
                            {
                                continue;
                            }
                            distributedTaskHandler.Start();
                        }

                        Current.Log.KeyValuePair("Task", $"[{item.Id}] {item}", Message.EContentType.Maintenance);

                        task = item.Instance.MaintenanceTask();

                        task?.Wait();
                    }
                    catch (Exception e)
                    {
                        Current.Log.Add(e);

                        if (task != null)
                        {
                            task.Result.Status  = Result.EResultStatus.Failed;
                            task.Result.Message = e.ToSummary();
                        }
                        else
                        {
                            tracking.LastMessage = e.ToSummary();
                            tracking.Success     = false;
                        }
                    }
                    finally
                    {
                        sw.Stop();
                        distributedTaskHandler?.Stop();


                        if (task != null)
                        {
                            if (task.Exception != null)
                            {
                                task.Result.Status  = Result.EResultStatus.Failed;
                                task.Result.Message = task.Exception.ToSummary();
                            }

                            task.Result.Counters?.ToLog();

                            tracking.LastResult  = task.Result;
                            tracking.Success     = task.Result.Status == Result.EResultStatus.Success;
                            tracking.Elapsed     = sw.Elapsed.ToString();
                            tracking.LastMessage = tracking.LastResult?.Message;
                        }

                        tracking.LastRun = DateTime.Now;

                        if (item.Setup.Cooldown != default)
                        {
                            tracking.NextRun = tracking.LastRun.Add(item.Setup.Cooldown);
                        }
                        tracking.RunOnce = item.Setup.RunOnce;

                        tracking.Save();
                    }
                }
            }
            finally
            {
                Monitor.Exit(LockObject);
            }
        }
示例#25
0
 public EVariable Solve(EScope scope)
 {
     return(expression.Solve(scope));
 }
示例#26
0
 public override EVariable Solve(EScope scope)
 {
     return(scope.Get(name));
 }