/// <summary> /// 构建Excel /// </summary> /// <typeparam name="T">泛型</typeparam> /// <param name="dt">Excel数据</param> /// <param name="workSheetName">Sheet名称</param> /// <param name="selectColumnsStr">选择列</param> /// <param name="isShowSequenced">是否显示序号</param> /// <returns>返回Workbook</returns> public static HSSFWorkbook ToHssfWorkbook <T>(List <DataTable> dt, string[] workSheetName, string[] selectColumnsStr, bool isShowSequenced) { GuardUtils.NotNull(workSheetName, nameof(workSheetName)); GuardUtils.NotNull(dt, nameof(dt)); var book = new HSSFWorkbook(); if (dt.Count > 0) { var exportAttributes = GetAttributesByClassName <T>((selectColumnsStr?[0]).Split(",")); for (int i = 0; i < dt.Count; i++) { ISheet sheet = book.CreateSheet(workSheetName[i]); ////获取Excel每个Sheet中行列属性 if (dt.Select(x => x.TableName).Distinct().ToList().Count > 1) { exportAttributes = GetAttributesByClassName <T>((selectColumnsStr?[i]).Split(",")); } ////表头 SetTitle(book, sheet, dt[i], exportAttributes, isShowSequenced); ////数据行 SetDataRow(book, sheet, dt[i], isShowSequenced); } } return(book); }
protected async Task <IQueryable> GetPageResultAsync <T>(ODataQueryOptions <T> options, IQueryable <T> queryable = null) where T : class, IEntitySet { GuardUtils.NotNull(options, nameof(options)); ////var appliedQueryOptions = AllowedQueryOptions.Skip | AllowedQueryOptions.Filter | AllowedQueryOptions.Expand; ////return options.ApplyTo(await GetAsync<T>(), appliedQueryOptions); return(options.ApplyTo(await GetAsync <T>())); }
/// <summary> /// 导出 /// </summary> /// <typeparam name="T">泛型</typeparam> /// <param name="excelBookInfo">需要写入Excel的WorkBook</param> /// <returns>返回HSSFWorkbook</returns> public static HSSFWorkbook Export <T>(this ExcelWorkBookInfo excelBookInfo) { GuardUtils.NotNull(excelBookInfo, nameof(excelBookInfo)); var book = ToHssfWorkbook <T>(excelBookInfo.Data, excelBookInfo.SheetName, excelBookInfo.ChoiseStr, excelBookInfo.IsShowSequenced ?? true); return(book); }
public bool BatchDelete <T>(IList <T> colls) where T : class, IEntitySet { GuardUtils.NotNull(colls, nameof(colls)); var filter = Builders <T> .Filter.In(x => x.Id, colls.Select(x => x.Id)); return(_context.Of <T>().DeleteMany(filter).DeletedCount > 0); }
public IList <T> BatchUpdate <T>(IList <T> colls) where T : class, IEntitySet { GuardUtils.NotNull(colls, nameof(colls)); _context.UpdateRange(colls); _context.SaveChanges(); return(colls); }
////[AuthorizePermission(FunctionsConst.SALARY_BASIC_SALARY_CREATE)] public async Task <IActionResult> Save([FromBody] ProductInfo info) { GuardUtils.NotNull(info, nameof(info)); var model = await _productService.Save(info); return(Json(model)); }
/// <summary> /// 导入 /// </summary> /// <typeparam name="T">泛型</typeparam> /// <param name="file">导入的文件</param> /// <returns>泛型集合</returns> public static IList <T> Import <T>(this IFormFile file) where T : class, new() { GuardUtils.NotNull(file, nameof(file)); var workbook = new XSSFWorkbook(file.OpenReadStream()); return(workbook.GetSheetAt(0).Import <T>().ToList()); }
public static IMongoCollection <T> Get <T>(this IMongoDatabase DBSession) { GuardUtils.NotNull(DBSession, nameof(DBSession)); string tableName = BsonClassMap.LookupClassMap(typeof(T)).Discriminator; return(DBSession.GetCollection <T>(tableName)); }
public static void FromXmlStringExtend(this RSACryptoServiceProvider rsa, string xmlString) { GuardUtils.NotNull(rsa, nameof(rsa)); RSAParameters parameters = new RSAParameters(); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(xmlString); if (xmlDoc.DocumentElement.Name.Equals("RSAKeyValue")) { foreach (XmlNode node in xmlDoc.DocumentElement.ChildNodes) { switch (node.Name) { case "Modulus": parameters.Modulus = Convert.FromBase64String(node.InnerText); break; case "Exponent": parameters.Exponent = Convert.FromBase64String(node.InnerText); break; case "P": parameters.P = Convert.FromBase64String(node.InnerText); break; case "Q": parameters.Q = Convert.FromBase64String(node.InnerText); break; case "DP": parameters.DP = Convert.FromBase64String(node.InnerText); break; case "DQ": parameters.DQ = Convert.FromBase64String(node.InnerText); break; case "InverseQ": parameters.InverseQ = Convert.FromBase64String(node.InnerText); break; case "D": parameters.D = Convert.FromBase64String(node.InnerText); break; default: throw new ArgumentException("Invalid XML RSA key.", nameof(xmlString)); } } } else { throw new ArgumentException("Invalid XML RSA key.", nameof(xmlString)); } rsa.ImportParameters(parameters); }
public static IActionResult ConvertFile(this ControllerBase c, byte[] bytes, string fileName) { GuardUtils.NotNull(c, nameof(c)); c.Response.Headers.Add("Content-Disposition", string.Format("attachment; filename=\"{0}\"", System.Web.HttpUtility.UrlEncode(fileName, Encoding.UTF8))); c.Response.Headers.Add("Content-Encoding", "utf8"); return(c.File(bytes, MimeKit.MimeTypes.GetMimeType(fileName))); }
/// <summary> /// 转换List为ExcelWorkBookInfo /// </summary> /// <typeparam name="T">泛型定义</typeparam> /// <param name="list">泛型List</param> /// <param name="sheetName">sheet名称</param> /// <param name="fileName">文件名</param> /// <param name="choiseStrs">选择列的字符串</param> /// <returns>ExcelWorkBookInfo对象</returns> public static ExcelWorkBookInfo ToExcelWorkBook <T>(this IList <T> list, string sheetName, string fileName, string[] choiseStrs) { var dts = new List <DataTable>(); GuardUtils.NotNull(choiseStrs, nameof(choiseStrs)); dts.AddRange(ToDataTable(list, choiseStrs[0].Split(","))); return(ConverteExcelWorkBook(dts, sheetName, fileName, choiseStrs[0])); }
public async Task <bool> DeleteAsync <T>(T t) where T : class, IEntitySet { GuardUtils.NotNull(t, nameof(t)); var filter = Builders <T> .Filter.Eq(x => x.Id, t.Id); await _context.Of <T>().DeleteOneAsync(filter); return(await GetAsync <T>(t.Id) == null); }
public static T Set <T>(this ICache cache, object key, T value) { GuardUtils.NotNull(cache, nameof(cache)); var entry = cache.CreateEntry(key); entry.Value = value; entry.Dispose(); return(value); }
public IModelBinder GetBinder(ModelBinderProviderContext context) { GuardUtils.NotNull(context, nameof(context)); if (context.Metadata.ModelType == typeof(DataSourceRequest)) { return(new CustomDataSourceRequestModelBinder()); } return(null); }
public async Task OnAuthorizationAsync(AuthorizationFilterContext context) { GuardUtils.NotNull(context, nameof(context)); AuthorizationResult ok = await _authService.AuthorizeAsync(context.HttpContext.User, null, _requirement); if (!ok.Succeeded) { context.Result = new ChallengeResult(); } }
/// <summary> /// 使用 IQueryable 或者 Get() 应用到 ODataQueryOptions 并生成查询表达式 /// </summary> /// <typeparam name="T">类型T</typeparam> /// <param name="options">ODataQueryOptions 类型参数实例</param> /// <param name="queryable">自定义的 IQueryable 类型实例, 如没有这个参数, 将使用 Get</param> /// <returns>返回应用到 ODataQueryOptions 之后的 IQueryable</returns> protected IQueryable Get <T>(ODataQueryOptions <T> options, IQueryable <T> queryable = null) where T : class, IEntitySet { GuardUtils.NotNull(options, nameof(options)); queryable = queryable ?? Get <T>(); if (WebConfig.CustomQuery != null && EnableCustomQuery) { return(options.ApplyTo(WebConfig.CustomQuery.Invoke(queryable))); } return(options.ApplyTo(queryable)); }
public static T Set <T>(this ICache cache, object key, T value, TimeSpan absoluteExpirationRelativeToNow) { GuardUtils.NotNull(cache, nameof(cache)); var entry = cache.CreateEntry(key); entry.AbsoluteExpirationRelativeToNow = absoluteExpirationRelativeToNow; entry.Value = value; entry.Dispose(); return(value); }
public T Update <T>(T t) where T : class, IEntitySet { GuardUtils.NotNull(t, nameof(t)); var filter = Builders <T> .Filter.Eq(x => x.Id, t.Id); _context.Of <T>().ReplaceOne(filter, t, new UpdateOptions() { IsUpsert = false }); return(t); }
public static T Set <T>(this ICache cache, object key, T value, DateTimeOffset absoluteExpiration) { GuardUtils.NotNull(cache, nameof(cache)); var entry = cache.CreateEntry(key); entry.AbsoluteExpiration = absoluteExpiration; entry.Value = value; entry.Dispose(); return(value); }
public async Task <IActionResult> Save([FromBody] SalaryInfo info) { GuardUtils.NotNull(info, nameof(info)); info.Key = string.IsNullOrEmpty(info.Key) ? info.Name : info.Key; info.FormType = FormType.Import; info.FormName = FormType.Import.GetDescription(); info.SalaryType = SalaryType.Import; var model = await _salaryService.Save(info); return(Json(model)); }
public static IActionResult ConvertFile(this ControllerBase c, string filePath, string fileName) { GuardUtils.NotNull(c, nameof(c)); if (filePath == null || !System.IO.File.Exists(filePath)) { return(c.NotFound()); } byte[] convertedContent = System.IO.File.ReadAllBytes(filePath); return(c.ConvertFile(convertedContent, string.Empty)); }
public async Task <T> SaveAsync <T>(T t) where T : class, IEntitySet { GuardUtils.NotNull(t, nameof(t)); var filter = Builders <T> .Filter.Eq(x => x.Id, t.Id); await _context.Of <T>().ReplaceOneAsync(filter, t, new UpdateOptions() { IsUpsert = true }); return(t); }
/// <summary> /// 文件字节 /// </summary> /// <typeparam name="T">泛型</typeparam> /// <param name="excelBookInfo">需要写入Excel的WorkBook</param> /// <returns>返回二进制数据</returns> public static byte[] ToBytes <T>(this ExcelWorkBookInfo excelBookInfo) { GuardUtils.NotNull(excelBookInfo, nameof(excelBookInfo)); var book = ToHssfWorkbook <T>(excelBookInfo.Data, excelBookInfo.SheetName, excelBookInfo.ChoiseStr, excelBookInfo.IsShowSequenced ?? true); //文件字节 using (var file = new MemoryStream()) { book.Write(file); return(file.ToArray()); } }
/// <summary> /// 导入 /// </summary> /// <typeparam name="T">泛型</typeparam> /// <param name="sheet">sheet</param> /// <returns>泛型集合</returns> public static IList <T> Import <T>(this ISheet sheet) where T : class, new() { GuardUtils.NotNull(sheet, nameof(sheet)); var type = typeof(T); var properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance); var dic = new Dictionary <string, PropertyInfo>(); foreach (var property in properties) { var attributes = property.GetCustomAttributes(typeof(ColumnNameAttribute), false); if (attributes.Length > 0) { var columnNameAttribute = attributes[0] as ColumnNameAttribute; if (columnNameAttribute != null) { dic.Add(columnNameAttribute.ColumnName, property); } } } IRow row = sheet.GetRow(0); var dic1 = new Dictionary <int, PropertyInfo>(); foreach (var cell in row.Cells) { var cellvalue = cell.StringCellValue; if (!string.IsNullOrEmpty(cellvalue)) { PropertyInfo pro = null; if (dic.TryGetValue(cellvalue, out pro)) { dic1.Add(cell.ColumnIndex, pro); } } } var list = new List <T>(); foreach (IRow r in sheet) { if (r.RowNum == 0) { continue; } dynamic info = Row2Object <T>(r, dic1); info.RowNum = r.RowNum + 1; list.Add(info); } return(list); }
/// <summary> /// Sheet填充数据 /// </summary> /// <param name="baseSheet">sheet</param> /// <param name="tbData">DataTable数据</param> public static void SetDataSourse(this ISheet baseSheet, DataTable tbData) { GuardUtils.NotNull(baseSheet, nameof(baseSheet)); GuardUtils.NotNull(tbData, nameof(tbData)); ////获取Title在DataTable数据中对应的列idx var dicData = GetTitleDic(tbData, baseSheet); for (int i = 0; i < tbData.Rows.Count; i++) { var row = i == 0 ? baseSheet.GetRow(i + 1) : baseSheet.CreateRow(i + 1); SetRowData(row, baseSheet, i, tbData, dicData); } }
public TokenProviderMiddleware( RequestDelegate next, IOptions <TokenProviderOptions> options) { GuardUtils.NotNull(options, nameof(options)); _next = next; _options = options.Value; ThrowIfInvalidOptions(_options); _serializerSettings = new JsonSerializerSettings { Formatting = Formatting.Indented }; }
public static bool VerifyWithTimeStamp(SortedDictionary <string, string> sParaTemp, string sign, long timeStamp, long expireTime = 180) { GuardUtils.NotNull(sParaTemp, nameof(sParaTemp)); ////if (!IsExpired(timeStamp)) ////{ //// if (Verify(sParaTemp, sParaTemp["Sign"])) //// { //// return true; //// } ////} ////return false; return(!IsExpired(timeStamp) && Verify(sParaTemp, sParaTemp["Sign"])); }
public static T Set <T>(this ICache cache, object key, T value, MemoryCacheEntryOptions options) { GuardUtils.NotNull(cache, nameof(cache)); using (var entry = cache.CreateEntry(key)) { if (options != null) { entry.SetOptions(options); } entry.Value = value; } return(value); }
public async Task Invoke(HttpContext context) { GuardUtils.NotNull(context, nameof(context)); try { await _next(context); } catch (Exception ex) { var statusCode = context.Response.StatusCode; log4net.LogManager.GetLogger(typeof(HttpContext)).Error(statusCode.ToString()); log4net.LogManager.GetLogger(typeof(HttpContext)).Error(ex.ToString()); await _next(context); } }
public Task Invoke(HttpContext context, Services.Contracts.IAccountService accountService) { GuardUtils.NotNull(context, nameof(context)); if (!context.Request.Path.Equals(_options.Path, StringComparison.Ordinal)) { return(_next(context)); } if (context.Request.Method.Equals("POST") && context.Request.HasFormContentType) { return(GenerateToken(context, accountService)); } context.Response.StatusCode = StatusCodes.Status400BadRequest; return(context.Response.WriteAsync("Bad request.")); }