Exemple #1
0
        /**********************************************************************************************//**
        * Replace value.
        *
        * \author  Ilan Hindy
        * \date    29/09/2016
        *
        * \return  An IndexCreatingOperation.
        *  .
        **************************************************************************************************/

        private IndexCreatingOperation replaceValue()
        {
            bool   converted;
            object value = TypesUtility.Parse(list.GetType().GenericTypeArguments[0], TextBox_Replace_AddValue.Text, out converted);

            if (converted)
            {
                if (ListBox_Elements.SelectedIndex >= 0)
                {
                    TypesUtility.InvokeMethodOfList(list, "RemoveAt", new object[] { ListBox_Elements.SelectedIndex }, false);
                    TypesUtility.InvokeMethodOfList(list, "Insert", new object[] { ListBox_Elements.SelectedIndex, value }, false);
                    return(IndexCreatingOperation.Current);
                }
                else
                {
                    TypesUtility.InvokeMethodOfList(list, "Add", new object[] { value }, false);
                    return(IndexCreatingOperation.Start);
                }
            }
            else
            {
                CustomizedMessageBox.Show("Cannot convert value " + TextBox_AddValue.Text + " to type " + list.GetType().GenericTypeArguments[0].ToString(), "List Input Message", Icons.Error);
                return(IndexCreatingOperation.Start);
            }
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \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);
        }
Exemple #3
0
 public Breakpoint(HostingElementTypes hostingElementType) :
     base(true)
 {
     Init(0);
     or[brp.ork.HostingElementType] = hostingElementType;
     or[brp.ork.Name] = TypesUtility.GetKeyToString(hostingElementType) + " Breakpoint";
 }
Exemple #4
0
        /**********************************************************************************************//**
        * Writes to edit log file.
        *
        * \author  Ilan Hindy
        * \date    16/01/2017
        *
        * \param   sender          The sender.
        * \param   messageLines    The message lines.
        * \param   result          The result.
        * \param   icon            The icon.
        **************************************************************************************************/

        public static string WriteOperationToEditLogFile(string sender, string [] messageLines, Icons icon, bool newLineAtTheEnd = true)
        {
            string timeString  = DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss.fff");
            string iconString  = TypesUtility.GetKeyToString(icon);
            string header      = timeString + " " + sender + iconString + " : ";
            string emptySpaces = new string(' ', header.Length);

            header += messageLines[0] + "\r\n";
            string log = header;

            for (int idx = 1; idx < messageLines.Length; idx++)
            {
                log += emptySpaces + messageLines[idx];
            }

            if (!newLineAtTheEnd)
            {
                log = log.Remove(log.Length - 3);
            }

            // The config is loaded before the edit log file is opened so we save the
            // logs untill the the file is opened and then dump them at the beginning of the log
            if (editTraceListener == null)
            {
                logsBeforeConfigLoad.Add(log);
            }
            else
            {
                editTraceListener.WriteLine(log);
                editTraceListener.Flush();
            }
            return(emptySpaces);
        }
Exemple #5
0
        /**********************************************************************************************//**
        * Init combo boxes.
        *
        * \author  Ilan Hindy
        * \date    29/09/2016
        *
        **************************************************************************************************/

        private void InitComboBoxes()
        {
            FillComboBox(ComboBox_SelectCategory, TypesUtility.GetTypesCategories());
            ComboBox_SelectCategory.SelectedIndex = 0;
            FillComboBox(ComboBox_SelectType, TypesUtility.GetTypesOfCategory((string)ComboBox_SelectCategory.SelectedItem));
            ComboBox_SelectType.SelectedIndex = 0;
        }
