Ejemplo n.º 1
0
        /// <summary>
        /// Builds the cache model.
        /// </summary>
        /// <param name="store">The store.</param>
        private void BuildCacheModels(IConfigurationStore store)
        {
            for (int i = 0; i < store.CacheModels.Length; i++)
            {
                IConfiguration cacheModelConfig = store.CacheModels[i];
                CacheModel     cacheModel       = CacheModelDeSerializer.Deserialize(cacheModelConfig, modelStore.DataExchangeFactory);

                string nameSpace = ConfigurationUtils.GetMandatoryStringAttribute(cacheModelConfig, ConfigConstants.ATTRIBUTE_NAMESPACE);

                // Gets all the flush on excecute statement id
                ConfigurationCollection flushConfigs = cacheModelConfig.Children.Find(ConfigConstants.ELEMENT_FLUSHONEXECUTE);
                for (int j = 0; j < flushConfigs.Count; j++)
                {
                    string statementId = flushConfigs[j].Attributes[ConfigConstants.ATTRIBUTE_STATEMENT];
                    if (useStatementNamespaces)
                    {
                        statementId = ApplyNamespace(nameSpace, statementId);
                    }

                    cacheModel.StatementFlushNames.Add(statementId);
                }

                modelStore.AddCacheModel(cacheModel);
            }
        }
        /// <summary>
        /// Builds the result properties.
        /// </summary>
        /// <param name="resultMapId">The result map id.</param>
        /// <param name="resultMapConfig">The result map config.</param>
        /// <param name="resultClass">The result class.</param>
        /// <param name="prefix">The prefix.</param>
        /// <param name="suffix">The suffix.</param>
        /// <param name="dataExchangeFactory">The data exchange factory.</param>
        /// <param name="waitResultPropertyResolution">The wait result property resolution.</param>
        /// <returns></returns>
        private static ResultPropertyCollection BuildResultProperties(
            string resultMapId,
            IConfiguration resultMapConfig,
            Type resultClass,
            string prefix,
            string suffix,
            DataExchangeFactory dataExchangeFactory,
            WaitResultPropertyResolution waitResultPropertyResolution)
        {
            ResultPropertyCollection properties = new ResultPropertyCollection();

            ConfigurationCollection resultsConfig = resultMapConfig.Children.Find(ConfigConstants.ELEMENT_RESULT);

            for (int i = 0; i < resultsConfig.Count; i++)
            {
                ResultProperty mapping = null;
                try
                {
                    mapping = ResultPropertyDeSerializer.Deserialize(resultsConfig[i], resultClass, prefix, suffix, dataExchangeFactory);
                }
                catch (Exception e)
                {
                    throw new ConfigurationException("In ResultMap (" + resultMapId + ") can't build the result property: " + ConfigurationUtils.GetStringAttribute(resultsConfig[i].Attributes, ConfigConstants.ATTRIBUTE_PROPERTY) + ". Cause " + e.Message, e);
                }
                if (mapping.NestedResultMapName.Length > 0)
                {
                    waitResultPropertyResolution(mapping);
                }
                properties.Add(mapping);
            }

            return(properties);
        }
        private ConfigurationCollection ComposeCollection(List <Bundle> bundles)
        {
            var conf = new ConfigurationCollection();

            conf.Overrides = new List <CollectionOverride>();
            foreach (var bundle in bundles)
            {
                Log?.LogMessage($" - Composing scripts for bundle {bundle.BundleId}");
                var scripts = bundle.Files.Select(r => PathHelpers.GetRequireRelativePath(EntryPoint, r.FileName)).ToList();
                var paths   = new RequirePaths
                {
                    PathList = new List <RequirePath>()
                };
                foreach (var script in scripts)
                {
                    var path = PathHelpers.GetRequireRelativePath(EntryPoint, bundle.Output);
                    paths.PathList.Add(new RequirePath(script, path));
                    Log?.LogMessage($"    - {script} -> {path}");
                }

                var over = new CollectionOverride
                {
                    BundleId       = bundle.BundleId,
                    BundledScripts = scripts,
                    Paths          = paths
                };
                conf.Overrides.Add(over);
            }

            return(conf);
        }
        /// <summary>
        /// Builds the discriminator and his subMaps
        /// </summary>
        /// <param name="resultMapConfig">The result map config.</param>
        /// <param name="resultClass">The result class.</param>
        /// <param name="dataExchangeFactory">The data exchange factory.</param>
        /// <param name="waitDiscriminatorResolution">The wait discriminator resolution.</param>
        /// <returns></returns>
        private static Discriminator BuildDiscriminator(
            IConfiguration resultMapConfig,
            Type resultClass,
            DataExchangeFactory dataExchangeFactory,
            WaitDiscriminatorResolution waitDiscriminatorResolution)
        {
            Discriminator discriminator = null;
            // Build the Discriminator/Case Property

            ConfigurationCollection discriminatorsConfig = resultMapConfig.Children.Find(ConfigConstants.ELEMENT_DISCRIMINATOR);

            if (discriminatorsConfig.Count > 0)
            {
                //configScope.ErrorContext.MoreInfo = "initialize discriminator";

                // Find the cases
                IList <Case>            cases       = new List <Case>();
                ConfigurationCollection caseConfigs = discriminatorsConfig[0].Children.Find(ConfigConstants.ELEMENT_CASE);
                for (int i = 0; i < caseConfigs.Count; i++)
                {
                    Case caseElement = CaseDeSerializer.Deserialize(caseConfigs[i]);
                    cases.Add(caseElement);
                }

                discriminator = DiscriminatorDeSerializer.Deserialize(
                    discriminatorsConfig[0],
                    resultClass,
                    dataExchangeFactory,
                    cases
                    );
                waitDiscriminatorResolution(discriminator);
            }
            return(discriminator);
        }
