Exemple #1
0
        public ActionResult MakeTheme(int docID, int attachmentID)
        {
            var item = models.GetTable <Article>().Where(a => a.DocID == docID).FirstOrDefault();

            if (item == null)
            {
                return(Json(new { result = false, message = "文章不存在!!" }));
            }

            var attachment = models.GetTable <Attachment>().Where(a => a.AttachmentID == attachmentID).FirstOrDefault();

            if (attachment == null)
            {
                return(Json(new { result = false, message = "圖檔不存在!!" }));
            }


            try
            {
                item.Illustration = attachment.AttachmentID;
                models.SubmitChanges();
                return(Json(new { result = true, message = "資料已更新!!" }));
            }
            catch (Exception ex)
            {
                ApplicationLogging.CreateLogger <InformationController>().LogError(ex, ex.Message);
                return(Json(new { result = false, message = ex.Message }));
            }
        }
        // GET: Error
        public async Task <ActionResult> GetBarCode39Async(String code)
        {
            Response.ContentType = "image/Jpeg";
            //response.Buffer = true;
            //response.ExpiresAbsolute = System.DateTime.Now.AddMilliseconds(0);
            //response.Expires = 0;

            if (!String.IsNullOrEmpty(code))
            {
                try
                {
                    using (Bitmap img = code.GetCode39(false))
                    {
                        img.SetResolution(_dpi, _dpi);
                        using (FileBufferingWriteStream output = new FileBufferingWriteStream())
                        {
                            img.Save(output, ImageFormat.Jpeg);
                            //output.Seek(0, SeekOrigin.Begin);
                            await output.DrainBufferAsync(Response.Body);
                        }
                    }
                }
                catch (Exception ex)
                {
                    ApplicationLogging.CreateLogger <PublishedController>().LogError(ex, ex.Message);
                }
            }

            //context.Response.CacheControl = "no-cache";
            //context.Response.AppendHeader("Pragma", "No-Cache");

            return(new EmptyResult());
        }
