////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \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);
        }
示例#3
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 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 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);
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \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);
            }
        }