Пример #1
0
        public void LoadFromXML(XmlNode resourceNode)
        {
            XMLResourceTypeFactory.LoadFromXML(resourceNode, this);

            /// if the display color is specified, then load it,
            /// otherwise use a random color
            if (resourceNode.Attributes["display_color"] != null)
            {
                this._displayColor = System.Drawing.Color.FromName(resourceNode.Attributes["display_color"].Value);
            }
            else
            {
                Random random = Controller.Random;
                this._displayColor = System.Drawing.Color.FromArgb(random.Next(256), random.Next(256), random.Next(256), random.Next(256));
            }

            XMLResourceTypeFactory.CreateResourceTypeFields(this.SubTypes, resourceNode);
            foreach (System.Xml.XmlNode node in resourceNode.ChildNodes)
            {
                switch (node.Name)
                {
                case "execute":
                    Scripts.Script executionType = XMLScriptFactory.CreateScript(node);
                    this.Executions.Add(executionType.Name, executionType);
                    break;

                default:
                    continue;
                }
            }
        }
Пример #2
0
            /// <summary>
            /// Loads the resources.
            /// </summary>
            public void LoadResources()
            {
                /// clear old DB and load resource types
                _resourceList.Clear();

                XMLResourceTypeFactory factory = new XMLResourceTypeFactory(Controller.ResourceTypesFile);

                _resourceTypes = factory.CreateResourceTypes();

                /// create the root resource
                Root = new Resource(new Guid(), _resourceTypes ["Family"], "general");
                _resourceList.Add(Root.QualifiedName, Root);

                /// load the actual resources
                if (!System.IO.File.Exists(Controller.ResourcesFile))
                {
                    /// if the file doesnt exist, create the empty file
                    SaveResources();
                }

                try
                {
                    LoadAdditionalResources(Controller.ResourcesFile, true);
                }
                catch (Exception x)
                {
                    Controller.ShowException("The file " + Controller.ResourcesFile + " could not be loaded. it may be corrupt. we recommend shutting the program down to avoid data loss.", x);
                }

                ///
                Root.Children.ChildAdded   += new SNAP.Util.ChildEvent <Resource>(Root_ResourceAdded);
                Root.Children.ChildRemoved += new SNAP.Util.ChildEvent <Resource>(Root_ResourceRemoved);
            }
Пример #3
0
        /// <summary>
        /// Loads the IResourceType from the specified XmlNode.
        /// </summary>
        /// <param name="node">The node.</param>
        public void LoadFromXML(System.Xml.XmlNode node)
        {
            System.Diagnostics.Debug.Assert(node.Name.Equals(Typename));

            XMLResourceTypeFactory.LoadFromXML(node, this);

            this.MinValue = decimal.MinValue;
            if (node.Attributes["min"] != null)
            {
                this.MinValue = decimal.Parse(node.Attributes["min"].Value);
            }

            this.MaxValue = decimal.MaxValue;
            if (node.Attributes["max"] != null)
            {
                this.MaxValue = decimal.Parse(node.Attributes["max"].Value);
            }

            if (node.Attributes["default"] != null)
            {
                this.DefaultValue = decimal.Parse(node.Attributes["default"].Value);
            }
            else
            {
                if (node.Attributes["min"] != null)
                {
                    if (node.Attributes["max"] != null)
                    {
                        this.DefaultValue = decimal.Divide((MinValue + MaxValue), 2);
                    }
                    else
                    {
                        this.DefaultValue = this.MinValue;
                    }
                }
                else if (node.Attributes["max"] != null)
                {
                    this.DefaultValue = this.MaxValue;
                }
                else
                {
                    this.DefaultValue = 0;
                }
            }

            this.Increment = 1;
            if (node.Attributes["increment"] != null)
            {
                this.Increment = decimal.Parse(node.Attributes["increment"].Value);
            }

            this.DecimalPlaces = 0;
            if (node.Attributes["precision"] != null)
            {
                this.DecimalPlaces = int.Parse(node.Attributes["precision"].Value);
            }

            /// the usual properties (name, help etc) are handled by the caller
        }
Пример #4
0
        public void LoadFromXML(System.Xml.XmlNode node)
        {
            System.Diagnostics.Debug.Assert(node.Name.Equals(Typename));
            XMLResourceTypeFactory.LoadFromXML(node, this);

            /// add all the elements of the enum
            foreach (XmlNode elementNode in node.SelectNodes("enum_element"))
            {
                EnumElementFieldType elementType = new EnumElementFieldType();
                elementType.LoadFromXML(elementNode);
                this._elements.Add(elementType.Name, elementType);
            }
        }
Пример #5
0
        public void LoadFromXML(System.Xml.XmlNode node)
        {
            System.Diagnostics.Debug.Assert(node.Name.Equals(Typename));
            XMLResourceTypeFactory.LoadFromXML(node, this);

            if (node.Attributes["mask"] != null)
            {
                string   maskString = node.Attributes["mask"].Value;
                string[] parts      = maskString.Split('|');
                for (int i = 0; i < parts.Length; ++i)
                {
                    string name          = parts [i];
                    string resourceTypes = parts [++i];
                    Masks.Add(new Mask(name, resourceTypes));
                }
            }
        }
Пример #6
0
 public void LoadFromXML(System.Xml.XmlNode node)
 {
     System.Diagnostics.Debug.Assert(node.Name.Equals(Typename));
     XMLResourceTypeFactory.LoadFromXML(node, this);
     XMLResourceTypeFactory.CreateResourceTypeFields(this.SubTypes, node);
 }