Exemplo n.º 1
0
        public void SetAppSetting(UserAppSettingData appSetting)
        {
            InitOnece();
            if (appSetting == null || string.IsNullOrEmpty(appSetting.LoginName))
            {
                return;
            }
            if (!_dicByLoginName.TryGetValue(appSetting.LoginName, out List <UserAppSettingData> list))
            {
                list = new List <UserAppSettingData>();
                _dicByLoginName.Add(appSetting.LoginName, list);
            }
            var exist = list.FirstOrDefault(a => a.Key == appSetting.Key);

            if (exist != null)
            {
                exist.Value = appSetting.Value;
            }
            else
            {
                list.Add(appSetting);
            }
            using (LiteDatabase db = WebApiRoot.CreateLocalDb()) {
                var col = db.GetCollection <UserAppSettingData>();
                col.Upsert(exist);
            }
        }
        public void SetAppSettingAsync(UserAppSettingData entity, Action <ResponseBase, Exception> callback)
        {
            DataRequest <UserAppSettingData> request = new DataRequest <UserAppSettingData>()
            {
                Data = entity
            };

            JsonRpcRoot.SignPostAsync(RpcRoot.OfficialServerHost, RpcRoot.OfficialServerPort, _controllerName, nameof(IUserAppSettingController.SetAppSetting), data: request, callback);
        }
Exemplo n.º 3
0
 public UserAppSettingSet()
 {
     VirtualRoot.BuildCmdPath <SetUserAppSettingCommand>(location: this.GetType(), LogEnum.DevConsole, path: message => {
         if (message.AppSetting == null)
         {
             return;
         }
         UserAppSettingData oldValue;
         if (_dicByKey.TryGetValue(message.AppSetting.Key, out UserAppSettingData entity))
         {
             oldValue = new UserAppSettingData {
                 Id        = entity.Id,
                 LoginName = entity.LoginName,
                 Key       = entity.Key,
                 Value     = entity.Value
             };
             entity.Value = message.AppSetting.Value;
         }
         else
         {
             entity   = UserAppSettingData.Create(message.AppSetting);
             oldValue = null;
             _dicByKey.Add(message.AppSetting.Key, entity);
         }
         RpcRoot.OfficialServer.UserAppSettingService.SetAppSettingAsync(entity, (response, exception) => {
             if (!response.IsSuccess())
             {
                 if (oldValue == null)
                 {
                     _dicByKey.Remove(message.AppSetting.Key);
                 }
                 else
                 {
                     entity.Value = oldValue.Value;
                 }
                 VirtualRoot.Out.ShowError(response.ReadMessage(exception), autoHideSeconds: 4);
             }
         });
     });
 }
Exemplo n.º 4
0
 public DataResponse <List <UserAppSettingData> > AppSettings([FromBody] DataRequest <string> request)
 {
     if (request == null || string.IsNullOrEmpty(request.Data))
     {
         return(ResponseBase.InvalidInput <DataResponse <List <UserAppSettingData> > >("参数错误"));
     }
     try {
         if (!IsValidUser(request, out DataResponse <List <UserAppSettingData> > response))
         {
             return(response);
         }
         var data = WebApiRoot.UserAppSettingSet;
         return(DataResponse <List <UserAppSettingData> > .Ok(data.GetAppSettings(request.Data).Select(a => UserAppSettingData.Create(a)).ToList()));
     }
     catch (Exception e) {
         Logger.ErrorDebugLine(e);
         return(ResponseBase.ServerError <DataResponse <List <UserAppSettingData> > >(e.Message));
     }
 }