Esempio n. 1
0
        public static PluginData Load(PluginVersion parent, string path)
        {
            FileInfo fileinfo = new FileInfo(path);

            if (!fileinfo.Exists)
            {
                return(null);
            }

            XmlDocument xmlDocument = new XmlDocument();

            try
            {
                xmlDocument.Load(path);
            }
            catch
            {
                string text = System.IO.File.ReadAllText(path, Encoding.Default);
                System.IO.File.WriteAllText(path, text, Encoding.UTF8);

                using (StreamReader streamreader = new StreamReader(path, Encoding.UTF8))
                    xmlDocument.Load(streamreader.BaseStream);
            }

            if (!xmlDocument.DocumentElement.Name.Equals("PluginData"))
            {
                return(null);
            }

            XmlElement documentElement = xmlDocument.DocumentElement;

            XmlAttribute id          = documentElement.Attributes["Id"];
            XmlAttribute productId   = documentElement.Attributes["ProductId"];
            XmlAttribute name        = documentElement.Attributes["Name"];
            XmlAttribute description = documentElement.Attributes["Description"];
            XmlAttribute version     = documentElement.Attributes["Version"];
            XmlAttribute creator     = documentElement.Attributes["Creator"];

            PluginData pluginData = new PluginData();

            pluginData.Id          = System.Convert.ToInt32(id.Value);
            pluginData.ProductId   = System.Convert.ToInt32(productId.Value);
            pluginData.Name        = name.Value;
            pluginData.Description = description.Value;
            pluginData.Version     = version.Value;
            pluginData.Creator     = creator.Value;
            pluginData.Parent      = parent;
            pluginData.Path        = path;

            foreach (XmlElement child in documentElement.ChildNodes)
            {
                if (child.Name.Equals("Content"))
                {
                    pluginData.Content = Content.Load(child);
                }
                else if (child.Name.Equals("HostApplications"))
                {
                    pluginData.HostApplications = HostApplications.Load(child);
                }
                else if (child.Name.Equals("DependancyAssemblies"))
                {
                    pluginData.DependencyAssemblies = DependencyAssemblies.Load(child);
                }
            }

            pluginData._created = true;

            return(pluginData);
        }