Exemple #3
0
        public ActionResult RemoveMember(EnterpriseGroupMemberViewModel viewModel)
        {
            ViewBag.ViewModel = viewModel;

            var item = models.GetTable <EnterpriseCourseMember>().Where(m => m.ContractID == viewModel.ContractID &&
                                                                        m.UID == viewModel.UID).FirstOrDefault();

            if (item == null)
            {
                return(Json(new { result = false, message = "資料錯誤!!" }));
            }

            try
            {
                models.ExecuteCommand(@"DELETE FROM RegisterLesson
                        FROM     EnterpriseCourseContract INNER JOIN
                                    RegisterLessonEnterprise ON EnterpriseCourseContract.ContractID = RegisterLessonEnterprise.ContractID INNER JOIN
                                    RegisterLesson ON RegisterLessonEnterprise.RegisterID = RegisterLesson.RegisterID
                        WHERE   (EnterpriseCourseContract.ContractID = {0}) AND (RegisterLesson.UID = {1})", item.ContractID, item.UID);

                models.DeleteAny <EnterpriseCourseMember>(m => m.ContractID == viewModel.ContractID &&
                                                          m.UID == viewModel.UID);

                return(Json(new { result = true }));
            }
            catch (Exception ex)
            {
                ApplicationLogging.CreateLogger <EnterpriseProgramController>().LogError(ex, ex.Message);;
                return(Json(new { result = false, message = ex.Message }));
            }
        }
Exemple #4
0
        public static IQueryable <T> Sort <T>(this IQueryable <T> source, QuerySet querySet, IDictionary <string, IEnumerable <Expression <Func <T, object> > > > selectors)
        {
            // TODO add better support to filter on multiple fields.
            // Now we assume all fields are sorted ASC or DESC. But actually querySet.Sort should support multiple fields
            IEnumerable <Expression <Func <T, object> > > selectorsForField;

            var field = querySet.Sort.Field;

            if (field != null && selectors.TryGetValue(field, out selectorsForField))
            {
                int i = 0;
                foreach (Expression <Func <T, object> > selector in selectorsForField)
                {
                    if (i == 0)
                    {
                        source = querySet.Sort.IsAscending ? source.OrderBy(selector) : source.OrderByDescending(selector);
                    }
                    else
                    {
                        var orderedQueryable = (IOrderedQueryable <T>)source;
                        source = querySet.Sort.IsAscending ? orderedQueryable.ThenBy(selector) : orderedQueryable.ThenByDescending(selector);
                    }
                    i++;
                }
            }
            else if (field != null)
            {
                ApplicationLogging.CreateLogger(typeof(BaseQueryExtensions).AssemblyQualifiedName)
                .LogWarning("'{Value}' is not supported as sort value on type {Type}", field, typeof(T).AssemblyQualifiedName);
            }

            return(source);
        }
Exemple #5
0
        /// <summary>
        /// Serialize the object to xml. Returns true if successful, false if failed. The out property is set to null on a failure, otherwise it contains the XML
        /// This code is designed to produce an XML Fragment suitable for use with a REST API. It omits the <xml/> declaration in the output
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="domainObject">The domain object.</param>
        /// <param name="body">The body.</param>
        /// <returns><c>true</c> if serialized, <c>false</c> otherwise.</returns>
        public static bool TryBuild <T>(T domainObject, out string body)
        {
            var ns = new XmlSerializerNamespaces();

            ns.Add("", "");
            var serializer = new XmlSerializer(typeof(T));
            var textWriter = new StringWriter();
            var writer     = XmlWriter.Create(textWriter, new XmlWriterSettings {
                OmitXmlDeclaration = true
            });

            try
            {
                serializer.Serialize(writer, domainObject, ns);
                body = textWriter.ToString();
                return(true);
            }
            catch (Exception e)
            {
                var logger = ApplicationLogging.CreateLogger <XmlRequestBuilder>();
                logger.LogTrace(e.Message);
                body = null;
                return(false);
            }
            finally
            {
                writer.Dispose();
                textWriter.Dispose();
            }
        }
Exemple #6
0
        public ActionResult UploadResource(int id)
        {
            var item = models.GetTable <Article>().Where(a => a.DocID == id).FirstOrDefault();

            if (item == null)
            {
                return(Json(new { result = false, message = "文章不存在!!" }));
            }
            if (Request.Form.Files.Count <= 0)
            {
                return(Json(new { result = false, message = "檔案上載失敗!!" }));
            }

            try
            {
                String storePath = Path.Combine(FileLogger.Logger.LogDailyPath, Guid.NewGuid().ToString() + Path.GetExtension(Request.Form.Files[0].FileName));
                Request.Form.Files[0].SaveAs(storePath);

                models.GetTable <Attachment>().InsertOnSubmit(new Attachment
                {
                    DocID      = item.DocID,
                    StoredPath = storePath
                });
                models.SubmitChanges();
                return(Json(new { result = true }));
            }
            catch (Exception ex)
            {
                ApplicationLogging.CreateLogger <InformationController>().LogError(ex, ex.Message);
                return(Json(new { result = false, message = ex.Message }));
            }
        }
Exemple #7
0
        /// <summary>
        /// Starts a mutation test run
        /// </summary>
        /// <exception cref="StrykerInputException">For managed exceptions</exception>
        /// <param name="options">The user options</param>
        public StrykerRunResult RunMutationTest(StrykerOptions options)
        {
            // start stopwatch
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            // Create output dir with gitignore
            _fileSystem.Directory.CreateDirectory(options.OutputPath);
            _fileSystem.File.Create(Path.Combine(options.OutputPath, ".gitignore")).Close();
            using (var file = _fileSystem.File.CreateText(Path.Combine(options.OutputPath, ".gitignore")))
            {
                file.WriteLine("*");
            }

            // setup logging
            ApplicationLogging.ConfigureLogger(options.LogOptions);
            var logger = ApplicationLogging.LoggerFactory.CreateLogger <StrykerRunner>();

            logger.LogDebug("Stryker started with options: {0}",
                            JsonConvert.SerializeObject(options, new StringEnumConverter()));

            try
            {
                // initialize
                _reporter = ReporterFactory.Create(options);
                _initialisationProcess = _initialisationProcess ?? new InitialisationProcess();
                _input = _initialisationProcess.Initialize(options);

                _mutationTestProcess = _mutationTestProcess ?? new MutationTestProcess(
                    mutationTestInput: _input,
                    reporter: _reporter,
                    mutationTestExecutor: new MutationTestExecutor(_input.TestRunner));

                // initial test
                _input.TimeoutMs = _initialisationProcess.InitialTest(options);

                // mutate
                _mutationTestProcess.Mutate(options);

                // coverage
                var coverage = _initialisationProcess.GetCoverage(options);

                _mutationTestProcess.Optimize(coverage);

                // test mutations and return results
                return(_mutationTestProcess.Test(options));
            }
            catch (Exception ex) when(!(ex is StrykerInputException))
            {
                logger.LogError(ex, "An error occurred during the mutation test run ");
                throw;
            }
            finally
            {
                // log duration
                stopwatch.Stop();
                logger.LogInformation("Time Elapsed {0}", stopwatch.Elapsed);
            }
        }
Exemple #8
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app,
                              IHostingEnvironment env,
                              ILoggerFactory loggerFactory)
        {
            loggerFactory
            .AddConsole()
            .AddDebug();

            ApplicationLogging.ConfigureLogger(loggerFactory);


            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseMvc();
            //just for testing now
            app.Run(async(context) =>
            {
                var logger = loggerFactory.CreateLogger("TodoApiSample.Startup");
                logger.LogInformation("No endpoint found for request {path}", context.Request.Path);
                await context.Response.WriteAsync("No endpoint found - try /api/todo.");
            });
        }
