Exemplo n.º 1
0
        public void Create()
        {
            UnitOfWork uOw = this._dbInfo.Work;

            TypeRegistrar.RegisterXpObjectToUoW <T>(uOw);
            uOw?.CommitChanges();
        }
Exemplo n.º 2
0
        public void Register_ClrType_InferSchemaTypes()
        {
            // arrange
            var initialTypes = new List <ITypeReference>();

            initialTypes.Add(new ClrTypeReference(
                                 typeof(Foo),
                                 TypeContext.Output));

            var serviceProvider = new EmptyServiceProvider();

            var typeRegistrar = new TypeRegistrar(
                serviceProvider, initialTypes);

            // act
            typeRegistrar.Complete();

            // assert
            typeRegistrar.Registerd
            .Select(t => t.Value.Type)
            .OfType <IHasClrType>()
            .ToDictionary(
                t => t.GetType().GetTypeName(),
                t => t.ClrType.GetTypeName())
            .MatchSnapshot(new SnapshotNameExtension("registered"));

            typeRegistrar.ClrTypes.ToDictionary(
                t => t.Key.ToString(),
                t => t.Value.ToString())
            .MatchSnapshot(new SnapshotNameExtension("clr"));
        }
Exemplo n.º 3
0
    static int Main(string[] args)
    {
        // to retrieve the log file name, we must first parse the command settings
        // this will require us to delay setting the file path for the file writer.
        // With serilog we can use an enricher and Serilog.Sinks.Map to dynamically
        // pull this setting.
        var serviceCollection = new ServiceCollection()
                                .AddLogging(configure =>
                                            configure.AddSerilog(new LoggerConfiguration()
                                                                 // log level will be dynamically be controlled by our log interceptor upon running
                                                                 .MinimumLevel.ControlledBy(LogInterceptor.LogLevel)
                                                                 // the log enricher will add a new property with the log file path from the settings
                                                                 // that we can use to set the path dynamically
                                                                 .Enrich.With <LoggingEnricher>()
                                                                 // serilog.sinks.map will defer the configuration of the sink to be ondemand
                                                                 // allowing us to look at the properties set by the enricher to set the path appropriately
                                                                 .WriteTo.Map(LoggingEnricher.LogFilePathPropertyName,
                                                                              (logFilePath, wt) => wt.File($"{logFilePath}"), 1)
                                                                 .CreateLogger()
                                                                 )
                                            );

        var registrar = new TypeRegistrar(serviceCollection);
        var app       = new CommandApp(registrar);

        app.Configure(config =>
        {
            config.SetInterceptor(new LogInterceptor()); // add the interceptor
            config.AddCommand <HelloCommand>("hello");
        });

        return(app.Run(args));
    }
Exemplo n.º 4
0
        public void ConfigureServices(IServiceCollection services)
        {
            TypeRegistrar.Register(services, Configuration);
            DataAccessRegistrar.Register(services);
            CommonRegistrar.Register(services);

            services.AddControllers();
            services.AddCors();
        }
Exemplo n.º 5
0
    public static int Main(string[] args)
    {
        // Create a type registrar and register any dependencies.
        // A type registrar is an adapter for a DI framework.
        var registrations = new ServiceCollection();

        registrations.AddSingleton <IGreeter, HelloWorldGreeter>();
        var registrar = new TypeRegistrar(registrations);

        // Create a new command app with the registrar
        // and run it with the provided arguments.
        var app = new CommandApp <DefaultCommand>(registrar);

        return(app.Run(args));
    }
Exemplo n.º 6
0
        public static int Main(string[] args)
        {
            Log.Logger = new LoggerConfiguration()
                         .WriteTo.File("Log.txt", LogEventLevel.Verbose, "[{Timestamp:yyyy-MM-dd:HH:mm:ss.ff} {Level:u4}] {Message:lj}{NewLine}{Exception}",
                                       rollingInterval: RollingInterval.Minute, rollOnFileSizeLimit: true, retainedFileCountLimit: 5, shared: false,
                                       hooks: new HeaderWriter("-----------------------", true))
                         .WriteTo.SpectreConsole("{Level:u3} > {Message:lj}{NewLine}{Exception}", LogEventLevel.Information)
                         .MinimumLevel.Verbose()
                         .CreateLogger();

            var conf = new ConfigurationBuilder()
                       .AddJsonFile("appsettings.json", true, false)
                       .Build();

            var services = new ServiceCollection();

            services.AddSingleton <IHookService, HookService>();
            services.AddSingleton <IMessageLoopService, MessageLoopService>();
            services.AddSingleton <ITrackRepository, TrackRepository>();
            services.AddSingleton <ITrackListPlayer, TrackListPlayer>();

            services.Configure <HotkeyOptions>(o => conf.GetSection(HotkeyOptions.Position).Bind(o));
            services.Configure <InputOptions>(o => conf.GetSection(InputOptions.Position).Bind(o));
            services.Configure <OutputOptions>(o => conf.GetSection(OutputOptions.Position).Bind(o));

            var registrar = new TypeRegistrar(services);
            var app       = new CommandApp <DefaultCommand>(registrar);

            app.Configure(config =>
            {
                config.SetApplicationName("TrackReader");

                config.AddExample(new[] { "-i tracks.tsv", "-o output.txt", "-f 24" });
                config.AddExample(new[] { "-i tracks.tsv", "-o output.txt", "-f 59.94" });
                config.AddExample(new[] { "-i tracks.tsv", "-o output.txt", "--framerate=23.97" });
                config.AddExample(new[] { "--input=tracks.tsv", "--output=output.txt", "--fps=23.97" });

                config.ValidateExamples();
            });

            var result = app.Run(args);

            Console.ReadKey();
            Log.CloseAndFlush();
            return(result);
        }