Exemple #6
0
        /**********************************************************************************************//**
        * Constructor.
        *
        * \author  Ilan Hindy
        * \date    29/09/2016
        *
        * \param   list        The list.
        * \param   network     The network.
        * \param   Editable    (Optional) True if editable.
        *
        **************************************************************************************************/

        public ListInput(object list, BaseNetwork network, bool Editable = true)
        {
            this.network       = network;
            listOfAttributes   = list.GetType().GenericTypeArguments[0].Equals(typeof(Attribute));
            this.list          = list;
            listForResetToInit = TypesUtility.CreateListFromString(list.GetType().ToString());
            TypesUtility.CopyList(list, listForResetToInit);
            listForResetToSaved = TypesUtility.CreateListFromString(list.GetType().ToString());
            TypesUtility.CopyList(list, listForResetToSaved);
            InitializeComponent();
            if (!listOfAttributes)
            {
                Button_Edit.Visibility = System.Windows.Visibility.Collapsed;
                ComboBox_Replace_SelectValue.Visibility = System.Windows.Visibility.Collapsed;
                ComboBox_SelectValue.Visibility         = System.Windows.Visibility.Collapsed;
                ComboBox_SelectCategory.Visibility      = System.Windows.Visibility.Collapsed;
                ComboBox_SelectType.Visibility          = System.Windows.Visibility.Collapsed;
            }
            else
            {
                InitComboBoxes();
            }
            this.Title = "Editting list of type " + list.GetType().GenericTypeArguments[0].ToString();
            FillListBox(list, IndexCreatingOperation.Start);
            editable = Editable;
        }
Exemple #7
0
        internal static void UpdateMockCounters()
        {
            foreach (KeyValuePair <MockCounterGroup, ConfigModel> kvp in MockCounter.loadedMockCounters)
            {
                Destroy(kvp.Key.CounterName);
                Destroy(kvp.Key.CounterData);
            }
            if (TextHelper.CounterCanvas != null)
            {
                Destroy(TextHelper.CounterCanvas.gameObject);
            }
            TextHelper.CounterCanvas = null;
            List <ConfigModel> loadedModels = TypesUtility.GetListOfType <ConfigModel>();

            loadedModels = loadedModels.Where(x => !(x is CustomConfigModel)).ToList();
            loadedModels.ForEach(x => x = ConfigLoader.DeserializeFromConfig(x, x.DisplayName) as ConfigModel);
            foreach (CustomCounter potential in CustomCounterCreator.LoadedCustomCounters)
            {
                loadedModels.Add(potential.ConfigModel);
            }
            loadedModels.RemoveAll(x => x is null);

            foreach (ConfigModel counter in loadedModels)
            {
                MockCounter.Update(counter);
            }
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \fn private bool IsTrue(EventTriggerType trigger, BaseMessage message)
        ///
        /// \brief Query if 'trigger' is true.
        ///
        /// \par Description.
        ///      -  Check other triggers type (not the Initialize trigger)
        ///
        /// \par Algorithm.
        ///      -  Get the MessageType of the message and the round of the message
        ///      -  Calculate the other end of the message according to the trigger
        ///         -   For Send events the other end is the target of the message
        ///         -   For Receive events the other end is the source of the message
        ///      -  Check if all the parameters retrieved from the message are equal to the
        ///         EventTrigger members
        ///
        /// \par Usage Notes.
        ///
        /// \author Ilanh
        /// \date 09/05/2018
        ///
        /// \param trigger  (EventTriggerType) - The trigger.
        /// \param message  (BaseMessage) - The message.
        ///
        /// \return True if true, false if not.
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        private bool IsTrue(EventTriggerType trigger, BaseMessage message)
        {
            // Get the data of the message that caused the event
            int     messageRound = message.GetHeaderField(bm.pak.Round);
            dynamic messageType  = message.GetHeaderField(bm.pak.MessageType);

            // Get the other end of the message that caused the event:
            // For a sending event this is the destination of the message
            // For a receive event this is the source of the message
            int messageOtherEnd;

            if (trigger == EventTriggerType.AfterSendMessage || trigger == EventTriggerType.BeforeSendMessage)
            {
                messageOtherEnd = message.GetHeaderField(bm.pak.DestProcess);
            }
            else
            {
                messageOtherEnd = message.GetHeaderField(bm.pak.SourceProcess);
            }

            if (this[Comps.Trigger] == trigger &&
                this[Comps.Round] == messageRound &&
                TypesUtility.CompareDynamics(this[Comps.MessageType], messageType) &&
                this[Comps.OtherEnd] == messageOtherEnd)
            {
                return(true);
            }
            return(false);
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \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);
        }