Exemple #9
0
        public Startup(IHostingEnvironment env)
        {
            var builder = new ConfigurationBuilder()
                          .SetBasePath(Directory.GetCurrentDirectory())
                          .AddJsonFile(config =>
            {
                config.Path           = "appSettings.json";
                config.ReloadOnChange = true;
            })
                          .AddJsonFile(options =>
            {
                options.Path           = $"appsettings.{env.EnvironmentName}.json";
                options.ReloadOnChange = true;
                options.Optional       = true;
            }
                                       )
                          .AddEnvironmentVariables();

            var configSettings = new AppSettings();

            builder.Build().Bind(configSettings);

            var settingsBuilder = new ConfigurationBuilder()
                                  .AddCustomConfig(configSettings);

            Configuration = settingsBuilder.Build();

            Log.Logger = ApplicationLogging
                         .GetSeriLogger(Configuration.AsEnumerable()
                                        .ToDictionary(x => x.Key, x => x.Value));
            _stsServer = "https://localhost:44364";//Configuration["StsServer"];
        }
Exemple #10
0
        public async Task <ActionResult> SearchWord(incParams incp, filter f, int count, int maxpage)
        {
            //global::System.Resources.ResourceManager rm = new global::System.Resources.ResourceManager("mphdeck.Resources.idispl", typeof(Resources.idispl).GetTypeInfo().Assembly);
            //System.Resources.ResourceManager rm = new System.Resources.ResourceManager(typeof(mphdeck.Resources.idispl));
            //System.Resources.ResourceManager rm = System.Resources.ResourceManager("mphdeck.Resources.idispl", typeof(Resources.idispl).GetTypeInfo().Assembly);
            //string test2 = mphdeck.Resources.idispl.ResourceManager.GetString("bname_ua", new System.Globalization.CultureInfo("uk"));
            //string test1 = mphdeck.Resources.idispl.ResourceManager.GetString("bname_ua", new System.Globalization.CultureInfo("en"));
            //System.Resources.ResourceManager resourceManager = new System.Resources.ResourceManager("MyResource", Assembly.GetExecutingAssembly
            //string test2 = rm.GetString("bname_ua", new System.Globalization.CultureInfo("uk"));
            //string test1 = rm.GetString("bname_ua", new System.Globalization.CultureInfo("en"));
            try
            {
                var dpg = new grdictParams()
                {
                    incp = incp, f = f, id_lang = db.lid.id_lang
                };
                dpg.count   = count;
                dpg.maxpage = maxpage;
                dpg.entry   = await db.getEntry(incp.wid);

                ViewBag.dp = new dictParams()
                {
                    gr = dpg, vtype = viewtype.dict
                };
                return(View("Index", dpg));
            }
            catch (Exception ex)
            {
                ApplicationLogging.CreateLogger <inflectionController>().LogError(new EventId(0), ex, ex.Message);
                return(BadRequest("Зверніться до розробника"));
            }
        }
