Global.asax.cs

81 lines | 2.228 kB Blame History Raw Download
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;

using System.IO;

using Newtonsoft.Json.Linq;

using Tools.SingletonTool.Manager;

using Learn_CSS.APP.Web.Models.Entities;
using Learn_CSS.APP.Web.Models.ViewEntity;
using Learn_CSS.APP.Web.Models.ModelBinders;
using Learn_CSS.APP.Web.Models.Services;

namespace Learn_CSS.APP.Web
{
    public class MvcApplication : System.Web.HttpApplication
    {
        //static readonly string TaskDirectory = "Tasks";

        public string GetPath_AppData => Server.MapPath("~/AppData");

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            RegisterModelBinders();
            RegisterTaskStorage();

        }

        private void RegisterModelBinders() 
        {
            ModelBinders.Binders.Add(typeof(JObject), new JsonModelBinder());
            ModelBinders.Binders.Add(typeof(ValidateEntity), new ValidateEntityBinder());
        }

        private void RegisterTaskStorage() 
        {
            //try
            //{
                var stor =
                    new SignlethonWithParamsManager<Storage, StorageParams>(new StorageParams()
                    {
                        Directory = GetPath_AppData,
                        TaskSerializerService = new TaskSerializerService('|')
                    }).Get();

                stor.Load();

                stor.Save();
            //}
            //catch (Exception ex)
            //{
            //    return;
            //}
            //if (stor.data.Count == 0) 
            //{
            //    for (int i = 0; i < 2; i++)
            //    {
            //        stor.data.Add(new TaskEntity() 
            //        {
            //            HTML_Text = "Text " + i,
            //            HTML_Template = "Template " + i,
            //            JSON_Result = "Result " + i
            //        });
            //    }
            //}            
        }

    }
}