Beispiel #1
0
        public void Save(Control murpleControl, string filename, PodGroup thisPodGroup)
        {
            StreamWriter streamWriter = new StreamWriter(filename);
            XmlWriter xmlWriter = XmlWriter.Create(streamWriter);

            XmlDocument document = new XmlDocument();
            document.AppendChild(document.CreateWhitespace("\n"));

            {
                XmlElement murpleElement = document.CreateElement("Murple");

                AddNewLine(document, murpleElement);

                foreach (KeyValuePair<System.Guid, Pod> thisPodPair in murpleControl.Pods)
                {
                    if(thisPodGroup.ContainsPod(thisPodPair.Key) == true)
                        AddPod(document, murpleElement, thisPodPair);
                }

                document.AppendChild(murpleElement);
            }

            document.Save(xmlWriter);
            streamWriter.Close();
        }
Beispiel #2
0
        public void Load(Control murpleControl, string filename)
        {
            StreamReader streamReader = new StreamReader(filename);
            XmlReader xmlReader = XmlReader.Create(streamReader);
            XmlDocument document = new XmlDocument();

            document.Load(xmlReader);

            XmlNodeList allDatabases = document.GetElementsByTagName("Database");

            foreach (XmlNode thisDatabase in allDatabases)
            {
                XmlNode databaseNameNode = thisDatabase.Attributes.GetNamedItem("name");
                string databaseName = databaseNameNode.Value;
                murpleControl.Database.Add(databaseName, new Database(databaseName));

                XmlNode currentChild = thisDatabase.FirstChild;

                while (currentChild != null)
                {
                    if (currentChild.Name == "Group")
                    {
                        ExtractGroup(murpleControl, currentChild, databaseName);
                    }
                    currentChild = currentChild.NextSibling;
                }
            }
            streamReader.Close();
        }
Beispiel #3
0
        public PodGroup Load(Control murpleControl, string filename)
        {
            PodGroup newPodGroup = new PodGroup();

            StreamReader streamReader = new StreamReader (filename);
            XmlReader xmlReader = XmlReader.Create (streamReader);
            XmlDocument document = new XmlDocument ();

            document.Load (xmlReader);

            XmlNodeList allPodsAsXml = document.GetElementsByTagName ("Pod");

            foreach(XmlNode thisPodAsXml in allPodsAsXml)
            {
                XmlNode podNameNode = thisPodAsXml.Attributes.GetNamedItem("name");
                string podType = podNameNode.Value;

                Pod newPod = new Pod();

                if(murpleControl.IsInDefinition(podType) == true)
                {
                    newPod = murpleControl.AddMurpleFromDefinition(podType);
                    System.Guid podUUID = XmlToPod(murpleControl, thisPodAsXml, ref newPod, filename);
                    newPod.UUID = podUUID;
                    murpleControl.AddPod(podUUID, newPod, filename);
                }
            }
            streamReader.Close();

            return newPodGroup;
        }
Beispiel #4
0
        private void ExtractGroup(Control murpleControl, XmlNode groupNode, string databaseName)
        {
            XmlNode currentChild = groupNode.FirstChild;
            string groupName = groupNode.Attributes.GetNamedItem("name").Value;

            while (currentChild != null)
            {
                if (currentChild.Name == "Element")
                {
                    string entryValue = currentChild.Attributes.GetNamedItem("name").Value;
                    murpleControl.Database[databaseName].AddDataToGroup(groupName, entryValue);
                }
                currentChild = currentChild.NextSibling;
            }
        }
Beispiel #5
0
        public new void Load(Control murpleControl, string filename)
        {
            StreamReader streamReader = new StreamReader (filename);
            XmlReader xmlReader = XmlReader.Create (streamReader);
            XmlDocument document = new XmlDocument ();

            document.Load (xmlReader);

            XmlNodeList allDefinitions = document.GetElementsByTagName ("Definition");

            foreach(XmlNode thisDefinition in allDefinitions)
            {
                XmlNode nameNode = thisDefinition.Attributes.GetNamedItem("name");
                XmlNode extendsOption = thisDefinition.Attributes.GetNamedItem("extends");
                string definitionName = nameNode.Value;

                if (murpleControl.HasMurpleDefinition(definitionName) == true)
                    System.Diagnostics.Debug.Assert(false, string.Format("We already have a murple definition called {0}", definitionName));

                Definition newDefinition = new Definition(definitionName, murpleControl);

                if (extendsOption != null && extendsOption.Value == "true")
                    newDefinition.ExtendedDefinition = true;

                XmlNode childNode = thisDefinition.FirstChild;

                while(childNode != null)
                {
                    XmlNode statTypeNode = childNode.Attributes.GetNamedItem("statType");

                    if(statTypeNode != null)
                    {
                        string statName = childNode.Name;
                        string statType = statTypeNode.Value;

                        newDefinition.AddDefinitionNode(statName, statType);//MURPLE.Types.GetTypeOfString(statType));
                    }

                    childNode = childNode.NextSibling;
                }

                murpleControl.AddMurpleDefinition(definitionName, newDefinition);

            }
            streamReader.Close();
        }
