Ejemplo n.º 1
0
 public ParameterInfo(String p_Category, String p_Name, String p_Field, String p_Combined, eParamParentType p_ParentType, String p_Value, String p_Description, String p_paramMin, String p_paramMax)
 {
     category = p_Category;
     name = p_Name;
     field = p_Field;
     combined = p_Combined;
     parentType = p_ParentType;
     paramValue = p_Value;
     description = p_Description;
     binaryData = null;
     paramMin = p_paramMin;
     paramMax = p_paramMax;
 }
Ejemplo n.º 2
0
        private void updateParameter(int parentID, eParamParentType parentType, String paramName, String value,
            String category, String name, String childField)
        {
            // now update parameter's value
            this.m_model.CreateParameter(parentID,
                parentType.ToString(),
                paramName, value, "");

            String key = "" + parentID;

            UpdateCacheWithValue(key, category, name, childField, value, parentType);
            cache.UpdateParameters(m_model, parentID, category, name, childField, value, parentType);
        }
Ejemplo n.º 3
0
        public void UpdateParameters(AME.Model.Model model, int parentID, string category, string name, string childField, string paramValue, eParamParentType paramParType)
        {
            XPathExpression exp = getParameterXPath(model, parentID, category, name, childField, paramParType);

            foreach (XmlDocument doc in documentCache[model].Values)
            {
                XPathNodeIterator nodes = doc.CreateNavigator().Select(exp);
                foreach (XPathNavigator node in nodes)
                {
                    node.MoveToAttribute(ConfigFileConstants.Value, "");
                    node.SetValue(paramValue);
                }
            }
        }
Ejemplo n.º 4
0
        private void ProcessNav(XPathNavigator nav, eParamParentType parentType, String classType)
        {
            PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(SelectedObject);

            XPathNodeIterator allComplex = null;

            if (parentType == eParamParentType.Component)
            {
                allComplex = nav.Select("ComponentParameters/Parameter[@type='" + ConfigFileConstants.complexType + "']");
            }
            else if (parentType == eParamParentType.Link)
            {
                allComplex = nav.Select("LinkParameters/Parameter[@type='" + ConfigFileConstants.complexType + "']");
            }

            while (allComplex.MoveNext())
            {
                String category = allComplex.Current.GetAttribute(ConfigFileConstants.category, allComplex.Current.NamespaceURI);
                XPathNodeIterator complexChildren = allComplex.Current.Select("Parameter");

                while (complexChildren.MoveNext())
                {
                    String displayName = complexChildren.Current.GetAttribute(ConfigFileConstants.displayedName, complexChildren.Current.NamespaceURI);
                    String value = complexChildren.Current.GetAttribute(ConfigFileConstants.Value, complexChildren.Current.NamespaceURI);

                    foreach (PropertyDescriptor thisProperty in properties)
                    {
                        if (thisProperty.DisplayName == displayName && thisProperty.Category == category)
                        {
                            UpdateValue(thisProperty, complexChildren.Current, value, this.SelectedObject);

                            // set browsable via reflection
                            String browsable = complexChildren.Current.GetAttribute(ConfigFileConstants.browsable, complexChildren.Current.NamespaceURI);
                            if (browsable != null && browsable.Length > 0)
                            {
                                bool stringToBool = Boolean.Parse(browsable);
   
                                try
                                {
                                    FieldInfo fld;
                                    BrowsableAttribute attr = (BrowsableAttribute)thisProperty.Attributes[BrowsableAttribute.Default.GetType()];

                                    Type attrType = attr.GetType();
                                    fld = attrType.GetField(ConfigFileConstants.browsable, BindingFlags.Instance | BindingFlags.NonPublic);
                                    fld.SetValue(attr, stringToBool);
                                }
                                catch (Exception Ex)
                                {
                                    throw Ex;
                                }
                            }

                            XPathNodeIterator structChildren = complexChildren.Current.Select("Parameters/Parameter");
                            if (structChildren.Count > 0)
                            {
                                Object structObject = LoadClass(classType, displayName);
                                while (structChildren.MoveNext())
                                {
                                    String name = structChildren.Current.GetAttribute(ConfigFileConstants.Name, structChildren.Current.NamespaceURI);
                                    value = structChildren.Current.GetAttribute(ConfigFileConstants.Value, structChildren.Current.NamespaceURI);

                                    foreach (PropertyDescriptor childProperty in thisProperty.GetChildProperties())
                                    {
                                        if (childProperty.DisplayName == name)
                                        {
                                            UpdateValue(childProperty, structChildren.Current, value, structObject);
                                            break;
                                        }
                                    }
                                }
                            }

                            break;
                        }
                    }
                }
            }

            this.Refresh();
        }
