コード例 #1
0
ファイル: Archivist.cs プロジェクト: mikagouzee/RpgSheetMaker
        public Archivist(IFileProvider fileProvider, ILogMachine logMachine)
        {
            _fileProvider = fileProvider;
            _logger       = logMachine;

            //this will get the folder from which the code is executed.
            //our code should use that path and search inside if the needed folders exists.

            var current = AssemblyLocator.GetAssemblyLocation();

            _logger.Log($"Archivist looking inside {current} for required folders...");

            var directories = Directory.GetDirectories(current);

            Directory.CreateDirectory(Path.Combine(current, "CharacterSheets"));
            _logger.Log($"Archivist created Character Sheet folder");

            sheetPath = Path.GetFullPath(Path.Combine(current, "CharacterSheets"));

            var archiveFolder = directories.FirstOrDefault(x => x == "Archives");

            Directory.CreateDirectory(Path.Combine(current, "Archives"));
            _logger.Log($"Archivist created Archives folder");
            archivePath = Path.GetFullPath(Path.Combine(current, "Archives"));

            _logger.Log($"Characters will be saved in {sheetPath} and archived in {archivePath} .");
        }
コード例 #2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            app.UseCors("CorsPolicy");

            app.UseForwardedHeaders(new ForwardedHeadersOptions
            {
                ForwardedHeaders = ForwardedHeaders.All
            });

            //clacks - overhead
            app.Use(async(context, next) =>
            {
                context.Response.Headers.Add("X-Clacks-Overhead", "GNU Terry Pratchett");
                await next.Invoke();
            });

            //log request/response headers
            app.Use(async(context, next) =>
            {
                _logMachine.Log("Request incoming");

                foreach (var item in context.Request.Headers)
                {
                    _logMachine.Log("Request header " + item.Key + " : " + item.Value);
                }


                _logMachine.Log("Response incoming");
                foreach (var item in context.Response.Headers)
                {
                    _logMachine.Log("Response header " + item.Key + " : " + item.Value);
                }


                await next.Invoke();
            });

            app.UseIdentityServer();
            app.UseAuthentication();

            app.UseCors("CorsPolicy");

            app.UseHttpsRedirection();
            app.UseMvc();
        }
コード例 #3
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            IdentityModelEventSource.ShowPII = true; //Add this line
            //log request/response headers
            app.Use(async(context, next) =>
            {
                _logMachine.Log("Request incoming");

                foreach (var item in context.Request.Headers)
                {
                    _logMachine.Log("Request header " + item.Key + " : " + item.Value);
                }


                _logMachine.Log("Response incoming");
                foreach (var item in context.Response.Headers)
                {
                    _logMachine.Log("Response header " + item.Key + " : " + item.Value);
                }


                await next.Invoke();
            });

            app.UseCors("CorsPolicy");

            app.UseForwardedHeaders(new ForwardedHeadersOptions
            {
                ForwardedHeaders = ForwardedHeaders.All
            });

            app.UseStaticFiles();


            app.UseAuthentication();

            app.UseMvc();

            app.UseSwagger();
            app.UseSwaggerUI(options =>
            {
                options.SwaggerEndpoint("/swagger/v1/swagger.json", "Klanik API");
            });
        }
コード例 #4
0
        public List <Character> GetAll(string context)
        {
            var allChar = _archivist.ReadAll();

            if (allChar.Count > 0)
            {
                _logger.Log($"Found {allChar.Count} characters");
            }
            else
            {
                _logger.Log($"No character found for {context}");
            }

            return(allChar.Where(c => c.GameName.ToLower() == context.ToLower()).ToList());
        }
コード例 #5
0
        public IActionResult CreateRandomly(string game, [FromBody] RandomCharacterCreationObject charac)
        {
            if (charac == null)
            {
                charac = new RandomCharacterCreationObject();
            }

            _logger.Log("In create randomly with parameter " + charac.Name);

            //charac.GameName = game;

            var myCharac = _service.CreateRandomly(game, charac);
            var response = new CharacterViewModel(myCharac);

            return(Ok(response));
        }
コード例 #6
0
ファイル: Archivist.cs プロジェクト: mikagouzee/RpgSheetMaker
        public List <Character> ReadAll()
        {
            var list = new List <Character>();

            _logger.Log($"Searching inside {sheetPath}");

            var files = from file in Directory.EnumerateFiles(sheetPath, "*.json", SearchOption.TopDirectoryOnly)
                        //where file.Contains("json")
                        select file;

            foreach (var item in files)
            {
                Character charac;

                using (StreamReader reader = new StreamReader(item))
                {
                    string jsonCharac = reader.ReadToEnd();
                    charac = JsonConvert.DeserializeObject <Character>(jsonCharac);
                    list.Add(charac);
                }
            }

            return(list);
        }