public void IntParseOrNull_Should_ReturnCorrectNumber_OnInt64Input() { const string input = "140737488355328"; const long expected = 140737488355328; Assert.AreEqual(expected, TypeParseHelper.LongParseOrNull(input)); }
public void IntParseOrNull_Should_ReturnCorrectNumber_OnValidInput() { const string input = "1234"; const long expected = 1234; Assert.AreEqual(expected, TypeParseHelper.LongParseOrNull(input)); }
/// <summary> /// 获得用户登陆信息 /// </summary> /// <param name="formsIdentity"></param> /// <param name="items"></param> /// <returns></returns> private static UserLogin GetUserLogin(FormsIdentity formsIdentity, IDictionary items) { UserLogin userLogin = null; if (formsIdentity == null || !formsIdentity.IsAuthenticated) { return(userLogin); } const string USER_LOGIN_COOKIE_ITEMS = "USER_LOGIN_COOKIE_ITEMS"; userLogin = items[USER_LOGIN_COOKIE_ITEMS] as UserLogin; if (userLogin == null) { FormsAuthenticationTicket ticket = formsIdentity.Ticket; string userIdentityName = ticket.UserData; if (!String.IsNullOrEmpty(userIdentityName)) { userLogin = new UserLogin(); string[] strQuery = userIdentityName.Split('&'); foreach (string parameters in strQuery) { string[] parameter = parameters.Split('='); if (parameter.Length == 2) { string attributeValue = parameter[1]; if (!string.IsNullOrEmpty(attributeValue)) { attributeValue = HttpUtility.UrlDecode(attributeValue); switch (parameter[0]) { case UserLogin._ID_: //用户数字ID userLogin.UserID = TypeParseHelper.StrToInt32(attributeValue); break; case UserLogin._EMAIL_: //用户Email userLogin.Email = attributeValue; break; case UserLogin._GUID_: //用户Email userLogin.Guid = attributeValue; break; case UserLogin._USER_TYPE_: //帐户类别 userLogin.UserType = TypeParseHelper.StrToInt32(attributeValue); break; } } } else { userLogin = null; break; } } } items[USER_LOGIN_COOKIE_ITEMS] = userLogin; } return(userLogin); }
/// <summary> /// 获取某一个语言的页数 /// </summary> /// <param name="cultureID"></param> /// <returns></returns> private static int Select(int cultureID) { IMongoQuery query = Query <MongoDBSpuItemModel> .EQ(item => item.CultureID, cultureID); long recordCount = MongoDBHelper.Count <MongoDBSpuItemModel>(query); int pageCount = TypeParseHelper.StrToInt32(recordCount / PAGE_SIZE); if (recordCount % PAGE_SIZE != 0) { pageCount += 1; } return(pageCount); }
static NVelocityBus() { CACHE_DATETIME = TypeParseHelper.StrToInt32(ConfigHelper.GetAppSettingValue("CACHE_DATETIME")); CACHE_DATETIME = Math.Max(CACHE_DATETIME, 20); CACHE_DAY = TypeParseHelper.StrToInt32(ConfigHelper.GetAppSettingValue("CACHE_DAY")); CACHE_DAY = Math.Max(CACHE_DAY, 2); //CACHE_REDIS = StackExchangeRedisManager.CACHE_REDIS; _VelocityEngine.SetProperty(RuntimeConstants.RESOURCE_LOADER, "file"); _VelocityEngine.SetProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, NVelocityBus._TemplatePhysicalPath);//模板文件所在的文件夹 _VelocityEngine.SetProperty(RuntimeConstants.INPUT_ENCODING, ENCODING); _VelocityEngine.SetProperty(RuntimeConstants.OUTPUT_ENCODING, ENCODING); _VelocityEngine.Init(); }
public UrlRoutingSetting(string routeName, string routeUrl, string physicalFile, string checkPhysicalUrlAccess, string defaults, string constraints) { this.RouteName = routeName; this.RouteUrl = routeUrl; this.PhysicalFile = physicalFile; try { this.CheckPhysicalUrlAccess = TypeParseHelper.StrToBoolean(checkPhysicalUrlAccess); this.Defaults = string.IsNullOrEmpty(defaults) ? new RouteValueDictionary() : JsonHelper.ConvertStrToJson <RouteValueDictionary>(defaults); this.Constraints = string.IsNullOrEmpty(constraints) ? new RouteValueDictionary() : JsonHelper.ConvertStrToJson <RouteValueDictionary>(constraints);; } catch (Exception ex) { System.Diagnostics.Trace.TraceError(ex.Message); throw ex; } }
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { Type modelType = bindingContext.ModelType; object obj = Activator.CreateInstance(modelType); PropertyInfo[] properties = modelType.GetProperties(); object idValue = null; foreach (PropertyInfo property in properties) { string propertyName = property.Name; Type propertyType = property.PropertyType; ValueProviderResult providerResult = bindingContext.ValueProvider.GetValue(propertyName); object objValue = null; if (providerResult != null) { objValue = providerResult.ConvertTo(propertyType); } if (objValue != null) { property.SetValue(obj, objValue); } if (propertyName == "ID") { idValue = objValue; } } if (obj is IEntity) { IEntity entity = obj as IEntity; if (idValue != null && TypeParseHelper.StrToInt32(idValue) > 0) { entity.UpdateTime = DateTime.Now; entity.UpdateUserName = "******"; } else { entity.CreateTime = DateTime.Now; entity.CreateUserName = "******"; } } return(obj); }
/// <summary> /// 根据MODEL的数据类型,对参数进行相应转化 /// </summary> /// <param name="typeName"></param> /// <param name="Value"></param> /// <returns></returns> private static object GetTypeValue(string typeName, string Value) { typeName = typeName.ToLower(); object v = null; switch (typeName) { case "int32": v = TypeParseHelper.StrToInt(Value, 0); break; case "int64": v = TypeParseHelper.StrToLong(Value, 0); break; case "boolean": v = TypeParseHelper.StrToBool(Value, false); break; case "decimal": v = TypeParseHelper.StrToDecimal(Value, 0); break; case "float": v = TypeParseHelper.StrToFloat(Value, 0); break; case "datetime": v = TypeParseHelper.StrToDateTime(Value, DateTime.MinValue); break; default: v = Convert.ToString(Value); break; } return(v); }
/// <summary> /// 添加对象映射关系 /// </summary> private void CreateMaps() { //https://www.cnblogs.com/fred-bao/p/5700776.html //https://www.cnblogs.com/caoyc/p/6367828.html //MAPPER_CONFIGURATION.CreateMap<UserAddress, OrderAddress>().ReverseMap():对象间可以相互替换 //f=>f.Condition(src=>src.Age>=0 && src.Age<=200) 符合条件才映射属性 //f=>f.Ignore():忽略当前属性 MAPPER_CONFIGURATION.CreateMap <UserAddress, OrderAddress>() .ForMember(d => d.OrderCountryName, f => f.MapFrom(src => src.CountryName)) //设置名称映射 .ForMember(d => d.Name, f => f.MapFrom(src => src.FirstName + " " + src.LastName)) //映射 //.ForMember(d => d.OrderCountryName, f => f.NullSubstitute("China!!")); //.ForMember(d=>d.Age,f=>f.Condition(s=>s.Age<60));//符合条件才映射属性 //.ForMember(d => d.Age, f => f.Ignore());//排除映射属性 ; //类型转换 MAPPER_CONFIGURATION.CreateMap <int, string>().ConvertUsing(item => item.ToString()); MAPPER_CONFIGURATION.CreateMap <string, int>().ConvertUsing(item => TypeParseHelper.StrToInt32(item)); MAPPER_CONFIGURATION.CreateMap <UserAddress, UserAddress>(); MAPPER_CONFIGURATION.CreateMap <OrderAddress, OrderAddress>(); AutoMapper.Mapper.Initialize(MAPPER_CONFIGURATION); }
public void IntParseOrNull_Should_ReturnNull_OnTooBigNumberInput() { const string input = "18446744073709551616"; Assert.IsNull(TypeParseHelper.LongParseOrNull(input)); }
public void IntParseOrNull_Should_ReturnNull_OnMixedInput() { Assert.IsNull(TypeParseHelper.LongParseOrNull("1 ab ;13")); }
public void IntParseOrNull_Should_ReturnNull_OnNonNumericInput() { Assert.IsNull(TypeParseHelper.LongParseOrNull("alskdjfh")); }
public void IntParseOrNull_Should_ReturnNull_OnEmptyInput() { Assert.IsNull(TypeParseHelper.LongParseOrNull(string.Empty)); }
public void IntParseOrNull_Should_ReturnNull_OnNullInput() { Assert.IsNull(TypeParseHelper.LongParseOrNull(null)); }
public void TestMethod6() { Assert.IsTrue(TypeParseHelper.Convert <bool>("True")); }
/// <summary> /// 将文件内容输出到客户端客户端浏览器,支持http头操作。 /// </summary> /// <param name="request"></param> /// <param name="response"></param> /// <param name="fileContent">要往客户端浏览器输出的文本内容</param> /// <param name="isHttpHead">True表示使用http头操作,False表示不使用http头操作</param> internal static void Output(HttpRequest request, HttpResponse response, string fileContent, string absoluteFilePath, bool isHttpHead) { if (string.IsNullOrWhiteSpace(fileContent)) { return; } //wangyunpeng 增加http头,把生成的路径输出出来,方便修改页面使用。 if (absoluteFilePath != null) { response.AddHeader("X-Page-Hash", absoluteFilePath); } HttpCachePolicy cache = response.Cache; cache.SetOmitVaryStar(true);//http://www.cnblogs.com/dudu/archive/2011/11/03/outputcache_Bug_vary.html //#if DEBUG //本地调试不使用浏览器缓存 //cache.SetCacheability(HttpCacheability.NoCache); //cache.SetExpires(DateTime.UtcNow.AddYears(-1)); //cache.SetMaxAge(TimeSpan.Zero); //cache.SetProxyMaxAge(TimeSpan.Zero); //cache.SetNoServerCaching(); //cache.SetNoStore(); //cache.SetNoTransforms(); //#else string ifModifiedSince = request.Headers["If-Modified-Since"]; if (isHttpHead) { if ( !string.IsNullOrWhiteSpace(ifModifiedSince) && TimeSpan.FromTicks(DateTime.Now.Ticks - TypeParseHelper.StrToDateTime(ifModifiedSince).Ticks).Minutes < CACHE_DATETIME) { response.StatusCode = (int)System.Net.HttpStatusCode.NotModified; response.StatusDescription = "Not Modified"; response.End(); return; } else { cache.SetLastModifiedFromFileDependencies(); cache.SetETagFromFileDependencies(); cache.SetCacheability(HttpCacheability.Public); cache.SetExpires(DateTime.UtcNow.AddMinutes(CACHE_DATETIME)); TimeSpan timeSpan = TimeSpan.FromMinutes(CACHE_DATETIME); cache.SetMaxAge(timeSpan); cache.SetProxyMaxAge(timeSpan); cache.SetLastModified(DateTime.Now); cache.SetValidUntilExpires(true); cache.SetSlidingExpiration(true); } } //#endif System.Text.Encoding encoding = IOHelper.GetHtmEncoding(fileContent) ?? NVelocityBus._GlobalizationSection.ResponseEncoding; response.ContentEncoding = encoding; response.ContentType = response.ContentType; response.Write(fileContent); //压缩页面 if (request.ServerVariables["HTTP_X_MICROSOFTAJAX"] == null) { if (NVelocityBus.IsAcceptEncoding(request, GZIP)) { response.Filter = new GZipStream(response.Filter, CompressionMode.Compress); NVelocityBus.SetResponseEncoding(response, GZIP); } else if (NVelocityBus.IsAcceptEncoding(request, DEFLATE)) { response.Filter = new DeflateStream(response.Filter, CompressionMode.Compress); NVelocityBus.SetResponseEncoding(response, DEFLATE); } } //强制结束输出 response.End(); }