예제 #1
0
        private void CacheDeserialization()
        {
            Child.InstallEnvironment = environment;
            SerializableXmlDocument doc = Child.OpenForReading <SerializableXmlDocument>().Object;

            doc.Normalize();

            XmlElement node = doc.FirstChild.NextSibling as XmlElement;

            // assert root node
            if (node.Name != "Application")
            {
                throw new AbortInstallationException("Source is not an application descriptor");
            }

            // check version
            if (new Version(node.GetAttribute("xversion")) > new Version(1, 0, 0))
            {
                throw new AbortInstallationException("Application descriptor is of an incorrect version");
            }

            string          name = node.GetAttribute("name");
            Guid            id   = new Guid(node.GetAttribute("id"));
            string          rootComponentName = node.GetAttribute("root");
            DocumentSupport apptype           = (DocumentSupport)Enum.Parse(typeof(DocumentSupport), node.GetAttribute("type"));
            string          friendlyName      = node.GetAttribute("friendly");

            List <ConfiguredComponent> defs = new List <ConfiguredComponent>();

            /** ok, construct **/
            ApplicationDesc app = new ApplicationDesc(id, apptype, name, friendlyName);

            foreach (XmlNode firstNode in node.ChildNodes)
            {
                if (firstNode.Name == "Components")
                {
                    /* load all components */
                    foreach (XmlNode componentNode in firstNode.ChildNodes)
                    {
                        if (componentNode.Name.StartsWith("#"))
                        {
                            continue;
                        }

                        if (componentNode.Name != "Component")
                        {
                            throw new AbortInstallationException("Application description is not well-formed. Only Component nodes are allowed in the Components section");
                        }

                        defs.Add(new ConfiguredComponent(componentNode));
                    }
                }
                if (firstNode.Name == "Bindings")
                {
                    foreach (XmlNode bindingNode in firstNode.ChildNodes)
                    {
                        if (bindingNode.Name != "Binding")
                        {
                            continue;
                        }

                        app.DefaultBindings[((XmlElement)bindingNode).GetAttribute("Type")] =
                            Array.ConvertAll <string, string>(
                                ((XmlElement)bindingNode).GetAttribute("Verbs").Split(','),
                                delegate(string s) { return(s.Trim()); });
                    }
                }
            }

            app.Components           = defs.ToArray();
            app.ApplicationComponent = rootComponentName;

            applicationDescriptor = app;
        }
예제 #2
0
        private void CacheDeserialization()
        {
            Child.InstallEnvironment = environment;
            SerializableXmlDocument doc = Child.OpenForReading <SerializableXmlDocument>().Object;

            doc.Normalize();

            XmlElement node = doc.FirstChild.NextSibling as XmlElement;

            // assert root node
            if (node.Name != "Library")
            {
                throw new AbortInstallationException("Source is not a library descriptor");
            }

            // check version
            if (new Version(node.GetAttribute("xversion")) > new Version(1, 0, 0))
            {
                throw new AbortInstallationException("Application descriptor is of an incorrect version");
            }

            string name = node.GetAttribute("name");
            // Guid id = new Guid(node.GetAttribute("id"));
            // string rootComponentName = node.GetAttribute("root");
            // ApplicationType apptype = (ApplicationType)Enum.Parse(typeof(ApplicationType), node.GetAttribute("type"));
            // string friendlyName = node.GetAttribute("friendly");

            List <ConfiguredComponent> defs = new List <ConfiguredComponent>();

            foreach (XmlNode firstNode in node.ChildNodes)
            {
                if (firstNode.Name == "Components")
                {
                    /* load all components */
                    foreach (XmlNode componentNode in firstNode.ChildNodes)
                    {
                        if (componentNode.Name.StartsWith("#"))
                        {
                            continue;
                        }

                        if (componentNode.Name != "Component")
                        {
                            throw new AbortInstallationException(
                                      String.Format(
                                          "Library description is not well-formed. Only Component nodes are allowed in the Components section. Found '{0}' instead",
                                          componentNode.Name));
                        }

                        defs.Add(new ConfiguredComponent(componentNode));
                    }
                }
            }

            /** ok, construct **/
            LibraryDesc lib = new LibraryDesc();

            lib.Components = defs.ToArray();

            applicationDescriptor = lib;
        }