Exemple #11
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory)
        {
            ApplicationLogging.ConfigureLogger(loggerFactory);

            Util._logger         = ApplicationLogging.CreateLogger("Util");
            EntityHelper._logger = ApplicationLogging.CreateLogger("EntityHelper");

            if (env.IsDevelopment())
            {
                app.UseExceptionHandler("/error-local-development");
            }
            else
            {
                app.UseExceptionHandler("/error");
            }

            app.UseRouting();

            // global cors policy
            app.UseCors(x => x
                        .AllowAnyOrigin()
                        .AllowAnyMethod()
                        .AllowAnyHeader());

            app.UseAuthentication();
            app.UseAuthorization();

            app.UseEndpoints(endpoints => {
                endpoints.MapControllers();
            });
        }
 public ApplicationLogging_Tests()
 {
     _applicationLogging = new ApplicationLogging();
     _testRO             = new ResultsObject();
     _roTestHelper       = new ResultsObjectTestDataHelper();
     _testRO             = _roTestHelper.CreateTestData();
 }
Exemple #13
0
        public void DoJob()
        {
            using (ModelSource <UserProfile> models = new ModelSource <UserProfile>())
            {
                try
                {
                    models.RegisterMonthlyGiftLesson();
                }
                catch (Exception ex)
                {
                    ApplicationLogging.CreateLogger <MonthlyJob>()
                    .LogError(ex, ex.Message);
                }
            }

            using (ModelSource <UserProfile> models = new ModelSource <UserProfile>())
            {
                try
                {
                    models.ClearUnpaidOverdueContract();
                }
                catch (Exception ex)
                {
                    ApplicationLogging.CreateLogger <MonthlyJob>()
                    .LogError(ex, ex.Message);
                }
            }
        }
        public void Run()
        {
            var logger = ApplicationLogging.CreateLogger <GCController>();

            logger.LogInformation("GC.Collect()");
            GC.Collect();
        }
        //public ActionResult InquireProjectCourse(LessonPriceQueryViewModel viewModel)
        //{
        //    IQueryable<LessonPriceType> items = models.GetTable<LessonPriceType>()
        //        .Where(p => !p.SeriesID.HasValue)
        //        .Where(p => p.BranchID.HasValue)
        //        .Where(p => p.IsInternalLesson == null)
        //        .Where(p => p.IsWelfareGiftLesson == null)
        //        .Where(p => p.Status == (int)Naming.LessonPriceStatus.一般課程 || p.Status == (int)Naming.LessonPriceStatus.已刪除);

        //    if (viewModel.Status.HasValue)
        //    {
        //        items = items.Where(p => p.Status == viewModel.Status);
        //    }
        //    if (viewModel.BranchID.HasValue)
        //    {
        //        items = items.Where(p => p.BranchID == viewModel.BranchID);
        //    }

        //    return View("~/Views/LessonPrice/Module/ProjectCourseList.ascx", items);
        //}

        public ActionResult DeleteLessonPrice(LessonPriceQueryViewModel viewModel)
        {
            LessonPriceType item;

            try
            {
                item = models.DeleteAny <LessonPriceType>(p => p.PriceID == viewModel.PriceID);
                if (item != null)
                {
                    return(Json(new { result = true }));
                }
                return(Json(new { result = false, message = "資料錯誤!!" }));
            }
            catch (Exception ex)
            {
                ApplicationLogging.CreateLogger <LessonPriceController>().LogError(ex, ex.Message);
            }

            item = models.GetTable <LessonPriceType>().Where(l => l.PriceID == viewModel.PriceID).FirstOrDefault();
            if (item == null)
            {
                return(Json(new { result = false, message = "資料錯誤!!" }));
            }

            item.Status = (int)Naming.LessonSeriesStatus.已停用;
            models.SubmitChanges();

            return(Json(new { result = true, message = "價目已使用,無法刪除,已改為停用!!" }));
        }
