public SsoUser GetUser() { //sso逻辑 var token = HttpContext.Current.Request.QueryString["token"]; if (token.IsNullOrEmpty()) { token = CookieHelper.GetCookieValue("token"); } //根据token 获取用户信息,并保存token if (!token.IsNullOrEmpty()) { try { var ssoserver = ConfigSettingHelper.GetAppStr("ssoserver"); var userinfojson = ApiDataHelper.GetData(ssoserver + api + "?token=" + token); var user = JsonHelper.DeserializeObject <SsoUser>(userinfojson); return(user); } catch (Exception ex) { LogHelper.Error(ex); } } return(null); }
/// <summary> /// get query script /// </summary> /// <param name="config"></param> /// <param name="configType"></param> /// <param name="isLogGet"></param> /// <param name="topCount"></param> /// <param name="sortdirection"></param> /// <returns></returns> public static string TBLQueryGet(ConfigurationSettingDataTbl config , ConfigSettingType configType , bool isLogGet , int topCount = 0 , CommonEnum.SortDirection sortdirection = CommonEnum.SortDirection.None) { string topStr = string.Empty; if (topCount > 0) { topStr = "top " + topCount; } string orderBy = string.Empty; if (sortdirection == CommonEnum.SortDirection.ASC) { orderBy = "order by 1 asc"; } else if (sortdirection == CommonEnum.SortDirection.DESC) { orderBy = "order by 1 desc"; } string tblName = (isLogGet) ? ConfigSettingHelper.ConfigLogTableNameGet(configType) : ConfigSettingHelper.ConfigTableNameGet(configType); string where = TBLQueryGetWhere(config, configType); return(string.Format("select {0} * from {1} {2} {3} ", topStr, tblName, where, orderBy)); }
static Composition() { var pluginName = ConfigSettingHelper.GetAppStr("PluginName"); var dirCatalog = new DirectoryCatalog(".", pluginName + ".*.dll"); container = new System.ComponentModel.Composition.Hosting.CompositionContainer(dirCatalog); }
/// <summary> /// get all configutaion entity list /// </summary> /// <param name="isLogGet"></param> /// <param name="defaultNullValue"></param> /// <returns></returns> public List <ConfigurationSettingDataTbl> CSDTblsGetAll(bool isLogGet = false, string defaultNullValue = null) { string tblName = (isLogGet) ? ConfigSettingHelper.ConfigLogTableNameGet(this.ConfigurationType) : ConfigSettingHelper.ConfigTableNameGet(this.ConfigurationType); string query = string.Format("select * from {0}", tblName); return(CSDTblsGet(query, this.ConnectionString, ConfigurationIDNameGet(isLogGet), defaultNullValue)); }
public override void OnAuthorization(AuthorizationContext filterContext) { base.OnAuthorization(filterContext); //todo 获取用户信息,获取到了直接返回,这里可以替换使用应用程序中的数据 var userName = CookieHelper.GetCookieValue(SsoClient.UserName); if (!userName.IsNullOrEmpty()) { FormsAuthentication.SetAuthCookie(userName, true); return; } var user = SsoClient.Instance.GetUser(); if (user == null) { //跳转到sso登录页面 var ssoserverLogin = ConfigSettingHelper.GetAppStr("ssoserver") + loginurl + "?returnurl=" + filterContext.RequestContext.HttpContext.Request.Url.AbsoluteUri; filterContext.Result = new RedirectResult(ssoserverLogin); return; } CookieHelper.SetCookie(SsoClient.Token, user.token); CookieHelper.SetCookie(SsoClient.UserName, user.username); FormsAuthentication.SetAuthCookie(user.username, true); filterContext.Result = new RedirectResult(filterContext.RequestContext.HttpContext.Request.Url.AbsoluteUri); }
public ActionResult GetModuleLinkUrl() { //.Where(t => t.LinkUrl.ToLower().Contains(term.ToLower())) var model = ConfigSettingHelper.GetAllModuleLinkUrl().ToList(); return(Json(model, JsonRequestBehavior.AllowGet)); }
/// <summary> /// 根据权限生成超链接,当没有权限返回空 /// </summary> /// <param name="helper"></param> /// <param name="linkText"></param> /// <param name="actionName"></param> /// <param name="controllerName"></param> /// <param name="class"></param> /// <param name="htmlAttrbuites"></param> /// <param name="routeAttributes"></param> /// <returns></returns> public static HtmlString AuthedLink(this HtmlHelper helper, string linkText, string actionName, string controllerName, string @class, object htmlAttrbuites, object routeAttributes) { var enablePermission = ConfigSettingHelper.GetAppStr <bool>("EnablePermission"); var area = ""; if (helper.ViewContext.RouteData.DataTokens["area"] != null) { area = helper.ViewContext.RouteData.DataTokens["area"].ToString(); } if (enablePermission) { var roles = LoginHelper.Instance.GetLoginUserRoles(); if (roles == null) { return(new HtmlString("")); } if (!roles.CheckRole(controllerName, actionName, area)) { return(new HtmlString("")); } } TagBuilder tag = new TagBuilder("a"); tag.AddCssClass(@class); if (htmlAttrbuites != null) { var ats = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttrbuites); foreach (var at in ats) { tag.Attributes.Add(at.Key, at.Value.ToString()); } } var d = new RouteValueDictionary(); d.Add("area", area); if (routeAttributes != null) { var atts = HtmlHelper.AnonymousObjectToHtmlAttributes(routeAttributes); foreach (var att in atts) { d.Add(att.Key, att.Value); } } UrlHelper urlhelp = new UrlHelper(helper.ViewContext.RequestContext); tag.Attributes.Add("href", urlhelp.Action(actionName, controllerName, d)); tag.InnerHtml = linkText; return(new HtmlString(tag.ToString())); }
/// <summary> /// get DB connection by service name /// </summary> /// <param name="service"></param> /// <returns></returns> public static string DBConnectionStringGet(CommonEnum.ServiceName service) { string dbStr = ConfigSettingHelper.DBConfigKeyGet(service); if (string.IsNullOrEmpty(dbStr)) { Assert.Fail(string.Format("no mapping ConnectionString in app.config for {0}!", service.ToString())); } return(ConfigurationManager.ConnectionStrings[dbStr].ConnectionString); }
public DBContextBase(DBOperationType dbType) { if (dbType == DBOperationType.Read) { _connstr = ConfigSettingHelper.GetConnectionStr(ConstArgs.ReadConnStrName); Init(); } if (dbType == DBOperationType.Write) { _connstr = ConfigSettingHelper.GetConnectionStr(ConstArgs.WriteConnStrName); Init(); } }
// isReturnConfigEnable false: will assert.fail when have any dismatch public static bool MachExpectedValueinDB(string expectedValue, string actualValue, string Configname , string tuid = "0", bool isUpdateIfNotMatch = false, ConfigSettingRequestData configSettingRequestData = null, bool isReturnConfigEnable = false) { bool isMatchExpectedValue = false; if (expectedValue == actualValue) { Console.WriteLine("Read the expected feature value for " + Configname + " in DB is " + expectedValue); isMatchExpectedValue = true; } else { if (!isUpdateIfNotMatch) { if (isReturnConfigEnable) { isMatchExpectedValue = false; } else { Assert.Fail("The feature value for " + Configname + " in DB is" + actualValue + ", but the expected feature value " + expectedValue); } } else { Console.WriteLine("The feature value for " + Configname + " in DB is" + actualValue + ", but the expected feature value " + expectedValue); //update to expect value if (configSettingRequestData != null) { Console.WriteLine("Update : " + Configname + " from " + actualValue + " to " + expectedValue); //update configuration cache ConfigSettingHelper.ConfiguationCacheUpdate(configSettingRequestData); //set value to actual value for rollback configSettingRequestData.ConfigSettingDatasSettingValueReset(actualValue); //add this data to rollback instance RollBackConfigurationSettingHelper.Instance.Add(configSettingRequestData, tuid); } else { Assert.Fail("No configSettingRequestData data, can not update " + Configname + " from " + actualValue + " to " + expectedValue); } } } return(isMatchExpectedValue); }
public static HtmlString AuthedLink(this HtmlHelper helper, string linkText, string actionName, string controllerName, string para = "", string @class = "", string attr = "" ) { var area = ""; if (helper.ViewContext.RouteData.DataTokens["area"] != null) { area = helper.ViewContext.RouteData.DataTokens["area"].ToString(); } var enablePermission = ConfigSettingHelper.GetAppStr <bool>("EnablePermission"); if (enablePermission) { var roles = LoginHelper.Instance.GetLoginUserRoles(); if (roles == null) { return(new HtmlString("")); } if (!roles.CheckRole(controllerName, actionName, area)) { return(new HtmlString("")); } } var d = new RouteValueDictionary(); d.Add("area", area); UrlHelper urlhelp = new UrlHelper(helper.ViewContext.RequestContext); var rurl = urlhelp.Action(actionName, controllerName, d) + "?" + para; return(new HtmlString("<a class='" + @class + "' " + attr + " href='" + rurl + "'>" + linkText + "</a>")); }
/// <summary> /// 获取appsetting /// </summary> /// <param name="knl"></param> /// <param name="key"></param> /// <returns></returns> public static string GetAppSetting(this IKernel knl, string key) { return(ConfigSettingHelper.GetAppStr(key)); }
public DBContextBase() { _connstr = ConfigSettingHelper.GetConnectionStr(ConstArgs.ConnStrName); Init(); }
public ConfigurationDBHelper(CommonEnum.ServieProvider serviceProvider, ConfigSettingType configType) { this.ConnectionString = CarSCSCommonHelper.DBConnectionStringGet(ConfigSettingHelper.ServiceNameGet(serviceProvider)); this.ConfigurationType = configType; }
public MongoDbRepository() { this._dbName = ConfigSettingHelper.GetAppStr("MongoDBName"); }
public static void Init() { Path = ConfigSettingHelper.GetAppStr("indexpath"); // FSDirectory directory = FSDirectory.Open(new DirectoryInfo(IndexPath), new NoLockFactory()); //_reader = IndexReader.Open(directory, true); }