////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \fn private void Label_Drop(object sender, DragEventArgs e)
        ///
        /// \brief
        ///
        /// \par Description.
        ///      -  The Drop event occurs in the target when the mouse is released.
        ///      -  There are 3 options :
        ///         -#  __Continue__ the change (In this case the permutation and the labels are not changed)
        ///         -#  __Apply__ (In this case the methods of the event are called)
        ///         -#  __Quit__ Change (In this case the permutations list and the label strings are restored)
        ///
        /// \par Algorithm.
        ///
        /// \par Usage Notes.
        ///
        /// \author Ilanh
        /// \date 27/05/2018
        ///
        /// \param sender  (object) - Source of the event.
        /// \param e       (DragEventArgs) - Drag event information.
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        private void Label_Drop(object sender, DragEventArgs e)
        {
            Label label = (Label)sender;

            MessageRouter.ReportMessage("GridView", "In DragDrop source = " + sourceLabel.Content + " target = " + label.Content, "");
            if (label != null)
            {
                label.Foreground = Brushes.Black;
                label.Background = Brushes.White;
                string result = EndDragQuestion();
                switch (result)
                {
                case "Continue Change":
                    break;

                case "Apply":
                    ChangeFinishedEvent(permutations, presentedItemId);
                    permutations = null;
                    break;

                case "Quit Change":
                    for (int idx = 0; idx < permutations.Count; idx++)
                    {
                        permutations[idx] = idx;
                    }
                    SetContents();
                    break;
                }
            }
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \fn private Attribute GetExistingChildAttribute(dynamic key, Attribute newAttribute)
        ///
        /// \brief Gets existing child attribute.
        ///
        /// \par Description.
        ///      There can be the following cases
        ///      -# The attribute is found in both lists/dictionaries (So the attribute will be found)
        ///      -# The attribute is found only in the exists list
        ///         In this case There was a merge between the lists\dictionaries that puts the attributes
        ///         of the existing in the new so the attribute will be found
        ///      -# The attribute exists in the new and the exists - In this case the method returns null
        ///         that will cause the algorithm to skip on all the attribute tree
        ///
        ///
        ///
        /// \par Algorithm.
        ///
        /// \par Usage Notes.
        ///
        /// \author Ilanh
        /// \date 28/12/2017
        ///
        /// \param key           (dynamic) - The key.
        /// \param newAttribute  (Attribute) - The new attribute.
        ///
        /// \return The existing child attribute.
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        private Attribute GetExistingChildAttribute(dynamic key, Attribute newAttribute)
        {
            Attribute existingComplexAttribute = complexAttributes.Peek();
            string    s      = "";
            Attribute result = null;

            if (Attribute.GetValueCategory(existingComplexAttribute) == Attribute.AttributeCategory.ListOfAttributes)
            {
                s      = "Tring to find IdInList : " + newAttribute.IdInList.ToString();
                result = ((AttributeList)existingComplexAttribute.Value).GetAttribute(newAttribute.IdInList.ToString());
            }

            if (Attribute.GetValueCategory(existingComplexAttribute) == Attribute.AttributeCategory.AttributeDictionary)
            {
                s      = "Tring to find attribute with key " + TypesUtility.GetKeyToString(key);
                result = ((AttributeDictionary)existingComplexAttribute.Value).GetAttribute(key);
            }

            if (Attribute.GetValueCategory(existingComplexAttribute) == Attribute.AttributeCategory.NetworkElementAttribute)
            {
                result = ((NetworkElement)existingComplexAttribute.Value).GetDictionaryAttribute(key);
            }

            if (result == null)
            {
                s += " failed : ";
                MessageRouter.ReportMessage("NetworkUpdate - retrieve existing child", "", s);
            }
            return(result);
        }
        /*
         * Start sending - the main method of the sending
         */

        /**********************************************************************************************//**
        * Starts a sending.
        *
        * \author  Ilan Hindy
        * \date    29/09/2016
        *
        * \param   message The message.
        * \param   process The process.
        * \param   channel The channel.
        *
        **************************************************************************************************/

        public static void StartSending(BaseMessage message, BaseProcess process, BaseChannel channel)
        {
            try
            {
                // Establish the remote endpoint for the socket.
                string     localAddress = Dns.GetHostEntry(Dns.GetHostName()).AddressList.First(f => f.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork).ToString();
                IPEndPoint remoteEP     = new IPEndPoint(IPAddress.Parse(localAddress), channel.or[bc.ork.DestPort]);

                // Build the state object
                SocketStateObject state = new SocketStateObject();
                state.process = process;

                Socket client;

                //If this is the first time that there is a sending through the channel
                if (channel.sendingSocket == null)
                {
                    //Establish the local end point for the socket
                    int        localPort     = channel.or[bc.ork.SourcePort];
                    IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Parse(localAddress), localPort);

                    //Create a new socket
                    client = new Socket(AddressFamily.InterNetwork,
                                        SocketType.Stream, ProtocolType.Tcp);

                    //Bind the local address
                    client.Bind(localEndPoint);

                    //Set the socket in the channel and in the state object
                    channel.sendingSocket = client;
                    state.clientSocket    = client;


                    // Connect to the remote endpoint.
                    Logger.Log(Logger.LogMode.MainLogAndProcessLogAndMessageTrace, process.GetProcessDefaultName(), "AsynchronousSender.StartSending()", "before BeginConnect()", "", "ProcessSend");
                    client.BeginConnect(remoteEP,
                                        new AsyncCallback(ConnectCallback), state);
                    state.connectDone.WaitOne();
                }
                else //This is not the first sending from the channel
                {
                    //Get the socket from the channel and set it in the state object
                    client             = channel.sendingSocket;
                    state.clientSocket = client;
                }

                // Send test data to the remote device.
                MessageRouter.ReportMessageSent(process, new object[] { message });
                Send(message, state);
                state.sendDone.WaitOne();
            }
            catch (Exception e)
            {
                Logger.Log(Logger.LogMode.MainLogProcessLogAndError, process.GetProcessDefaultName(), "AsynchronousSender.StartSending()", "Error", e.ToString(), "Error");
            }
        }
        /*
         * ReceiveHandling
         * This method is responssible to devide the data received to packets and call
         * the ReceiveHandling method of the process
         * Note that there no connection from the way the data is sent to the way it is
         * Received. That meens that a several packets can be received in one Receive and
         * There is no garentee that the last packet in the data will end.
         * The packets (messages) are send with '#' termination flag
         * The received data is collected in state.buffer
         * Then it is copied to state.sb . The role of this variable is to hold all the
         *      data that was not processed
         * Then it converted to string
         * Then it is devided to packets
         * Then each packet except the last packet is handled
         * Then the last packet is checked :
         *      If the data received ends with '#' - do nothing because that meens that the last
         *          packet is empty
         *      else clear the state.data and fill it with the unterminated last packet to be joined
         *          by the next receive data
         * The following is the handling of a complete packet
         * 1. Generate a message object from the message data
         * 2. If the MessageType attribute of the message is "Terminate" set the termnateFlag and return
         * 3. wait untill the ReceiveHandling method of the process is not locked by another
         *      AsynchronousReader object
         * 4. Activate the ReceiveHandling method of the process with the data.
         */

        /**********************************************************************************************//**
        * Receive handling.
        *
        * \author  Ilan Hindy
        * \date    29/09/2016
        *
        * \param   bytesReceived   The bytes received.
        *
        **************************************************************************************************/

        public void ReceiveHandling(int bytesReceived)
        {
            String content = String.Empty;

            // There  might be more data, so store the data received so far.
            state.sb.Append(Encoding.ASCII.GetString(
                                state.buffer, 0, bytesReceived));

            //Convert the data to string
            content = state.sb.ToString();

            // Get the process
            BaseProcess process = state.process;

            //If any end of packets was received
            if (content.IndexOf("#") > -1)
            {
                //Devide the data to packets
                string[] packets = Regex.Split(content, "#");

                //Packet handling
                for (int idx = 0; idx < packets.Length - 1; idx++)
                {
                    //Create message from the packet
                    //BaseMessage message = new BaseMessage(packets[idx]);
                    string processName = "Process_" + process.ea[ne.eak.Id].ToString();
                    Logger.Log(Logger.LogMode.MainLogAndProcessLog, processName, "Receive", "Received message - packets[idx]", packets[idx], "ProcessReceive");
                    BaseMessage message = BaseMessage.CreateMessage(process.Network, packets[idx]);


                    if (TypesUtility.CompareDynamics(message.GetHeaderField(bm.pak.MessageType), bm.MessageTypes.Terminate))
                    {
                        terminateFlag = true;
                    }
                    process.MessageQHandling(ref message, MessageQOperation.AddMessage);
                    MessageRouter.ReportMessageReceive(process, new object[] { message });
                    //Logger.Log(Logger.LogMode.MainLogAndProcessLog, process.ToString(), "Receive", "Received message", message);
                }

                //If there is a unfinished packet
                if (content[content.Length - 1] != '#')
                {
                    //This is the last packet received and it is fregmented with the next package
                    state.sb.Clear();
                    state.sb.Append(packets[packets.Length - 1]);
                }
                else
                {
                    state.sb.Clear();
                }
            }
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \fn private bool PerformQuestion(AttributeDictionary entry, List<int> messageIdxs)
        ///
        /// \brief Performs the question action.
        ///
        /// \par Description.
        ///      -  Ask the user if to perform an order change
        ///      -  There can be 3 answers
        ///         -#  Yes
        ///         -#  No
        ///         -#  Remove from the list
        ///
        /// \par Algorithm.
        ///
        /// \par Usage Notes.
        ///
        /// \author Ilanh
        /// \date 27/05/2018
        ///
        /// \param sourceProcess (int) - Source process.
        ///
        /// \param entry       (List&lt;int&gt;) - The permutations.
        /// \param messageIdxs (List&lt;int&gt;) - The message idxs.
        ///
        /// \return True if it succeeds, false if it fails.
        ///
        /// \param MessageQ (AttributeList) - The message q.
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        private bool PerformQuestion(AttributeDictionary entry, List <int> messageIdxs)
        {
            MessageBoxElementData l1 = new MessageBoxElementData("Message from process : " + Element.ToString(), new Font {
                alignment = HorizontalAlignment.Center, fontWeight = FontWeights.Bold
            });
            MessageBoxElementData l2 = new MessageBoxElementData("In Previous running of the algorithm the order of the messages was change");
            MessageBoxElementData l3 = new MessageBoxElementData("The source process is :" + entry[Comps.SourceProcess].ToString());
            MessageBoxElementData l4 = new MessageBoxElementData("The source list is :", new Font {
                fontWeight = FontWeights.Bold
            });
            List <string> originalContent = new List <string>();
            AttributeList messagesQ       = entry[Comps.MessageQ];

            messagesQ.ForEach(a => originalContent.Add(((BaseMessage)a.Value).Description()));
            string originalString;
            string transforedString;

            PermutationString(entry[Comps.Permutations].AsList(), originalContent, out originalString, out transforedString);
            MessageBoxElementData l5 = new MessageBoxElementData(originalString);
            MessageBoxElementData l6 = new MessageBoxElementData("The transformed list is :", new Font {
                fontWeight = FontWeights.Bold
            });
            MessageBoxElementData l7 = new MessageBoxElementData(transforedString);
            MessageBoxElementData l8 = new MessageBoxElementData("Do you want to apply this change ?", new Font {
                fontWeight = FontWeights.Bold
            });
            MessageBoxElementData b1 = new MessageBoxElementData("Yes");
            MessageBoxElementData b2 = new MessageBoxElementData("No");
            MessageBoxElementData b3 = new MessageBoxElementData("Remove");
            string result            = MessageRouter.CustomizedMessageBox(new List <MessageBoxElementData> {
                l1, l2, l3, l4, l5, l6, l7, l8
            },
                                                                          "ChangeMessageOrder Message",
                                                                          new List <MessageBoxElementData> {
                b1, b2, b3
            },
                                                                          Icons.Question, true);
            string s = "";

            switch (result)
            {
            case "Yes":
                return(true);

            case "Remove":
                Remove((Attribute)entry.Parent);
                return(false);

            default:
                return(false);
            }
        }
Пример #6
0
        /*
         * WriteLog
         * This method actually writes the log to all the log destinations
         */

        /**********************************************************************************************//**
        * Writes a log.
        *
        * \author  Ilan Hindy
        * \date    29/09/2016
        *
        * \param   logMode         The log mode.
        * \param   sourceObject    Source object.
        * \param   log             The log.
        * \param   messageTraceLog The message trace log.
        * \param   logFilter       A filter specifying the log.
        *
        **************************************************************************************************/

        private static void WriteLog(LogMode logMode, string sourceObject, string log, string messageTraceLog, string logFilter)
        {
            lock (WriteLogLockObject)
            {
                //Find Whether to log according to the filter
                //If the Filters list is empty write all the logs othere wise the logFilter parameter has
                //to be found in the Filters list in order to write the log
                if (Filters.Count > 0)
                {
                    if (Filters.FirstOrDefault(s => s == logFilter) is null)
                    {
                        return;
                    }
                }

                //Write to the main log file
                if (traceLogFile == null)
                {
                    OpenMainLogFile();
                }
                traceListener.WriteLine(log);
                traceListener.Flush();

                //Write to the process private log file
                if (logMode == LogMode.MainLogAndProcessLog ||
                    logMode == LogMode.MainLogProcessLogAndError ||
                    logMode == LogMode.MainLogAndProcessLogAndMessageTrace)
                {
                    TextWriterTraceListener processTraceListener = GetProcessTraceListener(sourceObject);
                    processTraceListener.WriteLine(log);
                    processTraceListener.Flush();
                }

                //Create error message if needed
                if (logMode == LogMode.MainLogAndError ||
                    logMode == LogMode.MainLogProcessLogAndError)
                {
                    MessageRouter.MessageBox(new List <String> {
                        log
                    }, "Log Report", null, Icons.Error);
                }
            }

            //Write to message trace window
            if (logMode == LogMode.MainLogAndProcessLogAndMessageTrace || logMode == LogMode.MainLogAndMessageTrace)
            {
                MessageRouter.ReportMessage(sourceObject, VectorClockString(), messageTraceLog);
            }
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \fn private void Label_DragEnter(object sender, DragEventArgs e)
        ///
        /// \brief Enabling the object to be a drag target
        ///
        /// \par Description.
        ///      -  The DragEnter event specifies how the target object will behave
        ///         when the source object will pass on it.
        ///
        /// \par Algorithm.
        ///      -  The method of the "drag" is to change the texts in the labels and the colors
        ///      -  The labels themselves are not replacing places
        ///
        /// \par Usage Notes.
        ///
        /// \author Ilanh
        /// \date 27/05/2018
        ///
        /// \param sender  (object) - Source of the event.
        /// \param e       (DragEventArgs) - Drag event information.
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        private void Label_DragEnter(object sender, DragEventArgs e)
        {
            Label label = sender as Label;

            MessageRouter.ReportMessage("GridView", "In DragEnter source = " + sourceLabel.Content + " target = " + label.Content, "");
            if (label != null)
            {
                sourceLabel.Foreground = Brushes.Black;
                sourceLabel.Background = Brushes.White;

                label.Foreground = Brushes.White;
                label.Background = Brushes.Blue;
                ReOrder(label);
            }
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \fn public void CheckFinishProcessingStep(BaseProcess process)
        ///
        /// \brief Check finish processing step.
        ///
        /// \brief #### Algorithm.
        ///
        /// \brief #### Usage Notes.
        ///
        /// \author Main
        /// \date 24/01/2017
        ///
        /// \param process The process.
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        public void CheckFinishProcessingStep(BaseProcess process)
        {
            //Logger.Log(Logger.LogMode.MainLogAndMessageTrace, "RunningHandler", "ProcessStartedReceiveIterationReport", " ProcessStartedReceiveIterationReport process id = " + process[ElementDictionaries.ElementAttributes].Value[NetworkElement.ElementAttributeKeys.Id].Value, "", "RunningHandler");
            if (finishDetector.CheckTermination(process, network))
            {
                network.UpdateRunningStatus(new object[] { processesInStep });
                Logger.Log(Logger.LogMode.MainLogAndMessageTrace, "RunningHandler TerminationAlgorithmStatus", "TerminationAlgorithmStatus", " TerminationAlgorithmStatus ", finishDetector.ReportStatus(), "RunningHandler TerminationAlgorithmStatus");
                Logger.Log(Logger.LogMode.MainLogAndMessageTrace, "RunningHandler", "", " -----------------------End Step " + step.ToString() + " -------------", "", "RunningHandler");
                step++;
                MessageRouter.UpdateRunningPresentation();
            }
            else
            {
                Logger.Log(Logger.LogMode.MainLogAndMessageTrace, "RunningHandler TerminationAlgorithmStatus", "TerminationAlgorithmStatus", " TerminationAlgorithmStatus ", finishDetector.ReportStatus(), "RunningHandler TerminationAlgorithmStatus");
            }
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \fn public void MessageReceiveReport(BaseProcess process, BaseMessage message)
        ///
        /// \brief Message receive report.
        ///
        /// \brief #### Algorithm.
        ///
        /// \brief #### Usage Notes.
        ///
        /// \author Main
        /// \date 24/01/2017
        ///
        /// \param process The process.
        /// \param message The message.
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        public void MessageReceiveReport(BaseProcess process, BaseMessage message)
        {
            vectorClock[process.ea[ne.eak.Id]] += 1;
            Logger.Log(Logger.LogMode.MainLogAndMessageTrace, "RunningHandler", "MessageReceiveReport", " MessageReceiveReport ", message, "RunningHandler");
            if (finishDetector.MessageReceiveReport(process, message, network))
            {
                network.UpdateRunningStatus(new object[] { processesInStep });
                Logger.Log(Logger.LogMode.MainLogAndMessageTrace, "RunningHandler TerminationAlgorithmStatus", "TerminationAlgorithmStatus", " TerminationAlgorithmStatus ", finishDetector.ReportStatus(), "RunningHandler TerminationAlgorithmStatus");
                Logger.Log(Logger.LogMode.MainLogAndMessageTrace, "RunningHandler", "", "-----------------------End Step " + step.ToString() + " -------------", "", "RunningHandler");
                MessageRouter.UpdateInitRunningPresentation();
                step++;
            }
            else
            {
                Logger.Log(Logger.LogMode.MainLogAndMessageTrace, "RunningHandler TerminationAlgorithmStatus", "TerminationAlgorithmStatus", " TerminationAlgorithmStatus ", finishDetector.ReportStatus(), "RunningHandler TerminationAlgorithmStatus");
            }
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \fn private void Report(string message)
        ///
        /// \brief Reports.
        ///
        /// \par Description.
        ///      Generate a message with the status to the MessagesWindow
        ///
        /// \par Algorithm.
        ///
        /// \par Usage Notes.
        ///
        /// \author Ilanh
        /// \date 07/01/2018
        ///
        /// \param message  (string) - The message.
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        private void Report(string message)
        {
            string s = "\n" + message + "\n";

            Attribute[] stack = complexAttributes.ToArray();
            for (int idx = 0; idx < stack.Length; idx++)
            {
                if (stack[idx].Parent != null)
                {
                    s += "\t\t\t" + stack[idx].Parent.GetChildKey(stack[idx]).ToString() + "\n";
                }
                else
                {
                    s += "\t\t\t" + stack[idx].Value.GetType().ToString();
                }
            }
            MessageRouter.ReportMessage("NetworkUpdate", "", s);
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \fn private void MergeDictionaries(Attribute existAttribute, Attribute newAttribute)
        ///
        /// \brief Merge dictionaries.
        ///
        /// \par Description.
        ///      -  Clever merge between the existing and new dictionaries
        ///         -  If the attribute is found in the existing and the new
        ///             -   Copy the value from the existing to the new only if the value of the attribute was changed during network build
        ///         -  If the attribute is found in the existing and not the new
        ///             -   Add the attribute tree to the new
        ///         -  If (Default case - automatically happens) The attribute exists in the new and not the old
        ///             -  keep it in the new
        ///      -  The attributes are identified using the keys
        ///
        /// \par Algorithm.
        ///
        /// \par Usage Notes.
        ///
        /// \author Ilanh
        /// \date 28/12/2017
        ///
        /// \param existAttribute  (Attribute) - The exist attribute.
        /// \param newAttribute     (Attribute) - The new attribute.
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        private void MergeDictionaries(Attribute existAttribute, Attribute newAttribute)
        {
            foreach (var existEntry in existAttribute.Value)
            {
                Attribute newAttr = ((AttributeDictionary)newAttribute.Value).FirstOrDefault(e => TypesUtility.CompareDynamics(e.Key, existEntry.Key)).Value;
                string    s       = " ** " + TypesUtility.GetKeyToString(existEntry.Key) + " **";
                if (newAttr == null)
                {
                    s += "Attribute null";
                }
                else
                {
                    s += "Attribute value = " + newAttr.Value.ToString();
                }
                MessageRouter.ReportMessage("Attribute Dictionary Merge ", "", s);
                if (newAttr is null)
                {
                    newAttr = new Attribute();
                    ((AttributeDictionary)newAttribute.Value).Add(existEntry.Key, newAttr);
                    newAttr.DeepCopy(existEntry.Value);
                }
                else
                {
                    if (existEntry.Value.Changed)
                    {
                        if (Attribute.GetValueCategory(existEntry.Value) == Attribute.AttributeCategory.PrimitiveAttribute)
                        {
                            newAttr.Value = existEntry.Value.Value;
                        }
                    }
                }
            }
            foreach (var newEntry in newAttribute.Value)
            {
                if (!existAttribute.Value.ContainsKey(newEntry.Key))
                {
                    Attribute attr = new Attribute();
                    attr.DeepCopy(newEntry.Value);
                    existAttribute.Value.Add(newEntry.Key, attr);
                }
            }
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \fn public void Terminate()
        ///
        /// \brief Terminates this object.
        ///
        /// \brief #### Algorithm.
        ///
        /// \brief #### Usage Notes.
        ///
        /// \author Main
        /// \date 24/01/2017
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        public void Terminate(bool alreadyRunning = true)
        {
            if (!alreadyRunning)
            {
                MessageRouter.ReportFinishRunning();
                return;
            }
            //First empty all the message queues of all the processors
            foreach (BaseProcess process in network.Processes)
            {
                BaseMessage message = new BaseMessage(network);
                process.MessageQHandling(ref message, MessageQOperation.EmptyQueue);
                process.or[bp.ork.TerminationStatus] = BaseProcess.TerminationStatuses.NotTerminated;
            }

            //If the process read a message but waiting for the breakpoint event to be released
            //Replace the message waiting with an empty message
            foreach (BaseProcess process in network.Processes)
            {
                if (process.WaitingForBreakpointEvent)
                {
                    process.MessageInProcess = new BaseMessage(network);
                }
            }

            //Activate terminate off all the processors
            network.or[bn.ork.SingleStepStatus] = false;
            foreach (BaseProcess process in network.Processes)
            {
                process.Terminate();
            }

            //Activating the processes
            network.or[bn.ork.SingleStepStatus] = false;

            foreach (BaseProcess process in network.Processes)
            {
                process.BreakpointEvent.Set();
            }
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \fn private string EndDragQuestion()
        ///
        /// \brief Ends drag question.
        ///
        /// \par Description.
        ///      Ask the user what he wants to do with the change
        ///
        /// \par Algorithm.
        ///
        /// \par Usage Notes.
        ///
        /// \author Ilanh
        /// \date 27/05/2018
        ///
        /// \return A string.
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        private string EndDragQuestion()
        {
            MessageBoxElementData l1 = new MessageBoxElementData("The permutation list is :", new Font {
                fontWeight = FontWeights.Bold, wrap = TextWrapping.NoWrap
            });
            MessageBoxElementData l2 = new MessageBoxElementData("The source list is :", new Font {
                fontWeight = FontWeights.Bold, wrap = TextWrapping.NoWrap
            });
            string originalString;
            string transforedString;

            PresentPermutationEvent(permutations, originalContent, out originalString, out transforedString);
            MessageBoxElementData l3 = new MessageBoxElementData(originalString, new Font {
                wrap = TextWrapping.NoWrap
            });
            MessageBoxElementData l4 = new MessageBoxElementData("The transformed list is :", new Font {
                fontWeight = FontWeights.Bold, wrap = TextWrapping.NoWrap
            });
            MessageBoxElementData l5 = new MessageBoxElementData(transforedString, new Font {
                wrap = TextWrapping.NoWrap
            });
            MessageBoxElementData l6 = new MessageBoxElementData("What do you want to do?", new Font {
                fontWeight = FontWeights.Bold, wrap = TextWrapping.NoWrap
            });
            MessageBoxElementData b1 = new MessageBoxElementData("Continue Change", new Font {
                fontWeight = FontWeights.Bold, wrap = TextWrapping.NoWrap
            });
            MessageBoxElementData b2 = new MessageBoxElementData("Apply");
            MessageBoxElementData b3 = new MessageBoxElementData("Quit Change", new Font {
                fontWeight = FontWeights.Bold, wrap = TextWrapping.NoWrap
            });

            return(MessageRouter.CustomizedMessageBox(new List <MessageBoxElementData> {
                l1, l2, l3, l4, l5, l6
            }, "GridView Message", new List <MessageBoxElementData> {
                b1, b2, b3
            }, Icons.Question, true));
        }
Пример #14
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \fn public static string Show(List<Control> controls = null, string title = "", List<Button> buttonsList = null, Icons imageIcon = Icons.Info, bool sizeToContent)
        ///
        /// \brief Shows.
        ///
        /// \par Description.
        ///
        /// \par Algorithm.
        ///
        /// \par Usage Notes.
        ///
        /// \author Ilanh
        /// \date 10/12/2017
        ///
        /// \param controls      (Optional)  (List&lt;Control&gt;) - The controls.
        /// \param title         (Optional)  (string) - The title.
        /// \param buttonsList   (Optional)  (List&lt;Button&gt;) - List of buttons.
        /// \param imageIcon     (Optional)  (Icons) - The image icon.
        /// \param sizeToContent  (bool) - true to size to content.
        ///
        /// \return A string.
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        public static string Show(List <Control> controls, string title, List <Button> buttonsList, Icons imageIcon, bool sizeToContent)
        {
            if (controls == null)
            {
                controls = new List <Control>();
            }
            if (controls.Count == 0)
            {
                controls.Add(SetLabel(""));
            }
            if (buttonsList == null)
            {
                buttonsList = new List <Button>();
                buttonsList.Add(SetButton("OK"));
            }

            CustomizedMessageBox messageBox = new CustomizedMessageBox();

            if (!sizeToContent)
            {
                messageBox.MaxWidth = 500;
            }

            messageBox.Title = title;

            //Image
            Image image = SetImage(imageIcon);

            messageBox.panImage.Children.Add(image);

            //Controls
            string fullMessage = "";

            foreach (Control control in controls)
            {
                messageBox.panText.Children.Add(control);
                if (control is TextBox)
                {
                    fullMessage += ((TextBox)control).Text + "\n";
                }
                else if (control is SyntaxHighlight)
                {
                    messageBox.MaxWidth = 1200;
                    fullMessage        += ((SyntaxHighlight)control).Text;
                }
            }

            //Buttons
            int insertIdx = 0;

            foreach (Button button in buttonsList)
            {
                messageBox.panButtons.ColumnDefinitions.Add(new ColumnDefinition());
                messageBox.panButtons.Children.Add(button);
                Grid.SetColumn(button, insertIdx);
                Grid.SetRow(button, 0);
                button.Click += new RoutedEventHandler(messageBox.Button_Click);
                insertIdx++;
            }

            MessageRouter.AddEditOperation(title, fullMessage, imageIcon, new Font("Calibbri", 12, FontStyles.Normal, FontWeights.Normal, new Thickness(0), HorizontalAlignment.Left, Brushes.Black, null, TextWrapping.NoWrap));
            messageBox.ShowDialog();
            MessageRouter.AddEditOperationResult(messageBox.Result, new Font("Calibbri", 12, FontStyles.Normal, FontWeights.Normal, new Thickness(0), HorizontalAlignment.Left, Brushes.Black, null, TextWrapping.NoWrap));
            return(messageBox.Result);
        }
Пример #15
0
 private void PrintResults()
 {
     MessageRouter.CustomizedMessageBox(results);
 }
Пример #16
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \fn public static void GenerateCheckMessage(this IValueHolder valueHolder, int nestingLevel, string key, string message)
        ///
        /// \brief Generates a check message.
        ///
        /// \par Description.
        ///
        /// \par Algorithm.
        ///
        /// \par Usage Notes.
        ///
        /// \author Ilanh
        /// \date 25/07/2017
        ///
        /// \param valueHolder  The valueHolder to act on.
        /// \param nestingLevel  (int) - The nesting level.
        /// \param key           (string) - The key.
        /// \param message       (string) - The message.
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        public static void GenerateCheckMessage(this IValueHolder valueHolder, int nestingLevel, string key, string message)
        {
            MessageRouter.ReportMessage(new string('\t', nestingLevel) + "[" + key + "] (" + valueHolder.GetType().ToString().Replace("DistributedAlgorithms.", "") + ") ", "", message);
        }
Пример #17
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \fn public static bool EqualsTo(this IValueHolder valueHolder, int nestingLevel, object key, IValueHolder other, bool checkNotSameObject = false)
        ///
        /// \brief Equals to.
        ///
        /// \par Description.
        ///      -  This method recursively checks if the first IValueHolder is equal to the second
        ///      -  The compare is for the values and not the pointers of the IValueHolder
        ///      -  The parameter checkNotSameObject is for checking that there was a copy (means created
        ///         new objects) and not assignments.
        ///
        /// \par Algorithm.
        ///      -# Common checks for all the IValueHolder
        ///         -#  The type of the 2 IValueHolder is the same
        ///         -#  If checkNotSameObject check that the objects are not the same objects
        ///      -# Activate the recursive compare by calling the IValueHolder's EqualsTo method.
        ///
        /// \par Usage Notes.
        ///
        /// \author Ilanh
        /// \date 25/07/2017
        ///
        /// \param valueHolder        The valueHolder to act on.
        /// \param nestingLevel        (int) - The nesting level.
        /// \param key                 (object) - The key.
        /// \param other               (IValueHolder) - The other.
        /// \param checkNotSameObject (Optional)  (bool) - true to check not same object.
        ///
        /// \return True if equals to, false if not.
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        public static bool CheckEqual(this IValueHolder valueHolder,
                                      int nestingLevel,
                                      object key,
                                      IValueHolder other,
                                      bool print = false,
                                      bool checkNotSameObject = false)
        {
            string keyString = TypesUtility.GetKeyToString(key);

            if (print)
            {
                if (nestingLevel == 0)
                {
                    MessageRouter.ReportMessage("----- Start EqualsTo -----", "", "");
                }

                valueHolder.GenerateCheckMessage(nestingLevel, keyString, " Start");
            }
            if (!valueHolder.GetType().Equals(other.GetType()))
            {
                valueHolder.GenerateCheckMessage(nestingLevel, keyString, "The type of one is : " + valueHolder.GetType() +
                                                 " The type of two is : " + other.GetType());
                return(false);
            }

            if (checkNotSameObject)
            {
                if (valueHolder == other)
                {
                    valueHolder.GenerateCheckMessage(nestingLevel, keyString, "The pointer of one and two is equal and it should not");
                    return(false);
                }
            }

            string error = "";

            if (valueHolder.EqualsTo(nestingLevel, ref error, other, print, checkNotSameObject))
            {
                if (print)
                {
                    if (nestingLevel == 0)
                    {
                        MessageRouter.ReportMessage("----- Start EqualsTo -----", "", "");
                    }
                    valueHolder.GenerateCheckMessage(nestingLevel, keyString, " End - True");
                }
                return(true);
            }
            else
            {
                if (print)
                {
                    valueHolder.GenerateCheckMessage(nestingLevel, keyString, " " + error);
                    valueHolder.GenerateCheckMessage(nestingLevel, keyString, " End - False");
                    if (nestingLevel == 0)
                    {
                        MessageRouter.ReportMessage("----- End EqualsTo -----", "", "");
                    }
                }
                return(false);
            }
        }