Exemple #16
0
        public async Task <IActionResult> Index(incParams incp, filter f, pclsfilter pclsf)
        {
            try
            {
                var dp = new dictParams()
                {
                    gr = new grdictParams()
                    {
                        f = f, incp = incp
                    },
                    pcls = new pclsdictParams()
                    {
                        indents = db.indent, f = pclsf, pclsinfo = await db.getPClass(pclsf.pclassPcls)
                    },
                    vtype = viewtype.pclass
                };

                if (pclsf.ispofsPcls)
                {
                    dp.pcls.indents = (from c in db.indents where c.gr_id == pclsf.pofsPcls select c).ToArray();
                }
                ViewBag.dp = dp;
                return(View(dp.pcls.pclsinfo));
            }
            catch (Exception ex)
            {
                ApplicationLogging.CreateLogger <flexesController>().LogError(new EventId(0), ex, ex.Message);
                return(BadRequest("Зверніться до розробника"));
            }
        }
Exemple #17
0
        private static async Task Main()
        {
            //Initialize the English built-in models
            Catalyst.Models.English.Register();

            //Storage.Current = new OnlineRepositoryStorage(new DiskStorage("catalyst-models"));

            Console.OutputEncoding = Encoding.UTF8;
            ApplicationLogging.SetLoggerFactory(LoggerFactory.Create(lb => lb.AddConsole()));

            // Catalyst currently supports 3 different types of models for Named Entity Recognition (NER):
            // - Gazetteer-like(i.e. [Spotter](https://github.com/curiosity-ai/catalyst/blob/master/Catalyst/src/Models/EntityRecognition/Spotter.cs))
            // - Regex-like(i.e. [PatternSpotter](https://github.com/curiosity-ai/catalyst/blob/master/Catalyst/src/Models/EntityRecognition/PatternSpotter.cs))
            // - Perceptron (i.e. [AveragePerceptronEntityRecognizer](https://github.com/curiosity-ai/catalyst/blob/master/Catalyst/src/Models/EntityRecognition/AveragePerceptronEntityRecognizer.cs))



            //var s = typeof(Catalyst.Models.English).Assembly.GetManifestResourceStream($"{typeof(Catalyst.Models.English).Assembly.GetName().Name}.Resources.sentence-detector.bin");
            //foreach(var name in typeof(Catalyst.Models.English).Assembly.GetManifestResourceNames())
            //{
            //    Console.WriteLine(name);
            //}

            var sd = await SentenceDetector.FromStoreAsync(Language.English, -1, "");

            var a = new AveragePerceptronTagger(Language.English, 0, "");
            await a.LoadDataAsync();


            var p = await AveragePerceptronTagger.FromStoreAsync(Language.English, -1, "");

            await DemonstrateAveragePerceptronEntityRecognizerAndPatternSpotter();

            DemonstrateSpotter();
        }
Exemple #18
0
        public async Task <ActionResult> SearchWord(etymincParams incp, etymfilter f, int count, int maxpage)
        {
            try
            {
                var dps = new etymdictParams()
                {
                    incp = incp, f = f
                };
                dps.count   = count;
                dps.maxpage = maxpage;
                dps.entry   = await db.getEntry(incp.idclass);

                dps.w = dps.entry != null?dps.entry.e_classes.Where(c => c.id == incp.idclass).FirstOrDefault().etymons.Where(c => c.id == incp.wid).FirstOrDefault().word : "";

                ViewBag.dp = new dictParams()
                {
                    etym = dps, vtype = viewtype.etym
                };
                return(View("Index", dps));
            }
            catch (Exception ex)
            {
                ApplicationLogging.CreateLogger <etymController>().LogError(new EventId(0), ex, ex.Message);
                return(BadRequest("Зверніться до розробника"));
            }
        }
