Пример #1
0
 private void SaveFile(string file)
 {
     currentFile         = file;
     CurrentProject.Name = file;
     ContentProject.Save(file, CurrentProject);
 }
Пример #2
0
        public static ContentProject Load(string filename)
        {
            var document = new XmlDocument();

            document.Load(filename);

            var root = document.ChildNodes.OfType <XmlElement>().FirstOrDefault(x => x.Name == "Content");

            if (root == null)
            {
                return(null);
            }
            ContentProject project = new ContentProject(filename);

            foreach (var child in root.ChildNodes.OfType <XmlElement>())
            {
                switch (child.Name)
                {
                case "References":
                {
                    project.References = new List <string>();
                    foreach (var reference in child.ChildNodes.OfType <XmlElement>())
                    {
                        if (reference.Name == "Reference")
                        {
                            var val = reference.ChildNodes.OfType <XmlText>().FirstOrDefault()?.InnerText;
                            if (val != null)
                            {
                                project.References.Add(val);
                            }
                        }
                    }
                }
                break;

                case "Configuration":
                {
                    var           val = child.ChildNodes.OfType <XmlText>().FirstOrDefault()?.InnerText;
                    Configuration config;
                    if (val != null && Enum.TryParse <Configuration>(val, out config))
                    {
                        project.Configuration = config;
                    }
                }
                break;

                case "OutputDir":
                {
                    var val = child.ChildNodes.OfType <XmlText>().FirstOrDefault()?.InnerText;
                    if (val != null)
                    {
                        project.OutputDir = val;
                    }
                }
                break;

                default:
                    project.ReadItem(child);
                    break;
                }
            }
            SearchParents(project);
            return(project);

            /* using (var reader = new XmlTextReader(filename, System.Text.Encoding.UTF8))
             * {
             *
             *   ContentProject proj = (ContentProject)serializer.Deserialize(fs.BaseStream);
             *   proj.File = filename;
             *   SearchParents(proj);
             *   return proj;
             * }*/
        }