Exemple #1
0
        public HttpServerAPIs(TaskManager serverContext, IDbOperator dbOperator, string logfilePath)
        {
            ServerContext   = serverContext;
            Dbop            = dbOperator;
            baseLogFilePath = logfilePath;

            //如果库中没有任何记录,则增加默认用户
            if (Dbop.GetLength() < 1)
            {
                AddUserV2("admin", "admin", "2");
            }

            serverContext.ReloadAssembly();
            serverContext.StartAllTask();
        }
Exemple #2
0
        public HttpServerAPIs(TaskManager serverContext, IDbOperator userDB, IDbOperator sysDB, string logfilePath)
        {
            ServerContext   = serverContext;
            UserDB          = userDB;
            SysDB           = sysDB;
            baseLogFilePath = logfilePath;

            //如果库中没有任何记录,则增加默认用户
            if (UserDB.GetLength() < 1)
            {
                AddUserV2("admin", "admin", "2", "false", "");
            }

            serverContext.ReloadAssembly();
            serverContext.StartAllTask();
        }
        /// <summary>
        /// http服务启动,初始化代码写在这里
        /// </summary>
        /// <param name="ctsHttp"></param>
        /// <param name="WebManagementPort"></param>
        /// <returns></returns>
        public async Task StartHttpService(CancellationTokenSource ctsHttp, int WebManagementPort)
        {
            try
            {
                HttpListener listener = new HttpListener();
                //缓存所有文件
                var dir   = new DirectoryInfo(BASE_FILE_PATH);
                var files = dir.GetFiles("*.*");
                foreach (var file in files)
                {
                    using (var fs = file.OpenRead())
                    {
                        var mms = new MemoryStream();
                        fs.CopyTo(mms);
                        FilesCache.Add(file.Name, mms);
                    }
                }
                Logger.Debug($"{files.Length} files cached.");

                //如果库中没有任何记录,则增加默认用户
                if (Dbop.GetLength() < 1)
                {
                    AddUserV2("admin", "admin", "1");
                }

                listener.Prefixes.Add($"http://+:{WebManagementPort}/");
                Logger.Debug("Listening HTTP request on port " + WebManagementPort.ToString() + "...");
                await AcceptHttpRequest(listener, ctsHttp);
            }
            catch (HttpListenerException ex)
            {
                Logger.Debug("Please run this program in administrator mode." + ex);
                Server.Logger.Error(ex.ToString(), ex);
            }
            catch (Exception ex)
            {
                Logger.Debug(ex);
                Server.Logger.Error(ex.ToString(), ex);
            }
            Logger.Debug("Http服务结束。");
        }