Beispiel #6
0
        private System.Guid XmlToPod(Control murpleControl, XmlNode thisPodAsXml, ref Pod newPod, string filename)
        {
            //DebugUtils.Assert (newPod != null, "Pod has not been created.");
            System.Guid podUUID = System.Guid.Empty;
            XmlNodeList allChildren = thisPodAsXml.ChildNodes;
            bool uuidFound = false;

            foreach(XmlNode thisChild in allChildren)
            {
                string name = thisChild.Name;
                XmlNode statTypeNode = thisChild.Attributes.GetNamedItem("statType");
                string statType = statTypeNode.Value;
                string statValue = thisChild.InnerText;

                if (name == "UUID")
                {
                    uuidFound = true;
                    // Can't do this in .Net 3.5 (Unity)
                    //if( System.Guid.TryParse(statValue, out podUUID) == false)
                    //{
                    //    podUUID = Pod.GenerateUUID();
                    //}
                    if (thisChild.InnerText == "")
                    {
                        podUUID = System.Guid.NewGuid();
                    }
                    else
                    {
                        podUUID = new System.Guid(thisChild.InnerText);    // Have to do this non-safe way :(
                    }

                    if (murpleControl.HasPod(podUUID) == true)
                    {
                        newPod = murpleControl.GetPod(podUUID);
                    }

                }
                else if (newPod.Stats.ContainsKey(name) == true)
                {
                    System.Diagnostics.Debug.Assert(uuidFound == true);

                    StatBase thisStatBase = newPod.Stats[name];

                    // FILLMEIN
                    if (thisStatBase.IsStatType(StatHelper.StatType.DatabaseType))
                        XmlToDatabase(thisChild, ref thisStatBase);
                    else if (thisStatBase.IsStatType(StatHelper.StatType.StringList))
                        XmlToStringList(thisChild, ref thisStatBase);
                    else if (thisStatBase.IsStatType(StatHelper.StatType.StringIntDictionary))
                        XmlToStringIntDictionary(thisChild, ref thisStatBase);
                    else if (thisStatBase.IsStatType(StatHelper.StatType.Pod))
                    {
                        Stat<Pod> newChildPod = GetPod(murpleControl, thisChild, filename, name);

                        //System.Guid childPodUUID = System.Guid.Parse(thisChild.InnerText);
                        System.Guid childPodUUID = new System.Guid(thisChild.InnerText);

                        System.Diagnostics.Debug.Assert(childPodUUID != System.Guid.Empty);

                        murpleControl.AddPod(childPodUUID, newChildPod.Value, filename);
                        thisStatBase = newChildPod;

                        /*
                        // The Xml has a reference to the name of the pod, we can create a dummy one here to be filled in later.
                        // Or if the Pod is already loaded than we will link it here.
                        Stat<Pod> newChildPod = new Stat<Pod>(new Pod());
                        string childPodName = thisChild.InnerText;

                        if (murpleControl.HasPod(childPodName))
                            newChildPod.Value = murpleControl.GetPod(childPodName);
                        else
                            newChildPod.Value = murpleControl.AddMurpleFromDefinition(name); ;

                        murpleControl.AddPod(childPodName, newChildPod.Value, filename);
                        thisStatBase = newChildPod;
                        */
                    }
                    else if (thisStatBase.IsStatType(StatHelper.StatType.PodList))
                    {
                        List<Pod> podList = new List<Pod>();
                        Stat<List<Pod>> podListStat = new Stat<List<Pod>>(podList);

                        XmlNodeList podListChildren = thisChild.ChildNodes;

                        foreach(XmlNode podChild in podListChildren)
                        {
                            string childPodType = podChild.Name;
                            string childStatType = podChild.Attributes.GetNamedItem("statType").Value;
                            System.Diagnostics.Debug.Assert(childStatType == "pod");

                            Stat <Pod> newChildPod = GetPod(murpleControl, podChild, filename, childPodType);

                            /*
                            if (murpleControl.HasPod(childPodUUID) == false)
                            {
                                murpleControl.AddPod(childPodUUID, newChildPod.Value, filename);
                            }
                            else
                            {
                                newChildPod.                                 = murpleControl.GetPod(childPodUUID);
                            }
                             * */

                            podList.Add(newChildPod.Value);

                        }

                        podListStat.Value = podList;
                        thisStatBase = podListStat;
                    }
                    else if (thisStatBase.IsStatType(StatHelper.StatType.Image))
                    {
                        XmlToImage(thisChild, ref thisStatBase);
                    }
                    else if (statValue != "")
                    {
                        thisStatBase.SetValueFromString(statValue);

                        // If it's a name then add a helper string for name for quick getting instead of having to go through the stats.
                        if (newPod.Name == "" && StatHelper.IsStatType(thisStatBase, StatHelper.StatType.String) && name.ToLower() == "name")
                        {
                            newPod.Name = statValue;
                        }

                    }
                    else
                        System.Diagnostics.Debug.Assert(false, string.Format("You haven't provided a way to extract a {0} from XML yet.", thisStatBase.GetType().ToString()));

                    newPod.Stats[name] = thisStatBase;

                }
            }
            return podUUID;
        }
Beispiel #7
0
 public Definition(string name, Control murpleControl)
 {
     mName = name;
     mMurpleControl = murpleControl;
 }
Beispiel #8
0
 public Definition(Control murpleControl)
 {
     mMurpleControl = murpleControl;
 }