Ejemplo n.º 5
0
 public void UpdateParameters(int parentID, string paramName, byte[] paramValue, eParamParentType paramParType)
 {
     UpdateParameters(parentID, paramName, paramValue, paramParType, true);
 }
Ejemplo n.º 6
0
        private ParameterInfo GetParameterInfo(XmlNode parameter,
        String category, String name, String field, Type cSharpType, ParamConstraint paramConstraint, eParamParentType parent)
        {
            XmlAttribute valueAttr, descriptionAttr;
            String valueAttrValue, descriptionAttrValue = "", combined;
            String paramMin = null;
            String paramMax = null;

            descriptionAttr = parameter.Attributes[ConfigFileConstants.description];

            if (descriptionAttr != null) // optional
            {
                descriptionAttrValue = descriptionAttr.Value;
            }

            combined = category + SchemaConstants.ParameterDelimiter + name;
            if (field.Length > 0)
            {
                combined = combined + SchemaConstants.FieldLeftDelimeter + field + SchemaConstants.FieldRightDelimeter;
            }

            paramMin = null;
            paramMax = null;

            if (paramConstraint != null)
            {
                paramMin = paramConstraint.Range.Min;
                paramMax = paramConstraint.Range.Max;
            }

            valueAttr = parameter.Attributes[ConfigFileConstants.Value];
            if (valueAttr != null)
            {
                valueAttrValue = valueAttr.Value;
                object oValidatedValue = this._ValidateValue(cSharpType, valueAttrValue, paramMin, paramMax);

                if (oValidatedValue is Array)
                {
                    // array - can't bulk insert, serialize
                    BinaryFormatter formatter = new BinaryFormatter();
                    MemoryStream memoryStream = new MemoryStream();
                    formatter.Serialize(memoryStream, oValidatedValue);
                    byte[] arrayData = memoryStream.ToArray();
                    return new ParameterInfo(category, name, field, combined, parent, "", descriptionAttrValue, paramMin, paramMax, arrayData);
                }
                else
                {
                    string sParamValToStore = (oValidatedValue == null) ? valueAttrValue : oValidatedValue.ToString();
                    return new ParameterInfo(category, name, field, combined, parent, sParamValToStore, descriptionAttrValue, paramMin, paramMax);
                }
            }
            else
            {
                return new ParameterInfo(category, name, field, combined, parent, "", descriptionAttrValue, paramMin, paramMax);
            }
        }
