Example #1
0
        /// <summary>
        /// Create a new Linked Parameter with the given name
        /// </summary>
        /// <param name="name">The name of the linked parameter</param>
        /// <param name="error">If an error occurs this will contain a message to describe it.</param>
        /// <returns>True if it executed successfully</returns>
        public bool NewLinkedParameter(string name, ref string error)
        {
            var lp = new LinkedParameterChange();

            return(_Session.RunCommand(
                       XTMFCommand.CreateCommand("New Linked Parameter", (ref string e) =>
            {
                LinkedParameter linkedParameter = new LinkedParameter(name);
                LinkedParameterModel newModel = new LinkedParameterModel(linkedParameter, _Session, _ModelSystem);
                _RealLinkedParameters.Add(linkedParameter);
                LinkedParameters.Add(newModel);
                lp.Model = newModel;
                lp.Index = LinkedParameters.Count - 1;
                return true;
            },
                                                 (ref string e) =>
            {
                LinkedParameters.RemoveAt(lp.Index);
                _RealLinkedParameters.RemoveAt(lp.Index);
                InvokeRemoved(lp);
                return true;
            },
                                                 (ref string e) =>
            {
                LinkedParameters.Insert(lp.Index, lp.Model);
                _RealLinkedParameters.Insert(lp.Index, lp.Model.RealLinkedParameter);
                return true;
            }),
                       ref error
                       ));
        }
Example #2
0
        /// <summary>
        /// Create a clone of this model system
        /// </summary>
        /// <param name="linkedParameters">The linked parameters</param>
        /// <returns>A cloned model system that can be used for editing.</returns>
        internal ModelSystemStructure CreateEditingClone(out List <ILinkedParameter> linkedParameters)
        {
            var ourClone = ModelSystemStructure.Clone();

            linkedParameters = LinkedParameters.Count > 0 ?
                               LinkedParameter.MapLinkedParameters(LinkedParameters, ourClone, ModelSystemStructure)
                : new List <ILinkedParameter>();
            return(ourClone as ModelSystemStructure);
        }
Example #3
0
        /// <summary>
        /// Add a new linked parameter without a command.  Only do this in another
        /// command where you will clean up afterwards.
        /// </summary>
        /// <param name="name">The name of the new linked parameter</param>
        /// <param name="value">The value to assign to it.</param>
        /// <returns>The newly created linked parameter</returns>
        internal LinkedParameterModel AddWithoutCommand(string name, string value)
        {
            LinkedParameter      linkedParameter = new LinkedParameter(name);
            LinkedParameterModel newModel        = new LinkedParameterModel(linkedParameter, _Session, _ModelSystem);

            AddWithoutCommand(newModel);
            string error = null;

            newModel.SetWithoutCommand(value, ref error);
            return(newModel);
        }
Example #4
0
        /// <summary>
        /// Create a clone of this model system
        /// </summary>
        /// <param name="linkedParameters">The linked parameters</param>
        /// <returns>A cloned model system that can be used for editing.</returns>
        internal ModelSystemStructure CreateEditingClone(out List <ILinkedParameter> linkedParameters, out List <IRegionDisplay> regionDisplays)
        {
            var ourClone = ModelSystemStructure.Clone();

            linkedParameters = LinkedParameters.Count > 0 ?
                               LinkedParameter.MapLinkedParameters(LinkedParameters, ourClone, ModelSystemStructure)
                : new List <ILinkedParameter>();

            regionDisplays = RegionDisplay.MapRegionDisplays(this._regionDisplays, ourClone);
            return(ourClone as ModelSystemStructure);
        }
Example #5
0
        private static ILinkedParameter CopyLinkedParameter(ILinkedParameter original)
        {
            var ret           = new LinkedParameter(original.Name);
            var oldParameters = original.Parameters;
            var parameters    = ret.Parameters;

            ret.Value = original.Value;
            for (int i = 0; i < oldParameters.Count; i++)
            {
                parameters.Add(oldParameters[i]);
            }
            return(ret);
        }
