static void Main(string[] args) { Log.Texte("", "-------------------------------", ConsoleColor.DarkBlue); Log.Texte("", " _____ _____ ", ConsoleColor.Cyan); Log.Texte("", " /\\ | __ \\ / ____|", ConsoleColor.Cyan); Log.Texte("", " / \\ | |__) | (___ ", ConsoleColor.Cyan); Log.Texte("", " / /\\ \\ | ___/ \\___ \\ ", ConsoleColor.Cyan); Log.Texte("", " / ____ \\| | ____) |", ConsoleColor.Cyan); Log.Texte("", "/_/ \\_\\_| |_____/ APB-File", ConsoleColor.Cyan); Log.Texte("", "http://AllPrivateServer.com", ConsoleColor.DarkCyan); Log.Texte("", "-------------------------------", ConsoleColor.DarkBlue); Assembly.Load("Common"); Log.Info("FileServer", "Starting..."); ConfigMgr.LoadConfigs(); Config = ConfigMgr.GetConfig<FileServerConfig>(); if (!Log.InitLog(Config.LogLevel, "FileServer")) ConsoleMgr.WaitAndExit(2000); Server = new RpcServer(Config.RpcInfo.RpcClientStartingPort, 0); if (!Server.Start(Config.RpcInfo.RpcIp, Config.RpcInfo.RpcPort)) ConsoleMgr.WaitAndExit(2000); Log.Success("FileServer", "Server loaded."); ConsoleMgr.Start(); }
static void Main(string[] args) { Log.Texte("", "-------------------------------", ConsoleColor.DarkBlue); Log.Texte("", " _____ _____ ", ConsoleColor.Cyan); Log.Texte("", " /\\ | __ \\ / ____|", ConsoleColor.Cyan); Log.Texte("", " / \\ | |__) | (___ ", ConsoleColor.Cyan); Log.Texte("", " / /\\ \\ | ___/ \\___ \\ ", ConsoleColor.Cyan); Log.Texte("", " / ____ \\| | ____) |", ConsoleColor.Cyan); Log.Texte("", "/_/ \\_\\_| |_____/ APB-File", ConsoleColor.Cyan); Log.Texte("", "http://AllPrivateServer.com", ConsoleColor.DarkCyan); Log.Texte("", "-------------------------------", ConsoleColor.DarkBlue); Assembly.Load("Common"); Log.Info("FileServer", "Starting..."); ConfigMgr.LoadConfigs(); Config = ConfigMgr.GetConfig <FileServerConfig>(); if (!Log.InitLog(Config.LogLevel, "FileServer")) { ConsoleMgr.WaitAndExit(2000); } Server = new RpcServer(Config.RpcInfo.RpcClientStartingPort, 0); if (!Server.Start(Config.RpcInfo.RpcIp, Config.RpcInfo.RpcPort)) { ConsoleMgr.WaitAndExit(2000); } Log.Success("FileServer", "Server loaded."); ConsoleMgr.Start(); }
public FileController(FileServerConfig config) { _config = config; }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { app.UseCors(options => { options.AllowAnyHeader(); options.AllowAnyMethod(); options.AllowAnyOrigin(); options.AllowCredentials(); }); #region 文件上传 FileServerConfig config = app.ApplicationServices.GetService <FileServerConfig>(); if (config != null && config.PathList != null) { List <PathItem> pathList = new List <PathItem>(); foreach (PathItem pi in config.PathList) { if (string.IsNullOrEmpty(pi.LocalPath)) { continue; } try { if (!System.IO.Directory.Exists(pi.LocalPath)) { System.IO.Directory.CreateDirectory(pi.LocalPath); } pathList.Add(pi); } catch (Exception e) { Console.WriteLine("文件夹创建失败:\r\n{0}", e.ToString()); } } if (config.Root != null) { if (!System.IO.Directory.Exists(config.Root.LocalPath)) { System.IO.Directory.CreateDirectory(config.Root.LocalPath); } pathList.Add(config.Root); } foreach (PathItem pi in pathList) { Console.WriteLine("Full Path: " + System.IO.Path.GetFullPath(pi.LocalPath)); app.UseStaticFiles(new StaticFileOptions() { FileProvider = new Microsoft.Extensions.FileProviders.PhysicalFileProvider(System.IO.Path.GetFullPath(pi.LocalPath)), RequestPath = pi.Url }); Console.WriteLine("路径映射:{0}-->{1}", pi.LocalPath, pi.Url); } } #endregion if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseStaticFiles(); app.UseMvc(); }