static void Main(string[] args) { string catalogsrc = "catalog.xml", command = "default", logfile = null, contextType = null; for (int i = 0; i < args.Length; i++) { switch (args[i]) { case "-c": case "-catalog": catalogsrc = args[++i]; break; case "-x": case "-command": command = args[++i]; break; case "-log": case "-f": logfile = args[++i]; break; case "-ctxtype": case "-contexttype": contextType = args[++i]; break; } } try { ICatalog catalog = CatalogFactory.GetFactory().GetCatalog(catalogsrc); IContext ctx; if (string.IsNullOrEmpty(contextType)) { ctx = new ContextBase(); } else { ctx = (IContext)Activator.CreateInstance(Type.GetType(contextType, true)); } catalog[command].Execute(ctx); } catch (Exception ex) { if (!string.IsNullOrEmpty(logfile)) try { System.IO.File.AppendAllText(logfile, ex.Message + " :: " + ex.StackTrace, Encoding.UTF8); } catch (Exception) { } Console.Error.WriteLine(ex.Message + " :: " + ex.StackTrace); Environment.ExitCode = 1; } }
public void SelfDispatchTest() { ICatalog catalog = CatalogFactory.GetFactory().GetCatalog(); DispatchLookupCommand dlc = new SelfDispatchingLookupCommand(); dlc.Name = "cmd"; dlc.CatalogKey = "cat"; dlc.Command = "_self"; dlc.DispatchMethod = "OtherMethod"; IContext ctx = new ContextBase(); ctx["cat"] = catalog; dlc.Execute(ctx); Assert.AreEqual(true, ctx["test"]); }
public void LookupCommandTest() { IContext ctx = new ContextBase(); ctx["test"] = "value"; Zetetic.Chain.Generic.CopyCommand toLookup = new Zetetic.Chain.Generic.CopyCommand(); toLookup.FromKey = "test"; toLookup.ToKey = "x"; toLookup.Name = "findMe"; Zetetic.Chain.Generic.LookupCommand cmd = new Zetetic.Chain.Generic.LookupCommand(); cmd.Command = "findMe"; cmd.Name = "finder"; cmd.CatalogKey = "CATALOG"; ICatalog cat = new CatalogBase(); cat[toLookup.Name] = toLookup; cat[cmd.Name] = cmd; ctx[cmd.CatalogKey] = cat; cat["finder"].Execute(ctx); Assert.AreEqual(ctx["x"], "value"); }
public void GeneralChainingTest() { IContext ctx = new ContextBase(); ctx["in"] = "value"; Zetetic.Chain.IChain chain = ChainFactory.GetFactory().CreateChain(); chain.Name = "chain"; Zetetic.Chain.Generic.CopyCommand cmd = new Zetetic.Chain.Generic.CopyCommand(); cmd.FromKey = "in"; cmd.ToKey = "middle"; chain.Add(cmd); cmd = new Zetetic.Chain.Generic.CopyCommand(); cmd.FromKey = "middle"; cmd.ToKey = "third"; chain.Add(cmd); Zetetic.Chain.Generic.RemoveCommand remo = new Zetetic.Chain.Generic.RemoveCommand(); remo.FromKey = "middle"; chain.Add(remo); ICatalog cat = new CatalogBase(); cat[chain.Name] = chain; cat["chain"].Execute(ctx); Assert.AreEqual("value", ctx["third"]); Assert.IsNull(ctx["middle"]); }
public void CatalogShouldRefuseMissingRequiredProperties() { IContext ctx = new ContextBase(); Zetetic.Chain.Generic.CopyCommand cmd = new Zetetic.Chain.Generic.CopyCommand(); ctx["in"] = "value"; cmd.FromKey = null; cmd.ToKey = "out"; cmd.Name = "test"; ICatalog cat = new XmlCatalog(); cat[cmd.Name] = cmd; Assert.Fail("Should have had exception"); }
public void CopyCommandShouldCopyValue() { IContext ctx = new ContextBase(); Zetetic.Chain.Generic.CopyCommand cmd = new Zetetic.Chain.Generic.CopyCommand(); ctx["in"] = "value"; cmd.FromKey = "in"; cmd.ToKey = "out"; cmd.Execute(ctx); Assert.IsNotNull(ctx["out"], "'out' value must be present in modified context"); Assert.AreEqual("value", ctx["out"]); }