Example #6
0
 private static ILinkedParameter CopyLinkedParameter(ILinkedParameter original)
 {
     var ret = new LinkedParameter( original.Name );
     var oldParameters = original.Parameters;
     var parameters = ret.Parameters;
     ret.Value = original.Value;
     for ( int i = 0; i < oldParameters.Count; i++ )
     {
         parameters.Add( oldParameters[i] );
     }
     return ret;
 }
Example #7
0
        private void LoadFromStream(Stream stream, IConfiguration config, ref string error)
        {
            if (_LinkedParameters == null)
            {
                _LinkedParameters = new List <ILinkedParameter>();
            }
            else
            {
                _LinkedParameters.Clear();
            }
            ModelSystemStructure          = XTMF.ModelSystemStructure.Load(stream, config);
            ModelSystemStructure.Required = true;
            // restart to get to the linked parameters
            stream.Seek(0, SeekOrigin.Begin);
            using (XmlReader reader = XmlReader.Create(stream))
            {
                bool skipRead = false;
                while (!reader.EOF && (skipRead || reader.Read()))
                {
                    skipRead = false;
                    if (reader.NodeType != XmlNodeType.Element)
                    {
                        continue;
                    }
                    switch (reader.LocalName)
                    {
                    case "LinkedParameter":
                    {
                        string linkedParameterName = "Unnamed";
                        string valueRepresentation = null;
                        var    startingDepth       = reader.Depth;
                        while (reader.MoveToNextAttribute())
                        {
                            if (reader.NodeType == XmlNodeType.Attribute)
                            {
                                if (reader.LocalName == "Name")
                                {
                                    linkedParameterName = reader.ReadContentAsString();
                                }
                                else if (reader.LocalName == "Value")
                                {
                                    valueRepresentation = reader.ReadContentAsString();
                                }
                            }
                        }
                        LinkedParameter lp = new LinkedParameter(linkedParameterName);
                        lp.SetValue(valueRepresentation, ref error);
                        _LinkedParameters.Add(lp);
                        skipRead = true;
                        while (reader.Read())
                        {
                            if (reader.Depth <= startingDepth && reader.NodeType != XmlNodeType.Element)
                            {
                                break;
                            }
                            if (reader.NodeType != XmlNodeType.Element)
                            {
                                continue;
                            }
                            if (reader.LocalName == "Reference")
                            {
                                string variableLink = null;
                                while (reader.MoveToNextAttribute())
                                {
                                    if (reader.Name == "Name")
                                    {
                                        variableLink = reader.ReadContentAsString();
                                    }
                                }
                                if (variableLink != null)
                                {
                                    IModuleParameter param = GetParameterFromLink(variableLink);
                                    if (param != null)
                                    {
                                        // in any case if there is a type error, just throw it out
                                        lp.Add(param, ref error);
                                    }
                                }
                            }
                        }
                    }
                    break;

                    case "Description":
                    {
                        bool textLast = false;

                        while (reader.Read())
                        {
                            if (reader.NodeType == XmlNodeType.Text)
                            {
                                textLast = true;
                                break;
                            }
                            if (reader.NodeType == XmlNodeType.Element)
                            {
                                skipRead = true;
                                break;
                            }
                        }
                        if (textLast)
                        {
                            Description = reader.ReadContentAsString();
                        }
                    }
                    break;
                    }
                }
            }
        }
