コード例 #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            services.AddDbContext <AppDbContext>(options =>
            {
                options.UseInMemoryDatabase("blog-in-memory");
            });

            services.AddScoped <IArticleRepository, ArticleRepository>();
            services.AddScoped <IArticleService, ArticleService>();

            services.AddScoped <IUserRepository, UserRepository>();
            services.AddScoped <IUserService, UserService>();

            services.AddScoped <IUnitOfWork, UnitOfWork>();

            DeltaConfig.Init(cfg => {
                cfg.AddEntity <Article>();
            });

            DeltaConfig.Init(cfg => {
                cfg.AddEntity <PatchArticleResource>();
            });

            services.AddAutoMapper();
        }
コード例 #2
0
        protected void Application_Start()
        {
            GlobalConfiguration.Configure(WebApiConfig.Register);

            DeltaConfig.Init(cfg => {
                cfg.AddEntity <Person>()
                .Property(x => x.Id).Exclude();
            });
        }
コード例 #3
0
        public void MappingFunction()
        {
            DeltaConfig.Init(cfg =>
            {
                cfg

                /* When the target property type is int and the input is string,
                *  then the assigned value will be the length of the input string*/
                .AddMapping((propType, newValue) =>
                {
                    var result = new MapResult <object>();

                    if (propType != typeof(int))
                    {
                        return(result.SkipMap());
                    }
                    if (newValue.GetType() != typeof(string))
                    {
                        return(result.SkipMap());
                    }

                    result.Value = newValue.ToString().Length;

                    return(result);
                })

                /* When the target property is double and the input is string,
                 * then the assigned value will be the length of the string + 0.5*/
                .AddMapping((propType, newValue) =>
                {
                    var result = new MapResult <object>();

                    if (propType != typeof(double))
                    {
                        return(result.SkipMap());
                    }

                    if (newValue.GetType() != typeof(string))
                    {
                        return(result.SkipMap());
                    }

                    result.Value = newValue.ToString().Length + 0.5;

                    return(result);
                })
                .AddEntity <Person>();
            });

            // First mapping function will be executed here, Age type is int
            CreateDelta <Person, int>(x => x.Age, "abc").Patch(John);
            Assert.AreEqual("abc".Length, John.Age);

            // Second mapping function will be executed here, Height type is double
            CreateDelta <Person, double>(x => x.Height, "abcdef").Patch(John);
            Assert.AreEqual("abcdef".Length + 0.5, John.Height);
        }
コード例 #4
0
ファイル: Globals.cs プロジェクト: zach88/SimplePatch
        public void ConfigFromAssembly()
        {
            var assembly = typeof(Person).Assembly;

            DeltaConfig.InitFromAssembly(cfg => {
                cfg.AddAssembly(assembly);
            });
            CreateDelta <Person>("Age", 23).Patch(John);
            Assert.AreEqual(23, John.Age);
        }
コード例 #5
0
ファイル: Startup.cs プロジェクト: BalanceHan/SimplePatch
        public Startup(IHostingEnvironment env)
        {
            var builder = new ConfigurationBuilder()
                          .SetBasePath(env.ContentRootPath)
                          .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
                          .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
                          .AddEnvironmentVariables();

            Configuration = builder.Build();

            DeltaConfig.Init(x => x.ExcludeProperties <Person>(y => y.Id));
        }
コード例 #6
0
        public void IgnoreLetterCase()
        {
            DeltaConfig.Init(cfg =>
            {
                cfg
                .IgnoreLetterCase()
                .AddEntity <Person>();
            });

            CreateDelta <Person>("AgE", 23).Patch(John);
            Assert.AreEqual(23, John.Age);
        }
コード例 #7
0
ファイル: Properties.cs プロジェクト: zach88/SimplePatch
        public void ExcludedByAttribute()
        {
            DeltaConfig.Init(cfg =>
            {
                cfg
                .AddEntity <Person>();
            });

            var initialAge = John.AgeExcludeByAttibute;

            CreateDelta <Person, int>(x => x.AgeExcludeByAttibute, 23).Patch(John);

            Assert.AreEqual(initialAge, John.AgeExcludeByAttibute);
        }
