コード例 #1
0
        private void ReadCommand(int gameMode, ILevel currentLevel)
        {
            ConsoleSetup.CleaningTheConsoleBuffer();

            string direction            = "right";
            string lastCorrectDirection = direction;

            while (currentLevel.CurrentlyEatenApples != currentLevel.ApplesTarget)
            {
                IsGameOver(currentLevel);
                Borders.PrintBorders();
                currentLevel.CheckForAppleTimeElapsed(currentLevel.Obstacles);
                if (Console.KeyAvailable)
                {
                    var currentCommand = Console.ReadKey(true);
                    if (gameMode == 1)
                    {
                        direction = GameModeOneKeyParser(currentCommand);
                    }
                    else
                    {
                        direction = GameModeTwoKeyParser(currentCommand);
                    }
                    //Checking and ignoring direction if incorrect key is pressed +
                    //Checking and ingnoring direction if opposite direction is chosen
                    CheckingCurrentDirection(ref direction, ref lastCorrectDirection);
                }
                ConsoleSetup.SlowAction(currentLevel.SlowActionGame);
                this.ProcessCommand(direction, currentLevel, currentLevel.Obstacles);
            }
            gamePoints.PositivePoints += currentLevel.AllLevelPoints;
        }
コード例 #2
0
        public static S3Client Create(string profileName)
        {
            ServiceCollection services = new ServiceCollection();

            //Here we setup our S3Client
            IS3ClientBuilder builder = services.AddSimpleS3();

            //Here we enable in-memory encryption using Microsoft Data Protection
            builder.CoreBuilder
            .UseProfileManager()
            .BindConfigToProfile(profileName)
            .UseDataProtection();

            //Finally we build the service provider and return the S3Client
            IServiceProvider serviceProvider = services.BuildServiceProvider();

            IProfileManager manager = serviceProvider.GetRequiredService <IProfileManager>();
            IProfile?       profile = manager.GetProfile(profileName);

            //If profile is null, then we do not yet have a profile stored on disk. We use ConsoleSetup as an easy and secure way of asking for credentials
            if (profile == null)
            {
                ConsoleSetup.SetupProfile(manager, profileName);
            }

            return(serviceProvider.GetRequiredService <S3Client>());
        }
