コード例 #1
0
        public void testFunctionalityOfPythonRuleItem()
        {
            ruleItem_script testItem = new ruleItem_script(Properties.Settings.Default.testDataPath + filename);
            testItem.pinInfo["myInputPin"].value.data = false;
            testItem.evaluate();
            Assert.IsTrue((testItem.pinInfo["myOutputPin"].value.asBoolean()) == false);

            testItem.pinInfo["myInputPin"].value.data = true;
            testItem.evaluate();
            Assert.IsTrue((testItem.pinInfo["myOutputPin"].value.asBoolean()) == true);
        }
コード例 #2
0
        public void testFunctionalityOfPythonRuleItemWithParameters()
        {
            ruleItem_script testItem = new ruleItem_script(Properties.Settings.Default.testDataPath + filenameParameters);

            testItem.parameters["clampToZero"] = "NO U";

            testItem.pinInfo["myInputPin"].value.data = true;
            testItem.evaluate();
            Assert.IsTrue(testItem.pinInfo["myOutputPin"].value.asBoolean());

            testItem.parameters["clampToZero"] = "yes";
            testItem.evaluate();
            Assert.IsFalse(testItem.pinInfo["myOutputPin"].value.asBoolean());
        }
コード例 #3
0
        public void testLoadOfPythonRuleItem()
        {
            ruleItem_script testItem = new ruleItem_script(Properties.Settings.Default.testDataPath + filename);

            Assert.AreEqual("test python rule item", testItem.ruleName());

            Dictionary<String, pin> pins = testItem.getPinInfo();

            Assert.IsTrue(testItem.getCategory() == "");

            Assert.IsTrue(pins.Count == 2 );
            Assert.IsTrue(pins.ContainsKey("myInputPin"));
            Assert.IsTrue(pins.ContainsKey("myOutputPin"));

            Assert.IsTrue(pins["myOutputPin"].direction == pinDirection.output);
            Assert.IsTrue(pins["myInputPin"].direction == pinDirection.input);
        }
コード例 #4
0
ファイル: rule.cs プロジェクト: randomdude/Lavalamp
        public ruleItemBase addRuleItem(ruleItemInfo info)
        {
            // Make new ruleItem control of this RuleItem type.
            ruleItemBase newRuleItem;
            if (info.itemType == ruleItemType.RuleItem)
            {
                // .net ruleItems are loaded via reflection. We find the parameterless
                // constructor, and then call it.
                ConstructorInfo constr = info.ruleItemBaseType.GetConstructor(new Type[0]);
                newRuleItem = (ruleItemBase)constr.Invoke(new object[0] { });
            }
            else if (info.itemType == ruleItemType.scriptFile)
            {
                // Script items are loaded by their own constructor, as we need information
                // at runtime.
                newRuleItem = new ruleItem_script(info.pythonFileName);
            }
            else
                // This should only happen if a ruleItem is loaded of an unsupported
                // type - ie, never.
                throw new Exception("Unrecognised file type");

            // Initialise the Pins on the control. This will generate a new guid for each pin.
            // FIXME: It's kind of messy that we have to do this here.
            newRuleItem.initPins();

            AddRuleItemToGlobalPool(newRuleItem);
            return newRuleItem;
        }
コード例 #5
0
        public void testLoadOfPythonRuleItemWithParameters()
        {
            ruleItem_script testItem = new ruleItem_script(Properties.Settings.Default.testDataPath + filenameParameters);

            Assert.AreEqual(2, testItem.parameters.Count);
            Assert.AreEqual("first value", testItem.parameters["clampToZero"]);
            Assert.AreEqual("second value", testItem.parameters["IAmTheSecondOption"]);

            Assert.AreEqual(2, testItem.parameters.Count);
            Assert.AreEqual("first value", testItem.parameters["clampToZero"]);
            Assert.AreEqual("second value", testItem.parameters["IAmTheSecondOption"]);
        }
コード例 #6
0
        public void testLoadOfPythonRuleItemWithCategory()
        {
            ruleItem_script testItem = new ruleItem_script(Properties.Settings.Default.testDataPath + filenameCategory);

            Assert.AreEqual("test python rule item", testItem.ruleName());
            Assert.AreEqual("test category", testItem.getCategory());
        }
コード例 #7
0
ファイル: rule-xml.cs プロジェクト: randomdude/Lavalamp
 private ruleItemBase makeRuleItem(ruleItemInfo info)
 {
     // Make new ruleItem control of this RuleItem type
     ruleItemBase newRuleItem;
     if (info.itemType == ruleItemType.RuleItem)
     {
         ConstructorInfo constr = info.ruleItemBaseType.GetConstructor(new Type[0]);
         newRuleItem = (ruleItemBase)constr.Invoke(new object[0] { });
     }
     else if (info.itemType == ruleItemType.scriptFile)
     {
         newRuleItem = new ruleItem_script(info.pythonFileName);
     }
     else
         throw new Exception("eh? Unrecognised file type?");
     return newRuleItem;
 }
コード例 #8
0
ファイル: frmRuleEdit.cs プロジェクト: randomdude/Lavalamp
        private void populateToolboxFromPythonFile(string filename)
        {
            try
            {
                ruleItem_script jake = new ruleItem_script(filename);

                ruleItemInfo itemInfo = new ruleItemInfo
                    {
                        itemType = ruleItemType.scriptFile,
                        pythonFileName = filename,
                        pythonCategory = jake.getCategory()
                    };

                this.addRuleItemObjectToToolbox(jake, itemInfo);
            }
            catch (Exception e)
            {
                // unable to load this file!
                MessageBox.Show("Unable to load file '" + filename +"', exception message: '" + e.Message + "'");
            }
        }