//////////////////////////////////////////////////////////////////////////////////////////////////// /// \fn public static NetworkElement BaseNetworkElement(string classType) /// /// \brief Base network element. /// /// \par Description. /// /// \par Algorithm. /// /// \par Usage Notes. /// /// \author Ilanh /// \date 19/11/2017 /// /// \param classType (string) - Type of the class. /// /// \return A NetworkElement. //////////////////////////////////////////////////////////////////////////////////////////////////// public static NetworkElement BaseNetworkElement(string classType) { NetworkElement result = (NetworkElement)TypesUtility.CreateObjectFromTypeString( GenerateNamespace("Base", "Base") + "." + "Base" + classType); return(result); }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// \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)); }
/* * Remove one presentation * This method removes from the dictionaries the control, network element and status * of the network element that has to be removed from the presentation * If this was the last network element of the presentation it deletes all the rest of the * controls from the canvas */ /**********************************************************************************************//** * Removes the one presentation described by networkElement. * * \author Ilan Hindy * \date 29/09/2016 * * \param networkElement The network element. * **************************************************************************************************/ public void RemoveOnePresentation(NetworkElement networkElement) { foreach (var entry in presentationElements[networkElement].controls) { if (entry.Key == PresentationElement.ControlKeys.Label) { Label label = (Label)entry.Value; ((StackPanel)additionalControls[AdditionalControlKeys.LabelsPanel]).Children.Remove(label); } else { canvas.Children.Remove((UIElement)entry.Value); } } networkElement.Presentation = null; presentationElements.Remove(networkElement); if (presentationElements.Count == 0) { foreach (UIElement control in additionalControls.Values) { canvas.Children.Remove(control); } } else { UpdatePresentation(); } }
/* * SetSelected - define the colors of the channels * If the status of the channel is DoNotShow the status will not be change by selecting * or deselecting of the channel * In order that a channel will be released from DoNotShow status one of the processes * has to be repositioned * In the PositionChannel there is a condition that if the processes are not detached * from one another they will get the status of DoNotShow. * If the reposition detach the processes the status will be change to NotSelected or Selected * According to whether the channel is selected in the main window * After this condition the controls will be colored in the following way: * The poligon of the channel will be colored according to the status * If one of the channels are in DoNotShow status the line and label will be colored according to * DoNotShow status * Else if one of the channels are in Selected status the line and the label will be colored * according to Selected color * Else (Both channels are NotSelected) the line and the label will be colored according to * NotSelected color */ /**********************************************************************************************//** * Sets a selected. * * \author Ilan Hindy * \date 29/09/2016 * * \param networkElement The network element. * \param selectedStatus The selected status. * **************************************************************************************************/ public override void SetSelected(NetworkElement networkElement, MainWindow.SelectedStatus selectedStatus) { if (presentationElements[networkElement].status == MainWindow.SelectedStatus.DoNotShow) { selectedStatus = MainWindow.SelectedStatus.DoNotShow; } else { presentationElements[networkElement].status = selectedStatus; } // Set the Arrow Head ((Polygon)presentationElements[networkElement].controls[PresentationElement.ControlKeys.ArrowHead]).Fill = selectedColors[(int)selectedStatus]; // Set the Labels SetLabelColors((BaseChannel)networkElement, selectedStatus); if (presentationElements.Values.Any(pe => pe.status == MainWindow.SelectedStatus.DoNotShow)) { ((Line)additionalControls[AdditionalControlKeys.Line]).Stroke = selectedColors[(int)MainWindow.SelectedStatus.DoNotShow]; SetBorderColors(selectedColors[(int)MainWindow.SelectedStatus.DoNotShow]); } else if (presentationElements.Values.Any(pe => pe.status == MainWindow.SelectedStatus.Selected)) { ((Line)additionalControls[AdditionalControlKeys.Line]).Stroke = selectedColors[(int)MainWindow.SelectedStatus.Selected]; SetBorderColors(selectedColors[(int)MainWindow.SelectedStatus.Selected]); } else //None of the channels is selected { ((Line)additionalControls[AdditionalControlKeys.Line]).Stroke = selectedColors[(int)MainWindow.SelectedStatus.NotSelected]; SetBorderColors(selectedColors[(int)MainWindow.SelectedStatus.NotSelected]); } }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// \fn public static bool CheckIfProcessExists(BaseNetwork network, NetworkElement networkElement, Attribute parentAttribute, Attribute attribute, string newValue, out string errorMessage, ElementWindow inputWindow = null) /// /// \brief Determine if process exists. /// /// \par Description. /// - This method is activated by the GUI after a value in one of the target processors /// for the message was changed. /// - The method checks whether there is a process with id equals to the new value in the network /// /// \par Algorithm. /// /// \par Usage Notes. /// /// \author Ilanh /// \date 09/05/2018 /// /// \param network (BaseNetwork) - The network. /// \param networkElement (NetworkElement) - The network element. /// \param parentAttribute (Attribute) - The parent attribute. /// \param attribute (Attribute) - The attribute. /// \param newValue (string) - The new value. /// \param [out] errorMessage (out string) - Message describing the error. /// \param inputWindow (Optional) (ElementWindow) - The input window. /// /// \return True if it succeeds, false if it fails. //////////////////////////////////////////////////////////////////////////////////////////////////// public static bool CheckIfProcessExists(BaseNetwork network, NetworkElement networkElement, Attribute parentAttribute, Attribute attribute, string newValue, out string errorMessage, ElementWindow inputWindow = null) { errorMessage = ""; try { errorMessage = "The value has to be int"; int id = int.Parse(newValue); errorMessage = "There is no processor with id :" + newValue; network.Processes.First(p => p.ea[ne.eak.Id] == id); errorMessage = ""; return(true); } catch { return(false); } }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// \fn public static bool EventTriggerChanged(BaseNetwork network, NetworkElement networkElement, Attribute parentAttribute, Attribute attribute, string newValue, out string errorMessage, ElementWindow inputWindow = null) /// /// \brief Event trigger changed. /// /// \par Description. /// - This method is activated by the GUI when the Trigger was changed /// - The purpose of this method is to disable all the other fields if the /// Event is initialize and enable all the fields otherwise /// /// \par Algorithm. /// /// \par Usage Notes. /// /// \author Ilanh /// \date 09/05/2018 /// /// \param network (BaseNetwork) - The network. /// \param networkElement (NetworkElement) - The network element. /// \param parentAttribute (Attribute) - The parent attribute. /// \param attribute (Attribute) - The attribute. /// \param newValue (string) - The new value. /// \param [out] errorMessage (out string) - Message describing the error. /// \param inputWindow (Optional) (ElementWindow) - The input window. /// /// \return True if it succeeds, false if it fails. //////////////////////////////////////////////////////////////////////////////////////////////////// public static bool EventTriggerChanged(BaseNetwork network, NetworkElement networkElement, Attribute parentAttribute, Attribute attribute, string newValue, out string errorMessage, ElementWindow inputWindow = null) { // Get All the childes of the parent attribute List <ElementWindow.ControlsAttributeLink> links = inputWindow.controlsAttributeLinks.Values.Where(l => l.parentAttribute == parentAttribute && l.attribute != attribute).ToList(); if (newValue == "Initialize") { foreach (ElementWindow.ControlsAttributeLink link in links) { link.newValueControl.IsEnabled = false; ((Control)link.newValueControl).Background = Brushes.LightGray; string defaultValue = ""; inputWindow.ChangeValue(defaultValue, link.attribute); } } else { string prevValue = inputWindow.controlsAttributeLinks.Values.First(l => l.attribute == attribute).existingNewValue; if (prevValue == "Initialize") { foreach (ElementWindow.ControlsAttributeLink link in links) { link.newValueControl.IsEnabled = true; ((Control)link.newValueControl).Background = Brushes.White; inputWindow.ChangeValue(link.existingValueTextBox.Text, link.attribute); } } } errorMessage = ""; return(true); }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// \fn public static ElementWindowPrms DisableIfTriggerInitialize(Attribute attribute, dynamic key, NetworkElement mainNetworkElement, NetworkElement.ElementDictionaries mainDictionary, NetworkElement.ElementDictionaries dictionary, InputWindows inputWindow, bool windowEdittable) /// /// \brief Disables if trigger initialize. /// /// \par Description. /// - This method is activated to set for the GUI the display parameters: /// - If the trigger is Initialize - disable the field /// - Else enable the fields /// /// \par Algorithm. /// /// \par Usage Notes. /// /// \author Ilanh /// \date 09/05/2018 /// /// \param attribute (Attribute) - The attribute. /// \param key (dynamic) - The key. /// \param mainNetworkElement (NetworkElement) - The main network element. /// \param mainDictionary (ElementDictionaries) - Dictionary of mains. /// \param dictionary (ElementDictionaries) - The dictionary. /// \param inputWindow (InputWindows) - The input window. /// \param windowEdittable (bool) - true if window edittable. /// /// \return The ElementWindowPrms. //////////////////////////////////////////////////////////////////////////////////////////////////// public static ElementWindowPrms DisableIfTriggerInitialize(Attribute attribute, dynamic key, NetworkElement mainNetworkElement, NetworkElement.ElementDictionaries mainDictionary, NetworkElement.ElementDictionaries dictionary, InputWindows inputWindow, bool windowEdittable) { ElementWindowPrms prms = new ElementWindowPrms(); attribute.DefaultNewValueFieldData(ref prms, mainNetworkElement, mainDictionary, dictionary, inputWindow, windowEdittable, attribute.Editable); if (((AttributeDictionary)attribute.Parent)[Comps.Trigger] == EventTriggerType.Initialize) { prms.newValueControlPrms.enable = false; } else { prms.newValueControlPrms.enable = true; } return(prms); }
/**********************************************************************************************//** * Updates the running status. * * \author Ilan Hindy * \date 29/09/2016 * * \param networkElement The network element. * \param parameters Options for controlling the operation. * **************************************************************************************************/ public override void UpdateRunningStatus(NetworkElement networkElement, object[] parameters) { // Update the shape parameters UpdatePresentationShapeParameters((BaseProcess)networkElement, false); /* * The parameters are: * [0] Whether the process is the process to be activated * [1] list of main breakpoints of the participated in last breakpoint evaluation */ UpdateBreakpointLabel((BaseProcess)networkElement, (List <Breakpoint>)parameters[1]); base.UpdateRunningStatus(networkElement, parameters); CreateFloatingSummary(); ((Ellipse)presentationElements[networkElement].controls[PresentationElement.ControlKeys.Circle]).Stroke = selectedColors[(int)(parameters[0])]; // There can be only one from DebugWindow and Floating summary if (presentationElements[networkElement].debugWindow != null) { presentationElements[networkElement].debugWindow.UpdateExistingValues(); } //if (presentationElements[networkElement].breakpointWindow != null) //{ // presentationElements[networkElement].breakpointWindow.UpdateExistingValues(); //} }
/* * Log a XmlDocument */ /**********************************************************************************************//** * Logs. * * \author Ilan Hindy * \date 29/09/2016 * * \param logMode The log mode. * \param sourceObject Source object. * \param function The function. * \param messageHeader The message header. * \param networkElement The network element. * \param logFilter (Optional) A filter specifying the log. * **************************************************************************************************/ public static void Log(LogMode logMode, string sourceObject, string function, string messageHeader, NetworkElement networkElement, string logFilter = "") { string messageTraceLog; string emptySpaces = null; string log = WriteLogHeader(sourceObject, function, messageHeader, out emptySpaces); if (networkElement != null) { string[] messageLines = formatXml(networkElement.ElementXml()); foreach (string line in messageLines) { log += emptySpaces + line + "\r\n"; } messageTraceLog = messageHeader + " " + networkElement.ShortDescription(); } else { messageTraceLog = messageHeader + " " + "Null network element"; } WriteLog(logMode, sourceObject, log, messageTraceLog, logFilter); }
/* * Get the circle control of a process */ /**********************************************************************************************//** * Gets process presentation circle. * * \author Ilan Hindy * \date 29/09/2016 * * \param processKey The process key. * * \return The process presentation circle. * . **************************************************************************************************/ private Ellipse GetProcessPresentationCircle(bc.eak processKey) { int processId = presentationElements.Keys.ElementAt(0).ea[processKey]; NetworkElement networkElement = mainWindow.net.Processes.First(p => p.ea[ne.eak.Id] == processId); return((Ellipse)networkElement.Presentation.presentationElements[networkElement].controls[PresentationElement.ControlKeys.Circle]); }
/******************************************************************** * Structure of ElementInput window * The main window is composed from 2 panels : * 1. Buttom panel for operations on the network element which has a fixed size * 2. Up panel for attributes which has a flexible size. * This panel is composed from 2 pannels: * 1.Panel for the labels which has a fixed size in the left side * 2.Pannel for inserting values which has a flexible size in the right side * The height of the window is determined by the number of attributes and cnnot be changed in run time * The width of the window can be changed in run time *********************************************************************/ /* * Constructor */ public ElementInput(Network network, NetworkElement networkElement, bool ediatble = true) { this.network = network; this.networkElement = networkElement; Ediatble = ediatble; InitializeComponent(); CreateAttributesControls(); }
/* * Update the network element data after move or resize processes */ /**********************************************************************************************//** * Updates the network element described by networkElement. * * \author Ilan Hindy * \date 29/09/2016 * * \param networkElement The network element. * **************************************************************************************************/ protected override void UpdateNetworkElement(NetworkElement networkElement) { base.UpdateNetworkElement(networkElement); networkElement.pp[bp.ppk.FrameHeight] = ((Ellipse)presentationElements[networkElement].controls[PresentationElement.ControlKeys.Circle]).Height; networkElement.pp[bp.ppk.FrameWidth] = ((Ellipse)presentationElements[networkElement].controls[PresentationElement.ControlKeys.Circle]).Width; networkElement.pp[bp.ppk.FrameLeft] = ((Ellipse)presentationElements[networkElement].controls[PresentationElement.ControlKeys.Circle]).Margin.Left; networkElement.pp[bp.ppk.FrameTop] = ((Ellipse)presentationElements[networkElement].controls[PresentationElement.ControlKeys.Circle]).Margin.Top; }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// \fn private void Update(NetworkElement existingNetworkElement, NetworkElement newNetworkElement) /// /// \brief Updates this object. /// /// \par Description. /// Starts a ScanAndReport process on the Network component /// /// \par Algorithm. /// /// \par Usage Notes. /// /// \author Ilanh /// \date 28/12/2017 /// /// \param existingNetworkElement (NetworkElement) - The existing network element. /// \param newNetworkElement (NetworkElement) - The new network element. //////////////////////////////////////////////////////////////////////////////////////////////////// private void Update(NetworkElement existingNetworkElement, NetworkElement newNetworkElement) { Report("Beginning of update"); newNetworkElement.Init(existingNetworkElement.ea[ne.eak.Id]); complexAttributes.Push(new Attribute() { Value = existingNetworkElement }); newNetworkElement.ScanAndReport(this, NetworkElement.ElementDictionaries.None, NetworkElement.ElementDictionaries.None); }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// \fn public static ElementWindowPrms InternalEventPrms(Attribute attribute, dynamic key, NetworkElement mainNetworkElement, NetworkElement.ElementDictionaries mainDictionary, NetworkElement.ElementDictionaries dictionary, InputWindows inputWindow, bool windowEditable) /// /// \brief Internal event prms. /// /// \par Description. /// - This method sets the parameters of this class representation in the GUI /// - It meant mainly to set the CreateDefaultEvent as the method to be activated /// When the Add button is pressed (When the Add button is pressed a new event /// with default values will be inserted) /// /// \par Algorithm. /// /// \par Usage Notes. /// /// \author Ilanh /// \date 09/05/2018 /// /// \param attribute (Attribute) - The attribute. /// \param key (dynamic) - The key. /// \param mainNetworkElement (NetworkElement) - The main network element. /// \param mainDictionary (ElementDictionaries) - Dictionary of mains. /// \param dictionary (ElementDictionaries) - The dictionary. /// \param inputWindow (InputWindows) - The input window. /// \param windowEditable (bool) - true if window editable. /// /// \return The ElementWindowPrms. //////////////////////////////////////////////////////////////////////////////////////////////////// public static ElementWindowPrms InternalEventPrms(Attribute attribute, dynamic key, NetworkElement mainNetworkElement, NetworkElement.ElementDictionaries mainDictionary, NetworkElement.ElementDictionaries dictionary, InputWindows inputWindow, bool windowEditable) { ElementWindowPrms elementWindowPrms = new ElementWindowPrms(); elementWindowPrms.newValueControlPrms.inputFieldType = InputFieldsType.AddRemovePanel; elementWindowPrms.newValueControlPrms.addAttributeMethod = CreateDefaultEvent; return(elementWindowPrms); }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// \fn public static ElementWindowPrms MessageListPrms(Attribute attribute, dynamic key, NetworkElement mainNetworkElement, NetworkElement.ElementDictionaries mainDictionary, NetworkElement.ElementDictionaries dictionary, InputWindows inputWindow, bool windowEditable) /// /// \brief Message list prms. /// /// \par Description. /// - The BaseAlgorithmMessages is part of an event in the BaseAlgorithmHandler list /// - This method is used by the BaseAlgorithmHandler to set the GUI presentation /// parameters /// - The purpose of this method is to set the EmptyMessagesData as the method that will /// Create a new entry in the list (When pressing the Add button of the messages list (this object) the EmptyMessageData /// will be activated in order to create a new empty message) /// /// \par Algorithm. /// /// \par Usage Notes. /// /// \author Ilanh /// \date 09/05/2018 /// /// \param attribute (Attribute) - The attribute. /// \param key (dynamic) - The key. /// \param mainNetworkElement (NetworkElement) - The main network element. /// \param mainDictionary (ElementDictionaries) - Dictionary of mains. /// \param dictionary (ElementDictionaries) - The dictionary. /// \param inputWindow (InputWindows) - The input window. /// \param windowEditable (bool) - true if window editable. /// /// \return The ElementWindowPrms. //////////////////////////////////////////////////////////////////////////////////////////////////// public static ElementWindowPrms MessageListPrms(Attribute attribute, dynamic key, NetworkElement mainNetworkElement, NetworkElement.ElementDictionaries mainDictionary, NetworkElement.ElementDictionaries dictionary, InputWindows inputWindow, bool windowEditable) { ElementWindowPrms prms = new ElementWindowPrms(); attribute.DefaultNewValueFieldData(ref prms, mainNetworkElement, mainDictionary, dictionary, inputWindow, true, true); prms.newValueControlPrms.addAttributeMethod = EmptyMessageData; return(prms); }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// \fn public static ElementWindowPrms IntListPrms(Attribute attribute, dynamic key, NetworkElement mainNetworkElement, NetworkElement.ElementDictionaries mainDictionary, NetworkElement.ElementDictionaries dictionary, InputWindows inputWindow, bool windowEditable) /// /// \brief Int list prms. /// /// \par Description. /// - This method is meant to set the GUI parameters for the field Targets of the messages /// - Each message contains a list of ints which are target for the message /// - This method is added to each possible target of the message /// - The purpose of this message is to assign a check that the target entered (a process id) /// exists in the network been designed /// /// \par Algorithm. /// /// \par Usage Notes. /// /// \author Ilanh /// \date 09/05/2018 /// /// \param attribute (Attribute) - The attribute. /// \param key (dynamic) - The key. /// \param mainNetworkElement (NetworkElement) - The main network element. /// \param mainDictionary (ElementDictionaries) - Dictionary of mains. /// \param dictionary (ElementDictionaries) - The dictionary. /// \param inputWindow (InputWindows) - The input window. /// \param windowEditable (bool) - true if window editable. /// /// \return The ElementWindowPrms. //////////////////////////////////////////////////////////////////////////////////////////////////// public static ElementWindowPrms IntListPrms(Attribute attribute, dynamic key, NetworkElement mainNetworkElement, NetworkElement.ElementDictionaries mainDictionary, NetworkElement.ElementDictionaries dictionary, InputWindows inputWindow, bool windowEditable) { ElementWindowPrms prms = new ElementWindowPrms(); prms.newValueControlPrms.inputFieldType = InputFieldsType.AddRemovePanel; prms.newValueControlPrms.addAttributeMethod = CreateProcessIdAttribute; return(prms); }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// \fn public static ElementWindowPrms MethodComboBoxPrms(Attribute attribute, dynamic key, NetworkElement mainNetworkElement, NetworkElement.ElementDictionaries mainDictionary, NetworkElement.ElementDictionaries dictionary, InputWindows inputWindow, bool windowEditable) /// /// \brief Method combo box prms. /// /// \par Description. /// - This method is used to set the parameters for a method field in the GUI /// - The purpose of this method is to set the options for the ComboBox as all the /// messages which has the delegate signature /// /// \par Algorithm. /// /// \par Usage Notes. /// /// \author Ilanh /// \date 09/05/2018 /// /// \param attribute (Attribute) - The attribute. /// \param key (dynamic) - The key. /// \param mainNetworkElement (NetworkElement) - The main network element. /// \param mainDictionary (ElementDictionaries) - Dictionary of mains. /// \param dictionary (ElementDictionaries) - The dictionary. /// \param inputWindow (InputWindows) - The input window. /// \param windowEditable (bool) - true if window editable. /// /// \return The ElementWindowPrms. //////////////////////////////////////////////////////////////////////////////////////////////////// public static ElementWindowPrms MethodComboBoxPrms(Attribute attribute, dynamic key, NetworkElement mainNetworkElement, NetworkElement.ElementDictionaries mainDictionary, NetworkElement.ElementDictionaries dictionary, InputWindows inputWindow, bool windowEditable) { ElementWindowPrms elementWindowPrms = new ElementWindowPrms(); elementWindowPrms.newValueControlPrms.inputFieldType = InputFieldsType.ComboBox; string[] options = TypesUtility.GetInternalEventMethods().ToArray(); elementWindowPrms.newValueControlPrms.options = options; elementWindowPrms.newValueControlPrms.Value = options[0]; return(elementWindowPrms); }
/**********************************************************************************************//** * Gets relative line position for label. * * \author Ilan Hindy * \date 29/09/2016 * * \param networkElement The network element. * * \return The relative line position for label. * . **************************************************************************************************/ private double GetRelativeLinePositionForLabel(NetworkElement networkElement) { double lineX1 = ((Line)additionalControls[AdditionalControlKeys.Line]).X1; double lineY1 = ((Line)additionalControls[AdditionalControlKeys.Line]).Y1; Polygon arrowHead = (Polygon)presentationElements[networkElement].controls[PresentationElement.ControlKeys.ArrowHead]; double polygonX1 = arrowHead.Points[0].X; double polygonY1 = arrowHead.Points[0].Y; if (lineX1 == polygonX1 && lineY1 == polygonY1) { return(labelRelativePosition[1]); } else { return(labelRelativePosition[0]); } }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// \fn public static ElementWindowPrms MessageTypePrms(Attribute attribute, dynamic key, NetworkElement mainNetworkElement, NetworkElement.ElementDictionaries mainDictionary, NetworkElement.ElementDictionaries dictionary, InputWindows inputWindow, bool windowEdittable) /// /// \brief Message type prms. /// /// \par Description. /// - This method is activated to set for the GUI the display parameters for the MessageType field /// - The purpose of the message is to set the values for the ComboBox /// All the message type of the algorithm + all the message types of the Base Algorithm /// /// \par Algorithm. /// /// \par Usage Notes. /// /// \author Ilanh /// \date 09/05/2018 /// /// \param attribute (Attribute) - The attribute. /// \param key (dynamic) - The key. /// \param mainNetworkElement (NetworkElement) - The main network element. /// \param mainDictionary (ElementDictionaries) - Dictionary of mains. /// \param dictionary (ElementDictionaries) - The dictionary. /// \param inputWindow (InputWindows) - The input window. /// \param windowEdittable (bool) - true if window edittable. /// /// \return The ElementWindowPrms. //////////////////////////////////////////////////////////////////////////////////////////////////// public static ElementWindowPrms MessageTypePrms(Attribute attribute, dynamic key, NetworkElement mainNetworkElement, NetworkElement.ElementDictionaries mainDictionary, NetworkElement.ElementDictionaries dictionary, InputWindows inputWindow, bool windowEdittable) { ElementWindowPrms prms = new ElementWindowPrms(); prms.newValueControlPrms.inputFieldType = InputFieldsType.ComboBox; prms.newValueControlPrms.options = TypesUtility.GetEnumKeysToStrings(attribute.Value.GetType().ToString()).ToArray(); prms.newValueControlPrms.enable = true; // List<string> baseMessagesTypes = TypesUtility.GetEnumKeysToStrings(typeof(bm.MessageTypes).ToString()); // prms.newValueControlPrms.options = messagesTypes.Concat(baseMessagesTypes).ToArray(); prms.newValueControlPrms.Value = TypesUtility.GetKeyToString(attribute.Value); return(prms); }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// \fn private bool CreateBaseClassText(ref string fileText, NetworkElement networkElement, string enumClass) /// /// \brief Creates base class text. /// /// \par Description. // Create the code to one Base algorithm class /// /// \par Algorithm. /// /// \par Usage Notes. /// /// \author Ilanh /// \date 18/03/2018 /// /// \param [in,out] fileText (ref string) - The file text. /// \param networkElement (NetworkElement) - The network element. /// \param enumClass (string) - The enum class. /// /// \return True if the user quitted . //////////////////////////////////////////////////////////////////////////////////////////////////// private bool CreateBaseClassText(ref string fileText, NetworkElement networkElement, string enumClass) { string classText = eol + "\t#region /// \\name partial class for " + "Base" + classNames[classIdx]; classText += eol + "\tpublic partial class " + "Base" + classNames[classIdx] + @": " + "NetworkElement"; classText += eol + "\t{"; classText += networkElement.CreateGettersSetters(enumClass, "Base", "Base"); classText += eol + "\t}"; classText += eol + "\t#endregion"; if (ShowClass(ref fileText, "partial", classText, "Base" + classNames[classIdx])) { return(true); } else { return(false); } }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// \fn public static bool CheckMembers(IValueHolder checkedValueHolder, BaseNetwork network, Permissions permissions, IValueHolder parent, int nestingLevel, string key, bool checkPermissions = true) /// /// \brief Check members. /// /// \par Description. /// This is a method that recursively check the members of a tree under the IValueHolder /// /// \par Algorithm. /// -# Check the members of the IValueHolder: /// -# The network (Has to be the same as the parent) /// -# The permissions (Has to be the same as the parent) /// -# The parent /// -# Cal the CheckMembers of the IValueHolder to implement the recursive check /// /// \par Usage Notes. /// /// \author Ilanh /// \date 25/07/2017 /// /// \param checkedValueHolder (IValueHolder) - The checked value holder. /// \param network (BaseNetwork) - The network. /// \param permissions (Permissions) - The permissions. /// \param parent (IValueHolder) - The parent. /// \param nestingLevel (int) - The nesting level. /// \param key (string) - The key. /// \param checkPermissions (Optional) (bool) - true to check permissions. /// /// \return True if it succeeds, false if it fails. //////////////////////////////////////////////////////////////////////////////////////////////////// #region /// \name Check building of members //////////////////////////////////////////////////////////////////////////////////////////////////// /// \fn public static bool CheckMembers(this IValueHolder checkedValueHolder, BaseNetwork network, Permissions permissions, IValueHolder parent, int nestingLevel, string key, bool checkPermissions = true) /// /// \brief An IValueHolder extension method that check members. /// /// \par Description. /// /// \par Algorithm. /// /// \par Usage Notes. /// /// \author Ilanh /// \date 10/09/2017 /// /// \param checkedValueHolder The checkedValueHolder to act on. /// \param network (BaseNetwork) - The network. /// \param permissions (Permissions) - The permissions. /// \param parent (IValueHolder) - The parent. /// \param nestingLevel (int) - The nesting level. /// \param key (string) - The key. /// \param checkPermissions (Optional) (bool) - true to check permissions. /// /// \return True if it succeeds, false if it fails. //////////////////////////////////////////////////////////////////////////////////////////////////// public static bool CheckMembers(this IValueHolder checkedValueHolder, BaseNetwork network, NetworkElement element, Permissions permissions, IValueHolder parent, int nestingLevel, string key, bool checkPermissions = true) { checkedValueHolder.GenerateCheckMessage(nestingLevel, key, " Start"); if (checkedValueHolder.Network != network) { checkedValueHolder.GenerateCheckMessage(nestingLevel, key, "The network is not equal"); return(false); } if (checkedValueHolder.Element != element) { checkedValueHolder.GenerateCheckMessage(nestingLevel, key, "The element is not equal"); return(false); } if (checkPermissions) { if (!checkedValueHolder.Permissions.Equals(permissions)) { checkedValueHolder.GenerateCheckMessage(nestingLevel, key, "The permissions are not equal"); return(false); } } if (checkedValueHolder.Parent != parent) { checkedValueHolder.GenerateCheckMessage(nestingLevel, key, "The parent is wrong"); return(false); } if (checkedValueHolder.CheckMembers(nestingLevel + 1)) { checkedValueHolder.GenerateCheckMessage(nestingLevel, key, " End - True"); return(true); } else { checkedValueHolder.GenerateCheckMessage(nestingLevel, key, " End - False"); return(false); } }
/* * EndRunningActions */ /**********************************************************************************************//** * Updates the end running described by networkElement. * * \author Ilan Hindy * \date 29/09/2016 * * \param networkElement The network element. * **************************************************************************************************/ public virtual void UpdateEndRunning(NetworkElement networkElement) { foreach (PresentationElement presentationElement in presentationElements.Values) { if (presentationElement.debugWindow != null) { presentationElement.debugWindow.Close(); presentationElement.debugWindow = null; } //if (presentationElement.breakpointWindow != null) //{ // presentationElement.breakpointWindow.Close(); // presentationElement.breakpointWindow = null; //} } if (additionalControls[AdditionalControlKeys.FloatingSummary] != null) { canvas.Children.Remove(additionalControls[AdditionalControlKeys.FloatingSummary]); additionalControls.Remove(AdditionalControlKeys.FloatingSummary); } }
/**********************************************************************************************//** * Updates the running status. * * \author Ilan Hindy * \date 29/09/2016 * * \param networkElement The network element. * \param parameters Options for controlling the operation. * **************************************************************************************************/ public override void UpdateRunningStatus(NetworkElement networkElement, object[] parameters) { //string msg = "Updating presentation of channel " + // ((BaseChannel)networkElement).ElementAttributes[NetworkElement.ElementAttributeKeys.Id].ToString() + // " The text is :" + ((BaseChannel)networkElement).pp[bc.ppk.PresentationText]; //CustomizedMessageBox.Show(msg, "", Icons.Info); //Update the incomming message GetRelativeLinePositionForLabel(networkElement); Label channelLabel = ((Label)(presentationElements[networkElement].controls[PresentationElement.ControlKeys.Label])); //UpdateMessagesLabel((BaseChannel)networkElement, (string)parameters[0]); UpdateMessagesGrid((BaseChannel)networkElement, (List <string>)parameters[0]); int sourceProcess = networkElement.ea[bc.eak.SourceProcess]; int destProcess = networkElement.ea[bc.eak.DestProcess]; if (sourceProcess != destProcess) { UpdateLabel((BaseChannel)networkElement, channelLabel); } CreateFloatingSummary(); }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// \fn private bool CreateNetworkElementText(ref string fileText) /// /// \brief Creates network element text. /// /// \par Description. /// /// \par Algorithm. /// /// \par Usage Notes. /// /// \author Ilanh /// \date 18/03/2018 /// /// \param [in,out] fileText (ref string) - The file text. /// /// \return True if it succeeds, false if it fails. //////////////////////////////////////////////////////////////////////////////////////////////////// private bool CreateNetworkElementText(ref string fileText) { NetworkElement networkElement = new NetworkElement(); networkElement.Init(0); string text = eol + @"namespace DistributedAlgorithms" + eol + "{" + eol; text += eol + "\t#region /// \\name partial class for " + "NetworkElement"; text += eol + "\tpublic partial class " + "NetworkElement" + @": " + "IValueHolder"; text += eol + "\t{"; text += networkElement.CreateGettersSetters("ne"); text += eol + "\t}"; text += eol + "\t#endregion"; text += eol + "}"; if (ShowClass(ref fileText, "partial", text, "NetworkElement")) { return(true); } else { return(false); } }
/**********************************************************************************************//** * Updates the end running described by process. * * \author Ilan Hindy * \date 29/09/2016 * * \param process The process. * **************************************************************************************************/ public override void UpdateEndRunning(NetworkElement process) { base.UpdateEndRunning(process); UpdateBreakpointLabel((BaseProcess)process, new List <Breakpoint>()); }
/* * Set the sircle status and colors according to if it was selectted or not */ /**********************************************************************************************//** * Sets a selected. * * \author Ilan Hindy * \date 29/09/2016 * * \param networkElement The network element. * \param selectedStatus The selected status. * **************************************************************************************************/ public override void SetSelected(NetworkElement networkElement, MainWindow.SelectedStatus selectedStatus) { presentationElements[networkElement].status = selectedStatus; ((Ellipse)presentationElements[networkElement].controls[PresentationElement.ControlKeys.Circle]).Stroke = selectedColors[(int)selectedStatus]; }
/**********************************************************************************************//** * Reports change presentation of component. * * \author Ilan Hindy * \date 29/09/2016 * * \param networkElement The network element. * \param parameters Options for controlling the operation. * **************************************************************************************************/ public static void ReportChangePresentationOfComponent(NetworkElement networkElement, object[] parameters) { ReportChangePresentationEvent(networkElement, parameters); }
/* * Update the running status of the network element */ /**********************************************************************************************//** * Updates the running status. * * \author Ilan Hindy * \date 29/09/2016 * * \param networkElement The network element. * \param parameters Options for controlling the operation. * **************************************************************************************************/ public virtual void UpdateRunningStatus(NetworkElement networkElement, object[] parameters) { }
/* * Update the network element after change in the presentation */ /**********************************************************************************************//** * Updates the network element described by networkElement. * * \author Ilan Hindy * \date 29/09/2016 * * \param networkElement The network element. * **************************************************************************************************/ protected virtual void UpdateNetworkElement(NetworkElement networkElement) { mainWindow.networkWasChanged = true; }
/* * Set the status of the network element and paint the presentation accordinally */ /**********************************************************************************************//** * Sets a selected. * * \author Ilan Hindy * \date 29/09/2016 * * \param element The element. * \param status The status. * **************************************************************************************************/ public virtual void SetSelected(NetworkElement element, MainWindow.SelectedStatus status) { }