Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        /// <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));
        }
Exemplo n.º 3
0
        static Composition()
        {
            var pluginName = ConfigSettingHelper.GetAppStr("PluginName");
            var dirCatalog = new DirectoryCatalog(".", pluginName + ".*.dll");

            container = new System.ComponentModel.Composition.Hosting.CompositionContainer(dirCatalog);
        }
Exemplo n.º 4
0
        /// <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));
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        public ActionResult GetModuleLinkUrl()
        {
            //.Where(t => t.LinkUrl.ToLower().Contains(term.ToLower()))
            var model = ConfigSettingHelper.GetAllModuleLinkUrl().ToList();

            return(Json(model, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 7
0
        /// <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()));
        }
Exemplo n.º 8
0
        /// <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);
        }
Exemplo n.º 9
0
        public DBContextBase(DBOperationType dbType)
        {
            if (dbType == DBOperationType.Read)
            {
                _connstr = ConfigSettingHelper.GetConnectionStr(ConstArgs.ReadConnStrName);
                Init();
            }

            if (dbType == DBOperationType.Write)
            {
                _connstr = ConfigSettingHelper.GetConnectionStr(ConstArgs.WriteConnStrName);
                Init();
            }
        }
Exemplo n.º 10
0
        // 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);
        }
Exemplo n.º 11
0
        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>"));
        }
Exemplo n.º 12
0
 /// <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));
 }
Exemplo n.º 13
0
 public DBContextBase()
 {
     _connstr = ConfigSettingHelper.GetConnectionStr(ConstArgs.ConnStrName);
     Init();
 }
Exemplo n.º 14
0
 public ConfigurationDBHelper(CommonEnum.ServieProvider serviceProvider, ConfigSettingType configType)
 {
     this.ConnectionString  = CarSCSCommonHelper.DBConnectionStringGet(ConfigSettingHelper.ServiceNameGet(serviceProvider));
     this.ConfigurationType = configType;
 }
Exemplo n.º 15
0
 public MongoDbRepository()
 {
     this._dbName = ConfigSettingHelper.GetAppStr("MongoDBName");
 }
Exemplo n.º 16
0
 public static void Init()
 {
     Path = ConfigSettingHelper.GetAppStr("indexpath");
     // FSDirectory directory = FSDirectory.Open(new DirectoryInfo(IndexPath), new NoLockFactory());
     //_reader = IndexReader.Open(directory, true);
 }