Ejemplo n.º 5
0
        public void TestCompareComparableTypes()
        {
            var testContext = _propertyTestData.GetContext();

            var x = new ConfigurationCollection <IChildElement>(null, testContext.ChildConfigurationCollectionPropertyDef,
                                                                testContext.Configuration.ConfigurationRoot, new ConfigurationObjectSettings());

            var customObjectA = testContext.GetChildElement("a");
            var configObjectA = x.AddCopy(customObjectA);

            var otherCustomObject = new ChildElementMock();

            otherCustomObject.Name  = customObjectA.Name;
            otherCustomObject.Value = customObjectA.Value;

            Assert.NotEqual(customObjectA, configObjectA);
            Assert.Equal(customObjectA, configObjectA, ConfigurationObjectComparer.Instance);

            Assert.Equal(configObjectA, configObjectA, ConfigurationObjectComparer.Instance);
            Assert.Equal(customObjectA, customObjectA, ConfigurationObjectComparer.Instance);

            Assert.Equal(otherCustomObject, configObjectA, ConfigurationObjectComparer.Instance);
            Assert.Equal(otherCustomObject, customObjectA, ConfigurationObjectComparer.Instance);

            Assert.NotEqual(customObjectA, null, ConfigurationObjectComparer.Instance);
            Assert.NotEqual(customObjectA, null, ConfigurationObjectComparer.Instance);
            Assert.NotEqual(otherCustomObject, null, ConfigurationObjectComparer.Instance);
            Assert.NotEqual(configObjectA, null, ConfigurationObjectComparer.Instance);

            Assert.NotEqual(null, customObjectA, ConfigurationObjectComparer.Instance);
            Assert.NotEqual(null, customObjectA, ConfigurationObjectComparer.Instance);
            Assert.NotEqual(null, otherCustomObject, ConfigurationObjectComparer.Instance);
            Assert.NotEqual(null, configObjectA, ConfigurationObjectComparer.Instance);
        }
        public void CollectionToAbstractConfigurationNodeXmlSerializer_Test()
        {
            var configuration =
                new ConfigurationCollection <ExampleConfigurationCollection>(new ConfigurationValueCollection());

            var    fs   = new PhysicalFileSystem();
            var    temp = Path.GetTempPath();
            var    pfs  = fs.GetOrCreateSubFileSystem(fs.ConvertPathFromInternal(temp));
            string test = Path.GetRandomFileName();
            var    dir  = new FS.Directory(test, pfs, pfs.GetDirectoryEntry("/"));

            dir.OpenDirectory("program")
            .OpenFile("RMGE01.wbfs").OpenStream().Close();
            configuration.Configuration.ExampleConfiguration.FullscreenResolution = FullscreenResolution.Resolution1152X648;
            var context = new ConfigurationTraversalContext(("game", dir));
            var list    = context.TraverseCollection(configuration);
            IAbstractConfigurationNode dolphinList = list["#dolphin"];

            var xmlSerializer = new SimpleXmlConfigurationSerializer("Config");

            string    outputXml = xmlSerializer.Visit(dolphinList);
            XDocument doc       = XDocument.Parse(outputXml);

            Assert.NotEmpty(doc.Nodes());
        }
        private ConfigurationCollection ComposeCollection(List <Bundle> bundles)
        {
            var conf = new ConfigurationCollection();

            conf.Overrides = new List <CollectionOverride>();
            foreach (var bundle in bundles)
            {
                var scripts = bundle.Files.Select(r => PathHelpers.GetRequireRelativePath(EntryPoint, r.FileName)).ToList();
                var paths   = new RequirePaths
                {
                    PathList = new List <RequirePath>()
                };
                foreach (var script in scripts)
                {
                    paths.PathList.Add(new RequirePath
                    {
                        Key   = script,
                        Value = PathHelpers.GetRequireRelativePath(EntryPoint, bundle.Output)
                    });
                }

                var over = new CollectionOverride
                {
                    BundleId       = bundle.BundleId,
                    BundledScripts = scripts,
                    Paths          = paths
                };
                conf.Overrides.Add(over);
            }

            return(conf);
        }
        public void CopyToTests()
        {
            var testContext = _propertyTestData.GetContext();
            var x           = new ConfigurationCollection <IChildElement>(null, testContext.ChildConfigurationCollectionPropertyDef,
                                                                          testContext.Configuration.ConfigurationRoot, new ConfigurationObjectSettings());

            var a = testContext.GetChildElement("a");
            var b = testContext.GetChildElement("b");
            var c = testContext.GetChildElement("c");

            x.AddCopy(a);
            x.AddCopy(b);
            x.AddCopy(c);

            var array = new IChildElement[3];

            x.CopyTo(array, 0);

            Assert.Equal(a, array[0], ConfigurationObjectComparer.Instance);
            Assert.Equal(b, array[1], ConfigurationObjectComparer.Instance);
            Assert.Equal(c, array[2], ConfigurationObjectComparer.Instance);

            Assert.Throws <ArgumentOutOfRangeException>(() => x.CopyTo(array, 1));

            Assert.Throws <ArgumentOutOfRangeException>(() => x.CopyTo(array, -1));

            array = new IChildElement[2];

            Assert.Throws <ArgumentOutOfRangeException>(() => x.CopyTo(array, 0));

            x.Dispose();
            Assert.Throws <ObjectDisposedException>(() => x.CopyTo(array, 0));
        }
