Example #1
0
        private List <string> GetLogLevels()
        {
            IAppSettingService appSetting = ApplicationConfig.DependencyResolver.GetInstance <IAppSettingService>();
            List <string>      logLevals  = new List <string>();
            var setting = appSetting.GetAppSetting(GetLoggerName());

            if (setting == null)
            {
                AddLogComponents();
                setting = appSetting.GetAppSetting(GetLoggerName());
            }
            if (setting[CommonConst.CommonField.DATA][CommonConst.CommonField.LOG_LOG_LEVELS] != null)
            {
                foreach (var item in setting[CommonConst.CommonField.DATA][CommonConst.CommonField.LOG_LOG_LEVELS] as JArray)
                {
                    logLevals.Add(item.ToString());
                }
            }
            return(logLevals);
        }
Example #2
0
        void LoadAppSettings()
        {
            IAppSettingService service = ServiceContainer.GetService <IAppSettingService>();

            this.ProductName = service.GetAppSetting("__About", "ProductName");
            this.HelpMenus   = service.GetAppSetting("__Web", "HelpMenus");

            string vText  = service.GetAppSetting("__Web", "PageSize");
            int    vValue = 0;

            if (int.TryParse(vText, out vValue))
            {
                this.PageSize = vValue;
            }
            else
            {
                this.PageSize = 15;
            }

            this.MenuType = service.GetAppSetting("__Web", "MenuType");
            this.Theme    = service.GetAppSetting("__Web", "Theme");
        }
        public IActionResult Contact(ContactViewModel model)
        {
            if (ModelState.IsValid)
            {
                var email = _appSetting.GetAppSetting(Common.Constants.SiteEmailAddress);
                if (string.IsNullOrWhiteSpace(email))
                {
                    // First param (key) is the name of the property, or empty for object level error.
                    ModelState.AddModelError("", "Could not send email, configuration problem.");
                }

                if (_mailService.SendMail(email, email, $"Contact Page from {model.Name} ({model.Email})", model.Message))
                {
                    ModelState.Clear(); // Clear the form so we have clean form when sending back the View (in case people click send many times, validation will fire on the clean form.)
                    ViewBag.Message = "Email sent. Thanks!";
                }
            }
            return(View());
        }
Example #4
0
        public static bool CreateUser(IDBService dbProxy, IAppSettingService appSettingService, string userid, UserIDType userType, string name, string email, string picture)
        {
            JObject userData = new JObject();

            userData[CommonConst.CommonField.USER_ID]   = userData[CommonConst.CommonField.DATA_KEY] = userid;
            userData[CommonConst.CommonField.USER_TYPE] = userType.ToString();

            var updateFilter = userData.ToString();

            userData[CommonConst.CommonField.DISPLAY_ID] = CommonUtility.GetNewID();
            userData[CommonConst.CommonField.IS_ENABLED] = true;
            userData[CommonConst.CommonField.NAME]       = name;
            userData[CommonConst.CommonField.EMAIL]      = email;

            userData[CommonConst.CommonField.IS_EMAIL_VALIDATE] = userType == UserIDType.Google ? true : false;
            userData[CommonConst.CommonField.IS_PHONE_VALIDATE] = false;
            var userGroup = appSettingService.GetAppSetting(ModuleAppConsts.Field.DEFAULT_USER_GROUPS_APP_SETTING_KEY);

            if (userGroup == null)
            {
                throw new Exception("User Group setting not found in AppSettings");
            }
            if (userGroup[CommonConst.CommonField.DATA] == null || userGroup[CommonConst.CommonField.DATA][CommonConst.CommonField.USER_GROUPS] == null)
            {
                throw new Exception("User Groups not found in AppSettings");
            }
            userData[CommonConst.CommonField.USER_GROUPS] = (userGroup[CommonConst.CommonField.DATA][CommonConst.CommonField.USER_GROUPS] as JArray);
            if (dbProxy.Write(CommonConst.Collection.USERS, userData, updateFilter, true))
            {
                var userInfo = new JObject();
                userInfo[CommonConst.CommonField.USER_ID] = userid;
                var filter = userInfo.ToString();
                userInfo[CommonConst.CommonField.USER_PIC] = picture;

                var dbresponse = dbProxy.Update(CommonConst.Collection.USER_INFO, filter, userInfo, true, MergeArrayHandling.Merge);
                return(dbresponse == 1);
            }
            else
            {
                return(false);
            }
        }