Example #8
0
        private void Load(IConfiguration config, string name)
        {
            if (name != null)
            {
                var fileName = Path.Combine(Config.ModelSystemDirectory, name + ".xml");
                if (_LinkedParameters == null)
                {
                    _LinkedParameters = new List <ILinkedParameter>();
                }
                else
                {
                    _LinkedParameters.Clear();
                }
                try
                {
                    ModelSystemStructure = XTMF.ModelSystemStructure.Load(fileName, config);
                    using (XmlReader reader = XmlReader.Create(fileName))
                    {
                        bool skipRead = false;
                        while (!reader.EOF && (skipRead || reader.Read()))
                        {
                            skipRead = false;
                            if (reader.NodeType != XmlNodeType.Element)
                            {
                                continue;
                            }
                            switch (reader.LocalName)
                            {
                            case "LinkedParameter":
                            {
                                string linkedParameterName = "Unnamed";
                                string valueRepresentation = null;
                                var    startingDepth       = reader.Depth;
                                while (reader.MoveToNextAttribute())
                                {
                                    if (reader.NodeType == XmlNodeType.Attribute)
                                    {
                                        if (reader.LocalName == "Name")
                                        {
                                            linkedParameterName = reader.ReadContentAsString();
                                        }
                                        else if (reader.LocalName == "Value")
                                        {
                                            valueRepresentation = reader.ReadContentAsString();
                                        }
                                    }
                                }
                                LinkedParameter lp    = new LinkedParameter(linkedParameterName);
                                string          error = null;
                                lp.SetValue(valueRepresentation, ref error);
                                _LinkedParameters.Add(lp);
                                skipRead = true;
                                while (reader.Read())
                                {
                                    if (reader.Depth <= startingDepth && reader.NodeType != XmlNodeType.Element)
                                    {
                                        break;
                                    }
                                    if (reader.NodeType != XmlNodeType.Element)
                                    {
                                        continue;
                                    }
                                    if (reader.LocalName == "Reference")
                                    {
                                        string variableLink = null;
                                        while (reader.MoveToNextAttribute())
                                        {
                                            if (reader.Name == "Name")
                                            {
                                                variableLink = reader.ReadContentAsString();
                                            }
                                        }
                                        if (variableLink != null)
                                        {
                                            IModuleParameter param = GetParameterFromLink(variableLink);
                                            if (param != null)
                                            {
                                                // in any case if there is a type error, just throw it out
                                                lp.Add(param, ref error);
                                            }
                                        }
                                    }
                                }
                            }
                            break;

                            case "Description":
                            {
                                bool textLast = false;

                                while (reader.Read())
                                {
                                    if (reader.NodeType == XmlNodeType.Text)
                                    {
                                        textLast = true;
                                        break;
                                    }
                                    else if (reader.NodeType == XmlNodeType.Element)
                                    {
                                        skipRead = true;
                                        break;
                                    }
                                }
                                if (textLast)
                                {
                                    Description = reader.ReadContentAsString();
                                }
                            }
                            break;
                            }
                        }
                    }
                }
                catch
                {
                    Description = string.Empty;
                    if (_ModelSystemStructure == null)
                    {
                        _ModelSystemStructure          = new ModelSystemStructure(Config, Name, typeof(IModelSystemTemplate));
                        _ModelSystemStructure.Required = true;
                    }
                    else
                    {
                        _ModelSystemStructure.ParentFieldType = typeof(IModelSystemTemplate);
                        _ModelSystemStructure.Required        = true;
                    }
                }
            }
        }