Exemple #10
0
        /**********************************************************************************************//**
        * Creates an attribute.
        *
        * \author  Ilan Hindy
        * \date    29/09/2016
        *
        * \param [out] newValue    The new value.
        *
        * \return  true if it succeeds, false if it fails.
        *  .
        **************************************************************************************************/

        private bool CreateAttribute(out object newValue)
        {
            string    valueString;
            Attribute attribute;

            if (!ComboBox_SelectValue.IsVisible)
            {
                valueString = TextBox_AddValue.Text;
            }
            else
            {
                valueString = (string)ComboBox_SelectValue.SelectedItem;
            }
            if (TypesUtility.CreateAttribute((string)ComboBox_SelectCategory.SelectedItem,
                                             (string)ComboBox_SelectType.SelectedItem,
                                             valueString, out attribute))
            {
                newValue = attribute;
                return(true);
            }
            else
            {
                CustomizedMessageBox.Show("Cannot convert value " + valueString + " to type " + (string)ComboBox_SelectType.SelectedItem, "List Input Message", Icons.Error);
                newValue = null;
                return(false);
            }
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \fn private MethodsLists()
        ///
        /// \brief Constructor that prevents a default instance of this class from being created.
        ///
        /// \par Description.
        ///
        /// \par Algorithm.
        ///
        /// \par Usage Notes.
        ///
        /// \author Ilanh
        /// \date 17/01/2018
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        private MethodsLists()
        {
            Mouse.OverrideCursor     = Cursors.Wait;
            endInputOperationMethods = TypesUtility.GetAllEndInputOperations();
            elementWindowPrmsMethod  = TypesUtility.GetAllElementWindowPrmsMethods();
            Mouse.OverrideCursor     = null;
        }
Exemple #12
0
        /**********************************************************************************************//**
        * Event handler. Called by Button_Add for click events.
        *
        * \author  Ilan Hindy
        * \date    29/09/2016
        *
        * \param   sender  Source of the event.
        * \param   e       Routed event information.
        *
        **************************************************************************************************/

        private void Button_Add_Click(object sender, RoutedEventArgs e)
        {
            if (!EditableCheck())
            {
                return;
            }
            bool   additionalSuccess;
            object newValue;

            if (listOfAttributes)
            {
                additionalSuccess = CreateAttribute(out newValue);
            }
            else
            {
                additionalSuccess = CreateValue(out newValue);
            }
            if (additionalSuccess)
            {
                TypesUtility.InvokeMethodOfList(list, "Add", new object[] { newValue }, false);
                FillListBox(list, IndexCreatingOperation.End);
                ListBox_Elements.SelectedIndex = ListBox_Elements.Items.Count - 1;
                if (Updated == false)
                {
                    Updated = true;
                }
            }
        }
        public static void GetFormatters(IMessagePackProvider provider, IMessagePackContext context, IDictionary <Type, IMessagePackFormatter> formatters, int formatterType, Assembly assembly = null)
        {
            if (provider == null)
            {
                throw new ArgumentNullException(nameof(provider));
            }
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            if (formatters == null)
            {
                throw new ArgumentNullException(nameof(formatters));
            }

            foreach (Type type in AssemblyUtility.GetBrowsableTypes <MessagePackFormatterAttribute>(assembly))
            {
                var attribute = type.GetCustomAttribute <MessagePackFormatterAttribute>(false);

                if (attribute.Type == formatterType && TypesUtility.TryCreateType(type, new object[] { provider, context }, out IMessagePackFormatter formatter))
                {
                    formatters.Add(formatter.TargetType, formatter);
                }
            }
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \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));
        }