Exemplo n.º 7
0
        private static int RunWithArguments(string[] args)
        {
            var serviceCollections = ConfigureApp();
            var registrar          = new TypeRegistrar(serviceCollections);

            var app = new CommandApp(registrar);

            app.Configure(config =>
            {
                config.PropagateExceptions();

                config.SetInterceptor(new LogInterceptor());

                config.SetExceptionHandler(ex =>
                {
                    Log.Logger.Error(ex.Message + " Stacktrace: " + ex.StackTrace);
                    return(-1);
                });

                config.AddCommand <RenameCommand>("rename")
                .WithDescription("Rename and sort video files in subfolders by sitename.")
                .WithExample(new[] { "rename", "--dryrun" });
                config.AddCommand <SetupCommand>("setup")
                .WithDescription("Interactive setup to configure pdbMate.")
                .WithExample(new[] { "setup" });
                config.AddCommand <DownloadCommand>("download")
                .WithDescription("Rename and sort video files in subfolders by sitename.")
                .WithExample(new[] { "download", "--dryrun" })
                .WithExample(new[] { "download", "--dryrun", "--client", "nzbget" });
                config.AddCommand <ChangeNamesCommand>("changenames")
                .WithDescription("Apply different naming template to an existing folder (a folder with sorted videos - only videos with a pdbid in their filename will be renamed).")
                .WithExample(new[] { "changenames", "--dryrun" });
                config.AddCommand <BackfillingCommand>("backfilling")
                .WithDescription("Backfilling by favorite sites and actors (0 means all favorite actors or sites - otherwise the id of one site or actor).")
                .WithExample(new[] { "backfilling", "--actor", "0" })
                .WithExample(new[] { "backfilling", "--actor", "0", "--site", "0" })
                .WithExample(new[] { "backfilling", "--site", "6" });
            });

            return(app.Run(args));
        }
Exemplo n.º 8
0
        /// <summary>
        /// Runs the build with the specified arguments.
        /// </summary>
        /// <param name="args">The arguments.</param>
        /// <returns>The exit code.</returns>
        public int Run(IEnumerable <string> args)
        {
            RegisterTasks(_assemblies);

            // Register all the user's registrations
            var registrar = new TypeRegistrar();

            registrar.RegisterInstance(typeof(IServiceCollection), _services);

            // Run the application
            var app = new CommandApp <DefaultCommand>(registrar);

            app.Configure(config =>
            {
                config.ValidateExamples();

                // Top level examples.
                config.AddExample(new[] { string.Empty });
                config.AddExample(new[] { "--verbosity", "quiet" });
                config.AddExample(new[] { "--tree" });
            });

            return(app.Run(args));
        }
Exemplo n.º 9
0
        public void Register_SchemaType_ClrTypeExists()
        {
            // arrange
            var initialTypes = new List <ITypeReference>();

            initialTypes.Add(new ClrTypeReference(
                                 typeof(FooType),
                                 TypeContext.Output));

            var serviceProvider = new EmptyServiceProvider();

            var typeRegistrar = new TypeRegistrar(
                serviceProvider,
                DescriptorContext.Create(),
                initialTypes,
                new Dictionary <ITypeReference, ITypeReference>(),
                new Dictionary <string, object>(),
                new AggregateTypeInitilizationInterceptor());

            // act
            typeRegistrar.Complete();

            // assert
            typeRegistrar.Registerd
            .Select(t => t.Value.Type)
            .OfType <IHasClrType>()
            .ToDictionary(
                t => t.GetType().GetTypeName(),
                t => t.ClrType.GetTypeName())
            .MatchSnapshot(new SnapshotNameExtension("registered"));

            typeRegistrar.ClrTypes.ToDictionary(
                t => t.Key.ToString(),
                t => t.Value.ToString())
            .MatchSnapshot(new SnapshotNameExtension("clr"));
        }