Example #9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="xmlNode"></param>
        /// <param name="mss"></param>
        /// <returns></returns>
        private List <ILinkedParameter> LoadLinkedParameters(XmlNode xmlNode, IModelSystemStructure mss)
        {
            List <ILinkedParameter> lpl = new List <ILinkedParameter>();

            // if there is nothing to load just return back a blank list
            if (!xmlNode.HasChildNodes)
            {
                return(lpl);
            }

            foreach (XmlNode lpNode in xmlNode.ChildNodes)
            {
                if (lpNode.Name == "LinkedParameter")
                {
                    var name       = "unnamed";
                    var value      = string.Empty;
                    var attributes = lpNode.Attributes;
                    if (attributes != null)
                    {
                        foreach (XmlAttribute attribute in attributes)
                        {
                            switch (attribute.Name)
                            {
                            case "Name":
                                {
                                    name = attribute.InnerText;
                                }
                                break;

                            case "Value":
                            {
                                value = attribute.InnerText;
                            }
                            break;
                            }
                        }
                    }

                    LinkedParameter lp    = new LinkedParameter(name);
                    string          error = null;
                    lp.SetValue(value, ref error);
                    lpl.Add(lp);
                    // if there are no references just continue
                    if (!lpNode.HasChildNodes)
                    {
                        continue;
                    }

                    foreach (XmlNode lpCNode in lpNode)
                    {
                        if (lpCNode.Name == "Reference")
                        {
                            if (lpCNode.Attributes != null)
                            {
                                foreach (XmlAttribute attribute in lpCNode.Attributes)
                                {
                                    if (attribute.Name == "Name")
                                    {
                                        var param = GetParameterFromLink(attribute.InnerText, mss);
                                        if (param != null)
                                        {
                                            lp.Add(param, ref error);
                                        }

                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(lpl);
        }
Example #10
0
        private void Load(IConfiguration config, string name)
        {
            if (name != null)
            {
                var fileName = Path.Combine(Config.ModelSystemDirectory, name + ".xml");
                if (_LinkedParameters == null)
                {
                    _LinkedParameters = new List<ILinkedParameter>();
                }
                else
                {
                    _LinkedParameters.Clear();
                }
                try
                {
                    ModelSystemStructure = XTMF.ModelSystemStructure.Load(fileName, config);
                    using (XmlReader reader = XmlReader.Create(fileName))
                    {
                        bool skipRead = false;
                        while (!reader.EOF && (skipRead || reader.Read()))
                        {
                            skipRead = false;
                            if (reader.NodeType != XmlNodeType.Element) continue;
                            switch (reader.LocalName)
                            {
                                case "LinkedParameter":
                                    {
                                        string linkedParameterName = "Unnamed";
                                        string valueRepresentation = null;
                                        var startingDepth = reader.Depth;
                                        while (reader.MoveToNextAttribute())
                                        {
                                            if (reader.NodeType == XmlNodeType.Attribute)
                                            {
                                                if (reader.LocalName == "Name")
                                                {
                                                    linkedParameterName = reader.ReadContentAsString();
                                                }
                                                else if (reader.LocalName == "Value")
                                                {
                                                    valueRepresentation = reader.ReadContentAsString();
                                                }
                                            }
                                        }
                                        LinkedParameter lp = new LinkedParameter(linkedParameterName);
                                        string error = null;
                                        lp.SetValue(valueRepresentation, ref error);
                                        _LinkedParameters.Add(lp);
                                        skipRead = true;
                                        while (reader.Read())
                                        {
                                            if (reader.Depth <= startingDepth && reader.NodeType != XmlNodeType.Element)
                                            {
                                                break;
                                            }
                                            if (reader.NodeType != XmlNodeType.Element)
                                            {
                                                continue;
                                            }
                                            if (reader.LocalName == "Reference")
                                            {
                                                string variableLink = null;
                                                while (reader.MoveToNextAttribute())
                                                {
                                                    if (reader.Name == "Name")
                                                    {
                                                        variableLink = reader.ReadContentAsString();
                                                    }
                                                }
                                                if (variableLink != null)
                                                {
                                                    IModuleParameter param = GetParameterFromLink(variableLink);
                                                    if (param != null)
                                                    {
                                                        // in any case if there is a type error, just throw it out
                                                        lp.Add(param, ref error);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    break;

                                case "Description":
                                    {
                                        bool textLast = false;

                                        while (reader.Read())
                                        {
                                            if (reader.NodeType == XmlNodeType.Text)
                                            {
                                                textLast = true;
                                                break;
                                            }
                                            else if (reader.NodeType == XmlNodeType.Element)
                                            {
                                                skipRead = true;
                                                break;
                                            }
                                        }
                                        if (textLast)
                                        {
                                            Description = reader.ReadContentAsString();
                                        }
                                    }
                                    break;
                            }
                        }
                    }
                }
                catch
                {
                    Description = string.Empty;
                    if (_ModelSystemStructure == null)
                    {
                        _ModelSystemStructure = new ModelSystemStructure(Config, Name, typeof(IModelSystemTemplate));
                        _ModelSystemStructure.Required = true;
                    }
                    else
                    {
                        _ModelSystemStructure.ParentFieldType = typeof(IModelSystemTemplate);
                        _ModelSystemStructure.Required = true;
                    }
                }
            }
        }
Example #11
0
 /// <summary>
 /// Add a new linked parameter without a command.  Only do this in another
 /// command where you will clean up afterwards.
 /// </summary>
 /// <param name="name">The name of the new linked parameter</param>
 /// <param name="value">The value to assign to it.</param>
 /// <returns>The newly created linked parameter</returns>
 internal LinkedParameterModel AddWithoutCommand(string name, string value)
 {
     LinkedParameter linkedParameter = new LinkedParameter(name);
     LinkedParameterModel newModel = new LinkedParameterModel(linkedParameter, Session, ModelSystem);
     AddWithoutCommand(newModel);
     string error = null;
     newModel.SetWithoutCommand(value, ref error);
     return newModel;
 }
Example #12
0
 /// <summary>
 /// Create a new Linked Parameter with the given name
 /// </summary>
 /// <param name="name">The name of the linked parameter</param>
 /// <param name="error">If an error occurs this will contain a message to describe it.</param>
 /// <returns>True if it executed successfully</returns>
 public bool NewLinkedParameter(string name, ref string error)
 {
     var lp = new LinkedParameterChange();
     return this.Session.RunCommand(
         XTMFCommand.CreateCommand((ref string e) =>
         {
             LinkedParameter linkedParameter = new LinkedParameter(name);
             LinkedParameterModel newModel = new LinkedParameterModel(linkedParameter, Session, ModelSystem);
             RealLinkedParameters.Add(linkedParameter);
             LinkedParameters.Add(newModel);
             lp.Model = newModel;
             lp.Index = this.LinkedParameters.Count - 1;
             return true;
         },
         (ref string e) =>
         {
             LinkedParameters.RemoveAt(lp.Index);
             RealLinkedParameters.RemoveAt(lp.Index);
             return true;
         },
         (ref string e) =>
         {
             LinkedParameters.Insert(lp.Index, lp.Model);
             RealLinkedParameters.Insert(lp.Index, lp.Model.RealLinkedParameter);
             return true;
         }),
         ref error
         );
 }
Example #13
0
        private List<ILinkedParameter> LoadLinkedParameters(XmlNode xmlNode, IModelSystemStructure mss)
        {
            List<ILinkedParameter> lpl = new List<ILinkedParameter>();
            // if there is nothing to load just return back a blank list
            if (!xmlNode.HasChildNodes)
            {
                return lpl;
            }

            foreach (XmlNode lpNode in xmlNode.ChildNodes)
            {
                if (lpNode.Name == "LinkedParameter")
                {
                    var name = "unnamed";
                    var value = string.Empty;
                    foreach (XmlAttribute attribute in lpNode.Attributes)
                    {
                        switch (attribute.Name)
                        {
                            case "Name":
                                {
                                    name = attribute.InnerText;
                                }
                                break;

                            case "Value":
                                {
                                    value = attribute.InnerText;
                                }
                                break;
                        }
                    }
                    LinkedParameter lp = new LinkedParameter(name);
                    string error = null;
                    lp.SetValue(value, ref error);
                    lpl.Add(lp);
                    // if there are no references just continue
                    if (!lpNode.HasChildNodes)
                    {
                        continue;
                    }
                    foreach (XmlNode lpCNode in lpNode)
                    {
                        if (lpCNode.Name == "Reference")
                        {
                            foreach (XmlAttribute attribute in lpCNode.Attributes)
                            {
                                if (attribute.Name == "Name")
                                {
                                    var param = GetParameterFromLink(attribute.InnerText, mss);
                                    if (param != null)
                                    {
                                        lp.Add(param, ref error);
                                    }
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            return lpl;
        }