//////////////////////////////////////////////////////////////////////////////////////////////////// /// \fn public BaseMessage(BaseNetwork network, BaseMessage sourceMessage, BaseChannel sendingChannel): base(true) /// /// \brief Constructor. /// /// \par Description. /// A message that is duplicatted to the source except for the channel parameters. /// /// \par Algorithm. /// /// \par Usage Notes. /// /// \author Ilanh /// \date 14/03/2017 /// /// \param network (BaseNetwork) - The network. /// \param sourceMessage (BaseMessage) - Message describing the source. /// \param sendingChannel (BaseChannel) - The sending channel. //////////////////////////////////////////////////////////////////////////////////////////////////// public BaseMessage(BaseNetwork network, BaseMessage sourceMessage, BaseChannel sendingChannel) : base(true) { this.network = network; pa.Add(bm.pak.MessageType, new Attribute { Value = sourceMessage.pa[bm.pak.MessageType] }); pa.Add(bm.pak.Round, new Attribute { Value = sourceMessage.pa[bm.pak.Round] }); pa.Add(bm.pak.LogicalClock, new Attribute { Value = sourceMessage.pa[bm.pak.LogicalClock] }); pa.Add(bm.pak.SourceProcess, new Attribute { Value = sendingChannel.ea[bc.eak.SourceProcess] }); pa.Add(bm.pak.SourcePort, new Attribute { Value = sendingChannel.or[bc.ork.SourcePort], IncludedInShortDescription = false, IncludeInEqualsTo = false }); pa.Add(bm.pak.DestProcess, new Attribute { Value = sendingChannel.ea[bc.eak.DestProcess] }); pa.Add(bm.pak.DestPort, new Attribute { Value = sendingChannel.or[bc.ork.DestPort], IncludedInShortDescription = false, IncludeInEqualsTo = false }); op.DeepCopy(sourceMessage.op); or.DeepCopy(sourceMessage.or); }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// \fn public BaseMessage(BaseNetwork network, string messageString) :base(true) /// /// \brief Constructor. /// /// \par Description. /// Create a message from string which holds the message xml. /// /// \par Algorithm. /// /// \par Usage Notes. /// /// \author Ilanh /// \date 14/03/2017 /// /// \param network (BaseNetwork) - The network. /// \param messageString (string) - A xml message string. //////////////////////////////////////////////////////////////////////////////////////////////////// public BaseMessage(BaseNetwork network, string messageString) : base(true) { this.network = network; XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(messageString); Load(xmlDoc.GetElementsByTagName("Message")[0]); }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// \fn public void CreateBackworedChannel(object parameters) /// /// \brief Creates backwored channel. /// /// \par Description. /// - This method is the correction for the check if a backword channel is needed /// - This method is used also when the network changes (In design phase) to not directed /// /// \par Algorithm. /// /// \par Usage Notes. /// /// \author Ilan Hindy /// \date 08/03/2017 /// /// \param parameters (object) - Options for controlling the operation. //////////////////////////////////////////////////////////////////////////////////////////////////// public void CreateBackworedChannel(object parameters) { BaseNetwork network = (BaseNetwork)parameters; int channelId = network.Channels.Last().ea[ne.eak.Id] + 1; BaseChannel channel = ClassFactory.GenerateChannel(network, channelId, ea[bc.eak.DestProcess], ea[bc.eak.SourceProcess]); ChannelPresentation presentation = (ChannelPresentation)Presentation; channel.Presentation = presentation; presentation.AddChannel(channel); network.Channels.Add(channel); }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// \fn public static BaseMessage CreateMessage(string messageString) /// /// \brief Creates a message. /// /// \par Description. /// - This method is used by the AsynchronousReader to generate all types of the messages /// - The messages are sent in Xml. /// - The root name is the type of the message /// /// \par Algorithm. /// -# Load the string to XmlDocument /// -# Get the root node /// -# Generate a message from the type which is the name of the root node /// -# Load all the message /// /// \par Usage Notes. /// /// \author Ilanh /// \date 26/04/2017 /// /// \param messageString (string) - The message string. /// /// \return The new message. //////////////////////////////////////////////////////////////////////////////////////////////////// public static BaseMessage CreateMessage(BaseNetwork network, string messageString) { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(messageString); XmlElement root = xmlDoc.DocumentElement; // Create a message with no parameters constructor so that the permissions will not interfeer with the // loading BaseMessage message = (BaseMessage)TypesUtility.CreateObjectFromTypeString(root.Name); message.Load(root); return(message); }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// \fn public bool CheckIfBackwordChannelNeeded(BaseNetwork net) /// /// \brief Determine if reverse channel needed. /// /// \par Description. /// /// \par Algorithm. /// /// \par Usage Notes. /// /// \author Ilan Hindy /// \date 08/03/2017 /// /// \param net (BaseNetwork) - The net. /// /// \return True if it succeeds, false if it fails. //////////////////////////////////////////////////////////////////////////////////////////////////// public bool CheckIfBackwordChannelNeeded(BaseNetwork net) { //Check if the channel has a backwored channel //Exclude the self connecting channels if (ea[bc.eak.SourceProcess] == ea[bc.eak.DestProcess]) { return(false); } if (net.Channels.Any(otherChannel => otherChannel.ea[bc.eak.SourceProcess] == ea[bc.eak.DestProcess] && otherChannel.ea[bc.eak.DestProcess] == ea[bc.eak.SourceProcess]) == true) { return(false); } return(true); }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// \fn public BaseMessage(BaseNetwork network, dynamic messageType, BaseChannel channel, string messageName = "" , int round = 0, int logicalClock = 0):base(true) /// /// \brief Constructor. /// /// \par Description. /// Construct a message from header parameters. /// /// \par Algorithm. /// /// \par Usage Notes. /// /// \author Ilanh /// \date 14/03/2017 /// /// \param network (BaseNetwork) - The network. /// \param messageType (dynamic) - Type of the message. /// \param channel (BaseChannel) - The channel. /// \param messageName (Optional) (string) - Name of the message. /// \param round (Optional) (int) - The round. /// \param logicalClock (Optional) (int) - The logical clock. //////////////////////////////////////////////////////////////////////////////////////////////////// public BaseMessage(BaseNetwork network, dynamic messageType, BaseChannel channel, string messageName = "", int round = 0, int logicalClock = 0) : base(true) { this.network = network; pa.Add(bm.pak.MessageType, new Attribute { Value = messageType }); pa.Add(bm.pak.SourceProcess, new Attribute { Value = channel.ea[bc.eak.SourceProcess] }); pa.Add(bm.pak.SourcePort, new Attribute { Value = channel.or[bc.ork.SourcePort], IncludedInShortDescription = false, IncludeInEqualsTo = false }); pa.Add(bm.pak.DestProcess, new Attribute { Value = channel.ea[bc.eak.DestProcess] }); pa.Add(bm.pak.DestPort, new Attribute { Value = channel.or[bc.ork.DestPort], IncludedInShortDescription = false, IncludeInEqualsTo = false }); pa.Add(bm.pak.Round, new Attribute { Value = round }); pa.Add(bm.pak.LogicalClock, new Attribute { Value = logicalClock }); if (messageName == "") { messageName = TypesUtility.GetKeyToString(messageType); } or.Add(bm.ork.Name, new Attribute { Value = messageName }); op.Add(bm.opk.Breakpoints, new Attribute { Value = new Breakpoint(Breakpoint.HostingElementTypes.Message), Editable = false, IncludedInShortDescription = false }); or.Add(bm.ork.PositionInProcessQ, new Attribute { Value = 0, IncludedInShortDescription = false }); }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// \fn public BaseMessage(BaseNetwork network, dynamic messageType, int sourceProcess, int sourcePort, int destProcess, int destPort, string messageName, int round, int logicalClock):base(true) /// /// \brief Constructor. /// /// \par Description. /// Create a message when all the header fields are given. /// /// \par Algorithm. /// /// \par Usage Notes. /// /// \author Ilanh /// \date 14/03/2017 /// /// \param network (BaseNetwork) - The network. /// \param messageType (dynamic) - Type of the message. /// \param sourceProcess (int) - Source process. /// \param sourcePort (int) - Source port. /// \param destProcess (int) - Destination process. /// \param destPort (int) - Destination port. /// \param messageName (string) - Name of the message. /// \param round (int) - The round. /// \param logicalClock (int) - The logical clock. //////////////////////////////////////////////////////////////////////////////////////////////////// public BaseMessage(BaseNetwork network, dynamic messageType, int sourceProcess, int sourcePort, int destProcess, int destPort, string messageName, int round, int logicalClock) : base(true) { this.network = network; pa.Add(bm.pak.MessageType, new Attribute { Value = messageType }); pa.Add(bm.pak.SourceProcess, new Attribute { Value = sourceProcess }); pa.Add(bm.pak.SourcePort, new Attribute { Value = sourcePort, IncludedInShortDescription = false, IncludeInEqualsTo = false }); pa.Add(bm.pak.DestProcess, new Attribute { Value = destProcess }); pa.Add(bm.pak.DestPort, new Attribute { Value = destPort, IncludedInShortDescription = false, IncludeInEqualsTo = false }); pa.Add(bm.pak.Round, new Attribute { Value = round }); pa.Add(bm.pak.LogicalClock, new Attribute { Value = logicalClock }); op.Add(bm.opk.Breakpoints, new Attribute { Value = new Breakpoint(Breakpoint.HostingElementTypes.Message), Editable = false, IncludedInShortDescription = false }); or.Add(bm.ork.Name, new Attribute { Value = messageName }); or.Add(bm.ork.PositionInProcessQ, new Attribute { Value = 0, IncludedInShortDescription = false }); }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// \fn public BaseMessage(BaseNetwork network, BaseMessage sourceMessage) : base(sourceMessage) /// /// \brief Constructor. /// /// \par Description. /// See explanation about constructors in NetworkElement /// /// \par Algorithm. /// /// \par Usage Notes. /// /// \author Ilanh /// \date 27/06/2017 /// /// \param network (BaseNetwork) - The network. /// \param sourceMessage (BaseMessage) - Message describing the source. //////////////////////////////////////////////////////////////////////////////////////////////////// public BaseMessage(BaseNetwork network, BaseMessage sourceMessage) : base(sourceMessage) { this.network = network; }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// \fn public BaseMessage(BaseNetwork network):base(network) /// /// \brief Constructor. /// /// \par Description. /// See explanation about constructors in NetworkElement /// /// \par Algorithm. /// /// \par Usage Notes. /// /// \author Ilanh /// \date 27/06/2017 /// /// \param network (BaseNetwork) - The network. //////////////////////////////////////////////////////////////////////////////////////////////////// public BaseMessage(BaseNetwork network) : base(network) { this.network = network; }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// \fn public BaseChannel(BaseNetwork network, int id, int sourceProcessId, int destProcessId) : base(network) /// /// \brief Constructor. /// /// \par Description. /// See explanation about constructors in NetworkElement /// /// \par Algorithm. /// /// \par Usage Notes. /// /// \author Ilanh /// \date 27/06/2017 /// /// \param network (BaseNetwork) - The network. /// \param id (int) - The identifier. /// \param sourceProcessId (int) - Identifier for the source process. /// \param destProcessId (int) - Identifier for the destination process. //////////////////////////////////////////////////////////////////////////////////////////////////// public BaseChannel(BaseNetwork network, int id, int sourceProcessId, int destProcessId) : base(network) { tmpSourceId = sourceProcessId; tmpDestId = destProcessId; Init(id, false); }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// \fn public BaseChannel(BaseNetwork network) : base(network) /// /// \brief Constructor. /// /// \par Description. /// See explanation about constructors in NetworkElement /// /// \par Algorithm. /// /// \par Usage Notes. /// /// \author Ilanh /// \date 27/06/2017 /// /// \param network (BaseNetwork) - The network. //////////////////////////////////////////////////////////////////////////////////////////////////// public BaseChannel(BaseNetwork network) : base(network) { }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// \fn public BaseMessage(BaseNetwork network, dynamic messageType, AttributeDictionary fields, BaseChannel channel, string messageName = "" , int round, int logicalClock):base(true) /// /// \brief Constructor. /// /// \par Description. /// Create a message from : /// -# The messageType /// -# Fields for the algorithm specific fields in attribute dictionary. /// -# The sending parameters from the channel /// -# The message name /// -# The parameters for the header : round, logical clock /// /// /// \par Algorithm. /// /// \par Usage Notes. /// /// \author Ilanh /// \date 14/03/2017 /// /// \param network (BaseNetwork) - The network. /// \param messageType (dynamic) - Type of the message. /// \param fields (AttributeDictionary) - The fields. /// \param channel (BaseChannel) - The channel. /// \param messageName (Optional) (string) - Name of the message. /// \param round (Optional) (int) - The round. /// \param logicalClock (Optional) (int) - The logical clock. //////////////////////////////////////////////////////////////////////////////////////////////////// public BaseMessage(BaseNetwork network, dynamic messageType, AttributeDictionary fields, BaseChannel channel, string messageName = "", int round = 0, int logicalClock = 0) : base(true) { InitElementAttributes(0); this.network = network; pa.Add(bm.pak.MessageType, new Attribute { Value = messageType }); try { pa.Add(bm.pak.SourceProcess, new Attribute { Value = channel.ea[bc.eak.SourceProcess] }); pa.Add(bm.pak.SourcePort, new Attribute { Value = channel.or[bc.ork.SourcePort], IncludedInShortDescription = false, IncludeInEqualsTo = false }); pa.Add(bm.pak.DestProcess, new Attribute { Value = channel.ea[bc.eak.DestProcess] }); pa.Add(bm.pak.DestPort, new Attribute { Value = channel.or[bc.ork.DestPort], IncludedInShortDescription = false, IncludeInEqualsTo = false }); } catch { pa.Add(bm.pak.SourceProcess, new Attribute { Value = 0 }); pa.Add(bm.pak.SourcePort, new Attribute { Value = 0, IncludedInShortDescription = false, IncludeInEqualsTo = false }); pa.Add(bm.pak.DestProcess, new Attribute { Value = 0 }); pa.Add(bm.pak.DestPort, new Attribute { Value = 0, IncludedInShortDescription = false, IncludeInEqualsTo = false }); } pa.Add(bm.pak.Round, new Attribute { Value = round }); pa.Add(bm.pak.LogicalClock, new Attribute { Value = logicalClock }); if (messageName == "") { messageName = TypesUtility.GetKeyToString(messageType); } or.Add(bm.ork.Name, new Attribute { Value = messageName }); op.Add(bm.opk.Breakpoints, new Attribute { Value = new Breakpoint(Breakpoint.HostingElementTypes.Message), Editable = false, IncludedInShortDescription = false }); or.Add(bm.ork.PositionInProcessQ, new Attribute { Value = 0, IncludedInShortDescription = false }); if (fields != null) { foreach (var entry in fields) { AddField(entry.Key, entry.Value); } } }