コード例 #1
0
        public static bool TryCreate(Options options, Dictionary <string, string> parameters, out Process process)
        {
            var logger = new NLogPipelineLogger(SlugifyTransform.Slugify(options.Arrangement));

            using (var scope = ConfigurationContainer.Create(options.Arrangement, logger, parameters, options.PlaceHolderStyle)) {
                process = scope.Resolve <Process>();
                var context = new PipelineContext(logger, process);
                foreach (var warning in process.Warnings())
                {
                    context.Warn(warning);
                }

                if (process.Errors().Any())
                {
                    foreach (var error in process.Errors())
                    {
                        context.Error(error);
                    }
                    context.Error("The configuration errors must be fixed before this job will run.");
                }
                else
                {
                    process.Preserve = true;
                }
            }

            return(process != null && process.Errors().Length == 0);
        }
コード例 #2
0
        public void Verify()
        {
            var instance = new ClassWithDictionary();

            instance.Dict.Add("key", 123);

            var configuration = new ConfigurationContainer();
            var serializer    = configuration.Create().ForTesting();

            serializer.Cycle(instance).Should().BeEquivalentTo(instance);
        }
コード例 #3
0
        public void VerifyConflict()
        {
            var types = new HashSet <Type> {
                typeof(string), typeof(Subject)
            };
            var configuration = new ConfigurationContainer();

            configuration.EnableImplicitTyping(types)
            .Type <Subject>()
            .Name("string");
            Assert.Throws <InvalidOperationException>(() => configuration.Create());
        }
コード例 #4
0
        public void VerifyOptimizedImplicitTyping()
        {
            var instance = new ClassWithDictionary();

            instance.Dict.Add("key", 123);

            var configuration = new ConfigurationContainer().UseOptimizedNamespaces().EnableImplicitTyping(typeof(ClassWithDictionary));
            var serializer    = configuration.Create().ForTesting();

            //serializer.WriteLine(instance);

            serializer.Cycle(instance).Should().BeEquivalentTo(instance);
        }
コード例 #5
0
        public void Verify()
        {
            var configuration = new ConfigurationContainer();

            configuration.UseAutoFormatting();
            var instance = new Subject
            {
                Struct = new ItemStruct()
            };

            var serializer = configuration.Create();

            serializer.Cycle(instance).Should().BeEquivalentTo(instance);
        }
コード例 #6
0
        public void ShouldPreserveNullObjectValueIfDefaultIsNotNull()
        {
            var config = new ConfigurationContainer();

            config.Emit(EmitBehaviors.Assigned);
            var serializer = config.Create();

            string xml = serializer.Serialize(new ClassWithDefaultString {
                Name = null, SubNode = null
            });
            var deserialized = serializer.Deserialize <ClassWithDefaultString>(xml);

            deserialized.SubNode.Should().BeNull();
        }
コード例 #7
0
        public void Start()
        {
            using (var outer = ConfigurationContainer.Create(_options.Arrangement, _logger, null, _options.PlaceHolderStyle)) {
                var process = outer.Resolve <Configuration.Process>();
                var log     = new PipelineContext(_logger, process);

                if (process.Entities.Any(e => process.Connections.First(c => c.Name == e.Connection).Provider != Constants.DefaultSetting && !e.Fields.Any(f => f.Input)))
                {
                    log.Debug(() => "Detecting schema...");
                    if (_schemaHelper.Help(process))
                    {
                        process.Check();
                    }
                }

                if (_options.Mode != null && _options.Mode.ToLower() == "check")
                {
                    SimplifyForOutput(process);
                    Console.WriteLine(process.Serialize());
                    return;
                }

                if (_options.Mode != "default")
                {
                    process.Mode = _options.Mode;
                }

                foreach (var warning in process.Warnings())
                {
                    log.Debug(() => warning);
                }

                if (process.Errors().Any())
                {
                    foreach (var error in process.Errors())
                    {
                        log.Error(error);
                    }
                    log.Error("The configuration errors must be fixed before this job will run.");
                    log.Logger.Clear();
                    return;
                }

                using (var inner = DefaultContainer.Create(process, _logger, _options.PlaceHolderStyle)) {
                    inner.Resolve <IProcessController>().Execute();
                }
            }
        }
