Пример #1
0
        private static string _GenerateTree(XamlGenerator generator, SetupXamlInformation setupXamlInfo)
        {
            if (setupXamlInfo == null)
            {
                throw new ArgumentNullException("setupXamlInfo");
            }

            _setupXamlInfo = setupXamlInfo;

            //
            // Generate xaml using XamlGenerator.
            // Note: generator code was referenced from ClientTestLibrary directory.
            //

            int maxTotalElements = _xamlDefinition.MaxTotalElements;
            int maxAttributes    = _xamlDefinition.MaxAttributes;
            int maxChildren      = _xamlDefinition.MaxChildren;
            int maxDepth         = _xamlDefinition.MaxDepth;

            DateTime start  = DateTime.Now;
            Stream   stream = generator.CreateStream(maxDepth, maxAttributes, maxChildren); // maxDepth, maxAttributes, maxChildren

            string xaml = "";

            // Store xaml in string.
            using (StreamReader sr = new StreamReader(stream))
            {
                xaml = sr.ReadToEnd();
            }


            xaml = ModifyXaml.PostProcess(xaml, setupXamlInfo);

            OnXamlGenerated(xaml);

            //
            // Return root of generated tree or the string depending of the parseXaml argument.
            //
            return(xaml);
        }
Пример #2
0
        /// <summary>
        /// </summary>
        public static void Initialize(WPFXamlDefinition xamlDefinition)
        {
            ValidateInitialization();

            lock (_lockObj)
            {
                ValidateInitialization();

                _xamlDefinition = xamlDefinition;
                _rnd            = xamlDefinition.RandomGenerator;


                string[] xamlFiles =
                {
                    BuildPath("pagesource1.xaml"),
                    BuildPath("pagesource2.xaml")
                };

                string[] resourcesFiles =
                {
                    BuildPath("arial.ttf"),
                    BuildPath("bee.wmv"),
                    BuildPath("Gone Fishing.bmp"),
                    BuildPath("small font.ttf")
                };

                string[] dllFiles =
                {
                    BuildPath("TestRuntimeUntrusted.dll")
                };


                DefaultResourcesFiles = new List <string>(4);
                DefaultXamlFiles      = new List <string>(2);
                DefaultDllFiles       = new List <string>(3);


                DefaultResourcesFiles.AddRange(resourcesFiles);
                DefaultXamlFiles.AddRange(xamlFiles);
                DefaultDllFiles.AddRange(dllFiles);


                DefaultRandomGenerator.SetGlobalRandomGenerator(xamlDefinition.RandomGenerator);

                //
                // Create generators.
                //
                List <XmlGenerator> generators = new List <XmlGenerator>();

                switch (_rnd.Next(5))
                {
                case 0:
                    // Includes everything except custom types, BitmapEffect, and LayoutTransform.
                    _generator = new XamlGenerator(BuildPath("RootTypes.xsd"));
                    break;

                case 1:
                    // Includes everything except custom types, MediaElement, and BitmapEffect.
                    _generator            = new XamlGenerator(BuildPath("RootTypes2.xsd"));
                    _shouldTestTransforms = true;
                    break;

                case 2:
                    // Includes everything except custom types, flow types, MediaElement, and BitmapEffect.
                    _generator            = new XamlGenerator(BuildPath("RootTypes3.xsd"));
                    _shouldTestTransforms = true;
                    break;

                case 3:
                    // Includes everything except flow types, MediaElement, BitmapEffect, and LayoutTransform.
                    _generator = new XamlGenerator(BuildPath("RootTypes4.xsd"));
                    break;

                case 4:
                    // Includes everything except custom types, flow types, MediaElement, and LayoutTransform.
                    _generator = new XamlGenerator(BuildPath("RootTypes5.xsd"));
                    _shouldTestBitmapEffects = true;
                    break;
                }


                _windowGenerator    = new XamlGenerator(BuildPath("WindowTypes.xsd"));
                _freezableGenerator = new XamlGenerator(BuildPath("RootFreezableTypes.xsd"));
                _resourceGenerator  = new XamlGenerator(BuildPath("ResourcesType.xsd"));
                generators.Add(_generator);
                generators.Add(_windowGenerator);
                generators.Add(_freezableGenerator);
                generators.Add(_resourceGenerator);

                TextContentHelper textContentHelper = new TextContentHelper(_GenerateText);
                ElementHelper     elementHelper     = new ElementHelper(_GenerateElement);
                AttributeHelper   attributeHelper1  = new AttributeHelper(_GenerateXmlLangValue);
                AttributeHelper   attributeHelper2  = new AttributeHelper(_GenerateNameValue);
                AttributeHelper   attributeHelper3  = new AttributeHelper(_GenerateAllowsTransparencyValue);

                foreach (XmlGenerator generator in generators)
                {
                    // Initialize XamlGenerator's random generator.
                    generator.Reset(_rnd.Next());

                    // Register helper for generating text content.
                    generator.RegisterTextHelper(textContentHelper);

                    // Register helper for generating elements so we can filter
                    // out stuff inside Templates.
                    generator.RegisterElementHelper(elementHelper);

                    // Register helpers for generating xml:lang, Name, and AllowsTransparency values.
                    generator.RegisterAttributeHelper(attributeHelper1, "lang");
                    generator.RegisterAttributeHelper(attributeHelper2, "Name");
                    generator.RegisterAttributeHelper(attributeHelper3, "AllowsTransparency");
                }



                _initialized = true;
            }
        }