Exemplo n.º 10
0
        public static Task <int> Main(string[] args)
        {
            var container = CreateContainer();
            var console   = container.Resolve <IConsoleWriter>();

            if (args.Any(a => string.Equals(a, "parse", StringComparison.OrdinalIgnoreCase)))
            {
                if (args.Any(a => string.Equals(a, "stdout", StringComparison.OrdinalIgnoreCase)))
                {
                    console.DisableNormalOutput();
                }

                if (args.Any(a => string.Equals(a, "stderr", StringComparison.OrdinalIgnoreCase)))
                {
                    console.DisableErrorOutput();
                }
            }

            const string text = "[lightyellow3 on black]\n" +
                                "  ____ ______     ___    ____  _   _\n" +
                                " / ___/ ___\\ \\   / / \\  |  _ \\| \\ | |\n" +
                                "| |  | |    \\ \\ / / _ \\ | |_) |  \\| |\n" +
                                "| |__| |___  \\ V / ___ \\|  _ <| |\\  |\n" +
                                " \\____\\____|  \\_/_/   \\_|_| \\_|_| \\_|\n" +
                                "[/][aqua on black]{0,37}[/]\n" +
                                "\n";

            var version = Assembly
                          .GetExecutingAssembly()
                          .GetCustomAttribute <AssemblyInformationalVersionAttribute>() !.InformationalVersion;

            if (version.IndexOf('+', StringComparison.Ordinal) > 0)
            {
                version = version.Substring(0, version.IndexOf('+', StringComparison.Ordinal));
            }

            console.WriteInfoLine(text, version);

            var registrar = new TypeRegistrar(container);

            try
            {
                var app = new CommandApp(registrar);

                app.Configure(config =>
                {
                    config.SetApplicationName("ccvarn");
                    config.ValidateExamples();

                    config.AddCommand <InitCommand>("init")
                    .WithExample(new[] { "init" })
                    .WithExample(new[] { "init", "--root", Environment.CurrentDirectory });

                    config.AddCommand <ParseCommand>("parse")
                    .WithExample(new[] { "parse", "ccvarn.json" })
                    .WithExample(new[] { "parse", "stdout" })
                    .WithExample(new[] { "parse", "stderr" })
                    .WithExample(new[] { "parse", "ccvarn.json", "--output", "ReleaseNotes.md", "--output", "ReleaseNotes.txt" })
                    .WithExample(new[] { "parse", "--output", "ReleaseNotes.md", "--output", "ReleaseNotes.txt" });
                });
                //app.SetDefaultCommand<ParseCommand>();

                return(app.RunAsync(args));
            }
            finally
            {
                container.Dispose();
            }
        }
Exemplo n.º 11
0
 public CommandAppSettings(ITypeRegistrar registrar)
 {
     Registrar       = new TypeRegistrar(registrar);
     CaseSensitivity = CaseSensitivity.All;
 }
Exemplo n.º 12
0
        private static int Main(string[] args)
        {
            var configuration = CreateConfigurationRoot();

            var services = new ServiceCollection()
                           .AddScoped <IAuthenticationProvider, AuthenticationProvider>()
                           .Configure <AppSettings>(configuration);

            services
            .AddHttpClient <IApiClient, ApiClient>();

            JsonConvert.DefaultSettings = () => new JsonSerializerSettings
            {
                NullValueHandling = NullValueHandling.Ignore,
                Converters        = new List <JsonConverter>
                {
                    new StringEnumConverter()
                }
            };

            var serviceProvider = services.BuildServiceProvider();

            var registrar = new TypeRegistrar(services);

            var app = new CommandApp(registrar);

            app.SetDefaultCommand <Commands.AppCommand>();
            app.Configure(config =>
            {
                config.AddBranch("subscriptions", subscription =>
                {
                    subscription.SetDescription("Commands to configure subscriptions.");
                    subscription.AddCommand <AddCommand>("add");
                    subscription.AddCommand <ListCommand>("list");
                    subscription.AddCommand <RemoveCommand>("remove");
                });

                config.AddBranch("security", security =>
                {
                    security.SetDescription("Commands related to Tenant Security.");
                    security.AddBranch("users", users =>
                    {
                        users.SetDescription("Commands related to Tenant Users security.");
                        users.AddCommand <Commands.Security.Users.AddCommand>("add");
                        users.AddCommand <Commands.Security.Users.ImportCommand>("import");
                    });
                });

                config.AddBranch("management", management =>
                {
                    management.SetDescription("Commands related to Management.");
                    management.AddBranch("tenants", tenants =>
                    {
                        tenants.SetDescription("Commands related to Tenants Management.");
                        tenants.AddCommand <Commands.Management.Tenants.AddCommand>("add");
                    });
                });

                config.AddBranch("model", model =>
                {
                    model.SetDescription("Commands related to Tenant Model.");
                    model.AddCommand <Commands.Model.ExportCommand>("export");
                    model.AddCommand <Commands.Model.Import.ImportCommand>("import");
                    model.AddCommand <Commands.Model.Apply.ApplyCommand>("apply");
                });

                config.AddBranch("application", application =>
                {
                    application.SetDescription("Commands related to Tenant.");
                    application.AddCommand <Commands.Application.ImportCommand>("import");
                });
            });


            var subscriptions = GetConfiguredSubscriptions(serviceProvider);

            if (subscriptions?.Count == 0)
            {
                ShowWelcomeScreen();
            }

            return(app.Run(args));
        }