コード例 #8
0
        public void VerifyAdditional()
        {
            var container = new Shared.Issue517.ContainerNameSpace.Container();

            for (int i = 0; i < 1; i++)
            {
                container.Childrens.Add(new Shared.Issue517.ItemNameSpace.Item());
            }

            IConfigurationContainer config = new ConfigurationContainer();

            config.Type <Shared.Issue517.ContainerNameSpace.Container>().AddMigration(new EmptyMigration());
            var serializer = config.Create().ForTesting();

            serializer.Cycle(container).Should().BeEquivalentTo(container);
        }
コード例 #9
0
ファイル: Program.cs プロジェクト: walac/NUIPreview
        private static string WriteAsXml(object instance)
        {
            var sb = new StringBuilder();
            var cc = new ConfigurationContainer();
            var xmlWriterSettings = new XmlWriterSettings
            {
                Indent = true,
            };

            using (var xmlWriter = XmlWriter.Create(new StringWriter(sb), xmlWriterSettings))
            {
                cc
                .Create()
                .Serialize(xmlWriter, instance);
            }

            return(sb.ToString());
        }
コード例 #10
0
        public void Verify()
        {
            IConfigurationContainer container = new ConfigurationContainer();
            var properties = typeof(Subject).GetProperties();
            var type       = container.GetTypeConfiguration(typeof(Subject));

            foreach (var property in properties)
            {
                if (property.IsDecoratedWith <CustomAttribute>())
                {
                    container = type.Get(property).Ignore(property);
                }
            }

            var sut      = container.Create().ForTesting();
            var instance = new Subject {
                Message = "Serialized", AnotherMessage = "Ignored"
            };
            var cycled = sut.Cycle(instance);

            cycled.Message.Should().NotBeNullOrEmpty();
            cycled.AnotherMessage.Should().BeNull();
        }
コード例 #11
0
        public void Examples()
        {
            new ConfigurationContainer().EnableDeferredReferences()
            .Type <IElement>().EnableReferences(p => p.Id)
            .Type <Section>().EnableReferences(p => p.Id)
            .Type <Building>().EnableReferences(p => p.Id)
            .Create();


            new ConfigurationContainer().Type <Section>()
            .Name("person")
            .Member(p => p.IsSelected).Name("Selected").Identity().Order(2)
            .Member(p => p.IsEmpty).Name("Empty")

            .Create();


            var serializer = new ConfigurationContainer()

                             .Type <Person>()         // Configuration of Person class
                             .Member(p => p.Password) // First member
                             .Name("P")
                             .Encrypt()
                             .Member(p => p.Name)    // Second member
                             .Name("T")
                             .UseEncryptionAlgorithm(new CustomEncryption())
                             .Type <TestClass>()   // Configuration of another class
                             .CustomSerializer(new TestClassSerializer())
                             .Create();


            new ConfigurationContainer()
            .Type <Person>()
            .Member(p => p.Name).Identity()
            .OnlyConfiguredProperties()
            .Create();

            new ConfigurationContainer().Type <Person>()
            .AddMigration(element => {})
            .OnlyConfiguredProperties()
            .Create();

            new ConfigurationContainer().Type <Person>()
            .OnlyConfiguredProperties()
            .AddMigration(element => { })
            .Create();

            new ConfigurationContainer()
            .Type <Person>()
            .Member(p => p.Name).Identity()
            .OnlyConfiguredProperties()
            .Create();

            new ConfigurationContainer()
            .Type <Person>()
            .OnlyConfiguredProperties()
            .Member(p => p.Name).Identity()
            .Create();

            new ConfigurationContainer().Type <Person>()
            .CustomSerializer((writer, person) => {}, element => new Person())
            .EnableReferences(p => p.Name);

            new ConfigurationContainer().Type <Person>()
            .EnableReferences(p => p.Name)
            .CustomSerializer((writer, person) => { }, element => new Person());

            new ConfigurationContainer().Type <Person>()
            .CustomSerializer((writer, person) => { }, element => new Person())
            .Member(p => p.Name).Identity();

            new ConfigurationContainer().Type <Person>()
            .Member(p => p.Name).Identity()
            .CustomSerializer((writer, person) => { }, element => new Person());

            new ConfigurationContainer().Type <Person>()
            .AddMigration(element => { })
            .Member(p => p.Name).Identity();

            new ConfigurationContainer().Type <Person>()
            .Member(p => p.Name)
            .Identity()
            .AddMigration(element => {});

            var config = new ConfigurationContainer();

            config.EnableDeferredReferences();
            config.Type <Section>().Member(p => p.Id).Name("Identity");
            config.Type <Section>().EnableReferences(p => p.Id);
            var exs = config.Create();
        }