コード例 #3
0
        private CliManager(string profileName, AwsRegion region)
        {
            ServiceCollection services = new ServiceCollection();
            IS3ClientBuilder  builder  = services.AddSimpleS3();

            builder.CoreBuilder.UseProfileManager()
            .UseDataProtection();

            //Override the region if it is set via commandline
            builder.Services.PostConfigure <S3Config>(config =>
            {
                if (region != AwsRegion.Unknown)
                {
                    config.Region = region;
                }
            });

            services.AddSingleton <BucketManager>();
            services.AddSingleton <ObjectManager>();

            ServiceProvider provider = services.BuildServiceProvider();

            ProfileManager = provider.GetRequiredService <IProfileManager>();

            IProfile profile = ProfileManager.GetProfile(profileName) ?? ConsoleSetup.SetupProfile(ProfileManager, profileName);

            S3Client      = provider.GetRequiredService <IClient>();
            BucketManager = provider.GetRequiredService <BucketManager>();
            ObjectManager = provider.GetRequiredService <ObjectManager>();
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: MARS22101996/Droid
        private static void SetUpContainers()
        {
            ConsoleSetup.Initialize();

            _serviceSql = ConsoleSetup.Container.Resolve <ISqlVacationService>();

            _serviceApi = ConsoleSetup.Container.Resolve <IApiVacationService>();
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: MollsAndHersh/SimpleS3
        private static async Task Main(string[] args)
        {
            IConfigurationRoot configRoot = new ConfigurationBuilder()
                                            .AddJsonFile("Config.json", false)
                                            .Build();

            ServiceCollection services = new ServiceCollection();

            services.Configure <S3Config>(configRoot);

            IS3ClientBuilder clientBuilder = services.AddSimpleS3((s3Config, provider) => configRoot.Bind(s3Config));

            string profileName = configRoot["ProfileName"];

            clientBuilder.CoreBuilder.UseProfileManager()
            .BindConfigToProfile(profileName)
            .UseDataProtection();

            IConfigurationSection proxySection = configRoot.GetSection("Proxy");

            if (proxySection != null && proxySection["UseProxy"].Equals("true", StringComparison.OrdinalIgnoreCase))
            {
                clientBuilder.HttpBuilder.WithProxy(proxySection["ProxyAddress"]);
            }

            using (ServiceProvider serviceProvider = services.BuildServiceProvider())
            {
                IProfileManager manager = serviceProvider.GetRequiredService <IProfileManager>();
                IProfile?       profile = manager.GetProfile(profileName);

                //If profile is null, then we do not yet have a profile stored on disk. We use ConsoleSetup as an easy and secure way of asking for credentials
                if (profile == null)
                {
                    ConsoleSetup.SetupProfile(manager, profileName);
                }

                S3Client client = serviceProvider.GetRequiredService <S3Client>();

                await foreach (S3Bucket bucket in client.ListAllBucketsAsync())
                {
                    if (!bucket.Name.StartsWith("testbucket-", StringComparison.OrdinalIgnoreCase))
                    {
                        continue;
                    }

                    DeleteAllObjectsStatus objDelResp = await client.DeleteAllObjectsAsync(bucket.Name).ConfigureAwait(false);

                    if (objDelResp == DeleteAllObjectsStatus.Ok)
                    {
                        await client.DeleteBucketAsync(bucket.Name).ConfigureAwait(false);
                    }
                }

                //Empty the main test bucket
                await client.DeleteAllObjectsAsync(configRoot["BucketName"]).ConfigureAwait(false);
            }
        }
コード例 #6
0
        public static void Main(string[] args)
        {
            using (var db = new BillsPaymentSystemContext())
            {
                DatabaseInitializer.ResetDatabase();

                // try to create UI in P03_PaymentSystemUI
                // bug found - when enter in list and then return to menu - there is no way to exit the program??? - to do

                ConsoleSetup.SetUp();
                Menu.Initialize();
            }
        }
コード例 #7
0
        public void Start()
        {
            ConsoleSetup.SetupConsole();
            int gameMode = this.ChooseGameMode();

            for (int i = firstLevelIndex; i <= lastLevelIndex; i++)
            {
                ILevel currentLevel = LevelGenerator(i);
                this.GameStartPreparation(i);
                this.InitializeSnake(currentLevel);
                this.InitializeGamePoints(currentLevel);
                currentLevel.GenerateApple(currentLevel.Obstacles);
                this.ReadCommand(gameMode, currentLevel);
            }
        }
コード例 #8
0
        private void GameStartPreparation(int level)
        {
            Console.Clear();
            string stringOfNewLines            = new string('\n', 18);
            string stringOfTabulationsForLevel = new string('\t', 9);
            string stringOfTabulationsForTime  = new string('\t', 7);

            Console.ForegroundColor = ConsoleColor.White;
            for (int i = initialSecond; i >= finalSecond; i--)
            {
                Console.Write($"{stringOfNewLines}{stringOfTabulationsForLevel}");
                Console.WriteLine($"{Constants.GameLevel} {level}");
                Console.Write($"\n{stringOfTabulationsForTime}");
                Console.Write($"{Constants.GameStartPreparation} {i} sec.");
                ConsoleSetup.SlowAction(1000);
                Console.Clear();
            }
        }
コード例 #9
0
        private static async Task Main(string[] args)
        {
            IConfigurationRoot root = new ConfigurationBuilder()
                                      .AddJsonFile("Config.json", false)
                                      .Build();

            ServiceCollection services = new ServiceCollection();

            services.Configure <S3Config>(root);

            IS3ClientBuilder clientBuilder = services.AddSimpleS3();

            clientBuilder.CoreBuilder.UseProfileManager()
            .BindConfigToDefaultProfile()
            .UseDataProtection();

            IConfigurationSection proxySection = root.GetSection("Proxy");

            if (proxySection != null && proxySection["UseProxy"].Equals("true", StringComparison.OrdinalIgnoreCase))
            {
                clientBuilder.HttpBuilder.WithProxy(proxySection["ProxyAddress"]);
            }

            using (ServiceProvider provider = services.BuildServiceProvider())
            {
                IProfileManager manager = provider.GetRequiredService <IProfileManager>();
                IProfile?       profile = manager.GetDefaultProfile();

                //If profile is null, then we do not yet have a profile stored on disk. We use ConsoleSetup as an easy and secure way of asking for credentials
                if (profile == null)
                {
                    Console.WriteLine("No profile found. Starting setup.");
                    ConsoleSetup.SetupDefaultProfile(manager);
                }

                IBucketClient bucketClient = provider.GetRequiredService <IBucketClient>();

                string bucketName = root["BucketName"];

                Console.WriteLine($"Setting up bucket '{bucketName}'");

                HeadBucketResponse headResp = await bucketClient.HeadBucketAsync(bucketName).ConfigureAwait(false);

                if (headResp.IsSuccess)
                {
                    Console.WriteLine($"'{bucketName}' already exist.");
                }
                else
                {
                    Console.WriteLine($"'{bucketName}' does not exist - creating.");
                    CreateBucketResponse createResp = await bucketClient.CreateBucketAsync(bucketName, x => x.EnableObjectLocking = true).ConfigureAwait(false);

                    if (createResp.IsSuccess)
                    {
                        Console.WriteLine($"Successfully created '{bucketName}'.");
                    }
                    else
                    {
                        Console.Error.WriteLine($"Failed to create '{bucketName}'. Exiting.");
                        return;
                    }
                }

                Console.WriteLine("Adding lock configuration");

                PutBucketLockConfigurationResponse putLockResp = await bucketClient.PutBucketLockConfigurationAsync(bucketName, true).ConfigureAwait(false);

                if (putLockResp.IsSuccess)
                {
                    Console.WriteLine("Successfully applied lock configuration.");
                }
                else
                {
                    Console.Error.WriteLine("Failed to apply lock configuration.");
                }

                List <S3Rule> rules = new List <S3Rule>
                {
                    new S3Rule("ExpireAll", true)
                    {
                        AbortIncompleteMultipartUploadDays = 1,
                        NonCurrentVersionExpirationDays    = 1,
                        Expiration = new S3Expiration(1),
                        Filter     = new S3Filter {
                            Prefix = ""
                        }
                    }
                };

                Console.WriteLine("Adding lifecycle configuration");

                PutBucketLifecycleConfigurationResponse putLifecycleResp = await bucketClient.PutBucketLifecycleConfigurationAsync(bucketName, rules).ConfigureAwait(false);

                if (putLifecycleResp.IsSuccess)
                {
                    Console.WriteLine("Successfully applied lifecycle configuration.");
                }
                else
                {
                    Console.Error.WriteLine("Failed to apply lifecycle configuration.");
                }
            }
        }