Exemple #19
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
        {
            if (!Env.EnvironmentName.Equals("production", StringComparison.CurrentCultureIgnoreCase))
            {
                app.UseDeveloperExceptionPage();
            }
            ;

            app.UseSwagger();
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("v1/swagger.json", $"Expense Tracker API V1");
            });

            app.UseForwardedHeaders();

            app.UseHttpsRedirection();
            app.UseRouting();
            app.UseStaticFiles();

            ApplicationLogging.ConfigureLogger(loggerFactory);

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
        public ActionResult UpdateBonusPromotionStatus(PromotionViewModel viewModel, bool?tryToDelete)
        {
            var item = loadPromotionItem(viewModel);

            if (item == null)
            {
                return(View("~/Views/Shared/JsAlert.cshtml", model: "活動方案資料錯誤!!"));
            }

            item.PDQQuestion.First().PDQQuestionExtension.Status = (int?)viewModel.Status;
            models.SubmitChanges();

            if (tryToDelete == true)
            {
                try
                {
                    models.ExecuteCommand("delete PDQGroup where GroupID = {0}", item.GroupID);
                    return(Json(new { result = true }));
                }
                catch (Exception ex)
                {
                    ApplicationLogging.CreateLogger <PromotionController>().LogError(ex, ex.Message);
                    return(Json(new { result = false, message = ex.Message }));
                }
            }
            else
            {
                return(Json(new { result = true }));
            }
        }
Exemple #21
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseHttpsRedirection();
            ApplicationLogging.ConfigureNlogLogger(loggerFactory);
            app.UseRouting();

            // global cors policy
            app.UseCors(x => x
                        .AllowAnyOrigin()
                        .AllowAnyMethod()
                        .AllowAnyHeader());

            app.UseAuthentication();
            app.UseAuthorization();

            // Enable middleware to serve generated Swagger as a JSON endpoint.
            app.UseSwagger();

            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "API V1.0");
            });

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
Exemple #22
0
        public async Task <ActionResult> SearchWord(synincParams incp, synsetsfilter f, int count, int maxpage)
        {
            try
            {
                var dps = new syndictParams()
                {
                    incp = incp, f = f, id_lang = db.lid.id_lang
                };
                dps.count   = count;
                dps.maxpage = maxpage;
                dps.entry   = await db.getEntry(incp.idset);

                dps.w      = dps.entry != null ? (from c in dps.entry._wlist where c.id == incp.wid select c.word).FirstOrDefault() : "";
                ViewBag.dp = new dictParams()
                {
                    syn = dps, vtype = viewtype.synsets
                };
                return(View("Index", dps));
            }
            catch (Exception ex)
            {
                ApplicationLogging.CreateLogger <synsetsController>().LogError(new EventId(0), ex, ex.Message);
                return(BadRequest("Зверніться до розробника"));
            }
        }
Exemple #23
0
        public ActionResult ContactUs(String email, String userName, String subject, String comment)
        {
            ThreadPool.QueueUserWorkItem(t => {
                try
                {
                    StringBuilder body = new StringBuilder();
                    System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
                    message.ReplyToList.Add(Startup.Properties["WebMaster"]);
                    message.From = new System.Net.Mail.MailAddress(email, userName);
                    message.To.Add(Startup.Properties["WebMaster"]);
                    message.Subject    = subject;
                    message.IsBodyHtml = true;

                    message.Body = HttpUtility.HtmlDecode(comment);

                    System.Net.Mail.SmtpClient smtpclient = new System.Net.Mail.SmtpClient(Startup.Properties["SmtpServer"]);
                    //smtpclient.Credentials = CredentialCache.DefaultNetworkCredentials;
                    smtpclient.Send(message);
                }
                catch (Exception ex)
                {
                    ApplicationLogging.CreateLogger <InformationController>().LogError(ex, ex.Message);
                }
            });

            ViewBag.Success = "Your comment was successfully added!";
            return(View("Success"));
        }
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                //app.UseExceptionHandler("/Home/Error");
                app.UseDeveloperExceptionPage();
                app.UseHsts();
            }
            app.UseStaticFiles();

            app.UseRouting();

            //app.UseAuthorization();
            //留意寫Code順序,先執行驗證...
            app.UseAuthentication();
            app.UseAuthorization();//Controller、Action才能加上 [Authorize] 屬性
            app.UseSession();

            app.Use(next =>
                    context =>
            {
                context.Request.EnableBuffering();
                return(next(context));
            });

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "Official",
                    pattern: "Official/{action}/{id?}/{keyID?}",
                    defaults: new { controller = "MainActivity", action = "Index" }
                    );

                endpoints.MapControllerRoute(
                    name: "OfficialActionName",
                    pattern: "Official/{*actionName}",
                    defaults: new { controller = "MainActivity", action = "HandleUnknownAction" });

                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");

                endpoints.MapControllerRoute(
                    name: "actionName",
                    pattern: "{controller}/{*actionName}",
                    defaults: new { action = "HandleUnknownAction" });
            });


            //call ConfigureLogger in a centralized place in the code
            ApplicationLogging.ConfigureLogger(loggerFactory);
            //set it as the primary LoggerFactory to use everywhere
            ApplicationLogging.LoggerFactory = loggerFactory;
            Environment = env;
        }
