Exemplo n.º 1
0
 /// <summary>
 /// Creates a new <see cref="CosmosInfectionReportRepository"/> instance
 /// </summary>
 /// <param name="dbContext"><see cref="CosmosContext"/> instance</param>
 public CosmosInfectionReportRepository(CosmosContext dbContext) : base(dbContext)
 {
     // Create container reference
     this.Container = this.Context.GetContainer(
         this.Context.SchemaOptions.MessageContainerName
         );
 }
Exemplo n.º 2
0
        public CosmosSaver(IConfiguration config, TelemetryConfiguration telemetryConfig, CosmosContext cosmosContext)
        {
            _config                 = config;
            _persistingContext      = cosmosContext;
            _cosmosAuthorizationKey = _config["CosmosAuthorizationKey"];
            _telemetryClient        = new TelemetryClient(telemetryConfig);
            _cosmosEndPointUrl      = _config["CosmosEndPointUrl"];
            if (_cosmosClient == null)
            {
                string endpoint = _cosmosEndPointUrl;
                if (string.IsNullOrEmpty(endpoint))
                {
                    throw new ArgumentNullException("Please specify a valid endpoint in the appSettings.json");
                }

                string authKey = _cosmosAuthorizationKey;
                if (string.IsNullOrEmpty(authKey) || string.Equals(authKey, "Super secret key"))
                {
                    throw new ArgumentException("Please specify a valid AuthorizationKey in the appSettings.json");
                }

                _databaseId = _persistingContext.CosmosDatabaseId;
                if (string.IsNullOrEmpty(_databaseId))
                {
                    throw new ArgumentException("Please specify a valid Cosmos Database Id in the settings.json");
                }

                _containerId = _persistingContext.CosmosContainerId;
                if (string.IsNullOrEmpty(_containerId))
                {
                    throw new ArgumentException("Please specify a valid Cosmos Database Container Id in the settings.json");
                }
                _cosmosClient = new CosmosClient(endpoint, authKey);
            }
        }
Exemplo n.º 3
0
 public Functions(CosmosContext context, DBAccess dbAccess, ILogger logger, IHttpContextAccessor httpContextAccessor)
 {
     this.context             = context;
     this.dbA                 = dbAccess;
     this.logger              = logger;
     this.httpContextAccessor = httpContextAccessor;
 }
Exemplo n.º 4
0
 public Worker(ILogger <Worker> logger,
               IConfiguration configuration)
 {
     _logger        = logger;
     _configuration = configuration;
     _context       = ConfigureStore(_configuration.GetSection("SummaryProjector"));
 }
Exemplo n.º 5
0
        private static void DeleteTaskFromUser(User currentUser, CosmosContext context)
        {
            bool keepLooping = true;

            if (currentUser.ToDoList == null)
            {
                currentUser.ToDoList = new List <Task> {
                };
            }
            while (keepLooping)
            {
                if (currentUser.ToDoList.Any())
                {
                    Console.Clear();
                    Console.WriteLine("Select the task you want to delete.");
                    var notes = new List <string>();
                    foreach (var task in currentUser.ToDoList)
                    {
                        Console.WriteLine($"[{task.Id.Remove(3)}] {task.Note}");
                        notes.Add(task.Id.Remove(3));
                    }
                    Console.WriteLine();
                    Console.WriteLine("[Exit] Type 'exit' to go back.");
                    string taskIDToDelete = Console.ReadLine().Trim();
                    if (notes.Contains(taskIDToDelete))
                    {
                        Console.WriteLine($"Deleting [{taskIDToDelete}] from your todolist.");
                        foreach (var task in currentUser.ToDoList)
                        {
                            if (task.Id.Remove(3).Equals(taskIDToDelete))
                            {
                                currentUser.ToDoList.Remove(task);
                                context.Tasks.Remove(task);
                                context.SaveChanges();
                                Console.WriteLine("Success");
                                break;
                            }
                        }
                        EnterToContinue();
                    }
                    else if (taskIDToDelete == "exit" || taskIDToDelete == "Exit")
                    {
                        keepLooping = false;
                    }
                    else
                    {
                        Console.WriteLine($"Can't find ID: {taskIDToDelete}");
                        EnterToContinue();
                    }
                }
                else
                {
                    Console.WriteLine("You have 0 tasks in your todolist.");
                    EnterToContinue();
                    keepLooping = false;
                }
            }
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            using (CosmosContext context = new CosmosContext())
            {
                context.Database.EnsureCreated();
                User currentUser = null;

                MainMenu(currentUser, context);
            }
        }
        public ContainerTests()
        {
            //DI のセットアップ
            ServiceCollection.AddCosmosContext(Configuration);

            // database / container を作成する



            _serviceProvider = ServiceCollection.BuildServiceProvider();
            _cosmosContext   = _serviceProvider.GetService <CosmosContext>();
        }
