Esempio n. 1
0
        /// <summary>
        /// Loads a behaviour from the given filename
        /// </summary>
        /// <param name="getBehaviorNode">The callback used to return the behavior.</param>
        public override void Load(List <Nodes.Node.ErrorCheck> result, GetBehaviorNode getBehaviorNode)
        {
            try
            {
                //FileStream fs = Plugin.ConcurrentSourceFileStreams.GetValueUnsafe(_filename);
                //if (fs == null)
                //{
                //    fs = new FileStream(_filename, FileMode.Open, FileAccess.Read, FileShare.Read);
                //}
                FileStream fs = new FileStream(_filename, FileMode.Open, FileAccess.Read, FileShare.Read);

                _xmlfile.Load(fs);
                fs.Close();

                XmlNode rootNode = _xmlfile.ChildNodes[1];

                int versionLoaded = (rootNode.Attributes != null) ? int.Parse(rootNode.Attributes["Version"] != null ? rootNode.Attributes["Version"].Value : "0") : 0;
                this._version = versionLoaded;

                if (versionLoaded > Nodes.Behavior.NewVersion)
                {
                    MessageBox.Show(Resources.FileVersionWarning, Resources.LoadWarning, MessageBoxButtons.OK);
                }

                foreach (XmlNode xmlNode in rootNode.ChildNodes)
                {
                    if (xmlNode.Name == "Node")
                    {
                        _behavior = (BehaviorNode)CreateNodeAndAdd(result, getBehaviorNode, xmlNode, null, null);

                        ProcessedBehaviors processedBehaviors = new ProcessedBehaviors();
                        DoPostLoad(processedBehaviors, (Node)_behavior);

                        break;
                    }
                }

                if (_behavior != null)
                {
                    if (versionLoaded != Nodes.Behavior.NewVersion)
                    {
                        _behavior.Version = Nodes.Behavior.NewVersion;
                        _behavior.TriggerWasModified((Node)_behavior);
                    }

                    string noError = rootNode.Attributes["NoError"] != null ? rootNode.Attributes["NoError"].Value : "false";
                    _behavior.HasNoError = (noError == "true");
                }
            }
            catch (Exception e)
            {
                string errorInfo = string.Format("{0}\n{1}", _filename, e.Message);
                MessageBox.Show(errorInfo, Resources.LoadError, MessageBoxButtons.OK);

                _xmlfile.RemoveAll();

                throw;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Loads a behaviour from the given filename
        /// </summary>
        /// <param name="getBehaviorNode">The callback used to return the behavior.</param>
        public override void Load(List <Nodes.Node.ErrorCheck> result, GetBehaviorNode getBehaviorNode)
        {
            try {
                FileStream fs = new FileStream(_filename, FileMode.Open, FileAccess.Read, FileShare.Read);
                _xmlfile.Load(fs);
                fs.Close();

                XmlNode rootNode = _xmlfile.ChildNodes[1];

                int versionLoaded = (rootNode.Attributes != null) ? int.Parse(rootNode.Attributes["Version"] != null ? rootNode.Attributes["Version"].Value : "0") : 0;
                this._version = versionLoaded;

                if (versionLoaded > Nodes.Behavior.NewVersion)
                {
                    MessageBox.Show(Resources.FileVersionWarning, Resources.LoadWarning, MessageBoxButtons.OK);
                }

                foreach (XmlNode xmlNode in rootNode.ChildNodes)
                {
                    if (xmlNode.Name == "Node")
                    {
                        _behavior = (BehaviorNode)CreateNodeAndAdd(result, getBehaviorNode, xmlNode, null, null);

                        ProcessedBehaviors processedBehaviors = new ProcessedBehaviors();
                        DoPostLoad(processedBehaviors, (Node)_behavior);

                        break;
                    }
                }

                if (_behavior != null && versionLoaded != Nodes.Behavior.NewVersion)
                {
                    _behavior.Version = Nodes.Behavior.NewVersion;
                    _behavior.TriggerWasModified((Node)_behavior);
                }
            } catch (Exception e) {
                MessageBox.Show(e.Message, Resources.LoadError, MessageBoxButtons.OK);

                _xmlfile.RemoveAll();

                throw;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Loads a behaviour from the given filename
        /// </summary>
        /// <param name="getBehaviorNode">The callback used to return the behavior.</param>
        public override void Load(GetBehaviorNode getBehaviorNode)
        {
            try
            {
                FileStream fs = new FileStream(_filename, FileMode.Open, FileAccess.Read, FileShare.Read);
                _xmlfile.Load(fs);
                fs.Close();

                foreach (XmlNode xmlNode in _xmlfile.ChildNodes[1].ChildNodes)
                {
                    if (xmlNode.Name == "Node")
                    {
                        _behavior = (BehaviorNode)CreateNodeAndAdd(getBehaviorNode, xmlNode, null, null);

                        ProcessedBehaviors processedBehaviors = new ProcessedBehaviors();
                        DoPostLoad(processedBehaviors, (Node)_behavior);
                    }
                    else if (xmlNode.Name == "Parameters")
                    {
                        Debug.Check(_behavior != null);
                        if (((Node)_behavior).Version == 0)
                        {
                            LoadParameters(xmlNode, (Node)_behavior, ((Node)_behavior).Pars);
                        }
                    }
                    else if (xmlNode.Name == "DescriptorRefs")
                    {
#if QUERY_EANBLED
                        LoadDescriptorRefs(xmlNode, _behavior as Behavior);
#endif//#if QUERY_EANBLED
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, Resources.LoadError, MessageBoxButtons.OK);

                _xmlfile.RemoveAll();

                throw;
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Loads a behaviour from the given filename
        /// </summary>
        /// <param name="getBehaviorNode">The callback used to return the behavior.</param>
        public override void Load(GetBehaviorNode getBehaviorNode)
        {
            try
            {
                _xmlfile.Load(_filename);

                XmlNode root = _xmlfile.ChildNodes[1].ChildNodes[0];

                _node = (BehaviorNode)CreateNodeAndAdd(getBehaviorNode, root, null, null);

                ProcessedBehaviors processedBehaviors = new ProcessedBehaviors();
                DoPostLoad(processedBehaviors, (Node)_node);
            }
            catch
            {
                _xmlfile.RemoveAll();

                throw;
            }
        }
Esempio n. 5
0
 /// <summary>
 /// Loads the behaviour of the given file and stores it in the Node member.
 /// </summary>
 public abstract void Load(GetBehaviorNode getBehaviorNode);
Esempio n. 6
0
        /// <summary>
        /// Loads a node from a given XML node.
        /// </summary>
        /// <param name="getBehaviorNode">The callback used to return the behavior.</param>
        /// <param name="xml">The XML node we want to create the node from.</param>
        /// <param name="parent">The parent this node will be added to.</param>
        /// <param name="connector">The connector used to add this node to the parent.</param>
        /// <returns>Returns the created node.</returns>
        protected Node CreateNodeAndAdd(List <Nodes.Node.ErrorCheck> result, GetBehaviorNode getBehaviorNode, XmlNode xml, Node parent, Node.Connector connector)
        {
            try {
                // get the type of the node and create it
                string clss = GetAttribute(xml, "Class");
                Type   t    = Plugin.GetType(clss);

                if (t == null)
                {
                    string msg = string.Format(Resources.ExceptionUnknownNodeType, clss);

                    string msgError = string.Format("{0}:\n{1}", this.Filename, msg);

                    //throw new Exception(msg);
                    MessageBox.Show(msgError, Resources.LoadError, MessageBoxButtons.OK);

                    parent.Behavior.TriggerWasModified(parent);

                    return(null);
                }

                Node node = Nodes.Node.Create(t);

                if (parent == null)
                {
                    //if this._version == 0, it means there is no Version attribute in the file
                    node.Behavior.Version = this._version;
                }

                // update the loaded behaviour member
                if (node is BehaviorNode)
                {
                    ((BehaviorNode)node).FileManager = this;
                }

                // add the node to the parent
                if (parent != null)
                {
                    if (connector != null)
                    {
                        parent.AddChildNotModified(connector, node);
                    }

                    else
                    {
                        parent.AddFSMNode(node);
                    }
                }

                int version = 0;

                if (node.Behavior != null)
                {
                    version = node.Behavior.Version;
                }
                else
                {
                    Debug.Check(true);
                }

                SetEnterExitSlot(result, xml, node, version);

                // initialise the properties
                IList <DesignerPropertyInfo> properties = node.GetDesignerProperties();
                foreach (DesignerPropertyInfo property in properties)
                {
                    if (!property.Attribute.HasFlags(DesignerProperty.DesignerFlags.NoSave))
                    {
                        InitProperty(result, xml, node, property);
                    }
                }

                // return the created behaviour node
                if (node is BehaviorNode)
                {
                    getBehaviorNode((BehaviorNode)node);
                }

                // maintain compatibility with version 1
                if (node is ReferencedBehaviorNode)
                {
                    ReferencedBehaviorNode refbehavior = (ReferencedBehaviorNode)node;

                    if (refbehavior.ReferenceFilename == null)
                    {
                        refbehavior.ReferenceFilename = GetAttribute(xml, "Reference");
                    }
                }

                // update node with properties
                node.OnPropertyValueChanged(false);

                // load child objects
                foreach (XmlNode xnode in xml.ChildNodes)
                {
                    if (xnode.NodeType == XmlNodeType.Element)
                    {
                        switch (xnode.Name)
                        {
                        // load parameters
                        case ("Parameters"):
                            if (node is Behavior || node is ReferencedBehavior)
                            {
                                LoadParameters(result, xnode, node, node.LocalVars);
                                node.Behavior.PostLoadPars();
                            }

                            break;

                        case ("DescriptorRefs"):
#if QUERY_EANBLED
                            LoadDescriptorRefs(result, xnode, node.Behavior as Behavior);
#endif//#if QUERY_EANBLED
                            break;

                        // maintain compatibility with version 1
                        case ("Node"):
                            CreateNodeAndAdd(result, getBehaviorNode, xnode, node, node.GetConnector(BaseNode.Connector.kGeneric));
                            break;

                        // maintain compatibility with version 2.1
                        case ("Event"):
                        case ("Attachment"): {
                            Attachments.Attachment a = CreateAttachment(result, node, xnode);

                            if (a != null)
                            {
                                node.AddAttachment(a);

                                a.PostCreate(result, version, node, xnode);
                            }
                        }
                        break;

                        case ("Comment"):
                            // create a comment object
                            node.CommentText = "temp";

                            // initialise the attributes
                            properties = node.CommentObject.GetDesignerProperties();
                            foreach (DesignerPropertyInfo property in properties)
                            {
                                if (property.Attribute.HasFlags(DesignerProperty.DesignerFlags.NoSave))
                                {
                                    continue;
                                }

                                string value;

                                if (GetAttribute(xnode, property.Property.Name, out value))
                                {
                                    property.SetValueFromString(result, node.CommentObject, value);
                                }
                            }
                            break;

                        case ("Connector"):
                            string identifier         = GetAttribute(xnode, "Identifier");
                            Nodes.Node.Connector conn = node.GetConnector(identifier);

                            foreach (XmlNode connected in xnode.ChildNodes)
                            {
                                if (connected.NodeType == XmlNodeType.Element && connected.Name == "Node")
                                {
                                    CreateNodeAndAdd(result, getBehaviorNode, connected, node, conn);
                                }
                            }
                            break;

                        case ("FSMNodes"):
                            string locationX = GetAttribute(xnode, "ScreenLocationX");
                            string locationY = GetAttribute(xnode, "ScreenLocationY");

                            if (!string.IsNullOrEmpty(locationX) && !string.IsNullOrEmpty(locationY))
                            {
                                try {
                                    float x = float.Parse(locationX);
                                    float y = float.Parse(locationY);
                                    node.ScreenLocation = new System.Drawing.PointF(x, y);
                                } catch {
                                }
                            }

                            foreach (XmlNode fsmNode in xnode.ChildNodes)
                            {
                                if (fsmNode.NodeType == XmlNodeType.Element && fsmNode.Name == "Node")
                                {
                                    CreateNodeAndAdd(result, getBehaviorNode, fsmNode, node, null);
                                }
                            }
                            break;
                        }
                    }
                }

                // update attachments with attributes
                foreach (Attachments.Attachment attach in node.Attachments)
                {
                    attach.OnPropertyValueChanged(false);
                }

                // set the properties from its prefab
                bool isPrefabInstance = !string.IsNullOrEmpty(node.PrefabName) && !node.HasOwnPrefabData;

                if (isPrefabInstance)
                {
                    Node prefabNode = Plugin.GetPrefabNode(node);

                    if (prefabNode != null)
                    {
                        node.ResetByPrefab(node.PrefabName, prefabNode);

                        Behavior b = node.Behavior as Behavior;
                        b.AgentType.AddPars(b.LocalVars);
                    }
                }

                node.PostCreate(result, version, xml);

                return(node);
            } catch (Exception e) {
                string idNode   = xml.Attributes["Id"].Value;
                string msgError = string.Format("{0}:\r\nNode Id:{1}\r\n{2}", this.Filename, idNode, e.Message);

                //throw new Exception(msg);
                MessageBox.Show(msgError, Resources.LoadError, MessageBoxButtons.OK);
            }

            return(null);
        }
Esempio n. 7
0
        /// <summary>
        /// Loads a behaviour from the given filename
        /// </summary>
        /// <param name="getBehaviorNode">The callback used to return the behavior.</param>
        public override void Load(List<Nodes.Node.ErrorCheck> result, GetBehaviorNode getBehaviorNode)
        {
            try {
                FileStream fs = new FileStream(_filename, FileMode.Open, FileAccess.Read, FileShare.Read);
                _xmlfile.Load(fs);
                fs.Close();

                XmlNode rootNode = _xmlfile.ChildNodes[1];

                int versionLoaded = (rootNode.Attributes != null) ? int.Parse(rootNode.Attributes["Version"] != null ? rootNode.Attributes["Version"].Value : "0") : 0;
                this._version = versionLoaded;

                if (versionLoaded > Nodes.Behavior.NewVersion)
                {
                    MessageBox.Show(Resources.FileVersionWarning, Resources.LoadWarning, MessageBoxButtons.OK);
                }

                foreach(XmlNode xmlNode in rootNode.ChildNodes) {
                    if (xmlNode.Name == "Node") {
                        _behavior = (BehaviorNode)CreateNodeAndAdd(result, getBehaviorNode, xmlNode, null, null);

                        ProcessedBehaviors processedBehaviors = new ProcessedBehaviors();
                        DoPostLoad(processedBehaviors, (Node)_behavior);

                        break;
                    }
                }

                if (_behavior != null && versionLoaded != Nodes.Behavior.NewVersion)
                {
                    _behavior.Version = Nodes.Behavior.NewVersion;
                    _behavior.TriggerWasModified((Node)_behavior);
                }

            } catch (Exception e) {
                MessageBox.Show(e.Message, Resources.LoadError, MessageBoxButtons.OK);

                _xmlfile.RemoveAll();

                throw;
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Loads a node from a given XML node.
        /// </summary>
        /// <param name="getBehaviorNode">The callback used to return the behavior.</param>
        /// <param name="xml">The XML node we want to create the node from.</param>
        /// <param name="parent">The parent this node will be added to.</param>
        /// <param name="connector">The connector used to add this node to the parent.</param>
        /// <returns>Returns the created node.</returns>
        protected Node CreateNodeAndAdd(List<Nodes.Node.ErrorCheck> result, GetBehaviorNode getBehaviorNode, XmlNode xml, Node parent, Node.Connector connector)
        {
            try {
                // get the type of the node and create it
                string clss = GetAttribute(xml, "Class");
                Type t = Plugin.GetType(clss);

                if (t == null) {
                    string msg = string.Format(Resources.ExceptionUnknownNodeType, clss);

                    string msgError = string.Format("{0}:\n{1}", this.Filename, msg);

                    //throw new Exception(msg);
                    MessageBox.Show(msgError, Resources.LoadError, MessageBoxButtons.OK);

                    parent.Behavior.TriggerWasModified(parent);

                    return null;
                }

                Node node = Nodes.Node.Create(t);

                if (parent == null) {
                    //if this._version == 0, it means there is no Version attribute in the file
                    node.Behavior.Version = this._version;
                }

                // update the loaded behaviour member
                if (node is BehaviorNode)
                { ((BehaviorNode)node).FileManager = this; }

                // add the node to the parent
                if (parent != null) {
                    if (connector != null)
                    { parent.AddChildNotModified(connector, node); }

                    else
                    { parent.AddFSMNode(node); }
                }

                int version = 0;

                if (node.Behavior != null) {
                    version = node.Behavior.Version;

                } else {
                    Debug.Check(true);
                }

                SetEnterExitSlot(result, xml, node, version);

                // initialise the properties
                IList<DesignerPropertyInfo> properties = node.GetDesignerProperties();
                foreach(DesignerPropertyInfo property in properties) {
                    if (!property.Attribute.HasFlags(DesignerProperty.DesignerFlags.NoSave)) {
                        InitProperty(result, xml, node, property);
                    }
                }

                // return the created behaviour node
                if (node is BehaviorNode)
                { getBehaviorNode((BehaviorNode)node); }

                // maintain compatibility with version 1
                if (node is ReferencedBehaviorNode) {
                    ReferencedBehaviorNode refbehavior = (ReferencedBehaviorNode)node;

                    if (refbehavior.ReferenceFilename == null)
                    { refbehavior.ReferenceFilename = GetAttribute(xml, "Reference"); }
                }

                // update node with properties
                node.OnPropertyValueChanged(false);

                // load child objects
                foreach(XmlNode xnode in xml.ChildNodes) {
                    if (xnode.NodeType == XmlNodeType.Element) {
                        switch (xnode.Name) {
                                // load parameters
                            case ("Parameters"):
                                if (node is Behavior || node is ReferencedBehavior) {
                                    LoadParameters(result, xnode, node, node.LocalVars);
                                    node.Behavior.PostLoadPars();
                                }

                                break;

                            case ("DescriptorRefs"):
#if QUERY_EANBLED
                                LoadDescriptorRefs(result, xnode, node.Behavior as Behavior);
#endif//#if QUERY_EANBLED
                                break;

                                // maintain compatibility with version 1
                            case ("Node"):
                                CreateNodeAndAdd(result, getBehaviorNode, xnode, node, node.GetConnector(BaseNode.Connector.kGeneric));
                                break;

                                // maintain compatibility with version 2.1
                            case ("Event"):
                            case ("Attachment"): {
                                Attachments.Attachment a = CreateAttachment(result, node, xnode);

                                if (a != null) {
                                    node.AddAttachment(a);

                                    a.PostCreate(result, version, node, xnode);
                                }
                            }
                            break;

                            case ("Comment"):
                                // create a comment object
                                node.CommentText = "temp";

                                // initialise the attributes
                                properties = node.CommentObject.GetDesignerProperties();
                                foreach(DesignerPropertyInfo property in properties) {
                                    if (property.Attribute.HasFlags(DesignerProperty.DesignerFlags.NoSave))
                                    { continue; }

                                    string value;

                                    if (GetAttribute(xnode, property.Property.Name, out value))
                                    { property.SetValueFromString(result, node.CommentObject, value); }
                                }
                                break;

                            case ("Connector"):
                                string identifier = GetAttribute(xnode, "Identifier");
                                Nodes.Node.Connector conn = node.GetConnector(identifier);

                                foreach(XmlNode connected in xnode.ChildNodes) {
                                    if (connected.NodeType == XmlNodeType.Element && connected.Name == "Node") {
                                        CreateNodeAndAdd(result, getBehaviorNode, connected, node, conn);
                                    }
                                }
                                break;

                            case ("FSMNodes"):
                                string locationX = GetAttribute(xnode, "ScreenLocationX");
                                string locationY = GetAttribute(xnode, "ScreenLocationY");

                                if (!string.IsNullOrEmpty(locationX) && !string.IsNullOrEmpty(locationY)) {
                                    try {
                                        float x = float.Parse(locationX);
                                        float y = float.Parse(locationY);
                                        node.ScreenLocation = new System.Drawing.PointF(x, y);

                                    } catch {
                                    }
                                }

                                foreach(XmlNode fsmNode in xnode.ChildNodes) {
                                    if (fsmNode.NodeType == XmlNodeType.Element && fsmNode.Name == "Node") {
                                        CreateNodeAndAdd(result, getBehaviorNode, fsmNode, node, null);
                                    }
                                }
                                break;
                        }
                    }
                }

                // update attachments with attributes
                foreach(Attachments.Attachment attach in node.Attachments)
                attach.OnPropertyValueChanged(false);

                // set the properties from its prefab
                bool isPrefabInstance = !string.IsNullOrEmpty(node.PrefabName) && !node.HasOwnPrefabData;

                if (isPrefabInstance) {
                    Node prefabNode = Plugin.GetPrefabNode(node);

                    if (prefabNode != null) {
                        node.ResetByPrefab(node.PrefabName, prefabNode);

                        Behavior b = node.Behavior as Behavior;
                        b.AgentType.AddPars(b.LocalVars);
                    }
                }

                node.PostCreate(result, version, xml);

                return node;

            } catch (Exception e) {
                string idNode = xml.Attributes["Id"].Value;
                string msgError = string.Format("{0}:\r\nNode Id:{1}\r\n{2}", this.Filename, idNode, e.Message);

                //throw new Exception(msg);
                MessageBox.Show(msgError, Resources.LoadError, MessageBoxButtons.OK);
            }

            return null;
        }
Esempio n. 9
0
 /// <summary>
 /// Loads the behaviour of the given file and stores it in the Node member.
 /// </summary>
 public abstract void Load(List <Nodes.Node.ErrorCheck> result, GetBehaviorNode getBehaviorNode);
Esempio n. 10
0
        /// <summary>
        /// Loads a node from a given XML node.
        /// </summary>
        /// <param name="getBehaviorNode">The callback used to return the behavior.</param>
        /// <param name="xml">The XML node we want to create the node from.</param>
        /// <param name="parent">The parent this node will be added to.</param>
        /// <param name="connector">The connector used to add this node to the parent.</param>
        /// <returns>Returns the created node.</returns>
        protected Node CreateNodeAndAdd(GetBehaviorNode getBehaviorNode, XmlNode xml, Node parent, Node.Connector connector)
        {
            // get the type of the node and create it
            string clss = GetAttribute(xml, "Class");
            Type   t    = Plugin.GetType(clss);

            if (t == null)
            {
                throw new Exception(string.Format(Resources.ExceptionUnknownNodeType, clss));
            }

            Node node = Nodes.Node.Create(t);

            // update the loaded behaviour member
            if (node is BehaviorNode)
            {
                ((BehaviorNode)node).FileManager = this;
            }

            // add the node to the parent
            if (parent != null)
            {
                Debug.Check(connector != null);
                parent.AddChildNotModified(connector, node);
            }

            // initialise the properties
            IList <DesignerPropertyInfo> properties = node.GetDesignerProperties();

            foreach (DesignerPropertyInfo property in properties)
            {
                if (property.Attribute.HasFlags(DesignerProperty.DesignerFlags.NoSave))
                {
                    continue;
                }

                InitProperty(xml, node, property);
                node.PostPropertyInit(property);
            }

            // return the created behaviour node
            if (node is BehaviorNode)
            {
                getBehaviorNode((BehaviorNode)node);
            }

            // maintain compatibility with version 1
            if (node is ReferencedBehaviorNode)
            {
                ReferencedBehaviorNode refbehavior = (ReferencedBehaviorNode)node;
                if (refbehavior.ReferenceFilename == null)
                {
                    refbehavior.ReferenceFilename = GetAttribute(xml, "Reference");
                }
            }

            // update node with properties
            node.OnPropertyValueChanged(false);

            // load child objects
            foreach (XmlNode xnode in xml.ChildNodes)
            {
                if (xnode.NodeType == XmlNodeType.Element)
                {
                    switch (xnode.Name.ToLowerInvariant())
                    {
                    // maintain compatibility with version 1
                    case ("node"):
                        CreateNodeAndAdd(getBehaviorNode, xnode, node, node.GetConnector("GenericChildren"));
                        break;

                    // maintain compatibility with version 2.1
                    case ("event"):

                    case ("attachment"):
                        node.AddAttachment(CreateAttachment(node, xnode));
                        break;

                    case ("comment"):
                        // create a comment object
                        node.CommentText = "temp";

                        // initialise the attributes
                        properties = node.CommentObject.GetDesignerProperties();
                        foreach (DesignerPropertyInfo property in properties)
                        {
                            if (property.Attribute.HasFlags(DesignerProperty.DesignerFlags.NoSave))
                            {
                                continue;
                            }

                            string value;
                            if (GetAttribute(xnode, property.Property.Name, out value))
                            {
                                property.SetValueFromString(node.CommentObject, value);
                            }
                        }
                        break;

                    case ("connector"):
                        string identifier         = GetAttribute(xnode, "Identifier");
                        Nodes.Node.Connector conn = node.GetConnector(identifier);

                        foreach (XmlNode connected in xnode.ChildNodes)
                        {
                            if (connected.NodeType == XmlNodeType.Element &&
                                connected.Name.ToLowerInvariant() == "node")
                            {
                                CreateNodeAndAdd(getBehaviorNode, connected, node, conn);
                            }
                        }
                        break;
                    }
                }
            }

            // update attachments with attributes
            foreach (Attachments.Attachment attach in node.Attachments)
            {
                attach.OnPropertyValueChanged(false);
            }

            return(node);
        }
Esempio n. 11
0
        /// <summary>
        /// Loads a behaviour from the given filename
        /// </summary>
        /// <param name="getBehaviorNode">The callback used to return the behavior.</param>
        public override void Load(GetBehaviorNode getBehaviorNode)
        {
            try
            {
                FileStream fs = new FileStream(_filename, FileMode.Open, FileAccess.Read, FileShare.Read);
                _xmlfile.Load(fs);
                fs.Close();

                foreach (XmlNode xmlNode in _xmlfile.ChildNodes[1].ChildNodes)
                {
                    if (xmlNode.Name == "Node")
                    {
                        _behavior = (BehaviorNode)CreateNodeAndAdd(getBehaviorNode, xmlNode, null, null);

                        ProcessedBehaviors processedBehaviors = new ProcessedBehaviors();
                        DoPostLoad(processedBehaviors, (Node)_behavior);
                    }
                    else if (xmlNode.Name == "Parameters")
                    {
                        Debug.Check(_behavior != null);
                        if (((Node)_behavior).Version == 0)
                            LoadParameters(xmlNode, (Node)_behavior, ((Node)_behavior).Pars);
                    }
                    else if (xmlNode.Name == "DescriptorRefs")
                    {
            #if QUERY_EANBLED
                        LoadDescriptorRefs(xmlNode, _behavior as Behavior);
            #endif//#if QUERY_EANBLED
                    }
                }
            }
            catch(Exception e)
            {
                MessageBox.Show(e.Message, Resources.LoadError, MessageBoxButtons.OK);

                _xmlfile.RemoveAll();

                throw;
            }
        }
Esempio n. 12
0
        /// <summary>
        /// Loads a node from a given XML node.
        /// </summary>
        /// <param name="getBehaviorNode">The callback used to return the behavior.</param>
        /// <param name="xml">The XML node we want to create the node from.</param>
        /// <param name="parent">The parent this node will be added to.</param>
        /// <param name="connector">The connector used to add this node to the parent.</param>
        /// <returns>Returns the created node.</returns>
        protected Node CreateNodeAndAdd(GetBehaviorNode getBehaviorNode, XmlNode xml, Node parent, Node.Connector connector)
        {
            try
            {
                // get the type of the node and create it
                string clss = GetAttribute(xml, "Class");
                Type t = Plugin.GetType(clss);

                if (t == null)
                {
                    string msg = string.Format(Resources.ExceptionUnknownNodeType, clss);

                    string msgError = string.Format("{0}:\n{1}", this.Filename, msg);

                    //throw new Exception(msg);
                    MessageBox.Show(msgError, Resources.LoadError, MessageBoxButtons.OK);

                    parent.Behavior.IsModified = true;

                    return null;
                }

                Node node = Nodes.Node.Create(t);

                // update the loaded behaviour member
                if (node is BehaviorNode)
                    ((BehaviorNode)node).FileManager = this;

                // add the node to the parent
                if (parent != null)
                {
                    Debug.Check(connector != null);
                    parent.AddChildNotModified(connector, node);
                }

                // initialise the properties
                IList<DesignerPropertyInfo> properties = node.GetDesignerProperties();
                foreach (DesignerPropertyInfo property in properties)
                {
                    if (!property.Attribute.HasFlags(DesignerProperty.DesignerFlags.NoSave))
                    {
                        InitProperty(xml, node, property);
                        node.PostPropertyInit(property);
                    }
                }

                // return the created behaviour node
                if (node is BehaviorNode)
                    getBehaviorNode((BehaviorNode)node);

                // maintain compatibility with version 1
                if (node is ReferencedBehaviorNode)
                {
                    ReferencedBehaviorNode refbehavior = (ReferencedBehaviorNode)node;
                    if (refbehavior.ReferenceFilename == null)
                        refbehavior.ReferenceFilename = GetAttribute(xml, "Reference");
                }

                // update node with properties
                node.OnPropertyValueChanged(false);

                // load child objects
                foreach (XmlNode xnode in xml.ChildNodes)
                {
                    if (xnode.NodeType == XmlNodeType.Element)
                    {
                        switch (xnode.Name.ToLowerInvariant())
                        {
                            // load parameters
                            case ("parameters"):
                                LoadParameters(xnode, node, node.Pars);
                                break;

                            case ("descriptorrefs"):
            #if QUERY_EANBLED
                                LoadDescriptorRefs(xnode, node.Behavior as Behavior);
            #endif//#if QUERY_EANBLED
                                break;

                            // maintain compatibility with version 1
                            case ("node"):
                                CreateNodeAndAdd(getBehaviorNode, xnode, node, node.GetConnector("GenericChildren"));
                                break;

                            // maintain compatibility with version 2.1
                            case ("event"):

                            case ("attachment"):
                                {
                                    Attachments.Attachment a = CreateAttachment(node, xnode);

                                    if (a != null)
                                    {
                                        node.AddAttachment(a);
                                    }
                                }
                                break;

                            case ("comment"):
                                // create a comment object
                                node.CommentText = "temp";

                                // initialise the attributes
                                properties = node.CommentObject.GetDesignerProperties();
                                foreach (DesignerPropertyInfo property in properties)
                                {
                                    if (property.Attribute.HasFlags(DesignerProperty.DesignerFlags.NoSave))
                                        continue;

                                    string value;
                                    if (GetAttribute(xnode, property.Property.Name, out value))
                                        property.SetValueFromString(node.CommentObject, value);
                                }
                                break;

                            case ("connector"):
                                string identifier = GetAttribute(xnode, "Identifier");
                                Nodes.Node.Connector conn = node.GetConnector(identifier);

                                foreach (XmlNode connected in xnode.ChildNodes)
                                {
                                    if (connected.NodeType == XmlNodeType.Element &&
                                        connected.Name.ToLowerInvariant() == "node")
                                    {
                                        CreateNodeAndAdd(getBehaviorNode, connected, node, conn);
                                    }
                                }
                                break;
                        }
                    }
                }

                // update attachments with attributes
                foreach (Attachments.Attachment attach in node.Attachments)
                    attach.OnPropertyValueChanged(false);

                // set the properties from its prefab
                bool isPrefabInstance = !string.IsNullOrEmpty(node.PrefabName) && !node.HasOwnPrefabData;
                if (isPrefabInstance)
                {
                    Node prefabNode = Plugin.GetPrefabNode(node);
                    if (prefabNode != null)
                    {
                        node.ResetByPrefab(node.PrefabName, prefabNode);
                    }
                }

                return node;
            }
            catch (Exception e)
            {
                string idNode = xml.Attributes["Id"].Value;
                string msgError = string.Format("{0}:\r\nNode Id:{1}\r\n{2}", this.Filename, idNode, e.Message);

                //throw new Exception(msg);
                MessageBox.Show(msgError, Resources.LoadError, MessageBoxButtons.OK);
            }

            return null;
        }
Esempio n. 13
0
 /// <summary>
 /// Loads the behaviour of the given file and stores it in the Node member.
 /// </summary>
 public abstract void Load(List<Nodes.Node.ErrorCheck> result, GetBehaviorNode getBehaviorNode);
Esempio n. 14
0
        /// <summary>
        /// Loads a node from a given XML node.
        /// </summary>
        /// <param name="getBehaviorNode">The callback used to return the behavior.</param>
        /// <param name="xml">The XML node we want to create the node from.</param>
        /// <param name="parent">The parent this node will be added to.</param>
        /// <param name="connector">The connector used to add this node to the parent.</param>
        /// <returns>Returns the created node.</returns>
        protected Node CreateNodeAndAdd(GetBehaviorNode getBehaviorNode, XmlNode xml, Node parent, Node.Connector connector)
        {
            try
            {
                // get the type of the node and create it
                string clss = GetAttribute(xml, "Class");
                Type   t    = Plugin.GetType(clss);

                if (t == null)
                {
                    string msg = string.Format(Resources.ExceptionUnknownNodeType, clss);

                    string msgError = string.Format("{0}:\n{1}", this.Filename, msg);

                    //throw new Exception(msg);
                    MessageBox.Show(msgError, Resources.LoadError, MessageBoxButtons.OK);

                    parent.Behavior.IsModified = true;

                    return(null);
                }

                Node node = Nodes.Node.Create(t);

                // update the loaded behaviour member
                if (node is BehaviorNode)
                {
                    ((BehaviorNode)node).FileManager = this;
                }

                // add the node to the parent
                if (parent != null)
                {
                    Debug.Check(connector != null);
                    parent.AddChildNotModified(connector, node);
                }

                // initialise the properties
                IList <DesignerPropertyInfo> properties = node.GetDesignerProperties();
                foreach (DesignerPropertyInfo property in properties)
                {
                    if (!property.Attribute.HasFlags(DesignerProperty.DesignerFlags.NoSave))
                    {
                        InitProperty(xml, node, property);
                        node.PostPropertyInit(property);
                    }
                }

                // return the created behaviour node
                if (node is BehaviorNode)
                {
                    getBehaviorNode((BehaviorNode)node);
                }

                // maintain compatibility with version 1
                if (node is ReferencedBehaviorNode)
                {
                    ReferencedBehaviorNode refbehavior = (ReferencedBehaviorNode)node;
                    if (refbehavior.ReferenceFilename == null)
                    {
                        refbehavior.ReferenceFilename = GetAttribute(xml, "Reference");
                    }
                }

                // update node with properties
                node.OnPropertyValueChanged(false);

                // load child objects
                foreach (XmlNode xnode in xml.ChildNodes)
                {
                    if (xnode.NodeType == XmlNodeType.Element)
                    {
                        switch (xnode.Name.ToLowerInvariant())
                        {
                        // load parameters
                        case ("parameters"):
                            LoadParameters(xnode, node, node.Pars);
                            break;

                        case ("descriptorrefs"):
#if QUERY_EANBLED
                            LoadDescriptorRefs(xnode, node.Behavior as Behavior);
#endif//#if QUERY_EANBLED
                            break;

                        // maintain compatibility with version 1
                        case ("node"):
                            CreateNodeAndAdd(getBehaviorNode, xnode, node, node.GetConnector("GenericChildren"));
                            break;

                        // maintain compatibility with version 2.1
                        case ("event"):

                        case ("attachment"):
                        {
                            Attachments.Attachment a = CreateAttachment(node, xnode);

                            if (a != null)
                            {
                                node.AddAttachment(a);
                            }
                        }
                        break;

                        case ("comment"):
                            // create a comment object
                            node.CommentText = "temp";

                            // initialise the attributes
                            properties = node.CommentObject.GetDesignerProperties();
                            foreach (DesignerPropertyInfo property in properties)
                            {
                                if (property.Attribute.HasFlags(DesignerProperty.DesignerFlags.NoSave))
                                {
                                    continue;
                                }

                                string value;
                                if (GetAttribute(xnode, property.Property.Name, out value))
                                {
                                    property.SetValueFromString(node.CommentObject, value);
                                }
                            }
                            break;

                        case ("connector"):
                            string identifier         = GetAttribute(xnode, "Identifier");
                            Nodes.Node.Connector conn = node.GetConnector(identifier);

                            foreach (XmlNode connected in xnode.ChildNodes)
                            {
                                if (connected.NodeType == XmlNodeType.Element &&
                                    connected.Name.ToLowerInvariant() == "node")
                                {
                                    CreateNodeAndAdd(getBehaviorNode, connected, node, conn);
                                }
                            }
                            break;
                        }
                    }
                }

                // update attachments with attributes
                foreach (Attachments.Attachment attach in node.Attachments)
                {
                    attach.OnPropertyValueChanged(false);
                }

                // set the properties from its prefab
                bool isPrefabInstance = !string.IsNullOrEmpty(node.PrefabName) && !node.HasOwnPrefabData;
                if (isPrefabInstance)
                {
                    Node prefabNode = Plugin.GetPrefabNode(node);
                    if (prefabNode != null)
                    {
                        node.ResetByPrefab(node.PrefabName, prefabNode);
                    }
                }

                return(node);
            }
            catch (Exception e)
            {
                string idNode   = xml.Attributes["Id"].Value;
                string msgError = string.Format("{0}:\r\nNode Id:{1}\r\n{2}", this.Filename, idNode, e.Message);

                //throw new Exception(msg);
                MessageBox.Show(msgError, Resources.LoadError, MessageBoxButtons.OK);
            }

            return(null);
        }
Esempio n. 15
0
 /// <summary>
 /// Loads the behaviour of the given file and stores it in the Node member.
 /// </summary>
 public abstract void Load(GetBehaviorNode getBehaviorNode);