コード例 #8
0
ファイル: Properties.cs プロジェクト: viktortat/SimplePatch
        public void Exclude()
        {
            DeltaConfig.Init(cfg =>
            {
                cfg
                .AddEntity <Person>()
                .Property(x => x.Age).Exclude();
            });

            var initialAge = John.Age;

            CreateDelta <Person, int>(x => x.Age, 23).Patch(John);

            Assert.AreEqual(initialAge, John.Age);
        }
コード例 #9
0
ファイル: Properties.cs プロジェクト: viktortat/SimplePatch
        public void IgnoreNullValue()
        {
            DeltaConfig.Init(cfg =>
            {
                cfg
                .AddEntity <Person>()
                .Property(x => x.Name).IgnoreNull();
            });

            var initialName = John.Name;

            CreateDelta <Person, string>(x => x.Name, null).Patch(John);

            Assert.AreEqual(initialName, John.Name);
        }
コード例 #10
0
        static void Main(string[] args)
        {
            //Get the config path, otherwise launch in CLI mode
            if (args.Length != 1)
            {
                new DeltaCLI().Run();
                return;
            }

            //Open config file
            cfg = DeltaConfig.OpenConfig(args[0]);

            //Init delta
            delta = new DeltaConnection(-1, -1, APP_VERSION_MAJOR, APP_VERSION_MINOR, DeltaCoreNetServerType.MASTER_CONTROL);
            delta.InitOffline(cfg.GetRemoteConfig(), new int[0]);

            //Init others
            admin_sessions = new List <AdminSession>();
            servers        = new List <DeltaManagerServer>();
            foreach (var s in cfg.registered_servers)
            {
                servers.Add(new DeltaManagerServer(s));
            }

            //Init underlying server
            server = new MasterControlServer(delta, new IPEndPoint(IPAddress.Any, cfg.general.public_serving_port));

            //Init web interface server
            web_interface = new DeltaWebServer(delta, cfg.general.admin_interface_port);
            web_interface.AddService(new LoginDefinition());
            web_interface.AddService(new MachineListDefinition());
            web_interface.AddService(new MachineEnrollDefinition());
            web_interface.AddService(new MachineStatusDefinition());
            web_interface.AddService(new MachineAddPackageDefinition());
            web_interface.AddService(new MachineAddVersionDefinition());
            web_interface.AddService(new MachineAddInstanceDefinition());
            web_interface.AddService(new MachineUpdateInstanceDefinition());
            web_interface.AddService(new MachineDestroyInstanceDefinition());
            web_interface.AddService(new MachineDeleteVersionDefinition());
            web_interface.AddService(new MachineAddSiteDefinition());
            web_interface.AddService(new MachineAssignSiteDefinition());
            web_interface.AddService(new MachineRebootInstanceDefinition());
            web_interface.AddService(new MachinePingInstanceDefinition());
            web_interface.AddService(new MachineInstanceManageDefinition());

            //Run
            web_interface.RunAsync().GetAwaiter().GetResult();
        }
コード例 #11
0
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;

            // Setup simple patch
            DeltaConfig.Init(config =>
            {
                config.AddEntity <Games>();
                config.AddEntity <Jams>();
                config.AddEntity <Ratings>();
                config.AddEntity <Themes>();
                config.AddEntity <Users>();

                config.IgnoreLetterCase();
            });
        }
コード例 #12
0
ファイル: Properties.cs プロジェクト: zach88/SimplePatch
        public void ExcludedByMapping()
        {
            var assembly = typeof(Person).Assembly;

            DeltaConfig.InitFromAssembly(cfg =>
            {
                cfg
                .AddAssembly(assembly);
            });

            var initialAge = John.AgeExcludeByAttibute;

            CreateDelta <Person, int>(x => x.AgeExcludeByMapping, 23).Patch(John);

            Assert.AreEqual(initialAge, John.AgeExcludeByAttibute);
        }
コード例 #13
0
        private void CmdLoadConfig()
        {
            //Prompt install location
            string installPath = CLITools.PromptFormTextInput("Load Config - Specify Path", "Type the filename to load.");

            //Verify
            if (!File.Exists(installPath))
            {
                CLITools.PrintText("ERROR: The file path you specified already exists.", ConsoleColor.Red);
                return;
            }

            //Load
            cfg     = DeltaConfig.OpenConfig(installPath);
            unsaved = false;

            //Write ack
            CLITools.PrintText("Configuration was successfully loaded.", ConsoleColor.Green);
        }
