Пример #1
0
        public ResponseBase RemoveUser([FromBody] DataRequest <string> request)
        {
            if (request == null || string.IsNullOrEmpty(request.Data))
            {
                return(ResponseBase.InvalidInput <DataResponse <string> >("参数错误"));
            }
            var user = WebApiRoot.UserSet.GetUser(UserId.CreateLoginNameUserId(request.Data));

            if (user == null)
            {
                return(ResponseBase.Ok("删除成功"));
            }
            if (user.IsAdmin())
            {
                return(ResponseBase.InvalidInput <DataResponse <string> >("不能操作admin"));
            }
            try {
                WebApiRoot.UserSet.Remove(request.Data);
                return(ResponseBase.Ok("删除成功"));
            }
            catch (Exception e) {
                return(ResponseBase.ServerError(e.Message));
            }
        }
Пример #2
0
 public DataResponse <string> GetLocalJson([FromBody] DataRequest <Guid> request)
 {
     if (request == null)
     {
         return(ResponseBase.InvalidInput <DataResponse <string> >("参数错误"));
     }
     try {
         if (!request.IsValid(HostRoot.Instance.UserSet.GetUser, ClientIp, out DataResponse <string> response))
         {
             return(response);
         }
         string localJsonFileFullName = SpecialPath.GetMineWorkLocalJsonFileFullName(request.Data);
         string data = string.Empty;
         if (File.Exists(localJsonFileFullName))
         {
             data = File.ReadAllText(localJsonFileFullName);
         }
         return(DataResponse <string> .Ok(data));
     }
     catch (Exception e) {
         Logger.ErrorDebugLine(e.Message, e);
         return(ResponseBase.ServerError <DataResponse <string> >(e.Message));
     }
 }
Пример #3
0
        public ResponseBase ActiveControlCenterAdmin([FromBody] string password)
        {
            if (string.IsNullOrEmpty(password))
            {
                return(ResponseBase.InvalidInput("密码不能为空"));
            }
            IUser user = HostRoot.Instance.UserSet.GetUser("admin");

            if (user == null)
            {
                var userData = new UserData {
                    LoginName   = "admin",
                    IsEnabled   = true,
                    Description = "群控初始用户",
                    Password    = password
                };
                VirtualRoot.Execute(new AddUserCommand(userData));
                return(ResponseBase.Ok());
            }
            else
            {
                return(ResponseBase.Forbidden());
            }
        }
Пример #4
0
        public DataResponse <List <ClientData> > RefreshClients([FromBody] MinerIdsRequest request)
        {
            if (request == null || request.ObjectIds == null)
            {
                return(ResponseBase.InvalidInput <DataResponse <List <ClientData> > >("参数错误"));
            }
            if (!HostRoot.Instance.HostConfig.IsPull)
            {
                return(ResponseBase.InvalidInput <DataResponse <List <ClientData> > >("服务端配置为不支持刷新"));
            }
            try {
                if (!request.IsValid(HostRoot.Instance.UserSet.GetUser, ClientIp, out DataResponse <List <ClientData> > response))
                {
                    return(response);
                }

                var data = HostRoot.Instance.ClientSet.RefreshClients(request.ObjectIds);
                return(DataResponse <List <ClientData> > .Ok(data));
            }
            catch (Exception e) {
                Logger.ErrorDebugLine(e.Message, e);
                return(ResponseBase.ServerError <DataResponse <List <ClientData> > >(e.Message));
            }
        }
Пример #5
0
        public ResponseBase RemoveClients([FromBody] MinerIdsRequest request)
        {
            if (request == null || request.ObjectIds == null)
            {
                return(ResponseBase.InvalidInput("参数错误"));
            }

            try {
                if (!request.IsValid(HostRoot.Instance.UserSet.GetUser, ClientIp, out ResponseBase response))
                {
                    return(response);
                }

                foreach (var objectId in request.ObjectIds)
                {
                    HostRoot.Instance.ClientSet.Remove(objectId);
                }
                return(ResponseBase.Ok());
            }
            catch (Exception e) {
                Logger.ErrorDebugLine(e.Message, e);
                return(ResponseBase.ServerError(e.Message));
            }
        }
Пример #6
0
        public ReportResponse ReportSpeed([FromBody] SpeedData speedData)
        {
            ReportResponse response;

            try {
                if (speedData == null)
                {
                    response             = ResponseBase.InvalidInput <ReportResponse>();
                    response.ServerState = ServerState.Empty;
                    return(response);
                }
                ClientData clientData = HostRoot.Instance.ClientSet.GetByClientId(speedData.ClientId);
                if (clientData == null)
                {
                    clientData = ClientData.Create(speedData, ClientIp);
                    HostRoot.Instance.ClientSet.Add(clientData);
                }
                else
                {
                    clientData.Update(speedData, ClientIp);
                }
                if (Version.TryParse(speedData.Version, out Version version))
                {
                    string jsonVersionKey = MainAssemblyInfo.GetServerJsonVersion(version);
                    response             = ResponseBase.Ok <ReportResponse>();
                    response.ServerState = HostRoot.GetServerState(jsonVersionKey);
                    return(response);
                }
            }
            catch (Exception e) {
                Logger.ErrorDebugLine(e);
            }
            response             = ResponseBase.InvalidInput <ReportResponse>();
            response.ServerState = ServerState.Empty;
            return(response);
        }