Exemple #15
0
        /**********************************************************************************************//**
        * Event handler. Called by ComboBox_SelectType for selection changed events.
        *
        * \author  Ilan Hindy
        * \date    29/09/2016
        *
        * \param   sender  Source of the event.
        * \param   e       Selection changed event information.
        *
        **************************************************************************************************/

        private void ComboBox_SelectType_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            FillComboBox(ComboBox_SelectValue, TypesUtility.GetPossibleValues((string)ComboBox_SelectType.SelectedItem));
            if (ComboBox_SelectValue.Items.Count != 0)
            {
                ComboBox_SelectValue.SelectedIndex = 0;
            }
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \fn public static BaseNetwork GenerateNetwork(string subject = null, string algorithm = null)
        ///
        /// \brief Generates a network.
        ///
        /// \par Description.
        ///
        /// \par Algorithm.
        ///
        /// \par Usage Notes.
        ///
        /// \author Ilanh
        /// \date 19/11/2017
        ///
        /// \param subject   (Optional)  (string) - The subject.
        /// \param algorithm (Optional)  (string) - The algorithm.
        ///
        /// \return The network.
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        public static BaseNetwork GenerateNetwork(string subject = null, string algorithm = null)
        {
            if (algorithm is null)
            {
                algorithm = Config.Instance[Config.Keys.SelectedAlgorithm];
            }
            return((BaseNetwork)TypesUtility.CreateObjectFromTypeString(GenerateNamespace(subject, algorithm) + "." + algorithm + "Network"));
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \fn public void Activate()
        ///
        /// \brief Performs this object.
        ///
        /// \par Description.
        ///      Activate all the methods in the list (By the processor)
        ///
        /// \par Algorithm.
        ///
        /// \par Usage Notes.
        ///
        /// \author Ilanh
        /// \date 09/05/2018
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        public void Activate()
        {
            List <string> methods = (List <string>)AsList();

            for (int idx = 0; idx < methods.Count; idx++)
            {
                TypesUtility.InvokeMethod(Element, methods[idx], new List <object>(), 1, false);
            }
        }
Exemple #18
0
        /*
         * The possible parameters are:
         * key - in this case find the attribute
         * if the attribute found is a list
         *  if only one value from the list is requested
         *      return the value according to an index
         *  else return the list
         * else (the value is not a list) return the value
         */

        /**********************************************************************************************//**
        * Evaluate parameter.
        *
        * \author  Ilan Hindy
        * \date    29/09/2016
        *
        * \exception   EvaluationException Thrown when an Evaluation error condition occurs.
        *
        * \param   evaluationMode  The evaluation mode.
        * \param   network         The network.
        * \param   process         The process.
        * \param   channel         The channel.
        * \param   message         The message.
        * \param   parameter       The parameter.
        *
        * \return  An Attribute.
        *  .
        **************************************************************************************************/

        private Attribute EvaluateParameter(EvaluationMode evaluationMode, BaseNetwork network, BaseProcess process, BaseChannel channel, BaseMessage message, Attribute parameter)
        {
            if (parameter.Value.GetType().IsEnum)
            {
                if (!NetworkElementExist(network, process, channel, message))
                {
                    return(new Attribute()
                    {
                        Value = false
                    });
                }
                Attribute attribute = FindAttribute(network, process, channel, message, parameter.Value);
                if (attribute == null)
                {
                    string typeOfHostingElementStr = TypesUtility.GetKeyToString(or[brp.ork.HostingElementType]);
                    throw new EvaluationException("Could not find attribute " + TypesUtility.GetKeyToString(parameter.Value) + " In element of type " + typeOfHostingElementStr);
                }
                else
                {
                    if (Attribute.GetValueCategory(attribute) == Attribute.AttributeCategory.ListOfAttributes)
                    {
                        if (or[brp.ork.ListParameterOneOrAll] == ListParameterOneOrAll.One)
                        {
                            object[] elements       = TypesUtility.InvokeMethodOfList(attribute.Value, "ToArray", new object[0], true);
                            int      requestedIndex = or[brp.ork.IndexInList];
                            if (elements.Count() <= requestedIndex)
                            {
                                throw new EvaluationException("The index requested : " + requestedIndex.ToString() + " is larger or equal to the number of elements in the list : " + elements.Count());
                            }
                            else
                            {
                                if (Attribute.GetValueCategory(attribute) == Attribute.AttributeCategory.ListOfAttributes)
                                {
                                    return((Attribute)elements[requestedIndex]);
                                }
                                else
                                {
                                    return(new Attribute()
                                    {
                                        Value = elements[requestedIndex]
                                    });
                                }
                            }
                        }
                    }
                    return(attribute);
                }
            }
            if (parameter.Value.GetType().Equals(typeof(Breakpoint)))
            {
                return(new Attribute()
                {
                    Value = parameter.Value.Evaluate(evaluationMode, network, process, channel, message)
                });
            }
            return(parameter);
        }
Exemple #19
0
        /**********************************************************************************************//**
        * Event handler. Called by Button_Save for click events.
        *
        * \author  Ilan Hindy
        * \date    29/09/2016
        *
        * \param   sender  Source of the event.
        * \param   e       Routed event information.
        *
        **************************************************************************************************/

        private void Button_Save_Click(object sender, RoutedEventArgs e)
        {
            if (!EditableCheck())
            {
                return;
            }
            TypesUtility.CopyList(list, listForResetToSaved);
            ListBox_Elements.UpdateLayout();
            CustomizedMessageBox.Show("Finished Saving", "List Input Message", Icons.Success);
        }
Exemple #20
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \fn private List<TextFragment> CreatePrimitiveTypes(string text)
        ///
        /// \brief Creates primitive types.
        ///
        /// \par Description.
        ///
        /// \par Algorithm.
        ///
        /// \par Usage Notes.
        ///
        /// \author Ilanh
        /// \date 18/10/2017
        ///
        /// \param text  (string) - The text.
        ///
        /// \return The new primitive types.
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        private List <TextFragment> CreatePrimitiveTypes(string text)
        {
            List <Type>      types        = TypesUtility.GetPrimitiveTypes();
            HashSet <string> typesStrings = new HashSet <string>();

            types.ForEach(t => typesStrings.Add(t.ToString()));
            string tokensString = CreateTokensString(typesStrings);

            return(CreateMatchList(text, tokensString, Brushes.Red));
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \fn public BaseMessage GenerateMessage(BaseNetwork network, string messageString, string subject = null, string algorithm = null)
        ///
        /// \brief Generates a message.
        ///
        /// \par Description.
        ///
        /// \par Algorithm.
        ///
        /// \par Usage Notes.
        ///
        /// \author Ilanh
        /// \date 19/11/2017
        ///
        /// \param network        (BaseNetwork) - The network.
        /// \param messageString  (string) - The message string.
        /// \param subject       (Optional)  (string) - The subject.
        /// \param algorithm     (Optional)  (string) - The algorithm.
        ///
        /// \return The message.
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        public BaseMessage GenerateMessage(BaseNetwork network, string messageString, string subject = null, string algorithm = null)
        {
            if (algorithm is null)
            {
                algorithm = Config.Instance[Config.Keys.SelectedAlgorithm];
            }
            return((BaseMessage)TypesUtility.CreateObjectFromTypeString(
                       GenerateNamespace(subject, algorithm) + "." + algorithm + "Message",
                       new object[] { network, messageString }));
        }
Exemple #22
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \fn protected void Selection_SourceSubject_SelectionChanged(object sender, EventArgs e)
        ///
        /// \brief Event handler. Called by Selection_SourceSubject for selection changed events.
        ///
        /// \par Description.
        ///      -  The Source algorithms control change (To present the algorithms of the subject)
        ///      -  The Target subject control change (To set the Target subject is set to the source subject
        ///
        /// \par Algorithm.
        ///
        /// \par Usage Notes.
        ///
        /// \author Ilanh
        /// \date 29/08/2017
        ///
        /// \param sender  (object) - Source of the event.
        /// \param e       (EventArgs) - Event information.
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        protected void Selection_SourceSubject_SelectionChanged(object sender, EventArgs e)
        {
            data[1].options     = TypesUtility.GetAlgorithmsOfSubject(Selection_SourceSubject.TextBox_Selected.Text);
            data[1].enableItems = null;
            Selection_SourceAlgorithm.Init(data[1]);
            if (((ListBoxItem)Selection_TargetSubject.ListBox_Options.Items[Selection_SourceSubject.ListBox_Options.SelectedIndex]).IsEnabled)
            {
                Selection_TargetSubject.ListBox_Options.SelectedIndex = Selection_SourceSubject.ListBox_Options.SelectedIndex;
            }
        }
Exemple #23
0
        /**********************************************************************************************//**
        * Event handler. Called by ListBox_Elements for selection changed events.
        *
        * \author  Ilan Hindy
        * \date    29/09/2016
        *
        * \param   sender  Source of the event.
        * \param   e       Selection changed event information.
        *
        **************************************************************************************************/

        private void ListBox_Elements_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (listOfAttributes)
            {
                Type      type;
                string    valueString;
                Attribute attribute;
                if (ListBox_Elements.SelectedItem == null)
                {
                    type        = typeof(string);
                    valueString = "";
                }
                else
                {
                    attribute   = ((List <Attribute>)list)[ListBox_Elements.SelectedIndex];
                    type        = attribute.Value.GetType();
                    valueString = attribute.GetValueToString();
                }
                if (type.IsEnum || type.Equals(typeof(bool)))
                {
                    FillComboBox(ComboBox_Replace_SelectValue, TypesUtility.GetPossibleValues(type.ToString()));
                    ComboBox_Replace_SelectValue.SelectedItem = valueString;
                    ComboBox_Replace_SelectValue.Visibility   = System.Windows.Visibility.Visible;
                    TextBox_Replace_AddValue.Visibility       = System.Windows.Visibility.Collapsed;
                    Button_Edit.Visibility         = System.Windows.Visibility.Collapsed;
                    Button_ReplaceValue.Visibility = System.Windows.Visibility.Visible;
                    return;
                }
                if (type.IsPrimitive || type.Equals(typeof(string)))
                {
                    TextBox_Replace_AddValue.Text           = valueString;
                    ComboBox_Replace_SelectValue.Visibility = System.Windows.Visibility.Collapsed;
                    TextBox_Replace_AddValue.Visibility     = System.Windows.Visibility.Visible;
                    Button_Edit.Visibility         = System.Windows.Visibility.Collapsed;
                    Button_ReplaceValue.Visibility = System.Windows.Visibility.Visible;
                    return;
                }
                ComboBox_Replace_SelectValue.Visibility = System.Windows.Visibility.Collapsed;
                TextBox_Replace_AddValue.Visibility     = System.Windows.Visibility.Collapsed;
                Button_Edit.Visibility         = System.Windows.Visibility.Visible;
                Button_ReplaceValue.Visibility = System.Windows.Visibility.Collapsed;
            }
            else
            {
                if (ListBox_Elements.SelectedItem != null)
                {
                    TextBox_Replace_AddValue.Text = ((ListBoxItem)(ListBox_Elements.SelectedValue)).Content.ToString();
                }
                else
                {
                    TextBox_Replace_AddValue.Text = TypesUtility.GetDefault(list.GetType().GenericTypeArguments[0]).ToString();
                    TextBox_AddValue.Text         = TypesUtility.GetDefault(list.GetType().GenericTypeArguments[0]).ToString();
                }
            }
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \fn public void Set(bool defaultValue)
        ///
        /// \brief Sets to default.
        ///
        /// \par Description.
        ///      Set all entries.
        ///
        /// \par Algorithm.
        ///
        /// \par Usage Notes.
        ///
        /// \author Ilanh
        /// \date 25/07/2017
        ///
        /// \param defaultValue (bool) - true to default value.
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        public void Set(bool defaultValue)
        {
            foreach (var phase in TypesUtility.GetAllEnumValues(typeof(MainWindow.ActivationPhases)))
            {
                foreach (var permition in TypesUtility.GetAllEnumValues(typeof(PermitionTypes)))
                {
                    permissions[(int)phase, (int)permition] = defaultValue;
                }
            }
            Set(MainWindow.ActivationPhases.Temp, true);
        }
Exemple #25
0
        /**********************************************************************************************//**
        * Convert this object into a string representation.
        *
        * \author  Ilan Hindy
        * \date    29/09/2016
        *
        *  Returns a string that represents the current object.
        *
        * \return  A string that represents the current object.
        *  .
        **************************************************************************************************/

        public override string ToString()
        {
            if (or.Count > 0)
            {
                return(TypesUtility.GetKeyToString(or[brp.ork.HostingElementType]) + ":" + or[brp.ork.Name]);
            }
            else
            {
                return("Brakepoint");
            }
        }
Exemple #26
0
        /**********************************************************************************************//**
        * Event handler. Called by Button_ResetToSaved for click events.
        *
        * \author  Ilan Hindy
        * \date    29/09/2016
        *
        * \param   sender  Source of the event.
        * \param   e       Routed event information.
        *
        **************************************************************************************************/

        private void Button_ResetToSaved_Click(object sender, RoutedEventArgs e)
        {
            if (!EditableCheck())
            {
                return;
            }
            TypesUtility.CopyList(listForResetToSaved, list);
            FillListBox(list, IndexCreatingOperation.Start);
            ListBox_Elements.UpdateLayout();
            CustomizedMessageBox.Show("Finished Reset to Saved", "List Input Message", Icons.Success);
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \fn public static BaseChannel GenerateChannel(bool permissionsValue, string subject = null, string algorithm = null)
        ///
        /// \brief Generates a channel.
        ///
        /// \par Description.
        ///
        /// \par Algorithm.
        ///
        /// \par Usage Notes.
        ///
        /// \author Ilanh
        /// \date 19/11/2017
        ///
        /// \param permissionsValue  (bool) - true to permissions value.
        /// \param subject          (Optional)  (string) - The subject.
        /// \param algorithm        (Optional)  (string) - The algorithm.
        ///
        /// \return The channel.
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        public static BaseChannel GenerateChannel(bool permissionsValue, string subject = null, string algorithm = null)
        {
            if (algorithm is null)
            {
                algorithm = Config.Instance[Config.Keys.SelectedAlgorithm];
            }
            BaseChannel channel = (BaseChannel)TypesUtility.CreateObjectFromTypeString(
                GenerateNamespace(subject, algorithm) + "." + algorithm + "Channel", new object[] { permissionsValue });

            return(channel);
        }
Exemple #28
0
        /**********************************************************************************************//**
        * Evaluate pair.
        *
        * \author  Ilan Hindy
        * \date    29/09/2016
        *
        * \exception   EvaluationException Thrown when an Evaluation error condition occurs.
        *
        * \param   prm1                    The first prm.
        * \param   prm2                    The second prm.
        * \param   evaluateExpressionFunc  The evaluate expression function.
        *
        * \return  true if it succeeds, false if it fails.
        *  .
        **************************************************************************************************/

        private bool EvaluatePair(dynamic prm1, dynamic prm2, EvaluateExpression evaluateExpressionFunc)
        {
            try
            {
                return(evaluateExpressionFunc(prm1, prm2));
            }
            catch (Exception e)
            {
                string operatorName = TypesUtility.GetKeyToString(or[brp.ork.Operator]);
                throw new EvaluationException("Error while evaluating " + operatorName + "(" + prm1.ToString() + "," + prm2.ToString() + ")" + "\n" + e.Message);
            }
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \fn public static BaseProcess GenerateProcess(bool permissionsValue, string subject = null, string algorithm = null)
        ///
        /// \brief Generates the process.
        ///
        /// \par Description.
        ///
        /// \par Algorithm.
        ///
        /// \par Usage Notes.
        ///
        /// \author Ilanh
        /// \date 19/11/2017
        ///
        /// \param permissionsValue  (bool) - true to permissions value.
        /// \param subject          (Optional)  (string) - The subject.
        /// \param algorithm        (Optional)  (string) - The algorithm.
        ///
        /// \return The process.
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        public static BaseProcess GenerateProcess(bool permissionsValue, string subject = null, string algorithm = null)
        {
            if (algorithm is null)
            {
                algorithm = Config.Instance[Config.Keys.SelectedAlgorithm];
            }

            BaseProcess process = (BaseProcess)TypesUtility.CreateObjectFromTypeString(
                GenerateNamespace() + "." + Config.Instance[Config.Keys.SelectedAlgorithm] + "Process", new object[] { permissionsValue });

            return(process);
        }
        /*
         * 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();
                }
            }
        }