Example #1
0
        public TokenSerivce(DataContext dataContext, ConfigFileService configFileService, IDistributedIdGenerator idGenerator)
        {
            this.idGenerator = idGenerator;

            this.dataContext = dataContext;
            this.config      = configFileService.WebConfig;
        }
Example #2
0
        /// <summary>
        /// 初始化模板
        /// </summary>
        private void InitTemplateConfig()
        {
            if (RuntimeEnvironment.IsWindows)
            {
                if (!Directory.Exists(@"C:\morenote"))
                {
                    Directory.CreateDirectory(@"C:\morenote");
                }
            }
            else
            {
                if (!Directory.Exists(@"/morenote"))
                {
                    Directory.CreateDirectory(@"/morenote");
                }
            }
            WebSiteConfig webSiteConfig = new WebSiteConfig();
            var           options       = new JsonSerializerOptions
            {
                WriteIndented = true,//优质打印 无压缩
            };
            string json = System.Text.Json.JsonSerializer.Serialize(webSiteConfig, options);

            File.Create(path).Close();
            File.WriteAllText(path, json);
        }
Example #3
0
        public FaceService(WebSiteConfig webConfig)
        {
            var config = webConfig.SecurityConfig.FaceConfig;

            this.directory = config.ModelFilesDirectory;
            this.tolerance = config.Tolerance;
        }
Example #4
0
        protected void Application_Start()
        {
            IUnityContainer container = UnityMVC.Build();

            IocConfig.Register(container);
            UnityMVC.Start(container);

            WebSiteConfig.Load();

            AreaRegistration.RegisterAllAreas();

            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            var allClientModelTypes = Assembly.GetExecutingAssembly().GetTypes()
                                      .Where(a => !a.IsAbstract && !a.IsGenericType && a.IsSubclassOf(typeof(ClientModel))).ToList();

            foreach (var clientModelType in allClientModelTypes)
            {
                ModelBinders.Binders.Add(clientModelType, new ClientModelMvcModelBinder());
            }

            ForceCallingStaticContructor();
        }
 private ConfigFileService()
 {
     if (config == null)
     {
         config = GetWebConfig();
     }
 }
        public static WebSiteConfig GetWebConfig()
        {
            if (config == null)
            {
                lock (locker)
                {
                    if (config == null)
                    {
                        if (RuntimeEnvironment.IsWindows)
                        {
                            path = @"C:\etc\morenote\WebSiteConfig.json";
                        }
                        else
                        {
                            path = "/etc/morenote/WebSiteConfig.json";
                        }
                        if (!File.Exists(path))
                        {
                            throw new IOException($"{path}不存在");
                        }
                        string json = File.ReadAllText(path);
                        config = System.Text.Json.JsonSerializer.Deserialize <WebSiteConfig>(json);
                    }
                }
            }

            return(config);
        }
Example #7
0
 public ConfigFileService()
 {
     if (_config == null)
     {
         this._config = WebConfig;
     }
 }
Example #8
0
 public NoteFileService(DataContext dataContext, ConfigFileService ConfigFileService)
 {
     this.dataContext       = dataContext;
     this.ConfigFileService = ConfigFileService;
     this.storeConfig       = ConfigFileService.WebConfig.FileStoreConfig;
     this.webSiteConfig     = ConfigFileService.WebConfig;
 }
Example #9
0
        public Startup(IConfiguration configuration, IWebHostEnvironment env)
        {
            Configuration = configuration;
            this._env     = env;
            ConfigFileService configFileService = new ConfigFileService();

            config = configFileService.WebConfig;
        }
Example #10
0
 public AuthService(DataContext dataContext, IPasswordStore passwordStore, NotebookService notebookService, ConfigFileService configFileService, IDistributedIdGenerator idGenerator, PasswordStoreFactory passwordStoreFactory)
 {
     this.idGenerator          = idGenerator;
     this.dataContext          = dataContext;
     this.passwordStore        = passwordStore;
     this.NotebookService      = notebookService;
     this.config               = configFileService.WebConfig;
     this.passwordStoreFactory = passwordStoreFactory;
 }
Example #11
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="dataContext"></param>
 /// <param name="configFileService"></param>
 public FIDO2Service(DataContext dataContext, IDistributedCache distributedCache, ConfigFileService configFileService, IFido2 fido2, IDistributedIdGenerator IdGenerator)
 {
     this.IdGenerator      = IdGenerator;
     this.dataContext      = dataContext;
     this.distributedCache = distributedCache;
     this.config           = configFileService.WebConfig;
     this.fido2Config      = config.SecurityConfig.FIDO2Config;
     this._fido2           = fido2;
 }
        public static void Save(WebSiteConfig tempConfig, string onePath)
        {
            if (tempConfig == null)
            {
                throw new System.Exception("config==null,无法将config持久化保存。");
            }
            string json = System.Text.Json.JsonSerializer.Serialize(tempConfig);

            File.WriteAllText(onePath, json);
        }
