コード例 #1
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \fn public static bool AddAlgorithmWindowAttributeEditable(this IValueHolder valueHolder, NetworkElement networkElement, NetworkElement.ElementDictionaries mainDictionary)
        ///
        /// \brief An IValueHolder extension method that decides whether an attribute is editable in AddAlgorithmWindow
        ///
        /// \par Description.
        ///
        /// \par Algorithm.
        ///
        /// \par Usage Notes.
        ///
        /// \author Ilanh
        /// \date 29/10/2017
        ///
        /// \param valueHolder    The valueHolder to act on.
        /// \param networkElement  (NetworkElement) - The network element.
        /// \param mainDictionary  (ElementDictionaries) - Dictionary of mains.
        ///
        /// \return True if it succeeds, false if it fails.
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        public static bool AddAlgorithmWindowAttributeEditable(this IValueHolder valueHolder, NetworkElement networkElement, NetworkElement.ElementDictionaries mainDictionary)
        {
            // In AddAlgorithm window the ElementAttributes should be disabled because this window
            // is for adding new keys for a new algorithm and the ElementAttributes dictionary is for
            // the base types only
            if (mainDictionary == NetworkElement.ElementDictionaries.ElementAttributes)
            {
                return(false);
            }

            // For other dictionaries if the AttributeDictionary belongs to the base class it should
            // be disabled because the window is allowed to change only attributes that belongs
            // to the Algorithm and not the base algorithm
            // This rule is not applied to the messages NetworkElement because all the messages
            // should be changeable (The base class is empty anyway)
            else
            {
                if (networkElement.GetType().Equals(typeof(NetworkElement)))
                {
                    return(true);
                }
                else
                {
                    return(!valueHolder.BelongsToBaseAlgorithmEnum(networkElement, mainDictionary));
                }
            }
        }
コード例 #2
0
        /*
         * Create a lebel and an input field for each one of the network element attributes
         */
        private void CreateAttributesControls()
        {
            /*
             * The windows header
             */
            TextBox_Name.Text = "Element of type : " + networkElement.GetType().ToString();

            /*
             * Add Attributes controls
             */
            foreach (var elementAttribute in networkElement[ElementDictionaries.ElementAttributes].Value)
            {
                string keyString     = TypesUtility.GenerateKeyString(elementAttribute.Key);
                string attributeName = TypesUtility.GetEnumValueToString(elementAttribute.Key);
                StackPanel_AttributeNames.Children.Add(CreateLabel("Label_Attribute_key_" + keyString, attributeName));
                Control control = Attribute.CreateInputField(elementAttribute.Value.Value, TypesUtility.GetEnumValueToString(elementAttribute.Key), elementAttribute.Value.Editable, Ediatble);
                control.Name = "AttributeInput_" + keyString;
                SetControl(control);
                StackPanel_AttributeValues.Children.Add(control);
            }

            foreach (var privateAttribute in networkElement[ElementDictionaries.PrivateAttributes].Value)
            {
                string keyString = TypesUtility.GenerateKeyString(privateAttribute.Key);
                StackPanel_AttributeNames.Children.Add(CreateLabel("Label_Attribute_key_" + keyString, keyString));
                Control control = Attribute.CreateInputField(privateAttribute.Value.Value, TypesUtility.GetEnumValueToString(privateAttribute.Key), privateAttribute.Value.Editable, Ediatble);
                control.Name = "AttributeInput_" + keyString;
                SetControl(control);
                StackPanel_AttributeValues.Children.Add(control);
            }

            /*
             * Set the windows height according to the number of the attributes
             */
            SetWindowHeight();
        }
コード例 #3
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// \fn public static bool CheckIfBelongsToBaseAlgorithmEnum(this IValueHolder valueHolder, NetworkElement networkElement, NetworkElement.ElementDictionaries mainDictionary)
        ///
        /// \brief An IValueHolder extension method that determine if belongs to base algorithm enum.
        ///
        /// \par Description.
        ///
        /// \par Algorithm.
        ///
        /// \par Usage Notes.
        ///
        /// \author Ilanh
        /// \date 29/10/2017
        ///
        /// \param valueHolder    The valueHolder to act on.
        /// \param networkElement  (NetworkElement) - The network element.
        /// \param mainDictionary  (ElementDictionaries) - Dictionary of mains.
        ///
        /// \return True if the value holder belongs to the base network element.
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        public static bool BelongsToBaseAlgorithmEnum(this IValueHolder valueHolder, NetworkElement networkElement, NetworkElement.ElementDictionaries mainDictionary)
        {
            // If the value holder is not attribute get the attribute of the value holder
            Attribute attribute;

            if (!(valueHolder is Attribute))
            {
                attribute = (Attribute)valueHolder.Parent;
            }
            else
            {
                attribute = (Attribute)valueHolder;
            }

            // The condition is that the attribute which is the ancestor of our attribute
            // which is in the main dictionary belongs to the base class
            // Find the ancestor.
            // The parent sequence is ending in the following way
            // null <- networkElement <- Attribute <- mainDictionary <- Attribute
            // We have to find the last element in the chain described below
            // We do it with a loop that advances 2 parameters: The attribute and the chain end
            // The chain end is 4 times the parent of the attribute
            // Get the first chain end (If we cannot end the chain that means that the valueHolder is
            // one of the value holders at the middle of the chain hence they are not attributes in the
            // base classes main dictionary
            IValueHolder chainEnd = attribute;

            for (int idx = 0; idx < 4; idx++)
            {
                chainEnd = chainEnd.Parent;
                if (chainEnd == null && idx != 3)
                {
                    return(false);
                }
            }

            // Find the ancestor
            while (chainEnd != null)
            {
                chainEnd  = chainEnd.Parent.Parent;
                attribute = (Attribute)attribute.Parent.Parent;
            }

            // Decide if the attribute is part of the main dictionary
            if (!((AttributeDictionary)networkElement[mainDictionary]).Values.Any(a => a == attribute))
            {
                return(false);
            }

            // Get the key of the attribute
            dynamic key = attribute.Parent.GetChildKey(attribute);

            if (TypesUtility.CompareDynamics(key, bn.ork.SingleStepStatus))
            {
                int x = 1;
            }

            // Get the base NetworkElement
            Type           baseNetworkElementType = networkElement.GetType().BaseType;
            NetworkElement baseNetworkElement     = (NetworkElement)TypesUtility.CreateObjectFromTypeString(baseNetworkElementType.ToString());

            baseNetworkElement.Init(0);

            // Check if the key is found in the base network element's dictionary
            return(((AttributeDictionary)baseNetworkElement[mainDictionary]).Keys.Any(k => TypesUtility.CompareDynamics(k, key)));
        }