ResolveReferences() public method

Resolves any reference elements in the configuration.
public ResolveReferences ( ) : void
return void
Exemplo n.º 1
0
        /// <summary>
        /// Override Clone so that we can force resolution of element references.
        /// </summary>
        /// <returns>
        /// A new object that is a copy of this instance.
        /// </returns>
        public override object Clone()
        {
            CodeConfiguration clone = base.Clone() as CodeConfiguration;

            clone.ResolveReferences();

            return(clone);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Loads a configuration from a stream.
        /// </summary>
        /// <param name="stream">The sream to load the configuration from.</param>
        /// <param name="resolveReferences">
        /// Whether or not element references should be resolved.
        /// </param>
        /// <returns>The code configuration if succesful, otherwise null.</returns>
        public static CodeConfiguration Load(Stream stream, bool resolveReferences)
        {
            CodeConfiguration configuration =
                _serializer.Deserialize(stream) as CodeConfiguration;

            if (resolveReferences)
            {
                configuration.ResolveReferences();
            }

            configuration.Upgrade();

            return(configuration);
        }
Exemplo n.º 3
0
        public void SerializeAndDeserializeTest()
        {
            CodeConfiguration origConfig = new CodeConfiguration();

            ElementConfiguration elementConfiguration1 = new ElementConfiguration();
            elementConfiguration1.ElementType = ElementType.Using;
            elementConfiguration1.Id = "TestId";
            origConfig.Elements.Add(elementConfiguration1);

            ElementConfiguration elementConfiguration2 = new ElementConfiguration();
            elementConfiguration2.ElementType = ElementType.Namespace;
            origConfig.Elements.Add(elementConfiguration2);

            ElementReferenceConfiguration elementReferenceConfiguration = new ElementReferenceConfiguration();
            elementReferenceConfiguration.Id = "TestId";
            origConfig.Elements.Add(elementReferenceConfiguration);

            RegionConfiguration regionConfiguration = new RegionConfiguration();
            regionConfiguration.Name = "Test Region";
            origConfig.Elements.Add(regionConfiguration);

            origConfig.ResolveReferences();
            Assert.AreEqual(
                elementConfiguration1.Elements.Count,
                elementReferenceConfiguration.ReferencedElement.Elements.Count,
                "Element reference was not resolved.");

            string tempFile = Path.GetTempFileName();
            try
            {
                //
                // Save the configuration to an XML file
                //
                origConfig.Save(tempFile);

                //
                // Load the configuration from the XML file
                //
                CodeConfiguration loadedConfig = CodeConfiguration.Load(tempFile);
                Assert.IsNotNull(loadedConfig, "Loaded configuration should not be null.");

                Assert.AreEqual(origConfig.Elements.Count, loadedConfig.Elements.Count, "An unexpected number of config elements were deserialized.");

                for (int index = 0; index < origConfig.Elements.Count; index++)
                {
                    if (origConfig.Elements[index] is ElementConfiguration)
                    {
                        ElementConfiguration origElement =
                            origConfig.Elements[index] as ElementConfiguration;
                        ElementConfiguration loadedElement =
                            loadedConfig.Elements[index] as ElementConfiguration;

                        Assert.AreEqual(origElement.ElementType, loadedElement.ElementType, "Unexpected element type.");
                    }
                    else if (origConfig.Elements[index] is ElementReferenceConfiguration)
                    {
                        ElementReferenceConfiguration origElement =
                            origConfig.Elements[index] as ElementReferenceConfiguration;
                        ElementReferenceConfiguration loadedElement =
                            loadedConfig.Elements[index] as ElementReferenceConfiguration;

                        Assert.AreEqual(origElement.Id, loadedElement.Id, "Unexpected element type.");
                        Assert.AreEqual(
                            origElement.ReferencedElement.Id,
                            loadedElement.ReferencedElement.Id,
                            "Unexpected referenced element.");
                    }
                    else if (origConfig.Elements[index] is RegionConfiguration)
                    {
                        RegionConfiguration origRegion =
                            origConfig.Elements[index] as RegionConfiguration;
                        RegionConfiguration loadedRegion =
                            loadedConfig.Elements[index] as RegionConfiguration;

                        Assert.AreEqual(origRegion.Name, loadedRegion.Name, "Unexpected region name.");
                    }
                }
            }
            finally
            {
                File.Delete(tempFile);
            }
        }