Example #13
0
        private void InitServers()
        {
            var sites = WebSiteConfig.GetAllSites();

            foreach (var site in sites)
            {
                var server = new HttpServer(site, log);
                servers.Add(server);
            }
        }
Example #14
0
        public void UpYunTest()
        {
            WebSiteConfig postgreSQLConfig = ConfigManager.GetPostgreSQLConfig();
            UpYun         upyun            = new UpYun(postgreSQLConfig.upyunBucket, postgreSQLConfig.upyunUsername, postgreSQLConfig.upyunPassword);
            ArrayList     str = upyun.readDir("/");

            foreach (var item in str)
            {
                Console.WriteLine(item);
            }
        }
Example #15
0
        public void PresignedGetObjectAsyncTest()
        {
            ConfigFileService configFileService = new ConfigFileService();
            WebSiteConfig     webSiteConfig     = configFileService.WebConfig;

            Console.WriteLine(webSiteConfig.MinIOConfig.Endpoint);

            var fileStore = new MinIOFileStoreService(webSiteConfig.MinIOConfig);
            var result    = fileStore.PresignedGetObjectAsync(webSiteConfig.MinIOConfig.NoteFileBucketName, "13a03c863d021000.png").Result;

            Console.WriteLine(result);
        }
Example #16
0
 public NoteContentService(DataContext dataContext,
                           JiebaSegmenterService jiebaSegmenter,
                           ConfigFileService configFileService,
                           ICryptographyProvider cryptographyProvider,
                           IDistributedIdGenerator idGenerator)
 {
     this.cryptographyProvider = cryptographyProvider;
     this.idGenerator          = idGenerator;
     this.dataContext          = dataContext;
     this.config = configFileService.WebConfig;
     this.jieba  = jiebaSegmenter;
 }
Example #17
0
        void addSite_SiteAddedEvent(WebSiteConfig obj)
        {
            var x = dic.Keys.Where(s => s.Config.Port == obj.Port).FirstOrDefault();

            if (x != null)
            {
                MessageBox.Show("端口号已占用!");
                return;
            }
            HttpServer server = new HttpServer(obj, log);

            AddServerNode(server);
        }
Example #18
0
        public void PutObjectAsyncTest()
        {
            ConfigFileService configFileService = new ConfigFileService();
            WebSiteConfig     webSiteConfig     = configFileService.WebConfig;

            Console.WriteLine(webSiteConfig.MinIOConfig.Endpoint);

            var fileStore  = new MinIOFileStoreService(webSiteConfig.MinIOConfig);
            var fileStream = File.OpenRead(@"C:\Users\huany\Pictures\130x130.jpg");
            var len        = fileStream.Length;

            // fileStore.PutObjectAsync("test", "/my/13a03c863d021000.png", fileStream, len).Wait();
        }
Example #19
0
 /// <summary>
 /// 从配置文件中重新加载配置文件,但是某些功能仍然需要重启程序后生效
 /// </summary>
 public void Reload()
 {
     lock (locker)
     {
         path = GetConfigPath();
         if (!File.Exists(path))
         {
             InitTemplateConfig();
         }
         string json = File.ReadAllText(path);
         this._config = System.Text.Json.JsonSerializer.Deserialize <WebSiteConfig>(json);
     }
 }
Example #20
0
 public void Save(WebSiteConfig tempConfig, string onePath)
 {
     lock (locker)
     {
         if (tempConfig == null)
         {
             return;
         }
         string json = System.Text.Json.JsonSerializer.Serialize(tempConfig);
         File.WriteAllText(onePath, json);
         _config = tempConfig;
     }
 }
Example #21
0
 public FileAPIController(AttachService attachService
                          , TokenSerivce tokenSerivce
                          , NoteFileService noteFileService
                          , UserService userService
                          , ConfigFileService configFileService
                          , IHttpContextAccessor accessor,
                          NoteService noteService
                          ) :
     base(attachService, tokenSerivce, noteFileService, userService, configFileService, accessor)
 {
     this.noteService   = noteService;
     this.webSiteConfig = configFileService.WebConfig;
 }
Example #22
0
        public void CreatTokenTest()
        {
            WebSiteConfig postgreSQLConfig = ConfigManager.GetPostgreSQLConfig();
            UpYun         upyun            = new UpYun("bucket", "username", "password");

            upyun.secret = postgreSQLConfig.upyunSecret;;
            Int32 unixTimestamp = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;

            unixTimestamp += 120;
            string _upt = upyun.CreatToken(unixTimestamp.ToString(), upyun.secret, $"/upload/debbb8740a597ca554d194818af6e560/270a9d65cfb903fb89cb21c78bd6bad106b543ca.jpg");

            Console.WriteLine($"https://upyun.morenote.top/upload/debbb8740a597ca554d194818af6e560/270a9d65cfb903fb89cb21c78bd6bad106b543ca.jpg?_upt={_upt}");
        }