コード例 #14
0
        private void CmdNewConfig()
        {
            //Prompt install location
            string installPath = CLITools.PromptFormTextInput("New Config - Specify Path", "Type the filename to save as. This will be a JSON file.");

            //Verify
            if (!Path.IsPathFullyQualified(installPath))
            {
                CLITools.PrintText("ERROR: The install path you specified is invalid.", ConsoleColor.Red);
                return;
            }
            if (File.Exists(installPath))
            {
                CLITools.PrintText("ERROR: The file path you specified already exists.", ConsoleColor.Red);
                return;
            }

            //Make
            cfg     = DeltaConfig.NewConfig(installPath);
            unsaved = true;

            //Write ack
            CLITools.PrintText("Configuration was successfully created.", ConsoleColor.Green);
        }
コード例 #15
0
 public void TestCleanup()
 {
     DeltaConfig.Clean();
 }
コード例 #16
0
        protected void Application_Start()
        {
            GlobalConfiguration.Configure(WebApiConfig.Register);

            DeltaConfig.Init(x => x.ExcludeProperties <Person>(y => y.Id));
        }
コード例 #17
0
 public static void ClassInit(TestContext context)
 {
     DeltaConfig.Init(cfg => cfg.AddEntity <PersonExtended>());
 }
コード例 #18
0
 public static void ClassCleanup()
 {
     DeltaConfig.Clean();
 }
コード例 #19
0
ファイル: Properties.cs プロジェクト: viktortat/SimplePatch
        public void MappingFunction()
        {
            DeltaConfig.Init(cfg =>
            {
                cfg

                /* When the target property type is string and the input is string, then the assigned value will be the reversed input string */
                .AddMapping((propType, newValue) =>
                {
                    var result = new MapResult <object>();

                    if (propType == typeof(string) && newValue.GetType() == typeof(string))
                    {
                        result.Value = string.Join("", newValue.ToString().ToCharArray().Reverse());
                    }
                    else
                    {
                        result.Skip = true;
                    }

                    return(result);
                })
                .AddEntity <Person>()
                .Property(x => x.Name)
                /* If the input value is string, then the assigned value will be the same string. Overriding global mapping function.*/
                .AddMapping((propType, newValue) =>
                {
                    if (newValue.GetType() != typeof(string))
                    {
                        return(new MapResult <string>().SkipMap());
                    }
                    return(new MapResult <string>()
                    {
                        Value = newValue.ToString()
                    });
                })
                /* If the input value is int, then the assigned value will be "number:{number}" */
                .AddMapping((propType, newValue) =>
                {
                    var result = new MapResult <string>();

                    if (newValue.GetType() != typeof(int))
                    {
                        return(result.SkipMap());
                    }

                    result.Value = "number:" + newValue.ToString();

                    return(result);
                })

                /* If the input value is DateTime, then the assigned value will be "datetime:{datetime}".
                 * This behavior could be accomplished using only the previous mapping function. They are separeted
                 * functions to test mapping functions order execution*/
                .AddMapping((propType, newValue) =>
                {
                    var result = new MapResult <string>();

                    if (newValue.GetType() != typeof(DateTime))
                    {
                        return(result.SkipMap());
                    }

                    result.Value = "datetime:" + ((DateTime)newValue).ToString("s");

                    return(result);
                });
            });

            // Global mapping function executed here
            CreateDelta <Person, string>(x => x.Surname, "Rossi").Patch(John);
            Assert.AreEqual("issoR", John.Surname);

            // First property mapping function executed here
            CreateDelta <Person, string>(x => x.Name, "Mario").Patch(John);
            Assert.AreEqual("Mario", John.Name);

            // Second property mapping function executed here
            CreateDelta <Person, string>(x => x.Name, 15).Patch(John);
            Assert.AreEqual("number:15", John.Name);

            // Third property mapping function executed here
            CreateDelta <Person, string>(x => x.Name, John.BirthDate).Patch(John);
            Assert.AreEqual("datetime:1990-02-01T20:15:10", John.Name);
        }