Exemple #25
0
        static async Task Main(string[] args)
        {
            Console.OutputEncoding = Encoding.UTF8;
            ApplicationLogging.SetLoggerFactory(LoggerFactory.Create(lb => lb.AddConsole()));

            //Configures the model storage to use the online repository backed by the local folder ./catalyst-models/
            Storage.Current = new OnlineRepositoryStorage(new DiskStorage("catalyst-models"));


            //Download the Reuters corpus if necessary
            var(train, test) = await Corpus.Reuters.GetAsync();

            //Parse the documents using the English pipeline, as the text data is untokenized so far
            var nlp = Pipeline.For(Language.English);

            var trainDocs = nlp.Process(train).ToArray();
            var testDocs  = nlp.Process(test).ToArray();

            //Train a FastText supervised classifier with a multi-label loss (OneVsAll)
            var fastText = new FastText(Language.English, 0, "Reuters-Classifier");

            fastText.Data.Type                    = FastText.ModelType.Supervised;
            fastText.Data.Loss                    = FastText.LossType.OneVsAll;
            fastText.Data.LearningRate            = 1f;
            fastText.Data.Dimensions              = 256;
            fastText.Data.Epoch                   = 100;
            fastText.Data.MinimumWordNgramsCounts = 5;
            fastText.Data.MaximumWordNgrams       = 3;
            fastText.Data.MinimumCount            = 5;

            fastText.Train(trainDocs);

            //You can also auto-tune the model using the algorithm from https://ai.facebook.com/blog/fasttext-blog-post-open-source-in-brief/
            fastText.AutoTuneTrain(trainDocs, testDocs, new FastText.AutoTuneOptions());

            //Compute predictions
            Dictionary <IDocument, Dictionary <string, float> > predTrain, predTest;

            using (new Measure(Logger, "Computing train-set predictions", trainDocs.Length))
            {
                predTrain = trainDocs.AsParallel().Select(d => (Doc: d, Pred: fastText.Predict(d))).ToDictionary(d => d.Doc, d => d.Pred);
            }

            using (new Measure(Logger, "Computing test set predictions", testDocs.Length))
            {
                predTest = testDocs.AsParallel().Select(d => (Doc: d, Pred: fastText.Predict(d))).ToDictionary(d => d.Doc, d => d.Pred);
            }

            var resultsTrain = ComputeStats(predTrain);
            var resultsTest  = ComputeStats(predTest);

            Console.WriteLine("\n\n\n--- Results ---\n\n\n");
            foreach (var res in resultsTrain.Zip(resultsTest))
            {
                Console.WriteLine($"\tScore cutoff: {res.First.Cutoff:n2} Train: F1={res.First.F1:n2} P={res.First.Precision:n2} R={res.First.Recall:n2} Test: F1={res.Second.F1:n2} P={res.Second.Precision:n2} R={res.Second.Recall:n2}");
            }

            Console.ReadLine();
        }