Exemplo n.º 8
0
 public void ConfigureStorage()
 {
     CloudFileContext.InitializeContext(
         Configuration["AzureCloudStorage:UserStoreName"],
         Configuration["AzureCloudStorage:UserStoreKey"]
         );
     CloudTableContext.InitializeContext(
         Configuration["AzureCloudStorage:UserStoreName"],
         Configuration["AzureCloudStorage:UserStoreKey"]
         );
     CosmosContext.InitializeContext(
         Configuration["CosmosDb:Database"],
         Configuration["CosmosDb:Endpoint"],
         Configuration["CosmosDb:Key"]
         );
 }
Exemplo n.º 9
0
 public static async Task <IActionResult> GetRoom(
     [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "room/{id}")] HttpRequest request,
     string id,
     ILogger log
     )
 {
     try
     {
         CosmosContext db = new CosmosContext();
         return(new OkObjectResult(await db.Rooms.FirstAsync(e => e.Id.Equals(id))));
     }
     catch (Exception ex)
     {
         log.LogError(new EventId(), ex, ex.FullMessage());
         throw;
     }
 }
Exemplo n.º 10
0
        private static User LoginWindow(User currentUser, CosmosContext context)
        {
            Console.WriteLine("Type in your username and hit enter to continue\n" +
                              "");
            Console.WriteLine("Username: "******"Found user {currentUser.Username}");
                Console.WriteLine("Enter password");

                var numberOfTries = 3;
                for (int i = 1; i < numberOfTries + 1; i++)
                {
                    string passwordInput = Console.ReadLine().Trim();
                    if (passwordInput == currentUser.Password)
                    {
                        Console.Clear();
                        Console.WriteLine("Password correct, you are logged in.");
                        EnterToContinue();
                        return(currentUser);
                    }
                    else
                    {
                        Console.Clear();
                        Console.WriteLine("Wrong password.");
                        Console.WriteLine($"Number of tries left {numberOfTries - i}");
                    }
                }
                return(null);
            }
            else
            {
                Console.WriteLine("Didnt find a registered account with that username.");
                EnterToContinue();
                return(null);
            }
        }
Exemplo n.º 11
0
 public static IActionResult GetCards(
     [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "cards/{count:int?}")] HttpRequest request,
     int?count,
     ILogger log
     )
 {
     try
     {
         CosmosContext db = new CosmosContext();
         return(count != null ?
                new OkObjectResult(db.Cards.Random(count.GetValueOrDefault())) : new OkObjectResult(db.Cards));
     }
     catch (Exception ex)
     {
         log.LogError(new EventId(), ex, ex.FullMessage());
         throw;
     }
 }
Exemplo n.º 12
0
        public static async Task <IActionResult> CreateRoom(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "room")] NewRoomInboundModel model,
            ILogger log
            )
        {
            try
            {
                CosmosContext db   = new CosmosContext();
                RoomEntity    room = new RoomEntity {
                    Team1 = new TeamEntity
                    {
                        Id      = Guid.NewGuid().ToString(),
                        Players = new List <PlayerEntity>
                        {
                            new PlayerEntity
                            {
                                Id           = Guid.NewGuid().ToString(),
                                Name         = model.PlayerName,
                                LastAction   = DateTime.UtcNow,
                                IsOwner      = true,
                                IsController = true
                            }
                        }
                    },
                    Team2 = new TeamEntity {
                        Id = Guid.NewGuid().ToString()
                    },
                    CreatedDate = DateTime.UtcNow
                };
                room.Id = room.UniqueId(db.Rooms.AsQueryable());

                db.Rooms.Add(room);
                await db.SaveChangesAsync();

                return(new OkObjectResult(room));
            }
            catch (Exception ex)
            {
                log.LogError(new EventId(), ex, ex.FullMessage());
                throw;
            }
        }
