示例#1
0
        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
		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
 private void WriteResponse(HttpProcessor p, Recipe engine)
 {
     p.WriteSuccess(engine.GetMacro(ContentType));
     p.OutputStream.WriteLine(engine.GetMacro(Response));
     engine.RemoveMacro(Response);
 }
示例#5
0
 public static void Test(string host, int port, Recipe engine, string recipe)
 {
     new Thread(new RecipeServer(host, port, engine, recipe).Listen).Start();
 }
示例#6
0
 internal RecipeServer(string host, int port, Recipe engine, string recipe)
     : base(host, port)
 {
     _Engine = engine;
     _Script = recipe;
 }
示例#7
0
 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
 internal Watcher(Recipe engine, string script)
 {
     _Engine = (Recipe)engine.Clone();
     _Script = script;
 }