Exemple #26
0
        static async Task Main(string[] args)
        {
            ApplicationLogging.SetLoggerFactory(LoggerFactory.Create(builder => builder.AddConsole()));
            ForceInvariantCultureAndUTF8Output();

            await Parser.Default
            .ParseArguments <CommandLineOptions>(args)
            .MapResult(
                async options =>
            {
                if (string.IsNullOrWhiteSpace(options.Token))
                {
                    Storage.Current = new DiskStorage(options.DiskStoragePath);
                }
                else
                {
                    //For uploading on the online models repository
                    Storage.Current = new OnlineWriteableRepositoryStorage(new DiskStorage(options.DiskStoragePath), options.Token);
                }

                Thread.CurrentThread.Priority = ThreadPriority.AboveNormal;

                using (var p = Process.GetCurrentProcess())
                {
                    p.PriorityClass = ProcessPriorityClass.High;
                }

                if (!string.IsNullOrWhiteSpace(options.UniversalDependenciesPath))
                {
                    TrainSentenceDetector.Train(options.UniversalDependenciesPath);
                    TrainPOSTagger.Train(udSource: options.UniversalDependenciesPath, ontonotesSource: options.OntonotesPath);
                }

                if (!string.IsNullOrWhiteSpace(options.WikiNERPath))
                {
                    await TrainWikiNER.TrainAsync(options.WikiNERPath, Language.English, 0, "WikiNER");
                    await TrainWikiNER.TrainAsync(options.WikiNERPath, Language.French, 0, "WikiNER");
                    await TrainWikiNER.TrainAsync(options.WikiNERPath, Language.German, 0, "WikiNER");
                    await TrainWikiNER.TrainAsync(options.WikiNERPath, Language.Spanish, 0, "WikiNER");
                    await TrainWikiNER.TrainAsync(options.WikiNERPath, Language.Italian, 0, "WikiNER");
                    await TrainWikiNER.TrainAsync(options.WikiNERPath, Language.Portuguese, 0, "WikiNER");
                    await TrainWikiNER.TrainAsync(options.WikiNERPath, Language.Russian, 0, "WikiNER");
                    await TrainWikiNER.TrainAsync(options.WikiNERPath, Language.Dutch, 0, "WikiNER");
                    await TrainWikiNER.TrainAsync(options.WikiNERPath, Language.Polish, 0, "WikiNER");
                }

                if (!string.IsNullOrWhiteSpace(options.FastTextLanguageSentencesPath))
                {
                    TrainLanguageDetector.Train(options.FastTextLanguageSentencesPath);
                    TrainLanguageDetector.Test(options.FastTextLanguageSentencesPath);
                }

                if (!string.IsNullOrWhiteSpace(options.LanguageJsonPath))
                {
                    TrainLanguageDetector.CreateLanguageDetector(options.LanguageJsonPath);
                }
            },
                error => Task.CompletedTask);
        }
        public MsSqlTests()
        {
            ViewModelBindable.isUnitTests = true;

            InitLogging(this);

            _logger = ApplicationLogging.CreateLogger <MsSqlTests>();
        }
Exemple #28
0
        public void TestGetLoggerByType()
        {
            ILogger logger = ApplicationLogging.CreateLogger(typeof(Program));
            Type    type   = logger.GetType();

            Assert.Equal("Logger", type.Name);
            Assert.Equal("Microsoft.Extensions.Logging.Logger", type.FullName);
        }
 public BotLogic(ITaskRepository _taskRepository, IUserRequestRepository _userRequestRepository, IEmailScenarioDecider _EmailScenarioFactory)
 {
     _logger = ApplicationLogging.CreateLogger();
     UserRequestRepository = _userRequestRepository;
     TaskRepository        = _taskRepository;
     Configurations        = new BotConfiguration();
     EmailScenarioFactory  = _EmailScenarioFactory;
 }
Exemple #30
0
        private static void HandleExceptionAsync(HttpContext context, Exception exception)
        {
            ILogger _logger = ApplicationLogging.CreateLogger <ExceptionMiddleware>() as ILogger <ExceptionMiddleware>;

            _logger.LogError($"Something went wrong: {exception}");

            context.Response.Redirect("/Error");
        }