Ejemplo n.º 9
0
        public void Nested_Test()
        {
            var configuration = new ConfigurationCollection <ExampleConfigurationCollection>();

            Assert.Equal(configuration.Configuration.ExampleConfiguration.Descriptor["FullscreenResolution"].Default,
                         configuration.Configuration.ExampleConfiguration.Configuration.Configuration.FullscreenResolution);
        }
Ejemplo n.º 10
0
        public void SetStringToNull_Test()
        {
            var configuration = new ConfigurationCollection <ExampleConfigurationCollection>();

            configuration.Configuration.ExampleConfiguration.ISOPath0 = null;
            Assert.Equal(String.Empty, configuration.Configuration.ExampleConfiguration.ISOPath0);
        }
        public void IndexerTests()
        {
            var testContext = _propertyTestData.GetContext();
            var x           = new ConfigurationCollection <IChildElement>(null, testContext.ChildConfigurationCollectionPropertyDef,
                                                                          testContext.Configuration.ConfigurationRoot, new ConfigurationObjectSettings());

            var a = testContext.GetChildElement("a");
            var b = testContext.GetChildElement("b");
            var c = testContext.GetChildElement("c");

            x.AddCopy(a);
            x.AddCopy(b);
            x.AddCopy(c);

            Assert.Equal(a, x[0], ConfigurationObjectComparer.Instance);
            Assert.Equal(b, x[1], ConfigurationObjectComparer.Instance);
            Assert.Equal(c, x[2], ConfigurationObjectComparer.Instance);

            var change = (NotifyCollectionChangedAction)(-1);

            x.CollectionChanged += (sender, args) => { change = args.Action; };

            x[0] = c;

            Assert.Equal(NotifyCollectionChangedAction.Replace, change);

            x[2] = a;

            Assert.Equal(c, x[0], ConfigurationObjectComparer.Instance);
            Assert.Equal(b, x[1], ConfigurationObjectComparer.Instance);
            Assert.Equal(a, x[2], ConfigurationObjectComparer.Instance);

            x.Dispose();
            Assert.Throws <ObjectDisposedException>(() => x[0]);
        }
Ejemplo n.º 12
0
        private ConfigurationCollection ProcessConfig()
        {
            string text;

            if (fileReader == null)
            {
                text = File.ReadAllText(Path);
            }
            else
            {
                text = fileReader.ReadFile(path);
            }

            var collection   = new ConfigurationCollection();
            var deserialized = (JObject)JsonConvert.DeserializeObject(text);

            collection.FilePath = Path;
            collection.Paths    = GetPaths(deserialized);
            collection.Shim     = GetShim(deserialized);
            collection.Map      = GetMap(deserialized);

            if (options.ProcessBundles)
            {
                collection.Bundles = GetBundles(deserialized);
            }

            collection.AutoBundles = GetAutoBundles(deserialized);
            collection.Overrides   = GetOverrides(deserialized);


            return(collection);
        }
Ejemplo n.º 13
0
        async Task CanConstructIndexCollection()
        {
            var feed = await TestAtomFeed.ReadFeed(Path.Combine(TestAtomFeed.Directory, "IndexCollection.GetAsync.xml"));

            using (var context = new Context(Scheme.Https, "localhost", 8089))
            {
                var expectedNames = new string[]
                {
                    "_audit",
                    "_blocksignature",
                    "_internal",
                    "_thefishbucket",
                    "history",
                    "main",
                    "splunklogger",
                    "summary"
                };

                var indexes = new ConfigurationCollection(context, feed);

                Assert.Equal(expectedNames, from index in indexes select index.Title);
                Assert.Equal(expectedNames.Length, indexes.Count);
                CheckCommonProperties("indexes", indexes);

                for (int i = 0; i < indexes.Count; i++)
                {
                    CheckCommonProperties(expectedNames[i], indexes[i]);
                }
            }
        }
