public TokenSerivce(DataContext dataContext, ConfigFileService configFileService, IDistributedIdGenerator idGenerator) { this.idGenerator = idGenerator; this.dataContext = dataContext; this.config = configFileService.WebConfig; }
/// <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); }
public FaceService(WebSiteConfig webConfig) { var config = webConfig.SecurityConfig.FaceConfig; this.directory = config.ModelFilesDirectory; this.tolerance = config.Tolerance; }
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); }
public ConfigFileService() { if (_config == null) { this._config = WebConfig; } }
public NoteFileService(DataContext dataContext, ConfigFileService ConfigFileService) { this.dataContext = dataContext; this.ConfigFileService = ConfigFileService; this.storeConfig = ConfigFileService.WebConfig.FileStoreConfig; this.webSiteConfig = ConfigFileService.WebConfig; }
public Startup(IConfiguration configuration, IWebHostEnvironment env) { Configuration = configuration; this._env = env; ConfigFileService configFileService = new ConfigFileService(); config = configFileService.WebConfig; }
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; }
/// <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); }
private void InitServers() { var sites = WebSiteConfig.GetAllSites(); foreach (var site in sites) { var server = new HttpServer(site, log); servers.Add(server); } }
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); } }
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); }
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; }
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); }
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(); }
/// <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); } }
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; } }
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; }
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}"); }
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; } }
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()); }
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; }
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; }
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"); } }
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; }
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); } }
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); } }