Пример #1
0
        public void Process(JObject command, Context context)
        {
            // get default property
            var file = JSONUtil.GetText(command, "#load-json");

            if (file == null)
            {
                file = JSONUtil.GetText(command, "file");
            }

            // get all other properties
            var set = JSONUtil.GetText(command, "set");

            if (set == null)
            {
                set = Guid.NewGuid().ToString();
            }

            // apply variables to properties (do this when getting property instead?)
            file = context.ReplaceVariables(file);

            // perform the action
            if (command["#debug"] != null && command["#debug"].ToString() == "true")
            {
                context.Trace($"Loading JSON File {file} into {set}");
            }


            var sub = JSONUtil.ReadFile(file);

            context.Store(set, sub);
        }
Пример #2
0
        public CommandEngine(string configPath, List <IModule> modules)
        {
            this.InitEngine();
            this.Modules.AddRange(modules);

            var configFile = JSONUtil.ReadFile(configPath);

            string basePath = configFile["$basePath"].ToString();

            this._context.Variables.Add("$basePath", basePath);

            //var items = configFile["connections"];

            //if (items != null)
            //{
            //    foreach (var item in items)
            //    {
            //        var envConfig = ConnectionConfig.GetConnectionConfig(item);

            //        foreach (var module in this.Modules)
            //        {
            //            var conn = module.ProvideConnection(envConfig);
            //            if (conn != null)
            //            {
            //                this._context.AddConnection(envConfig.Name, conn);

            //                if (envConfig.IsDefault == true) { this._context.DefaultConnection = conn; }
            //            }
            //        }
            //    }
            //}
        }
Пример #3
0
        public void Process(JObject command, Context context)
        {
            string file = JSONUtil.GetText(command, "#run-script");

            if (file == null)
            {
                file = command["script"].ToString();
            }
            file = context.ReplaceVariables(file);

            System.IO.FileInfo fi = new System.IO.FileInfo(file);
            var scriptDir         = fi.Directory.FullName;

            JArray items = (JArray)JSONUtil.ReadFile(file);

            if (items == null)
            {
                Console.WriteLine($"RunScript: Unable to read file {file}.");
                return;
            }

            foreach (var item in items)
            {
                var commandItem = Unification.Replace(item, "#scriptDir", scriptDir);
                context.CommandEngine.RunCommand(commandItem, context);
            }
        }
Пример #4
0
        public CommandEngine(string configPath)
        {
            this.InitEngine();

            var configFile = JSONUtil.ReadFile(configPath);

            var variables = configFile["variables"];

            if (variables != null)
            {
                foreach (JObject variable in variables)
                {
                    var varProp  = variable.Properties().FirstOrDefault();
                    var varKey   = varProp.Name;
                    var varValue = varProp.Value;
                    this._context.Variables.Add(varKey, varValue);
                }
            }
        }
Пример #5
0
        public void LoadInit()
        {
            // look for init.json in .exe path
            var exePath  = AppContext.BaseDirectory;
            var initFile = JSONUtil.ReadFile(exePath + "\\init.json");

            if (initFile != null) // if it's there
            {
                this._context.Trace("init.json found - loaded");
                this._context.Store("#init", initFile);

                var joCommand = new JObject();
                joCommand.Add("command", "assert");
                var joQuery = new JObject();
                joQuery.Add("#event", "engine-init");
                joCommand.Add("query", joQuery);

                this.RunCommand(joCommand, this._context);
            }
        }