Ejemplo n.º 14
0
        public static ConfigurationCollection CreateEmptyCollection()
        {
            var collection = new ConfigurationCollection();

            collection.Paths          = new RequirePaths();
            collection.Paths.PathList = new List <RequirePath>();

            collection.Packages             = new RequirePackages();
            collection.Packages.PackageList = new List <RequirePackage>();

            collection.AutoBundles         = new AutoBundles();
            collection.AutoBundles.Bundles = new List <AutoBundle>();

            collection.Bundles = new RequireBundles();
            collection.Bundles.BundleEntries = new List <RequireBundle>();

            collection.Map             = new RequireMap();
            collection.Map.MapElements = new List <RequireMapElement>();

            collection.Overrides        = new List <CollectionOverride>();
            collection.Shim             = new RequireShim();
            collection.Shim.ShimEntries = new List <ShimEntry>();

            return(collection);
        }
        public void IndexOfTests()
        {
            var testContext = _propertyTestData.GetContext();
            var x           = new ConfigurationCollection <IChildElement>(null, testContext.ChildConfigurationCollectionPropertyDef,
                                                                          testContext.Configuration.ConfigurationRoot, new ConfigurationObjectSettings());

            var a = testContext.GetChildElement("a");
            var b = testContext.GetChildElement("b");
            var c = testContext.GetChildElement("c");

            Assert.True(x.IndexOf(a) < 0);
            Assert.True(x.IndexOf(b) < 0);
            Assert.True(x.IndexOf(c) < 0);

            x.AddCopy(a);
            x.AddCopy(b);

            Assert.Equal(0, x.IndexOf(a));
            Assert.Equal(1, x.IndexOf(b));
            Assert.True(x.IndexOf(c) < 0);

            x.AddCopy(c);

            Assert.Equal(0, x.IndexOf(a));
            Assert.Equal(1, x.IndexOf(b));
            Assert.Equal(2, x.IndexOf(c));

            Assert.True(x.IndexOf(null) < 0);

            x.Dispose();
            Assert.Throws <ObjectDisposedException>(() => x.IndexOf(a));
        }
        public void TestConstructor()
        {
            var testContext = _propertyTestData.GetContext();
            var propertyDef = testContext.ChildConfigurationCollectionPropertyDef;

            var x = new ConfigurationCollection <IChildElement>(null, propertyDef, testContext.Configuration.ConfigurationRoot, new ConfigurationObjectSettings());

            Assert.NotNull(x);
            Assert.Equal(0, x.Count);
            Assert.Equal(propertyDef.PropertyName, x.PropertyDef.PropertyName);

            x = new ConfigurationCollection <IChildElement>(null, propertyDef, testContext.Configuration.ConfigurationRoot, (IEnumerable <IChildElement>)null, new ConfigurationObjectSettings());

            Assert.NotNull(x);
            Assert.Equal(0, x.Count);
            Assert.Equal(propertyDef.PropertyName, x.PropertyDef.PropertyName);

            var a = testContext.GetChildElement("a");
            var b = testContext.GetChildElement("b");

            x = new ConfigurationCollection <IChildElement>(null, propertyDef, testContext.Configuration.ConfigurationRoot, new ConfigurationObjectSettings(), a, b);

            Assert.NotNull(x);
            Assert.Equal(2, x.Count);
            Assert.Equal(propertyDef.PropertyName, x.PropertyDef.PropertyName);

            x = new ConfigurationCollection <IChildElement>(null, propertyDef, testContext.Configuration.ConfigurationRoot,
                                                            (IEnumerable <IChildElement>)(new[] { a, b }), new ConfigurationObjectSettings());

            Assert.NotNull(x);
            Assert.Equal(2, x.Count);
            Assert.Equal(propertyDef.PropertyName, x.PropertyDef.PropertyName);
        }
Ejemplo n.º 17
0
        internal static JsonRequireOutput createOutputConfigFrom(ConfigurationCollection resultingConfig, RequireRendererConfiguration config, string locale)
        {
            var outputConfig = new JsonRequireOutput
            {
                BaseUrl     = config.BaseUrl,
                Locale      = locale,
                UrlArgs     = config.UrlArgs,
                WaitSeconds = config.WaitSeconds,
                Paths       = resultingConfig.Paths.PathList.ToDictionary(r => r.Key, r => r.Value),
                Packages    = resultingConfig.Packages.PackageList,
                Shim        = resultingConfig.Shim.ShimEntries.ToDictionary(
                    r => r.For,
                    r => new JsonRequireDeps
                {
                    Dependencies = r.Dependencies.Select(x => x.Dependency).ToList(),
                    Exports      = r.Exports
                }),
                Map = resultingConfig.Map.MapElements.ToDictionary(
                    r => r.For,
                    r => r.Replacements.ToDictionary(x => x.OldKey, x => x.NewKey)),
                NodeIdCompat = resultingConfig.NodeIdCompat
            };

            config.ProcessConfig(outputConfig);

            return(outputConfig);
        }
