public static string ToXmlString(ConditionalBranchManager cbm) { StringBuilder sb = new StringBuilder(); sb.Append("<ConditionalBranchManager>\r\n<DefaultChannel>" + XmlTransform.Xmlify(cbm.m_defaultChannel) + "</DefaultChannel>\r\n"); foreach (BranchScenario bs in cbm.m_branchScenarios) { sb.Append("<BranchScenario>\r\n" + "<Channel>" + XmlTransform.Xmlify(bs.Channel) + "</Channel>\r\n" + "<Condition>" + XmlTransform.Xmlify(bs.Condition) + "</Condition>\r\n" + "<TargetGuid>" + XmlConvert.ToString(bs.TargetGuid) + "</TargetGuid>\r\n" + "<MasterGuid>" + XmlConvert.ToString(bs.MasterGuid) + "</MasterGuid>\r\n" + "</BranchScenario>\r\n"); } sb.Append("</ConditionalBranchManager>"); return(sb.ToString()); }
public static ConditionalBranchManager FromXml(IModel model, XmlNode node) { if (node == null) { throw new ArgumentException("Attempt to create a ConditionalBranchManager from a null XmlNode."); } XmlNode selectSingleNode = node.SelectSingleNode("DefaultChannel"); if (selectSingleNode != null) { ConditionalBranchManager cbm = new ConditionalBranchManager(model) { m_defaultChannel = XmlTransform.DeXmlify(selectSingleNode.InnerText) }; XmlNodeList xmlNodeList = node.SelectNodes("BranchScenario"); if (xmlNodeList != null) { foreach (XmlNode innerNode in xmlNodeList) { XmlNode singleNode = innerNode.SelectSingleNode("Condition"); if (singleNode == null) { continue; } string condition = singleNode.InnerText; //condition = XmlConvert.deXmlify(condition); Not necessary, since it came from an Xml document in the first place. XmlNode xmlNode = innerNode.SelectSingleNode("Channel"); if (xmlNode == null) { continue; } string channel = xmlNode.InnerText; //channel = XmlConvert.deXmlify(channel); Not necessary, since it came from an Xml document in the first place. XmlNode selectSingleNode1 = innerNode.SelectSingleNode("MasterGuid"); if (selectSingleNode1 == null) { continue; } Guid masterGuid = XmlConvert.ToGuid(selectSingleNode1.InnerText); XmlNode singleNode1 = innerNode.SelectSingleNode("TargetGuid"); if (singleNode1 == null) { continue; } Guid targetGuid = XmlConvert.ToGuid(singleNode1.InnerText); BranchScenario bs = new BranchScenario(model, condition, channel) { MasterGuid = masterGuid, TargetGuid = targetGuid }; cbm.m_branchScenarios.Add(bs); } } return(cbm); } return(null); }
/// <summary> /// Registers branch conditions for branching to be performed by a Conditional Branch Manager. /// The first condition specified is assumed to be the one that is true. /// </summary> /// <param name="model">The model in which these branch scenarios will run.</param> /// <param name="source">The source task from whose post vertex the branches emit.</param> /// <param name="conditions">The indexed conditions under which each channel is activated.</param> /// <param name="channels">The indexed channels for each branch.</param> /// <param name="targets">The target tasks to which the branches will pass control.</param> /// <param name="master">The master edge. Null, or same as source, if source is master.</param> /// <param name="force">if set to <c>true</c> [force] creation of a new Conditional Branch Manager.</param> public static void AddBranchScenarios(IModel model, Task source, List <string> conditions, List <string> channels, List <Task> targets, Task master, bool force) { ConditionalBranchManager cbm = For(source, true); cbm.AddBranchScenarios(model, conditions, channels, targets, master); }