/**********************************************************************************************//** * Gets message queue. * * \author Ilan Hindy * \date 29/09/2016 * * \param p The Process to process. * * \return The message queue. * . **************************************************************************************************/ private AttributeList GetMessageQ(BaseProcess p) { return(p.or[bp.ork.MessageQ]); }
/* * The possible parameters are: * key - in this case find the attribute * if the attribute found is a list * if only one value from the list is requested * return the value according to an index * else return the list * else (the value is not a list) return the value */ /**********************************************************************************************//** * Evaluate parameter. * * \author Ilan Hindy * \date 29/09/2016 * * \exception EvaluationException Thrown when an Evaluation error condition occurs. * * \param evaluationMode The evaluation mode. * \param network The network. * \param process The process. * \param channel The channel. * \param message The message. * \param parameter The parameter. * * \return An Attribute. * . **************************************************************************************************/ private Attribute EvaluateParameter(EvaluationMode evaluationMode, BaseNetwork network, BaseProcess process, BaseChannel channel, BaseMessage message, Attribute parameter) { if (parameter.Value.GetType().IsEnum) { if (!NetworkElementExist(network, process, channel, message)) { return(new Attribute() { Value = false }); } Attribute attribute = FindAttribute(network, process, channel, message, parameter.Value); if (attribute == null) { string typeOfHostingElementStr = TypesUtility.GetKeyToString(or[brp.ork.HostingElementType]); throw new EvaluationException("Could not find attribute " + TypesUtility.GetKeyToString(parameter.Value) + " In element of type " + typeOfHostingElementStr); } else { if (Attribute.GetValueCategory(attribute) == Attribute.AttributeCategory.ListOfAttributes) { if (or[brp.ork.ListParameterOneOrAll] == ListParameterOneOrAll.One) { object[] elements = TypesUtility.InvokeMethodOfList(attribute.Value, "ToArray", new object[0], true); int requestedIndex = or[brp.ork.IndexInList]; if (elements.Count() <= requestedIndex) { throw new EvaluationException("The index requested : " + requestedIndex.ToString() + " is larger or equal to the number of elements in the list : " + elements.Count()); } else { if (Attribute.GetValueCategory(attribute) == Attribute.AttributeCategory.ListOfAttributes) { return((Attribute)elements[requestedIndex]); } else { return(new Attribute() { Value = elements[requestedIndex] }); } } } } return(attribute); } } if (parameter.Value.GetType().Equals(typeof(Breakpoint))) { return(new Attribute() { Value = parameter.Value.Evaluate(evaluationMode, network, process, channel, message) }); } return(parameter); }
/**********************************************************************************************//** * Gets messages for other elements evaluation. * * \author Ilan Hindy * \date 29/09/2016 * * \param processForEvaluation The process for evaluation. * * \return The messages for other elements evaluation. * . **************************************************************************************************/ private List <BaseMessage> GetMessagesForOtherElementsEvaluation(BaseProcess processForEvaluation) { AttributeList messageAttributes = new AttributeList(); AttributeList messagesToOneProcessor; switch (messageHandlingForOtherElementOperation) { case MessageHandlingInOtherElementsOperation.FirstMessageForEachProcessor: messagesToOneProcessor = GetMessageQ(processForEvaluation); if (messagesToOneProcessor.Count > 0) { messageAttributes.Add(messagesToOneProcessor[0]); } break; case MessageHandlingInOtherElementsOperation.AllMessagesForEachProcessor: messagesToOneProcessor = GetMessageQ(processForEvaluation); if (messagesToOneProcessor.Count > 0) { messageAttributes = messagesToOneProcessor; } break; case MessageHandlingInOtherElementsOperation.OneFromFirstMessages: foreach (BaseProcess p in networkForOtherElementOperation.Processes) { messagesToOneProcessor = GetMessageQ(processForEvaluation); if (messagesToOneProcessor.Count > 0) { messageAttributes.Add(messagesToOneProcessor[0]); } } break; case MessageHandlingInOtherElementsOperation.OneMessage: foreach (BaseProcess p in networkForOtherElementOperation.Processes) { messagesToOneProcessor = GetMessageQ(processForEvaluation); if (messagesToOneProcessor.Count > 0) { messageAttributes = messageAttributes.Concat(GetMessageQ(p)).ToList().ToAttributeList(); } } break; case MessageHandlingInOtherElementsOperation.AllMessages: foreach (BaseProcess p in networkForOtherElementOperation.Processes) { messagesToOneProcessor = GetMessageQ(processForEvaluation); if (messagesToOneProcessor.Count > 0) { messageAttributes = messageAttributes.Concat(GetMessageQ(p)).ToList().ToAttributeList(); } } break; } List <BaseMessage> result = new List <BaseMessage>(); messageAttributes.ForEach(attribute => result.Add(attribute.Value)); return(result); }
public Protocol(E_PROTOCOL_TYPE type, BaseProcess process) { this.type = type; this.process = process; }
/**********************************************************************************************//** * Evaluates. * * \author Ilan Hindy * \date 29/09/2016 * * \param evaluationMode The evaluation mode. * \param network The network. * \param process The process. * \param channel The channel. * \param message The message. * * \return true if it succeeds, false if it fails. * . **************************************************************************************************/ public bool Evaluate(EvaluationMode evaluationMode, BaseNetwork network, BaseProcess process, BaseChannel channel, BaseMessage message) { string resultString; bool result; if (or[brp.ork.Enable] == false) { resultString = "False : The breakpoint is enabeled"; result = false; } else { try { //Duplicate the list of parameters because it can change for the evaluation (in AdjustForOtherElementsBreakpoints) //and the original list have to stay as the original AttributeList parametersList = new AttributeList(or[brp.ork.Parameters]); AdjustForOtherElementsBreakpoints(parametersList, network); AttributeList parameters = new AttributeList(); for (int idx = 0; idx < parametersList.Count; idx++) { parameters.Add(EvaluateParameter(evaluationMode, network, process, channel, message, parametersList.GetAttribute(idx))); } if (parameters.Count == 0) { resultString = "False : There are no parameters"; result = false; } else { if (parameters.Count == 1) { //If unary value the operator will work on the first //argument only the first argument is duplicatted //for comaptibillity parameters.Add(parameters.GetAttribute(0)); } result = Evaluate(parameters); resultString = result.ToString(); } } catch (EvaluationException exception) { resultString = "False : " + exception.Message; result = false; } } int processId = process.ea[ne.eak.Id]; CreateResultsLists(network.Processes); if (evaluationMode == EvaluationMode.Running) { or[brp.ork.LastRunningResult][processId] = resultString; } else if (evaluationMode == EvaluationMode.Checking) { or[brp.ork.LastCheckResult][processId] = resultString; } return(result); }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// \fn public void InternalOperationReport(BaseProcess process, string operationDescription) /// /// \brief Internal operation report. /// /// \brief #### Algorithm. /// /// \brief #### Usage Notes. /// /// \author Main /// \date 24/01/2017 /// /// \param process The process. /// \param operationDescription Information describing the operation. //////////////////////////////////////////////////////////////////////////////////////////////////// public void InternalOperationReport(BaseProcess process, string operationDescription) { vectorClock[process.ea[ne.eak.Id].Value] += 1; Logger.Log(Logger.LogMode.MainLogAndMessageTrace, "RunningHandler", "InternalOperationReport", " InternalOperationReport ", operationDescription, "RunningHandler"); }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// \fn public override void SetMembers(BaseNetwork network, NetworkElement element, Permissions permissions, IValueHolder parent, bool recursive = true) /// /// \brief Sets the members. /// /// \par Description. /// /// \par Algorithm. /// /// \par Usage Notes. /// /// \author Ilanh /// \date 30/05/2018 /// /// \param network (BaseNetwork) - The network. /// \param element (NetworkElement) - The element. /// \param permissions (Permissions) - The permissions. /// \param parent (IValueHolder) - The parent. /// \param recursive (Optional) (bool) - true to process recursively, false to process locally only. //////////////////////////////////////////////////////////////////////////////////////////////////// public override void SetMembers(BaseNetwork network, NetworkElement element, Permissions permissions, IValueHolder parent, bool recursive = true) { base.SetMembers(network, element, permissions, parent); process = (BaseProcess)Element; }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// \fn public static AttributeDictionary MessageDictionary(dynamic messageKey, NetworkElement messageDemo, BaseProcess process) /// /// \brief Message dictionary. /// Create a message dictionary according to the message type key /// /// \par Description. /// /// \par Algorithm. /// /// \par Usage Notes. /// /// \author Ilanh /// \date 24/12/2017 /// /// \param messageKey (dynamic) - The message key. /// \param messageDemo (NetworkElement) - The message demo. /// \param process (BaseProcess) - The process. /// /// \return An AttributeDictionary. //////////////////////////////////////////////////////////////////////////////////////////////////// public static AttributeDictionary MessageDictionary(dynamic messageKey, NetworkElement messageDemo, BaseProcess process) { // Add an empty dictionary to the OperationResults messageDemo.or.Add(messageKey, new Attribute { Value = new AttributeDictionary() }); // Generate the method name string methodName = ((AttributeDictionary)messageDemo.or[messageKey]).MessageMethodName(); // Generate the enum name of the message. Note that Enum names begin with small letter and // Enum values begin with big letter so there is a need to set the first letter to lower // In order to get the enum name string keyString = TypesUtility.GetKeyToString(messageKey); keyString = char.ToLower(keyString[0]) + keyString.Substring(1); // The method for getting the data is invoked by it's name. When invoking a method in this // way the exact number of parameters has to be given. Each method has a different number of parameters // (according to the number of entries in the message enum so this number has to be retrieved // from the enum int optionalPrmsCount = Enum.GetValues(GenerateMessageEnum(keyString)).Length; // Activating the method return((AttributeDictionary)TypesUtility.InvokeMethod(process, methodName, new List <object> { bm.PrmSource.Default, null }, optionalPrmsCount, true)); }
public ProcessForm(BaseProcess baseProcess) { InitializeComponent(); _process = baseProcess; }
internal void Log(string message, BaseProcess process) { Hub.Log(message, this, process); }