Ejemplo n.º 18
0
        private void MergeAutoBundles(ConfigurationCollection collection)
        {
            var finalAutoBundles = finalCollection.AutoBundles.Bundles;

            foreach (var autoBundle in collection.AutoBundles.Bundles)
            {
                var existing = finalAutoBundles.Where(r => r.Id == autoBundle.Id).FirstOrDefault();
                if (existing != null)
                {
                    if (!string.IsNullOrEmpty(autoBundle.OutputPath))
                    {
                        existing.OutputPath = autoBundle.OutputPath;
                    }

                    if (!string.IsNullOrEmpty(autoBundle.CompressionType))
                    {
                        existing.CompressionType = autoBundle.CompressionType;
                    }

                    foreach (var include in autoBundle.Includes)
                    {
                        existing.Includes.Add(include);
                    }

                    foreach (var exclude in autoBundle.Excludes)
                    {
                        existing.Excludes.Add(exclude);
                    }
                }
                else
                {
                    finalAutoBundles.Add(autoBundle);
                }
            }
        }
		public static IConfiguration GetDeserializedNode(XmlNode node)
		{
			var configChilds = new ConfigurationCollection();

			var configValue = new StringBuilder();
			if (node.HasChildNodes)
			{
				foreach (XmlNode child in node.ChildNodes)
				{
					if (IsTextNode(child))
					{
						configValue.Append(child.Value);
					}
					else if (child.NodeType == XmlNodeType.Element)
					{
						configChilds.Add(GetDeserializedNode(child));
					}
				}
			}

			var config = new MutableConfiguration(node.Name, GetConfigValue(configValue.ToString()));
			foreach (XmlAttribute attribute in node.Attributes)
			{
				config.Attributes.Add(attribute.Name, attribute.Value);
			}

			config.Children.AddRange(configChilds);

			return config;
		}
        public IConfigurationCollection <T> CreateConfigurationForGame <T>(IGameRecord gameRecord,
                                                                           string sourceName, string profileName)
            where T : class, IConfigurationCollectionTemplate
        {
            var collection = new ConfigurationCollection <T>();

            using var context = new DatabaseContext(this.Options.Options);

            var gameEntity = context.GameRecords
                             .Include(p => p.ConfigurationProfiles)
                             .SingleOrDefault(p => p.RecordID == gameRecord.RecordID);

            if (gameEntity == null)
            {
                throw new DependentEntityNotExistsException(gameRecord.RecordID);
            }

            var entity = context.ConfigurationProfiles
                         .Add(collection.AsModel(sourceName));

            gameEntity.ConfigurationProfiles.Add(new GameRecordConfigurationProfileModel
            {
                ProfileName         = profileName,
                ConfigurationSource = sourceName,
                Profile             = entity.Entity
            });

            context.SaveChanges();

            return(collection);
        }
