Пример #1
0
        private static void Push(IConsole console, string?registry, string?username, string?password, string?repository)
        {
            try
            {
                RegistryOption.EnsureNotNullorMalformed(registry);
                RepositoryOption.EnsureNotNullorMalformed(repository);
            }
            catch (ArgumentException e)
            {
                console.Error.WriteLine($"Push failed due to bad/missing argument:\t{e.ParamName}");
                return;
            }

            try
            {
                UsernameOption.EnsureNotNull(ref username);
                PasswordOption.EnsureNotNull(ref password);
            }
            catch (ArgumentException e)
            {
                if (CredentialHelper.TryGetCredentials(registry !, out var credential))
                {
                    username = credential !.UserName;
                    password = credential !.Password;
                }
 public static Command CreateCommand() => new Command(
     name: "import-base",
     description: "",
     symbols: new Option[]
 {
     RegistryOption.Create(),
     UsernameOption.Create(),
     PasswordOption.Create(),
     RepositoryOption.Create()
 },
     handler: CommandHandler.Create <IConsole, string?, string?, string?, string?>(ImportBaseAsync),
     isHidden: true
     );
Пример #3
0
 public static Command CreateCommand() => new Command(
     name: "push",
     description: "Invoke dotnet publish and push resulting artifact to registry",
     symbols: new Option[]
 {
     RegistryOption.Create(),
     UsernameOption.Create(),
     PasswordOption.Create(),
     RepositoryOption.Create()
 },
     handler: CommandHandler.Create <IConsole, string?, string?, string?, string?>(Push),
     isHidden: false
     );
        public static Func <T> Connection(DbType dbType, RepositoryOption repositoryOption)
        {
            switch (dbType)
            {
            case DbType.None:
                return(null);

            case DbType.Oracle:
                return(null);

            case DbType.Postgre:
                return(null);

            case DbType.SQLite:
                return(null);
            }

            return(null);
        }
Пример #5
0
        public static IServiceCollection AddSummerBootRepository(this IServiceCollection services, Action <RepositoryOption> action)
        {
            if (action == null)
            {
                throw new ArgumentNullException(nameof(action));
            }

            var option = new RepositoryOption();

            action(option);

            if (option.ConnectionString.IsNullOrWhiteSpace())
            {
                throw new Exception("ConnectionString is Require");
            }

            if (option.DbConnectionType == null)
            {
                throw new Exception("DbConnectionType is Require");
            }
            services.TryAddScoped <IDbFactory, DbFactory>();
            services.AddScoped <IUnitOfWork, UnitOfWork>();
            services.AddSingleton(t => option);
            RepositoryOption.Instance = option;

            services.AddScoped(typeof(BaseRepository <>));
            //services.AddSbSingleton<IDataSource, DruidDataSource>();
            services.AddScoped <RepositoryService>();

            services.TryAddSingleton <IRepositoryProxyBuilder, RepositoryProxyBuilder>();

            var types = Assembly.GetCallingAssembly().GetExportedTypes()
                        .Union(Assembly.GetExecutingAssembly().GetExportedTypes()).Distinct().ToList();

            var autoRepositoryTypes = types.Where(it => it.IsInterface && it.GetCustomAttribute <AutoRepositoryAttribute>() != null).ToList();

            foreach (var type in autoRepositoryTypes)
            {
                services.AddSummerBootRepositoryService(type, ServiceLifetime.Scoped);
            }

            return(services);
        }
Пример #6
0
        public static IServiceCollection AddSummerBootRepository(this IServiceCollection services, Action <RepositoryOption> action)
        {
            if (action == null)
            {
                throw new ArgumentNullException(nameof(action));
            }

            var option = new RepositoryOption();

            action(option);

            if (option.ConnectionString.IsNullOrWhiteSpace())
            {
                throw new Exception("ConnectionString is Require");
            }

            if (option.DbConnectionType == null)
            {
                throw new Exception("DbConnectionType is Require");
            }

            services.AddSingleton(t => option);

            //services.AddSbSingleton<IDataSource, DruidDataSource>();

            services.AddSbScoped <RepositoryInterceptor2>();

            services.TryAddSbScoped <IDbFactory, DbFactory>();

            var types = AppDomain.CurrentDomain.GetAssemblies().SelectMany(it => it.GetTypes());

            var repositoryTypes = types.Where(it => it.IsInterface && it.GetCustomAttribute <RepositoryAttribute>() != null);

            foreach (var type in repositoryTypes)
            {
                services.AddSbRepositoryService2(type, ServiceLifetime.Scoped);
            }

            services.AddSbRepositoryService(typeof(TransactionalInterceptor));
            return(services);
        }
Пример #7
0
 public CustomCustomerRepository(IUnitOfWork uow, IDbFactory dbFactory, RepositoryOption repositoryOption) : base(uow, dbFactory, repositoryOption)
 {
 }
        private static void Push(IConsole console, string?registry, string?username, string?password, string?repository)
        {
            try
            {
                RegistryOption.EnsureNotNullorMalformed(registry);
                UsernameOption.EnsureNotNull(ref username);
                PasswordOption.EnsureNotNull(ref password);
                RepositoryOption.EnsureNotNullorMalformed(repository);
            }
            catch (ArgumentException e)
            {
                console.Error.WriteLine($"Push failed due to bad/missing argument:\t{e.ParamName}");
                return;
            }


            var finder      = new MsBuildProjectFinder(Environment.CurrentDirectory);
            var projectFile = finder.FindMsBuildProject();
            var targetsFile = FindTargetsFile();

            var args = new[]
            {
                "msbuild",
                projectFile,
                "/nologo",
                "/restore",
                "/t:Publish",
                $"/p:CustomAfterMicrosoftCommonTargets={targetsFile}",
                $"/p:CustomAfterMicrosoftCommonCrossTargetingTargets={targetsFile}",
                $"/p:ImageName={registry}/{repository}",
                $"/p:RegistryUsername={username}",
                $"/p:RegistryPassword={password}"
            };
            var psi = new ProcessStartInfo
            {
                FileName  = DotNetMuxer.MuxerPathOrDefault(),
                Arguments = ArgumentEscaper.EscapeAndConcatenate(args),
                RedirectStandardOutput = true,
                RedirectStandardError  = true,
            };

            var process = Process.Start(psi);

            process.WaitForExit();
            console.Out.WriteLine(process.StandardOutput.ReadToEnd());

            string FindTargetsFile()
            {
                var assemblyDir = Path.GetDirectoryName(typeof(Program).Assembly.Location);
                var searchPaths = new[]
                {
                    Path.Combine(AppContext.BaseDirectory, "assets"),
                    Path.Combine(assemblyDir, "assets"),
                    AppContext.BaseDirectory,
                    assemblyDir,
                };

                var targetPath = searchPaths.Select(p => Path.Combine(p, "Oras.targets")).FirstOrDefault(File.Exists);

                if (targetPath == null)
                {
                    Console.WriteLine("Fatal error: could not find Oras.targets");
                }
                return(targetPath);
            }
        }