public static NodeInfo Convert(FactScheme.Functor functor) { var info = new NodeInfo(); info.Tag = functor; info.NodeNameProperty = functor.Name; for (int i = 0; i < functor.Inputs.Count; i++) { NodeInfo.SectionInfo attrInfo = new NodeInfo.SectionInfo(); attrInfo.IsInput = true; attrInfo.IsOutput = false; attrInfo.Data = functor.Inputs[i]; var l = new Label(); l.Content = functor.Inputs[i].name; attrInfo.UIPanel = l; info.Sections.Add(attrInfo); } var output = new NodeInfo.SectionInfo(); output.Data = functor.Output; output.IsInput = false; output.IsOutput = true; var outputLabel = new Label(); outputLabel.Content = "Output"; output.UIPanel = outputLabel; info.Sections.Add(output); //else // Button return(info); }
public XElement ToXml() { //if (_saved) // return _xml; XElement root = new XElement(FatonConstants.XML_SCHEME_TAG, new XAttribute(FatonConstants.XML_SCHEME_NAME, Name), new XAttribute(FatonConstants.XML_SCHEME_SEGMENT, Segment)); foreach (Argument arg in Arguments) { XElement xarg = new XElement(FatonConstants.XML_ARGUMENT_TAG, new XAttribute(FatonConstants.XML_ARGUMENT_ORDER, arg.Order), new XAttribute(FatonConstants.XML_ARGUMENT_OBJECTTYPE, arg.ArgType), new XAttribute(FatonConstants.XML_ARGUMENT_CLASSNAME, arg.Name), new XAttribute(FatonConstants.XML_ARGUMENT_COMPARETYPE, arg.CompareType)); var varattrs = from x in arg.Attributes where x.Varattr select x; foreach (var attr in varattrs) { XElement xattr = new XElement("VarAttr", new XAttribute("Name", attr.Name)); xarg.Add(xattr); } foreach (var pair in arg.Conditions) { foreach (var cond in pair.Value) { XElement xcond = new XElement(FatonConstants.XML_ARGUMENT_CONDITION_TAG, new XAttribute(FatonConstants.XML_ARGUMENT_CONDITION_ATTRNAME, pair.Key.Name), new XAttribute(FatonConstants.XML_ARGUMENT_CONDITION_TYPE, cond.CondType), new XAttribute(FatonConstants.XML_ARGUMENT_CONDITION_OPERATION, cond.Operation), new XAttribute(FatonConstants.XML_ARGUMENT_CONDITION_DATA, cond.Data)); xarg.Add(xcond); } } root.Add(xarg); } foreach (Result res in Results) { List <XAttribute> xattrs_ = new List <XAttribute>(); xattrs_.Add(new XAttribute(FatonConstants.XML_RESULT_NAME, res.Name)); xattrs_.Add(new XAttribute(FatonConstants.XML_RESULT_CLASSNAME, (res.Reference as OntologyClass).Name)); xattrs_.Add(new XAttribute(FatonConstants.XML_RESULT_TYPE, res.Type)); if (res.Type == ResultType.EDIT) { if (res.EditObject == null) { throw new Exception("Result type is EDIT, but no argument set"); } if (res.EditObject is Argument) { xattrs_.Add(new XAttribute(FatonConstants.XML_RESULT_ARGEDIT, ((Argument)res.EditObject).Order)); } else if (res.EditObject is Result) { xattrs_.Add(new XAttribute(FatonConstants.XML_RESULT_RESEDIT, ((Result)res.EditObject).Name)); } } XElement xres = new XElement(FatonConstants.XML_RESULT_TAG, xattrs_); foreach (KeyValuePair <string, Result.Rule> rulePair in res.Rules) { var rule = rulePair.Value; XElement xrul; List <XAttribute> xattrs = new List <XAttribute>(); xattrs.Add(new XAttribute(FatonConstants.XML_RESULT_RULE_TYPE, rule.Type)); xattrs.Add(new XAttribute(FatonConstants.XML_RESULT_RULE_ATTR, rule.Attribute.Name)); if (rule.Type == Result.RuleType.FUNC) { Functor f = rule.Reference as Functor; xattrs.Add(new XAttribute("FunctorName", f.Name)); xattrs.Add(new XAttribute("FunctorID", f.CID)); //xattrs.Add(new XAttribute("Default", f.DefaultValue)); if (rule.Default != null) { xattrs.Add(new XAttribute("Default", rule.Default)); } xrul = new XElement("Rule", xattrs); foreach (Functor.FunctorInput input in f.Inputs) { string resourceName = "", resourceType = ""; if (input.source is FactScheme.Argument) { resourceName = ((FactScheme.Argument)input.source).Order.ToString(); resourceType = "ARG"; } xrul.Add(new XElement(FatonConstants.XML_RESULT_RULE_FUNCTOR_INPUT, new XAttribute(FatonConstants.XML_RESULT_RULE_FUNCTOR_RESOURCETYPE, resourceType), new XAttribute(FatonConstants.XML_RESULT_RULE_FUNCTOR_RESOURCE, resourceName), new XAttribute(FatonConstants.XML_RESULT_RULE_FUNCTOR_ATTRFROM, input.value.Name))); } } else { xattrs.Add(new XAttribute(FatonConstants.XML_RESULT_RULE_RESOURCETYPE, rule.ResourceType)); if (rule.Reference is Argument) { xattrs.Add(new XAttribute(FatonConstants.XML_RESULT_RULE_RESOURCE, (rule.Reference as Argument).Order)); } else if (rule.Reference is Result) { xattrs.Add(new XAttribute(FatonConstants.XML_RESULT_RULE_RESOURCE, (rule.Reference as Result).Name)); } if (rule.Attribute.AttrType != OntologyNode.Attribute.AttributeType.OBJECT && rule.InputAttribute != null) { xattrs.Add(new XAttribute(FatonConstants.XML_RESULT_RULE_ATTRFROM, rule.InputAttribute.Name)); } if (rule.Default != null) { xattrs.Add(new XAttribute("Default", rule.Default)); } xrul = new XElement(FatonConstants.XML_RESULT_RULE_TAG, xattrs); } xres.Add(xrul); } root.Add(xres); } foreach (var conditionComplex in XMLConditionComplexes) { var xcomplex = new XElement(FatonConstants.XML_CONDITIONCOMPLEX_TAG, new XAttribute(FatonConstants.XML_ARGUMENT_CONDITION_ARG1, conditionComplex.Arg1), new XAttribute(FatonConstants.XML_ARGUMENT_CONDITION_ARG2, conditionComplex.Arg2)); foreach (var condition in conditionComplex.Conditions) { var xcond = new XElement(FatonConstants.XML_ARGUMENT_CONDITION_TAG); var xattrs = new List <XAttribute>(); if (condition.Arg1 == null || condition.Arg2 == null) { throw new ArgumentNullException("Scheme conditions must have both arguments set"); } xattrs.Add(new XAttribute(FatonConstants.XML_ARGUMENT_CONDITION_ID, condition.ID)); xattrs.Add(new XAttribute(FatonConstants.XML_ARGUMENT_CONDITION_TYPE, condition.Type)); xattrs.Add(new XAttribute(FatonConstants.XML_ARGUMENT_CONDITION_OPERATION, condition.Operation)); xattrs.Add(new XAttribute(FatonConstants.XML_ARGUMENT_CONDITION_DATA, condition.Data ?? "")); xcond.Add(xattrs); xcomplex.Add(xcond); } root.Add(xcomplex); } _xml = root; _saved = true; return(root); }