Exemplo n.º 13
0
        private static void UserLoggedInWindow(User currentUser, CosmosContext context)
        {
            while (currentUser != null)
            {
                Console.Clear();
                Console.WriteLine("Status: Logged In");
                Console.WriteLine("1. Add a task.");
                Console.WriteLine("2. Delete a task.");
                Console.WriteLine("3. Log out.");
                var userinput = Console.ReadKey();
                switch (userinput.Key)
                {
                case ConsoleKey.D1:
                {
                    Console.Clear();
                    Console.WriteLine("Please write a note, then hit enter to continue.");
                    string noteInput = Console.ReadLine().Trim();
                    EnterToContinue();
                    MakeSureInputValid(ref noteInput);
                    AddTaskToUser(noteInput, currentUser, context);
                    break;
                }

                case ConsoleKey.D2:
                {
                    Console.Clear();
                    DeleteTaskFromUser(currentUser, context);
                    break;
                }

                case ConsoleKey.D3:
                {
                    Console.Clear();
                    currentUser = null;
                    MainMenu(currentUser, context);
                    break;
                }
                }
            }
        }
Exemplo n.º 14
0
        private static void MainMenu(User currentUser, CosmosContext context)
        {
            while (currentUser == null)
            {
                Console.Clear();
                Console.WriteLine("Status: Logged Out");
                Console.WriteLine("1. Log in to an existing account.");
                Console.WriteLine("2. Register new account.");
                Console.WriteLine("3. Exit.");
                var userinput = Console.ReadKey();
                switch (userinput.Key)
                {
                case ConsoleKey.D1:
                {
                    Console.Clear();
                    currentUser = LoginWindow(currentUser, context);
                    if (currentUser != null)
                    {
                        UserLoggedInWindow(currentUser, context);
                    }
                    break;
                }

                case ConsoleKey.D2:
                {
                    Console.Clear();
                    RegisterWindow(currentUser, context);
                    break;
                }

                case ConsoleKey.D3:
                {
                    Console.Clear();
                    Environment.Exit(0);
                    break;
                }
                }
            }
        }
Exemplo n.º 15
0
        private static void RegisterWindow(User currentUser, CosmosContext context)
        {
            Console.WriteLine("Registerwindow");
            Console.WriteLine("Username: "******"There's already a registered account with this username.");
                EnterToContinue();
            }
            else
            {
                Console.WriteLine("The username is available.");
                Console.WriteLine("Enter a password");

                string passwordInput = Console.ReadLine().Trim();
                MakeSureInputValid(ref passwordInput);

                var user = new User
                {
                    Id       = Guid.NewGuid(),
                    Username = usernameInput,
                    Password = passwordInput
                };
                context.Users.Add(user);
                context.SaveChanges();
                Console.WriteLine("Account registered, you can now log in.");
                EnterToContinue();
            }
        }
Exemplo n.º 16
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, CosmosContext cosmosContext)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseSwagger();
                app.UseSwaggerUI(options =>
                {
                    options.SwaggerEndpoint("/swagger/v1/swagger.json", "v1");
                    options.RoutePrefix = string.Empty;
                });
            }

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
            // Custom setup
            cosmosContext.Database.EnsureCreated();
        }
Exemplo n.º 17
0
        private static void AddTaskToUser(string noteInput, User currentUser, CosmosContext context)
        {
            Task task = new Task
            {
                Id          = Guid.NewGuid().ToString(),
                User        = currentUser,
                DateOfEntry = DateTime.Now,
                Note        = noteInput,
            };

            if (currentUser.ToDoList == null)
            {
                currentUser.ToDoList = new List <Task> {
                    task
                };
            }
            else
            {
                currentUser.ToDoList.Add(task);
            }
            context.SaveChanges();
            Console.WriteLine("Your task has been added.");
            EnterToContinue();
        }
Exemplo n.º 18
0
 public TaskController(CosmosContext context)
 {
     _context = context;
 }
Exemplo n.º 19
0
 public CarRepository(CosmosContext context, ILogger <CarRepository> logger) : base(context, logger)
 {
     _logger = logger;
 }
Exemplo n.º 20
0
 public SubmissionController(CosmosContext context, ILogger <SubmissionController> logger, StorageService storage)
 {
     _context = context;
     _logger  = logger;
     _storage = storage;
 }
Exemplo n.º 21
0
        public IActionResult Get()
        {
            var cosmos = new CosmosContext();

            return(Ok(cosmos.GetAllTasks()));
        }
Exemplo n.º 22
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Repository"/> class.
 /// </summary>
 /// <param name="cosmosContext">Instance of CosmosContext.</param>
 /// <param name="tableClient">Instance of CloudTableClient.</param>
 public Repository(CosmosContext cosmosContext, CloudTableClient tableClient)
 {
     this.cosmosContext = cosmosContext;
     this.tableClient   = tableClient;
 }
 public ValuationsController(CosmosContext context)
 {
     _context = context;
 }
Exemplo n.º 24
0
 public CosmosProfileService(UserManager <CosmosUser> userManager, CosmosContext context)
 {
     _context     = context;
     _userManager = userManager;
 }