private bool isPrinterInstalled(string strUNC) { Debug.WriteLine(strUNC); NetworkPrinter myPrinter = getNetworkPrinter(strUNC); ManagementObjectSearcher printerQuery = new ManagementObjectSearcher("SELECT * from Win32_Printer Where Network = True"); if (string.IsNullOrEmpty(myPrinter.Name) || string.IsNullOrEmpty(myPrinter.Server)) { return(false); } ManagementObjectCollection colPrinters = printerQuery.Get(); foreach (ManagementObject printer in colPrinters) { //Name property is a UNC String tmpUNC = printer.Properties["Name"].Value.ToString(); NetworkPrinter testPrinter = getNetworkPrinter(tmpUNC); Debug.WriteLine("?..." + testPrinter.Name + "..." + testPrinter.Server); if (testPrinter.Name.ToLower() == myPrinter.Name.ToLower()) { if (testPrinter.Server.ToLower() == myPrinter.Server.ToLower()) { return(true); } } } //not found? return false return(false); }
/// <summary> /// Visualizes the network. /// </summary> /// <returns></returns> public string VisualizeNetwork() { NetworkPrinter printer = new NetworkPrinter(); _rete.DummyTopNode.Accept(printer); return(printer.Output); }
/// <summary> /// Visualizes the network to file. /// </summary> /// <param name="fileName">Name of the file.</param> /// <param name="append">if set to <c>true</c> [append].</param> public void VisualizeNetworkToFile(string fileName, bool append) { NetworkPrinter printer = new NetworkPrinter(); _rete.DummyTopNode.Accept(printer); using (StreamWriter writer = new StreamWriter(fileName, append)) { writer.Write(printer.Output); writer.Flush(); } }
public void Add_method_works_properly() { var logger = new FileLogger("Log.txt"); var manager = new PrinterManager(logger); var printer = new NetworkPrinter() { Name = "Canon", Model = "LBP6000" }; manager.Add(printer); Assert.AreEqual(printer, manager.Printers[0]); }
/// <summary>Print all labels, ignoring the progress. This method doesn't throw, returns false if failed.</summary> public async Task <bool> print(CancellationToken ct) { completed = false; exception = null; try { await NetworkPrinter.printLabels(ip, labels, d => { }, ct); completed = true; } catch (Exception ex) { exception = ex; } return(completed); }
public void Print_method_works_properly() { var logger = new FileLogger("Log.txt"); var manager = new PrinterManager(logger); var printer = new NetworkPrinter() { Name = "Canon", Model = "LBP6000" }; manager.Add(printer); string expected = "12345"; string path = @"C:\Users\Илья\Desktop\12.txt"; string result = manager.Print(printer, path); Assert.AreEqual(expected, result); }
static void Main(string[] args) { Console.WriteLine("Enter printer IP address: (e.g. 192.168.0.2) default port is 9100"); var ip = Console.ReadLine(); var printer = new NetworkPrinter(string.IsNullOrEmpty(ip) ? "192.168.3.100" : ip, 9100, true); var e = new EPSON(); printer.Write(ByteSplicer.Combine( e.Initialize(), e.PrintLine("Hello Xprinter!"), e.CodePage(CodePage.CHINA), e.PrintLine("中文菜单"), e.FullCutAfterFeed(3) )); Console.Read(); }
private NetworkPrinter getNetworkPrinter(String unc) { String pattern = @"^\\\\(?<serverName>[^\\\.]+).*?\\(?<printerName>\w+)"; Regex rgx = new Regex(pattern); MatchCollection matches = Regex.Matches(unc, pattern); NetworkPrinter tmpPrinter = new NetworkPrinter(); foreach (Match mtch in matches) { tmpPrinter.Name = mtch.Groups["printerName"].ToString(); tmpPrinter.Server = mtch.Groups["serverName"].ToString(); } return(tmpPrinter); }
public void EvaluatorTest() { Production prod = new Production(); prod.Label = "find-stack-of-two-blocks-to-the-left-of-a-red-block"; Variable x = new Variable("x"); Variable y = new Variable("y"); Variable z = new Variable("z"); //Variable c = new Variable("c"); prod.AddConditionToLHS(new PositiveCondition("C1", x, "on", y)); prod.AddConditionToLHS(new PositiveCondition("C2", y, "left of", z)); //prod.AddConditionToLHS(new condition("C3", z, "color", "red")); PositiveCondition noteq = new PositiveCondition("NOT BLUE", x, "color", "blue"); noteq.Evaluator = EvaluatorManager.Instance.Evaluators["NotEquals"]; prod.AddConditionToLHS(noteq); prod.AddConditionToRHS(new AssertCondition("C5", x, "calls", z)); Rete rete = new Rete(); rete.AddProduction(prod); WME wme1 = new WME("W1"); wme1.Fields[0] = "B1"; wme1.Fields[1] = "on"; wme1.Fields[2] = "B2"; rete.AddWME(wme1); WME wme2 = new WME("W2"); wme2.Fields[0] = "B1"; wme2.Fields[1] = "on"; wme2.Fields[2] = "B3"; rete.AddWME(wme2); WME wme3 = new WME("W3"); wme3.Fields[0] = "B1"; wme3.Fields[1] = "color"; wme3.Fields[2] = "red"; rete.AddWME(wme3); WME wme4 = new WME("W4"); wme4.Fields[0] = "B2"; wme4.Fields[1] = "on"; wme4.Fields[2] = "table"; rete.AddWME(wme4); WME wme5 = new WME("W5"); wme5.Fields[0] = "B2"; wme5.Fields[1] = "left of"; wme5.Fields[2] = "B3"; rete.AddWME(wme5); WME wme6 = new WME("W6"); wme6.Fields[0] = "B2"; wme6.Fields[1] = "color"; wme6.Fields[2] = "blue"; rete.AddWME(wme6); WME wme7 = new WME("W7"); wme7.Fields[0] = "B3"; wme7.Fields[1] = "left of"; wme7.Fields[2] = "B4"; rete.AddWME(wme7); WME wme8 = new WME("W8"); wme8.Fields[0] = "B3"; wme8.Fields[1] = "on"; wme8.Fields[2] = "table"; rete.AddWME(wme8); WME wme9 = new WME("W9"); wme9.Fields[0] = "B3"; wme9.Fields[1] = "color"; wme9.Fields[2] = "red"; rete.AddWME(wme9); NetworkPrinter printer = new NetworkPrinter(); rete.DummyTopNode.Accept(printer); using (StreamWriter writer = new StreamWriter(@"C:\Temp\EvaluatorTest.log", false)) { writer.Write(printer.Output); writer.Flush(); } Assert.IsTrue(prod.InferredFacts.Count == 2, "Wrong number of conclusions"); Assert.IsTrue(rete.WorkingMemory.Count == 9, "Bad"); }
public void ReteWithHash() { Production prod = new Production(); prod.Label = "ReteWithHash"; Variable a = new Variable("a"); Variable b = new Variable("b"); Variable c = new Variable("c"); Variable d = new Variable("d"); Variable s = new Variable("s"); Variable x = new Variable("x"); Variable y = new Variable("y"); Variable z = new Variable("z"); prod.AddConditionToLHS(new PositiveCondition("C1", x, "on", y)); prod.AddConditionToLHS(new PositiveCondition("C2", y, "left of", z)); prod.AddConditionToLHS(new PositiveCondition("C3", z, "color", "red")); prod.AddConditionToLHS(new PositiveCondition("C4", a, "color", "maize")); prod.AddConditionToLHS(new PositiveCondition("C5", b, "color", "blue")); prod.AddConditionToLHS(new PositiveCondition("C6", c, "color", "green")); prod.AddConditionToLHS(new PositiveCondition("C7", d, "color", "white")); prod.AddConditionToLHS(new PositiveCondition("C8", s, "on", "table")); prod.AddConditionToLHS(new PositiveCondition("C9", z, a, b)); prod.AddConditionToLHS(new PositiveCondition("C10", a, "left of", d)); prod.AddConditionToRHS(new AssertCondition("C4", x, "is", "on top")); Rete rete = new Rete(); rete.AddProduction(prod); NetworkPrinter printer = new NetworkPrinter(); rete.DummyTopNode.Accept(printer); using (StreamWriter writer = new StreamWriter(@"C:\Temp\ReteWithHash-Pre.log", false)) { writer.Write(printer.Output); writer.Flush(); } WME wme1 = new WME("W1"); wme1.Fields[0] = "B1"; wme1.Fields[1] = "on"; wme1.Fields[2] = "B2"; rete.AddWME(wme1); WME wme2 = new WME("W2"); wme2.Fields[0] = "B1"; wme2.Fields[1] = "on"; wme2.Fields[2] = "B3"; rete.AddWME(wme2); WME wme3 = new WME("W3"); wme3.Fields[0] = "B1"; wme3.Fields[1] = "color"; wme3.Fields[2] = "red"; rete.AddWME(wme3); WME wme4 = new WME("W4"); wme4.Fields[0] = "B2"; wme4.Fields[1] = "on"; wme4.Fields[2] = "table"; rete.AddWME(wme4); WME wme5 = new WME("W5"); wme5.Fields[0] = "B2"; wme5.Fields[1] = "left of"; wme5.Fields[2] = "B3"; rete.AddWME(wme5); WME wme6 = new WME("W6"); wme6.Fields[0] = "B2"; wme6.Fields[1] = "color"; wme6.Fields[2] = "blue"; rete.AddWME(wme6); WME wme7 = new WME("W7"); wme7.Fields[0] = "B3"; wme7.Fields[1] = "left of"; wme7.Fields[2] = "B4"; rete.AddWME(wme7); WME wme8 = new WME("W8"); wme8.Fields[0] = "B3"; wme8.Fields[1] = "on"; wme8.Fields[2] = "table"; rete.AddWME(wme8); WME wme9 = new WME("W9"); wme9.Fields[0] = "B3"; wme9.Fields[1] = "color"; wme9.Fields[2] = "red"; rete.AddWME(wme9); printer = new NetworkPrinter(); rete.DummyTopNode.Accept(printer); using (StreamWriter writer = new StreamWriter(@"C:\Temp\ReteWithHash.log", false)) { writer.Write(printer.Output); writer.Flush(); } Assert.IsTrue(prod.InferredFacts.Count == 0, "Wrong number of conclusions"); }
public void TestAddProduction() { Production prod = new Production(); prod.Label = "find-stack-of-two-blocks-to-the-left-of-a-red-block"; Variable x = new Variable("x"); Variable y = new Variable("y"); Variable z = new Variable("z"); prod.AddConditionToLHS(new PositiveCondition("C1", x, "on", y)); prod.AddConditionToLHS(new PositiveCondition("C2", y, "left of", z)); prod.AddConditionToLHS(new PositiveCondition("C3", z, "color", "red")); prod.AddConditionToRHS(new AssertCondition("C4", x, "is", "on top")); Rete rete = new Rete(); rete.AddProduction(prod); WME wme1 = new WME("W1"); wme1.Fields[0] = "B1"; wme1.Fields[1] = "on"; wme1.Fields[2] = "B2"; rete.AddWME(wme1); WME wme2 = new WME("W2"); wme2.Fields[0] = "B1"; wme2.Fields[1] = "on"; wme2.Fields[2] = "B3"; rete.AddWME(wme2); WME wme3 = new WME("W3"); wme3.Fields[0] = "B1"; wme3.Fields[1] = "color"; wme3.Fields[2] = "red"; rete.AddWME(wme3); WME wme4 = new WME("W4"); wme4.Fields[0] = "B2"; wme4.Fields[1] = "on"; wme4.Fields[2] = "table"; rete.AddWME(wme4); WME wme5 = new WME("W5"); wme5.Fields[0] = "B2"; wme5.Fields[1] = "left of"; wme5.Fields[2] = "B3"; rete.AddWME(wme5); WME wme6 = new WME("W6"); wme6.Fields[0] = "B2"; wme6.Fields[1] = "color"; wme6.Fields[2] = "blue"; rete.AddWME(wme6); WME wme7 = new WME("W7"); wme7.Fields[0] = "B3"; wme7.Fields[1] = "left of"; wme7.Fields[2] = "B4"; rete.AddWME(wme7); WME wme8 = new WME("W8"); wme8.Fields[0] = "B3"; wme8.Fields[1] = "on"; wme8.Fields[2] = "table"; rete.AddWME(wme8); WME wme9 = new WME("W9"); wme9.Fields[0] = "B3"; wme9.Fields[1] = "color"; wme9.Fields[2] = "red"; rete.AddWME(wme9); NetworkPrinter printer = new NetworkPrinter(); rete.DummyTopNode.Accept(printer); using (StreamWriter writer = new StreamWriter(@"C:\Temp\TestAddProduction - 1.log", false)) { writer.Write(printer.Output); writer.Flush(); } //Assert.IsTrue(rete.RulesThatFired.Count == 1, "Rule did not fire."); Assert.IsTrue(prod.InferredFacts.Count == 1, "Wrong number of conclusions"); Assert.IsTrue(rete.WorkingMemory.Count == 9, "Bad"); }
public void GrandParents() { Rete rete = new Rete(); Production prod = new Production(); prod.Label = "Whose your daddy"; Variable x = new Variable("x"); Variable y = new Variable("y"); Variable z = new Variable("z"); prod.AddConditionToLHS(new PositiveCondition(x, "parent", y)); prod.AddConditionToRHS(new AssertCondition(y, "child", x)); rete.AddProduction(prod); Production prod1 = new Production(); prod1.Label = "Whose your grand daddy"; prod1.AddConditionToLHS(new PositiveCondition(x, "parent", y)); prod1.AddConditionToLHS(new PositiveCondition(y, "parent", z)); prod1.AddConditionToRHS(new AssertCondition(x, "gparent", z)); rete.AddProduction(prod1); Production prod2 = new Production(); prod2.Label = "Whose your grand child"; prod2.AddConditionToLHS(new PositiveCondition(x, "gparent", y)); prod2.AddConditionToRHS(new AssertCondition(y, "gchild", x)); rete.AddProduction(prod2); Production prod3 = new Production(); prod3.Label = "Whose your great grand daddy"; prod3.AddConditionToLHS(new PositiveCondition(x, "parent", y)); prod3.AddConditionToLHS(new PositiveCondition(y, "gparent", z)); prod3.AddConditionToRHS(new AssertCondition(x, "ggparent", z)); rete.AddProduction(prod3); List <WME> wmes = new List <WME>(); wmes.Add(new WME("george", "gchild", "kendall")); wmes.Add(new WME("kendall", "parent", "immanuel")); wmes.Add(new WME("louis", "gparent", "richard")); wmes.Add(new WME("jacques", "parent", "jean-francois")); wmes.Add(new WME("friedrich", "parent", "louis")); wmes.Add(new WME("louis", "gparent", "willard")); wmes.Add(new WME("willard", "gchild", "ludwig")); wmes.Add(new WME("miles", "parent", "ludwig")); wmes.Add(new WME("ludwig", "gchild", "noam")); wmes.Add(new WME("miles", "gparent", "wilhelm")); wmes.Add(new WME("friedrich", "parent", "jean-francois")); wmes.Add(new WME("bijan", "gchild", "george")); wmes.Add(new WME("wilhelm", "gparent", "bertrand")); wmes.Add(new WME("alan", "parent", "bijan")); wmes.Add(new WME("kendall", "parent", "gottlob")); wmes.Add(new WME("david", "gchild", "bertrand")); wmes.Add(new WME("alan", "gchild", "henry")); wmes.Add(new WME("kendall", "gparent", "louis")); wmes.Add(new WME("willard", "gchild", "willard")); wmes.Add(new WME("richard", "gchild", "pat")); wmes.Add(new WME("miles", "parent", "friedrich")); wmes.Add(new WME("noam", "gparent", "ludwig")); wmes.Add(new WME("jean-francois", "gchild", "bertrand")); wmes.Add(new WME("louis", "parent", "bijan")); wmes.Add(new WME("willard", "parent", "kendall")); wmes.Add(new WME("gottlob", "gparent", "kendall")); wmes.Add(new WME("immanuel", "gchild", "wilhelm")); wmes.Add(new WME("george", "parent", "drew")); wmes.Add(new WME("friedrich", "gchild", "david")); wmes.Add(new WME("gottlob", "gchild", "bertrand")); wmes.Add(new WME("wilhelm", "parent", "ludwig")); wmes.Add(new WME("henry", "gchild", "willard")); wmes.Add(new WME("alan", "gchild", "richard")); wmes.Add(new WME("george", "gchild", "miles")); wmes.Add(new WME("george", "gparent", "willard")); wmes.Add(new WME("alasdair", "gparent", "willard")); wmes.Add(new WME("willard", "gparent", "immanuel")); wmes.Add(new WME("jacques", "gparent", "george")); wmes.Add(new WME("henry", "gchild", "rudolf")); wmes.Add(new WME("wilhelm", "gparent", "miles")); wmes.Add(new WME("noam", "gparent", "jean-francois")); wmes.Add(new WME("pat", "gchild", "friedrich")); wmes.Add(new WME("rudolf", "gchild", "david")); wmes.Add(new WME("john", "gchild", "stanley")); wmes.Add(new WME("jacques", "gchild", "bijan")); wmes.Add(new WME("george", "parent", "miles")); wmes.Add(new WME("louis", "parent", "drew")); wmes.Add(new WME("rudolf", "parent", "jacques")); wmes.Add(new WME("bertrand", "gparent", "ludwig")); wmes.Add(new WME("gottlob", "parent", "john")); wmes.Add(new WME("miles", "gchild", "miles")); wmes.Add(new WME("bijan", "gchild", "noam")); wmes.Add(new WME("jean-francois", "gparent", "george")); wmes.Add(new WME("miles", "gparent", "henry")); wmes.Add(new WME("kendall", "gchild", "ludwig")); wmes.Add(new WME("louis", "gparent", "david")); wmes.Add(new WME("noam", "parent", "george")); wmes.Add(new WME("pat", "parent", "richard")); wmes.Add(new WME("george", "parent", "ludwig")); wmes.Add(new WME("george", "gparent", "alan")); wmes.Add(new WME("pat", "gparent", "louis")); wmes.Add(new WME("david", "parent", "friedrich")); wmes.Add(new WME("wilhelm", "gchild", "alasdair")); wmes.Add(new WME("pat", "gchild", "bertrand")); wmes.Add(new WME("noam", "parent", "stanley")); wmes.Add(new WME("friedrich", "gparent", "bijan")); wmes.Add(new WME("willard", "gchild", "bertrand")); wmes.Add(new WME("kendall", "gparent", "noam")); wmes.Add(new WME("kendall", "gparent", "george")); wmes.Add(new WME("drew", "parent", "gottlob")); wmes.Add(new WME("david", "parent", "kendall")); wmes.Add(new WME("alan", "gparent", "gottlob")); wmes.Add(new WME("richard", "parent", "jacques")); wmes.Add(new WME("alasdair", "gchild", "david")); wmes.Add(new WME("richard", "parent", "bijan")); wmes.Add(new WME("jean-francois", "gparent", "alan")); wmes.Add(new WME("jacques", "gchild", "louis")); wmes.Add(new WME("miles", "gchild", "jean-francois")); wmes.Add(new WME("pat", "parent", "miles")); wmes.Add(new WME("kendall", "parent", "gottlob")); wmes.Add(new WME("gottlob", "parent", "willard")); wmes.Add(new WME("jean-francois", "parent", "willard")); wmes.Add(new WME("stanley", "gchild", "ludwig")); wmes.Add(new WME("john", "gchild", "miles")); wmes.Add(new WME("john", "parent", "jean-francois")); wmes.Add(new WME("alan", "gchild", "louis")); wmes.Add(new WME("stanley", "gchild", "wilhelm")); wmes.Add(new WME("drew", "gparent", "miles")); wmes.Add(new WME("jacques", "parent", "immanuel")); wmes.Add(new WME("david", "gparent", "willard")); wmes.Add(new WME("miles", "parent", "alasdair")); wmes.Add(new WME("immanuel", "gparent", "ludwig")); wmes.Add(new WME("kendall", "gparent", "henry")); wmes.Add(new WME("immanuel", "gparent", "ludwig")); wmes.Add(new WME("miles", "gchild", "john")); wmes.Add(new WME("louis", "gchild", "alan")); wmes.Add(new WME("willard", "parent", "alan")); wmes.Add(new WME("kendall", "parent", "ludwig")); wmes.Add(new WME("george", "gchild", "alasdair")); wmes.Add(new WME("richard", "gparent", "bertrand")); int i = 1; foreach (WME wme in wmes) { wme.Label = "W" + i++; rete.AddWME(wme); } NetworkPrinter printer = new NetworkPrinter(); rete.DummyTopNode.Accept(printer); using (StreamWriter writer = new StreamWriter(@"C:\Temp\GrandParentsTest.log", false)) { writer.Write(printer.Output); writer.Flush(); } Assert.IsTrue(rete.WorkingMemory.Count == 100, "Bad"); Assert.IsTrue(prod.InferredFacts.Count == 33, "Wrong number of conclusions"); Assert.IsTrue(prod1.InferredFacts.Count == 42, "Wrong number of conclusions"); Assert.IsTrue(prod2.InferredFacts.Count == 29, "Wrong number of conclusions"); Assert.IsTrue(prod3.InferredFacts.Count == 38, "Wrong number of conclusions"); }
public void MultiBuiltinTest() { Production prod = new Production(); prod.Label = "find-stack-of-two-blocks-to-the-left-of-a-red-block"; Variable x = new Variable("x"); Variable y = new Variable("y"); //Variable z = new Variable("z"); Variable c = new Variable("c"); prod.AddConditionToLHS(new PositiveCondition("C1", x, "on", y)); //prod.AddConditionToLHS(new condition("C2", y, "left of", z)); prod.AddConditionToLHS(new PositiveCondition("C3", x, "color", c)); FunctionCondition funCond = new FunctionCondition("F4", c, new FuncTerm("funcNotEquals", new funcNotEquals()), new StringTerm("blue")); funCond.ConditionType = ConditionType.Function; prod.AddConditionToLHS(funCond); prod.AddConditionToRHS(new AssertCondition("C4", x, "is", c)); Rete rete = new Rete(); rete.AddProduction(prod); NetworkPrinter printer = new NetworkPrinter(); rete.DummyTopNode.Accept(printer); using (StreamWriter writer = new StreamWriter(@"C:\Temp\MultiBuiltinTest.log", false)) { writer.Write(printer.Output); writer.WriteLine(); writer.WriteLine(); writer.WriteLine(); writer.WriteLine(); writer.WriteLine("-----------------------------------------------"); writer.Flush(); } WME wme1 = new WME("W1"); wme1.Fields[0] = "B1"; wme1.Fields[1] = "on"; wme1.Fields[2] = "B2"; rete.AddWME(wme1); WME wme2 = new WME("W2"); wme2.Fields[0] = "B1"; wme2.Fields[1] = "on"; wme2.Fields[2] = "B3"; rete.AddWME(wme2); WME wme3 = new WME("W3"); wme3.Fields[0] = "B1"; wme3.Fields[1] = "color"; wme3.Fields[2] = "red"; rete.AddWME(wme3); WME wme4 = new WME("W4"); wme4.Fields[0] = "B2"; wme4.Fields[1] = "on"; wme4.Fields[2] = "table"; rete.AddWME(wme4); WME wme5 = new WME("W5"); wme5.Fields[0] = "B2"; wme5.Fields[1] = "left of"; wme5.Fields[2] = "B3"; rete.AddWME(wme5); WME wme6 = new WME("W6"); wme6.Fields[0] = "B2"; wme6.Fields[1] = "color"; wme6.Fields[2] = "blue"; rete.AddWME(wme6); WME wme7 = new WME("W7"); wme7.Fields[0] = "B3"; wme7.Fields[1] = "left of"; wme7.Fields[2] = "B4"; rete.AddWME(wme7); WME wme8 = new WME("W8"); wme8.Fields[0] = "B3"; wme8.Fields[1] = "on"; wme8.Fields[2] = "table"; rete.AddWME(wme8); WME wme9 = new WME("W9"); wme9.Fields[0] = "B3"; wme9.Fields[1] = "color"; wme9.Fields[2] = "red"; rete.AddWME(wme9); printer = new NetworkPrinter(); rete.DummyTopNode.Accept(printer); using (StreamWriter writer = new StreamWriter(@"C:\Temp\MultiBuiltinTest.log", true)) { writer.WriteLine(); writer.WriteLine(); writer.WriteLine(); writer.WriteLine(); writer.Write(printer.Output); writer.Flush(); } //Assert.IsTrue(rete.RulesThatFired.Count == 1, "Rule did not fire."); Assert.IsTrue(prod.InferredFacts.Count == 2, "Wrong number of InferredFacts"); Assert.IsTrue(rete.WorkingMemory.Count == 9, "Bad"); }