/// <summary> /// 获得剩余值 /// </summary> /// <param name="accountId"></param> /// <returns></returns> public static string GetFreeVolumnByAccountId(string accountId) { var used = GetUseageByAccountId(accountId); var total = GetLimitByAccountId(accountId); var free = total - used; return(StringExtend.GetSize((long)free)); }
public ControlModel(string title, Type content, string xaml = "", string code = "", string tags = "") { Title = title; TitlePinyin = StringExtend.GetPinyin(title); Content = content; Tags = tags; XAML = xaml; Code = code; }
public ControlModel(string title, Type content, DemoType type = DemoType.Demo, ControlState state = ControlState.Nor, string xaml = "", string code = "", string tags = "") { Title = title; TitlePinyin = StringExtend.GetPinyin(title); Content = content; Type = type; Tags = tags; XAML = xaml; Code = code; State = state; }
public void ToStringTest() { var format1 = Guid.NewGuid().ToString(); var arg0 = Guid.NewGuid().ToString(); var arg1 = Guid.NewGuid().ToString(); var format = "{0}" + format1 + "{1}"; var expected = string.Format(format, arg0, arg1); var actual = StringExtend.ToString(format, arg0, arg1); Assert.AreEqual(expected, actual, "String.ToString format failed"); }
private void TestToInt16(string value, Int16 expected, bool isException = false) { try { if (isException) { var actual = StringExtend.ToInt16(value); Assert.Fail("String.ToInt16 Convert [{0}] Failed, the exception should be happened but not", value); } else { Assert.AreEqual(expected, StringExtend.ToInt16(value), "String.ToInt16 Convert [{0}] Failed", value); } } catch { if (!isException) { Assert.Fail("String.ToInt16 Convert [{0}] Failed, exception happened", value); } } }
public static void ReloadShader(GameObject p_obj) { string _log = ""; if (p_obj == null) { Debug.LogError("ReloadShader Failed : No GameObject"); return; } try{ Renderer[] _renders = p_obj.GetComponentsInChildren <Renderer> (true); Material[] _materials; int f, f2; int len = _renders.Length; if (len <= 0) { Debug.LogError("No Material In GameObject : " + p_obj.name); return; } int len2; Shader _shader; _log += "Reload Shader : " + p_obj.name; for (f = 0; f < len; f++) { _materials = _renders[f].sharedMaterials; len2 = _materials.Length; for (f2 = 0; f2 < len2; f2++) { if (_materials[f2].shader == null) { _log += "\n Set Shader " + _renders[f].gameObject.name + " material " + f2.ToString() + StringExtend.RichColor(" Failed", Color.green) + "\n Shader is Null"; } else { string _name = _materials[f2].shader.name; _log += "\n Set Shader [" + _name + "] to " + _renders[f].gameObject.name + " material " + f2.ToString(); if (!shaderDict.TryGetValue(_name, out _shader)) { _shader = Shader.Find(_name); if (_shader == null) { _log += StringExtend.RichColor(" Failed", Color.green) + "\n Can't Find Shader : [" + _name + "]"; continue; } } _materials[f2].shader = _shader; _log += StringExtend.RichColor(" OK", Color.green); } } } Debug.Log(_log); }catch (System.Exception e) { _log += StringExtend.RichColor("\nException : " + e.Message, Color.red); Debug.LogError(_log); } }
private void TestIsInt16(string value, bool expected) { Assert.AreEqual(expected, StringExtend.IsInt16(value), "String.IsInt16 Test [{0}] Failed", value); }
private void TestTryToInt16DefaultMinus(string value, Int16 expected) { var actual = StringExtend.TryToInt16(value, -1); Assert.AreEqual(expected, actual, "String.TryToInt16 Convert [{0}] Failed, actual is [{1}]", value, actual); }
private void TestTryToInt64DefaultZero(string value, Int64 expected) { var actual = StringExtend.TryToInt64(value); Assert.AreEqual(expected, actual, "String.TryToInt64 Convert [{0}] Failed, actual is [{1}]", value, actual); }
public static void StringToInt32_OverFlowExeption(this string number, int radix) => Assert.Throws <OverflowException>(() => StringExtend.StringToInt32(number, radix));
public static void StringToInt32_ArgumentExeption(this string number, int radix) => Assert.Throws <ArgumentException>(() => StringExtend.StringToInt32(number, radix));
public static int StringToInt32_ValidCases(this string number, int radix) => StringExtend.StringToInt32(number, radix);
public NGPResponse <TokenReponse> Certification(TokenRequest userInfo) { // 对密码进行加密 var password = StringExtend.Encrypt(userInfo.Password); // 数据库查询 var dbUser = _repository.FirstOrDefault <Sys_Org_User>(s => s.LoginName == userInfo.LoginName); // 用户不存在 if (dbUser == null) { return(new NGPResponse <TokenReponse> { ErrorCode = ErrorCode.NonExistent, Status = OperateStatus.Error, Message = string.Format(CommonResource.NotExist, ServiceResource.UserName) }); } // 用户不存在 var employee = _repository.FirstOrDefault <Sys_Org_Employee>(s => !s.IsDelete && !s.IsDelete && s.Id == dbUser.EmpId); if (employee == null) { return(new NGPResponse <TokenReponse> { ErrorCode = ErrorCode.NonExistent, Status = OperateStatus.Error, Message = string.Format(CommonResource.NotExist, ServiceResource.UserName) }); } // 用户被删除 if (dbUser.IsDelete) { return(new NGPResponse <TokenReponse> { ErrorCode = ErrorCode.CheckError, Status = OperateStatus.Error, Message = string.Format(ServiceResource.UserDeleted) }); } // 用户被禁用 if (!dbUser.UserDisabled) { return(new NGPResponse <TokenReponse> { ErrorCode = ErrorCode.CheckError, Status = OperateStatus.Error, Message = string.Format(ServiceResource.UserDisabled) }); } // 密码不正确 if (!string.Equals(dbUser.UserPwd, password, StringComparison.CurrentCulture)) { return(new NGPResponse <TokenReponse> { ErrorCode = ErrorCode.CheckError, Status = OperateStatus.Error, Message = string.Format(ServiceResource.PasswordError) }); } var emplpyeeDept = _repository.FirstOrDefault <Sys_Org_EmplDept>(s => s.EmplId == employee.Id); // 生成token var tokenHandler = new JwtSecurityTokenHandler(); var key = Encoding.ASCII.GetBytes(_config.Secret); var authTime = DateTime.UtcNow; var expiresAt = authTime.AddHours(_config.TokenExpiresHour.To <int>()); var tokenDescriptor = new SecurityTokenDescriptor { Subject = new ClaimsIdentity(new Claim[] { new Claim(JwtClaimTypes.Audience, "api"), // 用户id new Claim(JwtClaimTypes.Id, employee.Id), // 登录名 new Claim(JwtClaimTypes.Name, employee.EmplName), // 部门 new Claim("DeptId", emplpyeeDept.DeptId), // 登录名 new Claim("LoginName", dbUser.LoginName), // 用户编号 new Claim("EmplNo", employee.EmplNo), // 是否管理员 new Claim("IsSystemAdmin", employee.IsSystemAdmin.ToString()) }), Expires = expiresAt, SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature) }; var token = tokenHandler.CreateToken(tokenDescriptor); var tokenString = tokenHandler.WriteToken(token); // 写入地址 dbUser.UserLastLogonIp = _webHelper.GetCurrentIpAddress(); dbUser.UserLastLogonTime = DateTime.Now; dbUser.UserLogonTimes = (dbUser.UserLogonTimes ?? 0) + 1; _repository.Update(dbUser); var tokenInfo = new TokenReponse { AccessToken = tokenString, TokenType = "Bearer" }; return(new NGPResponse <TokenReponse> { Message = CommonResource.OperatorSuccess, Status = OperateStatus.Success, Data = tokenInfo }); }