コード例 #1
0
ファイル: RecipeServer.cs プロジェクト: ashish-antil/Products
        private void CopyHeaders(HttpProcessor p, Recipe engine)
        {
            foreach (string key in p.HttpHeaders.Keys)
            {
                engine.SetMacro("q_" + key, p.HttpHeaders[key]);
            }
            int i = p.HttpUrl.IndexOf('?');
            string path;
            if (i == -1)
            {
                path = Unescape(p.HttpUrl);
            }
            else
            {
                path = Unescape(p.HttpUrl.Substring(0, i));

                var query = p.HttpUrl.Substring(i + 1); // skip '?'
                string[] pairs = query.Split('&');
                foreach (string s in pairs)
                {
                    string u = Unescape(s);
                    string[] t = u.Split('=');
                    string key = t[0];
                    string value = t.Length == 1 ? "" : t[1];
                    engine.SetMacro("q_" + key, value); // try to avoid clashing with existing macros by prefixing with q_
                }
            }
            engine.SetMacro("query", path);
        }
コード例 #2
0
ファイル: MainForm.cs プロジェクト: ashish-antil/Products
		public MainForm(string[] args)
		{
			InitializeComponent();
			InitializeMacros();
			_Recipe = new Recipe();
			_Recipe.Message += HandleMessage;
			_Recipe.Input = GetInput;
			_Recipe.Interactive = true;
			_Recipe.Write = false;
			_Recipe.Warn = true;
			_Recipe.Log = true;
			_Recipe.Show = true;
			_Editor1 = CreateEditor(txtRecipe);
			_Editor2 = CreateEditor(txtNotepad);

			_ScriptWatch = new FileSystemWatcher();
			_ScriptWatch.Changed += new FileSystemEventHandler(ScriptWatch_Changed);
			if (args.Length > 0) Open(args[0]);
		}
コード例 #3
0
        private void InitializeRecipe()
        {
            try
            {
                ConfigUtils.RefreshAppSettings();
                string recipePath = ConfigUtils.GetString("Path", @"~prog\Main.rcp");
                recipePath = ExpandPath(recipePath);
                _LogLevel = ConfigUtils.GetValue("LogLevel", 1);

                var macros = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
                // add all environment variables to the dictionary
                IDictionary env = Environment.GetEnvironmentVariables();
                foreach (string key in env.Keys) macros.Add(key, (string)env[key]);

                // parse config file arguments and add to dictionary
                string[] args = ConfigUtils.GetArray("Macros", "");
                var sb = new StringBuilder();
                if (args != null)
                {
                    foreach (string t in args)
                    {
                        string[] nv = t.Split('=');
                        if (nv.Length == 2)
                        {
                            string key = nv[0].Trim();
                            string value = ExpandPath(nv[1].Trim());
                            macros[key] = value;
                            sb.Append(key).Append('=').Append(value).Append('|');
                        }
                        else throw new Exception("Invalid argument: " + t);
                    }
                }
                Log(0, "Macros from configuration: [{0}]", sb.ToString().TrimEnd('|'));
                _RecipeExec = new Recipe { Write = true };
                _RecipeExec.ClearHandlers();
                _RecipeExec.Message += HandleMessage;
                _RecipeExec.SetRootPath(recipePath);

                using (LineReader sr = new LineReader(File.OpenText(recipePath), name: recipePath))
                {
                    Log(0, "Running: [{0}] LogLevel: {1}", recipePath, _LogLevel);
                    _RecipeExec.Run(sr, macros, string.Empty);
                }
            }
            catch (ApplicationException)
            {
                Log(0, "Recipe Exit {0}");
            }
            catch (Exception ex)
            {
                Log(1, "{0}", ex);
            }
        }
コード例 #4
0
ファイル: RecipeServer.cs プロジェクト: ashish-antil/Products
 private void WriteResponse(HttpProcessor p, Recipe engine)
 {
     p.WriteSuccess(engine.GetMacro(ContentType));
     p.OutputStream.WriteLine(engine.GetMacro(Response));
     engine.RemoveMacro(Response);
 }
コード例 #5
0
ファイル: RecipeServer.cs プロジェクト: ashish-antil/Products
 public static void Test(string host, int port, Recipe engine, string recipe)
 {
     new Thread(new RecipeServer(host, port, engine, recipe).Listen).Start();
 }
コード例 #6
0
ファイル: RecipeServer.cs プロジェクト: ashish-antil/Products
 internal RecipeServer(string host, int port, Recipe engine, string recipe)
     : base(host, port)
 {
     _Engine = engine;
     _Script = recipe;
 }
コード例 #7
0
ファイル: Recipe.cs プロジェクト: ashish-antil/Products
 public object Clone()
 {
     var r = new Recipe();
     r.Write = Write;
     r.Message = Message;
     r._Macros = CopyMacros(_Macros);
     r._ExceptionHandlers = _ExceptionHandlers.ToList();
     return r;
 }
コード例 #8
0
ファイル: Watcher.cs プロジェクト: ashish-antil/Products
 internal Watcher(Recipe engine, string script)
 {
     _Engine = (Recipe)engine.Clone();
     _Script = script;
 }