Ejemplo n.º 21
0
        public static IConfiguration GetDeserializedNode(XmlNode node)
        {
            var configChilds = new ConfigurationCollection();

            var configValue = new StringBuilder();

            if (node.HasChildNodes)
            {
                foreach (XmlNode child in node.ChildNodes)
                {
                    if (IsTextNode(child))
                    {
                        configValue.Append(child.Value);
                    }
                    else if (child.NodeType == XmlNodeType.Element)
                    {
                        configChilds.Add(GetDeserializedNode(child));
                    }
                }
            }

            var config = new MutableConfiguration(node.Name, GetConfigValue(configValue.ToString()));

            foreach (XmlAttribute attribute in node.Attributes)
            {
                config.Attributes.Add(attribute.Name, attribute.Value);
            }

            config.Children.AddRange(configChilds);

            return(config);
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Runs the specified service.
        /// </summary>
        /// <param name="service">The service.</param>
        /// <returns>a task</returns>
        private static async Task Run(Service service)
        {
            try
            {
                await service.GetConfigurationsAsync();
            }
            catch (AuthenticationFailureException e)
            {
                Console.WriteLine("Can't get service configuration without log in");
            }

            Console.WriteLine("Login as admin");
            string username = "******";
            string password = "******";
            await service.LoginAsync(username, password);

            Console.WriteLine("List all configurations of the Splunk service:");
            ConfigurationCollection configs = service.GetConfigurationsAsync().Result;

            foreach (Configuration config in configs)
            {
                Console.WriteLine(config.Id);
            }

            Console.WriteLine("Log off");
            await service.LogoffAsync();
        }
        public void Defaults_Tests()
        {
            var configuration = new ConfigurationCollection <ExampleConfigurationCollection>();

            Assert.Equal(configuration.GetSection(e => e.ExampleConfiguration).Descriptor["FullscreenResolution"].Default,
                         configuration.Configuration.ExampleConfiguration.FullscreenResolution);
        }
        public void ClearTests()
        {
            var testContext = _propertyTestData.GetContext();
            var a           = testContext.GetChildElement("a");
            var b           = testContext.GetChildElement("b");
            var c           = testContext.GetChildElement("c");
            var d           = testContext.GetChildElement("d");
            var x           = new ConfigurationCollection <IChildElement>(null, testContext.ChildConfigurationCollectionPropertyDef,
                                                                          testContext.Configuration.ConfigurationRoot, new ConfigurationObjectSettings(), a, b, c, d);

            Assert.Equal(4, x.Count);

            var change = (NotifyCollectionChangedAction)(-1);

            x.CollectionChanged += (sender, args) => { change = args.Action; };

            x.Clear();

            Assert.Equal(NotifyCollectionChangedAction.Reset, change);

            Assert.Equal(0, x.Count);

            foreach (var item in x)
            {
                Assert.True(false);
            }

            x.Dispose();
            Assert.Throws <ObjectDisposedException>(() => x.Clear());
        }
Ejemplo n.º 25
0
        private void MergeAutoBundles(ConfigurationCollection collection)
        {
            var finalAutoBundles = finalCollection.AutoBundles.Bundles;

            foreach (var autoBundle in collection.AutoBundles.Bundles)
            {
                var existing = finalAutoBundles.Where(r => r.Id == autoBundle.Id).FirstOrDefault();
                if (existing != null)
                {
                    foreach (var include in autoBundle.Includes)
                    {
                        existing.Includes.Add(include);
                    }

                    foreach (var exclude in autoBundle.Excludes)
                    {
                        existing.Excludes.Add(exclude);
                    }
                }
                else
                {
                    finalAutoBundles.Add(autoBundle);
                }
            }
        }
Ejemplo n.º 26
0
        public void WriteConfig(ConfigurationCollection conf)
        {
            dynamic obj = new ExpandoObject();

            if (conf.Paths != null && conf.Paths.PathList != null && conf.Paths.PathList.Any())
            {
                obj.Paths = conf.Paths.PathList.ToDictionary(r => r.Key, r => r.Value);
            }

            if (conf.Overrides != null && conf.Overrides.Any())
            {
                obj.Overrides = conf.Overrides.ToDictionary(
                    r => r.BundleId,
                    r => new
                {
                    Paths          = r.Paths.PathList.ToDictionary(x => x.Key, x => x.Value),
                    BundledScripts = r.BundledScripts
                });
            }

            File.WriteAllText(
                Path,
                JsonConvert.SerializeObject(
                    obj,
                    new JsonSerializerSettings
            {
                Formatting       = Formatting.Indented,
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            }));
        }
        public void InsertTests_WithCollection()
        {
            var testContext = _propertyTestData.GetContext();
            var x           = new ConfigurationCollection <IChildElement>(null, testContext.ChildConfigurationCollectionPropertyDef,
                                                                          testContext.Configuration.ConfigurationRoot, new ConfigurationObjectSettings());

            var a = testContext.GetChildElement("a");
            var b = testContext.GetChildElement("b");
            var c = testContext.GetChildElement("c");
            var d = testContext.GetChildElement("d");
            var e = testContext.GetChildElement("e");

            x.AddCopy(a);
            x.AddCopy(c);

            var changes = new List <NotifyCollectionChangedAction>();

            x.CollectionChanged += (sender, args) => { changes.Add(args.Action); };

            x.InsertCopy(1, b);

            Assert.Equal(2, changes.Count);
            Assert.Equal(NotifyCollectionChangedAction.Add, changes[0]);
            Assert.Equal(NotifyCollectionChangedAction.Move, changes[1]);

            Assert.Equal(3, x.Count);

            Assert.Equal(a, x[0], ConfigurationObjectComparer.Instance);
            Assert.Equal(b, x[1], ConfigurationObjectComparer.Instance);
            Assert.Equal(c, x[2], ConfigurationObjectComparer.Instance);

            x.InsertCopy(x.Count, d);

            Assert.Equal(4, x.Count);
            Assert.Equal(a, x[0], ConfigurationObjectComparer.Instance);
            Assert.Equal(b, x[1], ConfigurationObjectComparer.Instance);
            Assert.Equal(c, x[2], ConfigurationObjectComparer.Instance);
            Assert.Equal(d, x[3], ConfigurationObjectComparer.Instance);

            x.InsertCopy(0, e);

            Assert.Equal(5, x.Count);
            Assert.Equal(e, x[0], ConfigurationObjectComparer.Instance);
            Assert.Equal(a, x[1], ConfigurationObjectComparer.Instance);
            Assert.Equal(b, x[2], ConfigurationObjectComparer.Instance);
            Assert.Equal(c, x[3], ConfigurationObjectComparer.Instance);
            Assert.Equal(d, x[4], ConfigurationObjectComparer.Instance);

            Assert.Throws <ArgumentOutOfRangeException>(() => { x.InsertCopy(-1, a); });
            Assert.Throws <ArgumentOutOfRangeException>(() => { x.InsertCopy(x.Count + 1, a); });

            Assert.Throws <TypeMismatchException>(() => { x.Insert(1, a); });

            x.InsertCopy(0, null);
            Assert.Null(x[0]);

            x.Dispose();
            Assert.Throws <ObjectDisposedException>(() => x.InsertCopy(1, b));
        }
Ejemplo n.º 28
0
        public void CollectionTest()
        {
            var x = new ConfigurationCollection <IRetroArchConfig>();

            x.Configuration.VideoConfiguration.VideoDriver = VideoDriver.SDL2;
            Console.Write(x.GetEnumerator());
            Assert.Equal(VideoDriver.SDL2, x.Configuration.VideoConfiguration.VideoDriver);
        }
Ejemplo n.º 29
0
        public void WriteConfig(ConfigurationCollection conf)
        {
            var paths     = this.GetPaths(conf.Paths);
            var overrides = this.GetOverridess(conf.Overrides);
            var document  = new XDocument(new XElement("configuration", paths, overrides));

            File.WriteAllText(Path, document.ToString());
        }
        public void IsReadOnlyTests()
        {
            var testContext = _propertyTestData.GetContext();
            var x           = new ConfigurationCollection <IChildElement>(null, testContext.ChildConfigurationCollectionPropertyDef,
                                                                          testContext.Configuration.ConfigurationRoot, new ConfigurationObjectSettings());

            Assert.False(x.IsReadOnly);
        }
Ejemplo n.º 31
0
        public void CollectionToAbstractConfigurationNode_Test()
        {
            var configuration =
                new ConfigurationCollection <ExampleConfigurationCollection>(new ConfigurationValueCollection());

            var fs   = new PhysicalFileSystem();
            var temp = Path.GetTempPath();
            var pfs  = fs.GetOrCreateSubFileSystem(fs.ConvertPathFromInternal(temp));
            var dir  = new FS.Directory("test", pfs, pfs.GetDirectoryEntry("/"));

            configuration.Configuration.ExampleConfiguration.FullscreenResolution = FullscreenResolution.Resolution1152X648;
            var context = new ConfigurationTraversalContext(("game", dir));

            var list = context.TraverseCollection(configuration.Configuration);

            Assert.Equal(2, list.Count);
            Assert.Equal(2, list["#dolphin"].Value.Count);
            Assert.DoesNotContain("TestCycle1", list.Keys);
            Assert.DoesNotContain("TestCycle2", list.Keys);

            var dolphinList = list["#dolphin"];

            foreach (var node in dolphinList.Value)
            {
                if (node.Key == "Display")
                {
                    var confList = (node as ListConfigurationNode).Value;
                    Assert.Equal(7, confList.Count);
                    Assert.Equal("FullscreenResolution", confList[0].Key);
                    Assert.IsType <EnumConfigurationNode>(confList[0]);
                    Assert.Equal("1152x648", ((EnumConfigurationNode)confList[0]).Value);
                    Assert.Equal(FullscreenResolution.Resolution1152X648, confList[0].Value);

                    Assert.Equal("Fullscreen", confList[1].Key);
                    Assert.IsType <BooleanConfigurationNode>(confList[1]);

                    Assert.Equal("RenderToMain", confList[2].Key);
                    Assert.IsType <BooleanConfigurationNode>(confList[2]);

                    Assert.Equal("RenderWindowWidth", confList[3].Key);
                    Assert.IsType <IntegralConfigurationNode>(confList[3]);

                    Assert.Equal("RenderWindowHeight", confList[4].Key);
                    Assert.IsType <IntegralConfigurationNode>(confList[4]);

                    Assert.Equal("ISOPath0", confList[5].Key);
                    Assert.IsType <StringConfigurationNode>(confList[5]);

                    Assert.Equal("InternalCpuRatio", confList[6].Key);
                    Assert.IsType <DecimalConfigurationNode>(confList[6]);
                }

                if (node.Key == "TestNestedSection")
                {
                    Assert.Equal("TestNestedNestedSection", (node as ListConfigurationNode).Value[0].Key);
                }
            }
        }
Ejemplo n.º 32
0
        private bool ConfigurationContainKey(ConfigurationCollection confs, string key)
        {
            foreach (Configuration conf in confs)
            {
                if (conf.ResourceName.Title == key)
                {
                    return true;
                }
            }

            return false;
        }
 private void ResolveIncludeStatement(ConfigurationCollection includes)
 {
     for (int i = 0; i < includes.Count;i++ )
     {
         IConfiguration include = includes[i];
         IConfiguration toInclude =
                   configurationStore.GetStatementConfiguration(include.Id);
         if (toInclude == null)
         {
             throw new ConfigurationException("There's no include statement named '" + include.Id + "'");
         }
         IConfiguration parent = include.Parent;
         int childIndex = include.Parent.Children.IndexOf(include);
         parent.Children.RemoveAt(childIndex);
         parent.Children.InsertRange(childIndex, toInclude.Children);
     }
 }
Ejemplo n.º 34
0
 /// <summary>
 /// 处理includes节点信息
 /// </summary>
 /// <param name="includes"></param>
 private void ResolveIncludeStatement(ConfigurationCollection includes)
 {
     for (int i = 0; i < includes.Count;i++ )
     {
         IConfiguration include = includes[i];
         IConfiguration toInclude =
                   configurationStore.GetStatementConfiguration(include.Id);//获得include节点属性值所对应的目标节点
         if (toInclude == null)//如果是不存在的include目标 出错
         {
             throw new ConfigurationException("There's no include statement named '" + include.Id + "'");
         }
         //包含include节点的父节点信息 也即update insert delete statement select节点配置
         IConfiguration parent = include.Parent;
         //include在父节点children中的下标位置
         int childIndex = include.Parent.Children.IndexOf(include);
         //移除include节点
         parent.Children.RemoveAt(childIndex);
         //用include节点引用的目标节点代替原来的内容
         parent.Children.InsertRange(childIndex, toInclude.Children);
     }
 }
Ejemplo n.º 35
0
 /// <summary>
 /// Asynchronously retrieves the collection of all configuration files 
 /// known to Splunk.
 /// </summary>
 /// <returns>
 /// An object representing the collection of all configuration files
 /// known to Splunk.
 /// </returns>
 /// <remarks>
 /// This method uses the <a href="http://goo.gl/Unj6fs">GET 
 /// properties</a> endpoint/> to construct the <see cref=
 /// "ConfigurationCollection"/> it returns.
 /// </remarks>
 public async Task<ConfigurationCollection> GetConfigurationsAsync()
 {
     var collection = new ConfigurationCollection(this.Context, this.Namespace);
     await collection.GetAsync();
     return collection;
 }
        async Task CanConstructConfigurationCollection()
        {
            var feed = await TestAtomFeed.ReadFeed(Path.Combine(TestAtomFeed.Directory, "ConfigurationCollection.GetAsync.xml"));

            using (var context = new Context(Scheme.Https, "localhost", 8089))
            {
                var expectedConfigurationNames = new string[] 
                { 
                    "alert_actions",
                    "app",
                    "audit",
                    "authentication",
                    "authorize",
                    "commands",
                    "conf",
                    "crawl",
                    "datatypesbnf",
                    "default-mode",
                    "delete-me-0af59d05d0124e4ab915398500a45262",
                    "delete-me-1c58e9c0851d435aba8b5c53b0c73959",
                    "delete-me-233bbea06392457c9f38b629a912baff",
                    "delete-me-24d778d67e7b4f4e9704c8118e9cbc75",
                    "delete-me-2a38f8d7bfa542c9a09b201ee29da2a8",
                    "delete-me-2f884142c52b4c0883399dfa30fff5bf",
                    "delete-me-3322c0339fb849d98605559cf119a369",
                    "delete-me-33bc32518a364599a08d4bfb226a0975",
                    "delete-me-35a847f36e8a491d962d04a037310dfd",
                    "delete-me-42cecdc8e72f4645b75616c94cd93399",
                    "delete-me-446ee1261b424ae3aec66b67e391df69",
                    "delete-me-4d5457f77b6d49479d518cc4204f300d",
                    "delete-me-59aa7746422549368e550e1bded488af",
                    "delete-me-6d374e8b93014515b506918ada66026e",
                    "delete-me-6d4d46fe88f0444cb330f2a6f022477a",
                    "delete-me-71e7fd0fc0fc420e9dd034a3fd6ae989",
                    "delete-me-7311a03780674f5dbff082fe5f09b458",
                    "delete-me-7a48db483d73412480efd9883af53001",
                    "delete-me-7a4ad0da232f45dab041343c2235a5b0",
                    "delete-me-980b1cb1b2f34884a972ed8bf0c680e2",
                    "delete-me-9940cceaeaf74309b415c43e648ff9eb",
                    "delete-me-9bd517dbec464d32a3b0b51f79bcdad9",
                    "delete-me-9d0b6101094141eab7a69d0daabdce76",
                    "delete-me-9fd99ef85a3641b09a2d5a512bc692c0",
                    "delete-me-a017f23857f14f9fa66e060fbdbd0b37",
                    "delete-me-a5999e197618423ab0c9afffd052c7a9",
                    "delete-me-b8b05d95822a4552bc9c67f863975f0f",
                    "delete-me-c5c6edfa1ccc470981e794d50f2940c6",
                    "delete-me-c6d66b4d921242608962431036860b50",
                    "delete-me-d7e1572f83644e658ccc926c1a736a7f",
                    "delete-me-d8dc0fb200ab4be9862d7e042e919b2c",
                    "delete-me-f8565b63b2af4c0993481440e81ee018",
                    "delete-me-fd46773243cc4b5a8b731483a13e55fb",
                    "distsearch",
                    "event_renderers",
                    "eventdiscoverer",
                    "eventtypes",
                    "fields",
                    "indexes",
                    "inputs",
                    "launcher",
                    "limits",
                    "literals",
                    "lookups",
                    "macros",
                    "manager",
                    "migration",
                    "multikv",
                    "nav",
                    "outputs",
                    "pdf_server",
                    "prefs",
                    "procmon-filters",
                    "props",
                    "quickstart",
                    "restmap",
                    "savedsearches",
                    "searchbnf",
                    "searchscripts",
                    "segmenters",
                    "server",
                    "serverclass",
                    "source-classifier",
                    "sourcetypes",
                    "times",
                    "transactiontypes",
                    "transforms",
                    "ui-prefs",
                    "user-prefs",
                    "views",
                    "viewstates",
                    "web",
                    "workflow_actions"
                };

                var configurations = new ConfigurationCollection(context, feed);

                Assert.Equal(expectedConfigurationNames, from configuration in configurations select configuration.Title);
                Assert.Equal(expectedConfigurationNames.Length, configurations.Count);

                for (int i = 0; i < configurations.Count; i++)
                {
                    Assert.Equal(expectedConfigurationNames[i], configurations[i].Title);

                    Assert.DoesNotThrow(() => { var value = configurations[i].GeneratorVersion; });
                    Assert.DoesNotThrow(() => { var value = configurations[i].Id; });
                    Assert.DoesNotThrow(() => { var value = configurations[i].Updated; });
                }
            }
        }
 public void BeforeEachTest()
 {
     _collection = new ConfigurationCollection();
 }