Example #5
0
        /// <summary>
        /// 实现拦截器
        /// </summary>
        /// <param name="targetMethod"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public object InterceptAsync(MethodInfo targetMethod, object[] parameters)
        {
            ServiceContract _contract = new ServiceContract
            {
                ServiceName     = targetMethod.DeclaringType.FullName,
                MethodName      = targetMethod.Name,
                IsGenericMethod = targetMethod.IsGenericMethod
            };

            if (_contract.IsGenericMethod)
            {
                _contract.GenericType = targetMethod.GetGenericArguments();
            }
            _contract.Paras = new Dictionary <string, string>();
            int i      = 0;
            var _paras = targetMethod.GetParameters();

            foreach (var p in _paras)
            {
                _contract.Paras.Add(p.Name, JsonHelper.Serialize(_paras[i]));
                i++;
            }
            HttpClient _client           = new HttpClient();
            string     _ServiceAddressEx = targetMethod.CustomAttributes.FirstOrDefault(p =>
                                                                                        p.AttributeType == typeof(NotAuthorizeAttribute)) == null
                                        ? FDConst.ServiceAddressEx : FDConst.NotAuthorizeServiceAddressEx;
            string _url = _AppSettings.GetAppSetting(FDConst.AppSettings_ServiceAddress);

            if (_url.EndsWith("/"))
            {
                _url += _ServiceAddressEx;
            }
            else
            {
                _url += "/" + _ServiceAddressEx;
            }
            var _returnType = targetMethod.ReturnType;

            if (this._Token != null)
            {
                _client.SetBearerToken(_Token);
            }
            else
            {
                return(Activator.CreateInstance(_returnType));
            }
            try
            {
                HttpContent _content = new StringContent(JsonHelper.Serialize(_contract));
                _content.Headers.ContentType = new MediaTypeHeaderValue(FDConst.HTTPContent_Json)
                {
                    CharSet = FDConst.Encoding_UTF8
                };
                _client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(FDConst.HTTPContent_Json));
                HttpResponseMessage httpResponse = _client.PostAsync(_url, _content).Result; //Post

                if (httpResponse.StatusCode.Equals(HttpStatusCode.Unauthorized))             //Token Expirded
                {
                    var _refreshToken = _Context.GetValue("");                               //get refresh token
                    var address       = _AppSettings.GetAppSetting(FDConst.AppSettings_ServiceAddress);
                    if (!string.IsNullOrEmpty(_refreshToken) && !string.IsNullOrEmpty(address))
                    {
                        var isError = RefreshToken(_refreshToken, address);
                        if (!isError)
                        {
                            _Token = this._Context.GetValue(FDConst.IS_AuthenticationToken).ToString();
                            return(this.InterceptAsync(targetMethod, parameters));
                        }
                    }
                }

                httpResponse.EnsureSuccessStatusCode();
                if (httpResponse.IsSuccessStatusCode)
                {
                    String    _sResult = httpResponse.Content.ReadAsStringAsync().Result;
                    ApiResult _result  = JsonHelper.Deserialize <ApiResult>(_sResult);

                    if (_result.IsSuccess)
                    {
                        var _t = targetMethod.ReturnType;
                        if (_t.FullName == typeof(void).FullName)
                        {
                            return(null);
                        }

                        var _r = JsonHelper.Deserialize(_result.Message, _t);
                        return(_r);
                    }
                    else
                    {
                        throw new Exception(_result.Message);
                    }
                }
                else
                {
                    throw new Exception(string.Format("连接服务器失败,错误代码:{0}", httpResponse.StatusCode));
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                _client.Dispose();
            }
        }