Example #23
0
        private void button2_Click(object sender, EventArgs e)
        {
            WebSiteConfig cfg = new WebSiteConfig {
                SiteName = siteName.Text.Trim(), Port = port.Text.Trim(), PhysicalPath = physicalPath.Text.Trim()
            };

            if (cfg.Save())
            {
                if (SiteAddedEvent != null)
                {
                    SiteAddedEvent(cfg);
                }
                this.DialogResult = DialogResult.OK;
            }
        }
Example #24
0
        public IActionResult Install()
        {
            WebSiteConfig webSiteConfig = configFileService.WebConfig;

            if (webSiteConfig != null && webSiteConfig.IsAlreadyInstalled)
            {
                string path = RuntimeEnvironment.IsWindows?@"C:\morenote\WebSiteConfig.json":"/morenote/WebSiteConfig.json";
                return(Content($"请设置{path}的IsAlreadyInstalled变量为false"));
            }
            ViewBag.config = string.Empty;


            ViewBag.Title = "网站初始化向导";
            SetLocale();
            return(View());
        }
Example #25
0
        public BaseController(AttachService attachService
                              , TokenSerivce tokenSerivce
                              , NoteFileService noteFileService
                              , UserService userService
                              , ConfigFileService configFileService
                              , IHttpContextAccessor accessor

                              )
        {
            this.attachService     = attachService;
            this.tokenSerivce      = tokenSerivce;
            this.noteFileService   = noteFileService;
            this.configFileService = configFileService;
            this.userService       = userService;
            this._accessor         = accessor;

            config = configFileService.WebConfig;
        }
Example #26
0
        public AuthController(AttachService attachService
                              , TokenSerivce tokenSerivce
                              , NoteFileService noteFileService
                              , UserService userService
                              , ConfigFileService configFileService
                              , IDistributedCache distributedCache

                              , IHttpContextAccessor accessor,
                              AuthService authService,
                              ConfigService configService
                              ) :
            base(attachService, tokenSerivce, noteFileService, userService, configFileService, accessor)
        {
            this.distributedCache = distributedCache;
            this.authService      = authService;
            this.configService    = configService;
            this.config           = configService.config;
        }
Example #27
0
        public static IFileStorageService Instance(WebSiteConfig webSiteConfig)
        {
            switch (webSiteConfig.FileStoreConfig.FileStorage)
            {
            case "minio":
                return(new MinIOFileStoreService(webSiteConfig));

            case "upyun":
                return(new UpyunFileStoreService(webSiteConfig));

            case "disk":
                return(new DiskFileStoreService());

            default:

                throw new ArgumentException("FileStoreConfig.FileStorage is error", "FileStorage");
            }
        }
Example #28
0
        public APIController(AttachService attachService
                             , TokenSerivce tokenSerivce
                             , NoteFileService noteFileService
                             , UserService userService
                             , ConfigFileService configFileService
                             , IHttpContextAccessor accessor,
                             AccessService accessService,
                             DataContext dataContext


                             ) : base(attachService, tokenSerivce, noteFileService, userService, configFileService, accessor)
        {
            this.AccessService = accessService;
            this.dataContext   = dataContext;

            this.configFileService = configFileService;
            webcConfig             = configFileService.WebConfig;

            _randomImageFuseSize = webcConfig.PublicAPI.RandomImageFuseSize;
        }
Example #29
0
 public static WebSiteConfig GetPostgreSQLConfig()
 {
     if (config != null)
     {
         return(config);
     }
     if (RuntimeEnvironment.Islinux)
     {
         string        path             = "/etc/morenote/PostgreSQLConfig.json";
         string        json             = File.ReadAllText(path);
         WebSiteConfig postgreSQLConfig = System.Text.Json.JsonSerializer.Deserialize <WebSiteConfig>(json);
         config = postgreSQLConfig;
         return(postgreSQLConfig);
     }
     else
     {
         string        path             = @"C:\etc\morenote\PostgreSQLConfig.json";
         string        json             = File.ReadAllText(path);
         WebSiteConfig postgreSQLConfig = System.Text.Json.JsonSerializer.Deserialize <WebSiteConfig>(json);
         config = postgreSQLConfig;
         return(postgreSQLConfig);
     }
 }
Example #30
0
        private ConsumeModel GetConsumeModel()
        {
            WebSiteConfig webSiteConfig = ConfigFileService.WebConfig;

            if (consumeModel == null)
            {
                lock (lockObj)
                {
                    if (consumeModel == null)
                    {
                        consumeModel = new ConsumeModel();
                        if (consumeModel.predEngine == null)
                        {
                            consumeModel.loadModel(webSiteConfig.MachineLearning.SpamModelPath);
                        }
                    }
                    return(consumeModel);
                }
            }
            else
            {
                return(consumeModel);
            }
        }