Ejemplo n.º 7
0
        private XmlNode FindStructureInCache(String key, String category, String name, String childField, eParamParentType parentType)
        {
            Dictionary<AME.Model.Model, Dictionary<String, XmlDocumentFragment>> cache;

            if (parentType == eParamParentType.Component)
            {
                cache = componentParametersXMLCache;
            }
            else
            {
                cache = linkParametersXMLCache;
            }

            if (cache[m_model].ContainsKey(key))
            {
                XmlNodeList categoryChildren = cache[m_model][key].FirstChild.ChildNodes;
                XmlAttribute categoryAttr;

                foreach (XmlNode categoryChild in categoryChildren)
                {
                    categoryAttr = categoryChild.Attributes["category"];
                    if (categoryAttr.Value.Equals(category))
                    {
                        XmlNodeList children = categoryChild.ChildNodes;
                        foreach (XmlNode child in children)
                        {
                            if (child.Attributes["displayedName"].Value.Equals(name))
                            {
                                if (childField.Length == 0)
                                {
                                    XmlAttribute value = child.Attributes["value"];
                                    if (value != null)
                                    {
                                        return child;
                                    }
                                }
                                else
                                {
                                    XmlNodeList structChildren = child.FirstChild.ChildNodes;
                                    foreach (XmlNode structChild in structChildren)
                                    {
                                        if (structChild.Attributes["name"].Value.Equals(childField))
                                        {
                                            XmlAttribute value = structChild.Attributes["value"];
                                            if (value != null)
                                            {
                                                return structChild;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return null;
        }
Ejemplo n.º 8
0
 private List<ParameterInfo> GetParameterInfoList(XmlNode parametersNode, String componentType,
     String linkType, String fromType, String toType, eParamParentType parent)
 {
     return GetParameterInfoList(parametersNode, componentType, linkType, fromType, toType, parent, false, "");
 }
Ejemplo n.º 9
0
        // Process parameters the same way for link and component
        // Node looks like '/Parameters'
        private XmlDocument ProcessParameters(XmlNode parameters, int componentOrLinkID, Component.eComponentType eType, 
            eParamParentType paramParType, Dictionary<String, List<DataRow>> parameterTableCache)
        {
            bool IDisClass = eType == Component.eComponentType.Class;
            bool IDisSubclass = eType == Component.eComponentType.Subclass;

            // prepare values from DB
            Dictionary<String, String> parameterNameValues = new Dictionary<String, String>();
            Dictionary<String, List<NameValuePair>> parameterArrayNameValues = new Dictionary<String, List<NameValuePair>>();
            if (parameterTableCache != null)
            {
                String key = componentOrLinkID+paramParType.ToString();
                if (parameterTableCache.ContainsKey(key))
                {
                    List<DataRow> parameterRows = parameterTableCache[key];

                    parameterNameValues = new Dictionary<String, String>();

                    foreach (DataRow parameterRow in parameterRows)
                    {
                        ProcessParameterDataRow(parameterRow, ref parameterNameValues, ref parameterArrayNameValues);
                    }
                }
                else
                {
                    parameterNameValues = new Dictionary<String, String>();
                }
            }
            else
            {
                DataTable parameterTable = this.m_model.GetParameterTable(componentOrLinkID, paramParType.ToString());

                foreach (DataRow parameterRow in parameterTable.Rows)
                {
                    ProcessParameterDataRow(parameterRow, ref parameterNameValues, ref parameterArrayNameValues);
                }
            }

            // prepare XML document for view
            XmlDocument toView = new XmlDocument();
            XmlElement parametersNodeForView = null;

            if (paramParType == eParamParentType.Component)
            {
                parametersNodeForView = toView.CreateElement(XmlSchemaConstants.Display.sComponentParameters); // ComponentParameters
            }
            else if (paramParType == eParamParentType.Link)
            {
                parametersNodeForView = toView.CreateElement(XmlSchemaConstants.Display.sLinkParameters);  // LinkParameters
            }

            XmlNode parametersRoot = toView.AppendChild(parametersNodeForView);

            if (parameters != null) 
            {
                // create Parameters with type 'Complex', these will hold all the parameters for a category.
                List<String> categories = new List<String>();

                XmlNodeList allCategories = parameters.SelectNodes(XmlSchemaConstants.Display.sParameter);
                foreach (XmlNode categoryNode in allCategories) // collect all categories
                {
                    String category = categoryNode.Attributes[ConfigFileConstants.category].Value;
                    if (!categories.Contains(category))
                    {
                        categories.Add(category);
                    }
                }

                foreach (String category in categories) // go through categories, build parent node, collect children
                {
                    XmlElement newComplex = toView.CreateElement("Parameter");

                    XmlAttribute categoryAttributeForNewComplex = toView.CreateAttribute(ConfigFileConstants.category);
                    categoryAttributeForNewComplex.Value = category; 

                    XmlAttribute typeAttributeForNewComplex = toView.CreateAttribute(ConfigFileConstants.Type);
                    typeAttributeForNewComplex.Value = ConfigFileConstants.complexType; // type="Complex"

                    newComplex.SetAttributeNode(categoryAttributeForNewComplex);
                    newComplex.SetAttributeNode(typeAttributeForNewComplex);

                    XmlNodeList complexChildren = parameters.SelectNodes("Parameter[@category='" + category + "']"); // go through children...

                    foreach (XmlNode complexChild in complexChildren)
                    {
                        String name = complexChild.Attributes[ConfigFileConstants.displayedName].Value;
                        String combined = category + SchemaConstants.ParameterDelimiter + name;  // category.name

                        XmlNode copy = complexChild.CloneNode(true);

                        // check browsable attribute
                        XmlAttribute browseAttr = copy.Attributes[ConfigFileConstants.browsable];
                        if (browseAttr == null)
                        {
                            browseAttr = copy.OwnerDocument.CreateAttribute(ConfigFileConstants.browsable);
                            browseAttr.Value = "true";
                            copy.Attributes.Append(browseAttr);
                        }

                        // check classOnly - 
                        // if parameter is specified as class only: 
                        // For a class, set browsable to true, otherwise false.
                        // otherwise, use browse attribute value
                        XmlAttribute classAttr = copy.Attributes[ConfigFileConstants.classOnly];
                        if (classAttr != null)
                        {
                            String classAttrValue = classAttr.Value;
                            if (classAttrValue.Equals("true"))
                            {
                                if (IDisClass)
                                {
                                    browseAttr.Value = "true";
                                }
                                else if (IDisSubclass && combined != Component.Class.InstancesUseClassName.Name) // don't show InstancesUseClassName name for subclasses
                                {
                                    browseAttr.Value = "true";
                                }
                                else
                                {
                                    browseAttr.Value = "false";
                                }
                            }
                        }

                        copy = ProcessChildParameterValue(copy, combined, parameterNameValues, parameterArrayNameValues);

                        // check for struct children
                        XmlNodeList structChildren = copy.SelectNodes("Parameters/Parameter");
                        for (int i = 0; i < structChildren.Count; i++)
                        {
                            XmlNode structChild = structChildren[i];
                            String fieldName = structChild.Attributes[ConfigFileConstants.Name].Value;
                            String structName = combined + SchemaConstants.FieldLeftDelimeter + fieldName + SchemaConstants.FieldRightDelimeter;

                            structChild = ProcessChildParameterValue(structChild, structName, parameterNameValues, parameterArrayNameValues);
                        }

                        newComplex.AppendChild(toView.ImportNode(copy, true));
                    } // parameter loop

                    // sanity check: if complex has no children, don't add it (they might have all been empty IgnoreEmptyString is true)
                    if (newComplex.HasChildNodes)
                    {
                        parametersRoot.AppendChild(newComplex); // append complex node to root
                    }
                } // complex loop
            }
            return toView;
        }
Ejemplo n.º 10
0
        // validates type, checks constraints, and updates parameter values for both components and links
        private bool Check_Type_Constraints_And_Update(int parentID, string paramName, string paramValue, eParamParentType parentType)
        {
            string paramMin = null;
            string paramMax = null;
            Type cSharpType;
            String linkType = "";
            String fromType = "";
            String toType = ""; 
            String componentType = "";

            // intialize anything we need...
            if (parentType == eParamParentType.Link)
            {
                GetLinkIDInfo(parentID, out linkType, out fromType, out toType);
            }
            else if (parentType == eParamParentType.Component)
            {
                componentType = GetComponentType(parentID);
            }

            // category.name -> category, name
            String name, category, childField;
            String parameterTypeConverter = "";
            if (GetCategoryNameAndField(paramName, out category, out name, out childField))
            {
                // convert string type to C# Type
                String parameterType = "";
           
                if (parentType == eParamParentType.Link) // (XML is in different places in config file)
                {
                    linkType = GetBaseLinkType(linkType);
                    parameterType = this.m_model.GetParameterType(linkType, fromType, toType, category, name, childField);
                    parameterTypeConverter = this.m_model.GetParameterTypeConverter(linkType, fromType, toType, category, name, childField);

                }
                else if (parentType == eParamParentType.Component)
                {
                    parameterType = this.m_model.GetParameterType(componentType, category, name, childField);
                    parameterTypeConverter = this.m_model.GetParameterTypeConverter(componentType, category, name, childField);
                }

                cSharpType = AMEManager.GetType(parameterType, componentType); 

                // Look up constraint 
                ParamConstraint paramConstraint = GetConstraint(category, name, childField, parentType, componentType, linkType, fromType, toType);

                if (paramConstraint != null)
                {
                    paramMin = paramConstraint.Range.Min;
                    paramMax = paramConstraint.Range.Max;
                }
            }
            else
            {
                throw new Exception("Could not find parameter category and name from: " + paramName);
            }

            //For valid type conversion will go fine, else will throw exception.
            object oValidatedValue = this._ValidateValue(cSharpType, paramValue, paramMin, paramMax, parameterTypeConverter);
            string sParamValueToStore = (oValidatedValue == null) ? paramValue : oValidatedValue.ToString();

            // now update parameter's value
            updateParameter(parentID, parentType, paramName, sParamValueToStore, category, name, childField);
         
            return true;
        }
Ejemplo n.º 11
0
 public void UpdateParameters(string parentID, string paramName, string value, eParamParentType paramParType)
 {
     if (!parametersPresent)
     {
         parametersPresent = true;
     }
     CreateParameter(parentID, paramParType.ToString(), paramName, value, "");
 }
Ejemplo n.º 12
0
        private void writeParameter(String newComponentID, XPathNavigator parameter, eParamParentType parent, List<String> ignore)
        {
            String category, pname, full, value;
            category = parameter.GetAttribute(ConfigFileConstants.category, String.Empty);
            pname = parameter.GetAttribute(ConfigFileConstants.displayedName, String.Empty);
            
            full = category + SchemaConstants.ParameterDelimiter + pname;
            value = parameter.GetAttribute(ConfigFileConstants.Value, String.Empty);

            if (ignore.Count == 0 || !ignore.Contains(full))
            {
                UpdateParameters(newComponentID, full, value, parent);
            }
        }
Ejemplo n.º 13
0
        public void UpdateParameters(AME.Model.Model model, int parentID, string category, string name, string childField, List<XmlElement> newChildren, eParamParentType paramParType)
        {
            XPathExpression exp = getParameterXPath(model, parentID, category, name, childField, paramParType);

            foreach (XmlDocument doc in documentCache[model].Values)
            {
                XPathNodeIterator nodes = doc.CreateNavigator().Select(exp);
                foreach (XPathNavigator node in nodes)
                {
                    XPathNodeIterator oldChildren = node.SelectChildren(XPathNodeType.Element);
                    for (int i = oldChildren.Count-1; i >= 0; i--)
                    {
                        oldChildren.MoveNext();
                        oldChildren.Current.DeleteSelf();
                    }

                    foreach (XmlNode newChild in newChildren)
                    {
                        node.AppendChild(newChild.CreateNavigator());
                    }
                }
            }
        }
Ejemplo n.º 14
0
        private List<Int32> BulkCreateDefaultParameters(
            DataTable parentTable, eParamParentType parent, Dictionary<int, int> skipIDs, Dictionary<String, String> namesWithParameters,
            List<ComponentInfo> bulkComponentInfo, List<LinkInfo> bulkLinkInfo)
        {
            Int32 i = 0;
            Dictionary<String, List<ParameterInfo>> typeToInfoCache = BulkDefaultParameterInfo(parent, parentTable);

            List<Int32> componentIds = new List<Int32>();

            List<ParameterInfo> infoList;
            int incrementer = 0;
            int id, fromID, toID;
            String componentName, componentType, key = null, fromType, toType, linkType;
            int rowCount = 0;
            String parentString = parent.ToString();
            foreach (DataRow row in parentTable.Rows)
            {
                id = Int32.Parse(row[SchemaConstants.Id].ToString());

                if (!skipIDs.ContainsKey(id)) // is this a new component?
                {
                    if (parent == eParamParentType.Component)
                    {
                        componentName = row[SchemaConstants.Name].ToString();
                        componentType = row[SchemaConstants.Type].ToString();
                        key = componentType;
                    }
                    else if (parent == eParamParentType.Link)
                    {
                        fromID = Int32.Parse(row[SchemaConstants.From].ToString());
                        toID = Int32.Parse(row[SchemaConstants.To].ToString());
                        linkType = row[SchemaConstants.Type].ToString();
                        bool getFromTo = this.GetLinkIDInfo(fromID, toID, out fromType, out toType);
                        if (getFromTo)
                        {
                            // different xml location, same processing
                            linkType = this.GetBaseLinkType(linkType);
                            key = this.Configuration + linkType + fromType + toType;
                        }
                    }

                    componentIds.Add(id); // store and return the ID to match to the holder name

                    if (typeToInfoCache.ContainsKey(key)) // look up stored ParameterInfos for this type
                    {
                        infoList = typeToInfoCache[key];

                        foreach (ParameterInfo info in infoList)
                        {
                            // skip if this holder name matches a name with parameters to be created later on
                            if ((parent == eParamParentType.Component && !namesWithParameters.ContainsKey(bulkComponentInfo[incrementer].HolderName + info.Combined))
                                 ||
                                 parent == eParamParentType.Link && !namesWithParameters.ContainsKey(bulkLinkInfo[incrementer].HolderName + info.Combined))
                            {
                                if (info.Description.Equals(""))
                                {
                                    info.Description = "\0"; // use null -> sql interprets as empty string
                                }
                                if (info.Value.Equals(""))
                                {
                                    info.Value = "\0"; // use null -> sql interprets as empty string
                                }

                                if (info.BinaryData != null)
                                {
                                    try
                                    {
                                        this.UpdateParameters(id, info.Combined, info.BinaryData, parent);
                                    }
                                    catch (Exception ex)
                                    {
                                        MessageBox.Show(ex.Message, "Error setting default array value");
                                    }
                                }
                                else
                                {
                                    streamWrite.WriteLine(Convert.ToString(i++) + "\t" + id + "\t" + parentString + "\t" + info.Combined + "\t" + info.Value + "\t" + info.Description + "\t");
                                    rowCount++;
                                }
                            }
                        }
                    }
                    else
                    {
                        throw new Exception("Could not find type: " + key);
                    }
                    incrementer++;
                }
            }

            if (streamWrite != null)
            {
                streamWrite.Close();
            }

            if (rowCount > 0)
            {
                String formatFile = "ParameterTableFormatDefault.fmt";
                this.m_model.BulkCreate("ParameterTable", bulkInfo, formatFile, rowCount);
            }
            else
            {
                if (bulkInfo != null && bulkInfo.Exists)
                {
                    bulkInfo.Delete();
                }
            }
            return componentIds;
        }
Ejemplo n.º 15
0
 private void UpdateCacheWithValue(String key, String category, String name, String childField, String value, eParamParentType parentType)
 {
     XmlNode find = FindStructureInCache(key, category, name, childField, parentType);
     if (find != null)
     {
         find.Attributes["value"].Value = value;
     }
 }
Ejemplo n.º 16
0
        private Dictionary<String, List<ParameterInfo>> BulkDefaultParameterInfo(eParamParentType parent, DataTable parentTable)
        {
            Dictionary<String, List<ParameterInfo>> typeToInfoCache = new Dictionary<string, List<ParameterInfo>>();
            XmlNode complex = null;
            List<ParameterInfo> infoForType;
            String componentType = "", fromType = "", toType = "", linkType = "", key = "";
            int fromID, toID;
            bool getFromTo;
            foreach (DataRow row in parentTable.Rows)
            {
                if (parent == eParamParentType.Component)
                {
                    componentType = row[SchemaConstants.Type].ToString();
                    key = componentType;
                }
                else if (parent == eParamParentType.Link)
                {
                    fromID = Int32.Parse(row[SchemaConstants.From].ToString());
                    toID = Int32.Parse(row[SchemaConstants.To].ToString());
                    linkType = row[SchemaConstants.Type].ToString();
                    getFromTo = this.GetLinkIDInfo(fromID, toID, out fromType, out toType);
                    if (getFromTo)
                    {
                        linkType = this.GetBaseLinkType(linkType);
                        key = this.Configuration + linkType + fromType + toType;
                        componentType = linkType + fromType + toType;
                    }
                }

                if (!typeToInfoCache.ContainsKey(key))
                {
                    infoForType = new List<ParameterInfo>();

                    if (parent == eParamParentType.Component)
                    {
                        complex = this.m_model.GetParametersXML(componentType);
                    }
                    else if (parent == eParamParentType.Link)
                    {
                        complex = this.m_model.GetParametersXML(linkType, fromType, toType);
                    }

                    if (complex != null)
                    {
                        infoForType = GetParameterInfoList(complex, componentType, linkType, fromType, toType, parent, true, key);
                        typeToInfoCache.Add(key, infoForType);
                    }
                    else
                    {
                        typeToInfoCache.Add(key, new List<ParameterInfo>());
                    }
                }

            }
            return typeToInfoCache;
        }
Ejemplo n.º 17
0
 private string GetCacheValue(String key, String category, String name, String childField, eParamParentType parentType)
 {
     XmlNode find = FindStructureInCache(key, category, name, childField, parentType);
     if (find != null)
     {
         return find.Attributes["value"].Value;
     }
     else
     {
         return null;
     }
 }
Ejemplo n.º 18
0
        private List<ParameterInfo> GetParameterInfoList(XmlNode parametersNode, String componentType, 
            String linkType, String fromType, String toType, eParamParentType parent, bool addToValidationInfo, String key)
        {
            XmlAttribute typeAttr, nameAttr, categoryAttr;
            Type cSharpType;
            ParamConstraint paramConstraint;
            List<ParameterInfo> infoList = new List<ParameterInfo>();
            String category, name, field;
            ParameterInfo info;

            XmlNodeList allParameters = parametersNode.SelectNodes("Parameter");
     
            foreach (XmlNode parameter in allParameters) // process each parameter...
            {
                nameAttr = parameter.Attributes[ConfigFileConstants.displayedName];
                categoryAttr = parameter.Attributes[ConfigFileConstants.category];
                typeAttr = parameter.Attributes[ConfigFileConstants.Type];
                if (typeAttr != null &&
                    typeAttr.Value != ConfigFileConstants.complexType &&
                    nameAttr != null &&
                    categoryAttr != null)
                {
                    category = categoryAttr.Value;
                    name = nameAttr.Value;
                    field = "";
                    cSharpType = AMEManager.GetType(typeAttr.Value, componentType);
                    paramConstraint = GetConstraint(category, name, field, parent, componentType, linkType, fromType, toType);
                    info = GetParameterInfo(parameter, category, name, field, cSharpType, paramConstraint, parent);
                    infoList.Add(info);

                    if (addToValidationInfo)
                    {
                        parameterValidationInfo.Add(key + info.Combined, new ParameterValidationInfo(cSharpType, info.ParamMin, info.ParamMax));
                    }
                 
                    XmlNodeList structChildren = parameter.SelectNodes("Parameters/Parameter");

                    foreach (XmlNode structChild in structChildren) // process each parameter...
                    {
                        typeAttr = structChild.Attributes[ConfigFileConstants.Type];
                        cSharpType = AMEManager.GetType(typeAttr.Value, componentType);
                        field = structChild.Attributes[ConfigFileConstants.Name].Value;
                        paramConstraint = GetConstraint(category, name, field, parent, componentType, linkType, fromType, toType);
                        info = GetParameterInfo(structChild, category, name, field, cSharpType, paramConstraint, parent);
                        infoList.Add(info);
                        
                        if (addToValidationInfo)
                        {
                            parameterValidationInfo.Add(key + info.Combined, new ParameterValidationInfo(cSharpType, info.ParamMin, info.ParamMax));
                        }
                    }
                }
            }
            return infoList;
        }
Ejemplo n.º 19
0
        // Get a constraint for a component or link
        public ParamConstraint GetConstraint(String category, String name, String childField, eParamParentType componentOrLink, String componentType,
            String linkType, String fromType, String toType)
        {
            XPathNavigator targetParameter = null; // get the parameter node

            if (componentOrLink == eParamParentType.Component) // (XML is in different places in config file)
            {
                targetParameter = this.m_model.GetParameter(componentType, category, name, childField);
            }
            else if (componentOrLink == eParamParentType.Link)
            {
                targetParameter = this.m_model.GetParameter(linkType, fromType, toType, category, name, childField);
            }

            if (targetParameter != null) // populate constraints object if any are provided for parameter
            {
                XPathNodeIterator constraints = targetParameter.Select("Constraints/Constraint");

                if (constraints.Count > 0)
                {
                    ParamConstraint paramConstraint = new ParamConstraint();

                    foreach (XPathNavigator constraint in constraints)
                    {
                        string sConstraintName = constraint.GetAttribute(ConfigFileConstants.constraintName, constraint.NamespaceURI);
                        string sConstraintValue = constraint.GetAttribute(ConfigFileConstants.constraintValue, constraint.NamespaceURI);

                            switch (sConstraintName.ToLower())
                            {
                                case ConfigFileConstants.minConstraint: // "min"
                                    paramConstraint.Range.Min = sConstraintValue;
                                    break;
                                case ConfigFileConstants.maxConstraint: // "max"
                                    paramConstraint.Range.Max = sConstraintValue;
                                    break;
                            }
                        }
                        return paramConstraint;
                    }
                }
            return null;
        }
Ejemplo n.º 20
0
 public ParameterInfo(int p_ParentID, String p_Combined, eParamParentType p_ParentType, String p_Value, String p_Description)
     : this("", "", "", p_Combined, p_ParentType, p_Value, p_Description, null, null)
 {
     parentID = p_ParentID;
 }
Ejemplo n.º 21
0
        // Update parameters for a link or component
        private bool _UpdateParameters(int parentID, string paramName, string paramValue, eParamParentType paramParType)
        {
            //Component.eComponentType eComponentType = _GetComponentType(parentID);

            // check type, constraints, and update
            return Check_Type_Constraints_And_Update(parentID, paramName, paramValue, paramParType);
        }
Ejemplo n.º 22
0
 public ParameterInfo(String p_Category, String p_Name, String p_Field, String p_Combined, eParamParentType p_ParentType, String p_Value, String p_Description, String p_paramMin, String p_paramMax, byte[] p_binaryData)
     : this(p_Category, p_Name, p_Field, p_Combined, p_ParentType, p_Value, p_Description, p_paramMin, p_paramMax)
 {
     this.binaryData = p_binaryData;
 }
Ejemplo n.º 23
0
        private bool _UpdateParameters(int parentID, string paramName, byte[] paramValue, eParamParentType paramParType)
        {
            this.m_model.CreateParameter(parentID,
                paramParType.ToString(),
                paramName, paramValue, "");

            // update fragment
            String key = "" + parentID;
            String name, category, childField;
            GetCategoryNameAndField(paramName, out category, out name, out childField);
            XmlNode find = FindStructureInCache(key, category, name, childField, paramParType);

            if (find == null)
            {
                Console.WriteLine("Couldn't find XML cache node: " + paramName);
                return false;
            }

            List<NameValuePair> nameValues = GetNameValuesFromBinary(paramValue);
            List<XmlElement> newChildren = GetNameValuesParameterXML(find.OwnerDocument, nameValues);

            XmlNodeList oldChildren = find.ChildNodes;
            for (int i = (oldChildren.Count - 1); i >= 0; i--)
            {
                find.RemoveChild(oldChildren[i]);
            }

            foreach (XmlNode newChild in newChildren)
            {
                find.AppendChild(newChild);
            }

            // category.name -> category, name
            cache.UpdateParameters(m_model, parentID, category, name, childField, newChildren, paramParType);

            return true;
        }
Ejemplo n.º 24
0
        public void UpdateParameters(int parentID, string paramName, byte[] paramValue, eParamParentType paramParType, bool sendUpdate)
        {
            CheckUseLoadingCaches();

            if (AllowNewData)
            {
                bool bSuccess = this._UpdateParameters(parentID, paramName, paramValue, paramParType);

                if (bSuccess && sendUpdate)
                {
                    SendUpdateOfType(UpdateType.Parameter, true, paramName);
                }
            }
        }
Ejemplo n.º 25
0
 // Create defaults for a link or a component
 private bool CreateDefaults(XmlNode parameters, int componentOrLinkID, eParamParentType componentOrLink, String componentType,
     String linkType, String fromType, String toType)
 {
     if (parameters != null)
     {
         List<ParameterInfo> infoList = GetParameterInfoList(parameters, componentType, linkType, fromType, toType, componentOrLink);
         foreach (ParameterInfo info in infoList)
         {
             if (info.BinaryData != null)
             {
                 this.UpdateParameters(componentOrLinkID, info.Combined, info.BinaryData, componentOrLink);
             }
             else
             {
                 updateParameter(componentOrLinkID, componentOrLink, info.Combined, info.Value, info.Category, info.Name, info.Field);
             }
         }
     }
     return true;
 }
Ejemplo n.º 26
0
        private void writeParameter(String copyChildID, XPathNavigator parameter, eParamParentType parent)
        {
            String category, pname, full, value, isOutput;
            category = parameter.GetAttribute(ConfigFileConstants.category, String.Empty);
            pname = parameter.GetAttribute(ConfigFileConstants.displayedName, String.Empty);
            full = category + SchemaConstants.ParameterDelimiter + pname;

            if (skipParametersMap.ContainsKey(full))
            {
                return;
            }
            
            value = parameter.GetAttribute(ConfigFileConstants.Value, String.Empty);

            isOutput = parameter.GetAttribute(ConfigFileConstants.isOutput, String.Empty);
            if (copyOutput)
            {
                if (isOutput != null && isOutput.Length > 0 && Boolean.Parse(isOutput))
                {
                    try
                    {
                        IXPathNavigable existingFile = readingController.GetOutputXml(value);
                        value = value + " (" + copiedRootName + ")";
                        readingController.WriteOutputXml(value, (XmlDocument)existingFile);
                    }
                    catch (FileNotFoundException)
                    {
                        MessageBox.Show("Warning: Trying to copy referenced output file: " + value + " but it does not exist in the output directory.  Skipping");
                    }
                }
            }

            helper.UpdateParameters(copyChildID, full, value, parent);
        }
Ejemplo n.º 27
0
        private XPathExpression getParameterXPath(AME.Model.Model model, int id, string category, string name, string childField, eParamParentType parent)
        {
            bool component = true;
            String key = category + name + childField;
            Dictionary<AME.Model.Model, Dictionary<int, Dictionary<string, XPathExpression>>> lookup;
           
            if (parent.ToString() == eParamParentType.Component.ToString())
            {
                lookup = componentParameterXPaths;
            }
            else
            {
                lookup = linkParameterXPaths;
                component = false;
            }

            if (!lookup[model].ContainsKey(id))
            {
                lookup[model][id] = new Dictionary<string, XPathExpression>();
            }

            if (!lookup[model][id].ContainsKey(key))
            {
                lookup[model][id].Add(key, XPathExpression.Compile(createParameterXPath(id, category, name, childField, component)));
            }
            return lookup[model][id][key];
        }