Exemplo n.º 1
0
        //[Ignore("XInclude migration in progress.")]
        public void FullLoad()
        {
            XIncludingReader ir = new XIncludingReader(new XmlTextReader(BaseDir + "mainconfig.xml"));

            // Dump for debugging purposes.
            XmlTextWriter tw = new XmlTextWriter(Console.Out);

            tw.WriteNode(ir, false);
            ir = new XIncludingReader(new XmlTextReader(BaseDir + "mainconfig.xml"));

            XmlSerializer   ser     = new GuidancePackageSerializer();
            GuidancePackage package = (GuidancePackage)ser.Deserialize(ir);

            // Check included recipe
            Assert.AreEqual("ReusableRecipe", package.Recipes[0].Name);
            // Check included types in included recipe
            Assert.AreEqual("Page", package.Recipes[0].Types[1].Name);
            // Check included wizard
            Assert.IsNotNull(package.Recipes[0].GatheringServiceData);

            XmlSerializer wzser = new XmlSerializer(typeof(Wizard));
            Wizard        wz    = (Wizard)wzser.Deserialize(new XmlNodeReader(package.Recipes[0].GatheringServiceData.Any));

            Assert.AreEqual("ExistingWizard", wz.Name);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GuidancePackage"/> class with a
        /// configuration model, ready for use.
        /// </summary>
        /// <param name="configuration">The configuration for the package.</param>
        /// <param name="basePath">Location to use as the base folder to resolve types used by the package.
        /// Can be <see langword="null"/> or an empty string to use the <see cref="RecipeManager"/> installation folder.</param>
        /// <remarks>
        /// Types used by the package configuration are resolved relative to the framework installation only.
        /// Use the overload receiving the base path to change this behavior.
        /// </remarks>
        public GuidancePackage(Configuration.GuidancePackage configuration, string basePath)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }
            InitializeServices();

            // We need to serialize it and reprocess, to ensure validity and indexing.
            using (Stream mem = new MemoryStream())
            {
                // We avoid the perf. cost of generating a runtime serialization assembly
                // by using a design-time generated one that knows how to deal with out config.
                GuidancePackageSerializer ser = new GuidancePackageSerializer();
                ser.Serialize(mem, configuration);

                // Reinitialize with the other overload.
                mem.Seek(0, SeekOrigin.Begin);
                Initialize(new XmlTextReader(mem));
            }

            // Force Path validation if non-empty.
            if (basePath != null && basePath.Length > 0)
            {
                this.basePath = Path.GetDirectoryName(basePath);
            }
        }
Exemplo n.º 3
0
        public void LoadNoValidateOrInclusions()
        {
            XIncludingReader  ir = new XIncludingReader(new XmlTextReader(BaseDir + "smallconfig.xml"));
            XmlReaderSettings validateReaderSettings = new XmlReaderSettings();

            // Add the schema to validate against.
            validateReaderSettings.ValidationType = ValidationType.Schema;
            validateReaderSettings.Schemas.Add("http://schemas.microsoft.com/pag/gax-core", "GuidancePackageConfig.xsd");
            XmlReader vr = XmlReader.Create(ir, validateReaderSettings);

            // Deserialize with validating reader.
            XmlSerializer   ser     = new GuidancePackageSerializer();
            GuidancePackage package = (GuidancePackage)ser.Deserialize(vr);
            // Done!
        }
Exemplo n.º 4
0
        //[Ignore("Validation with inclusions fails as per bug #")]
        public void FullLoadAndValidation()
        {
            XIncludingReader  ir = new XIncludingReader(BaseDir + "mainconfig.xml");
            XmlReaderSettings validateReaderSettings = new XmlReaderSettings();

            validateReaderSettings.ValidationType = ValidationType.Schema;
            validateReaderSettings.Schemas.Add(XmlSchema.Read(
                                                   new XmlTextReader("GuidancePackageConfig.xsd"), null));

            // Dump for debugging purposes.
            XmlReader vr = XmlReader.Create(ir, validateReaderSettings);
            XmlWriter tw = XmlWriter.Create(Console.Out);

            tw.WriteNode(ir, false);

            // Read into memory with full inclusions as workaround
            ir = new XIncludingReader(BaseDir + "mainconfig.xml");
            MemoryStream mem = new MemoryStream();

            vr = XmlReader.Create(ir, validateReaderSettings);
            tw = XmlWriter.Create(mem);
            tw.WriteNode(ir, false);
            tw.Flush();
            mem.Position = 0;

            vr = XmlReader.Create(mem, validateReaderSettings);
            XmlSerializer ser = new GuidancePackageSerializer();

            // Deserialize with validating reader
            GuidancePackage package = (GuidancePackage)ser.Deserialize(vr);

            // Check included recipe
            Assert.AreEqual("ReusableRecipe", package.Recipes[0].Name);
            // Check included types in included recipe
            Assert.AreEqual("Page", package.Recipes[0].Types[1].Name);

            XmlSerializer wzser = new XmlSerializer(typeof(Wizard));
            Wizard        wz    = (Wizard)wzser.Deserialize(new XmlNodeReader(package.Recipes[0].GatheringServiceData.Any));

            Assert.AreEqual("ExistingWizard", wz.Name);
        }