private void updateAggregates(ColumnAttributes col, CellAttributes cell) { if (cell == null || col.AggregateFunction == null) { return; } col.AggregateFunction.CellAdded(cell.RowData.Value, CurrentRowInfoData.IsNewGroupStarted); var columnRowSummary = new SummaryCellData { CellData = new CellData { PropertyName = col.PropertyName, PropertyValue = cell.RowData.Value }, GroupAggregateValue = FuncHelper.ApplyFormula(col.AggregateFunction.DisplayFormatFormula, col.AggregateFunction.GroupValue), GroupRowNumber = CurrentRowInfoData.LastGroupRowNumber, OverallAggregateValue = FuncHelper.ApplyFormula(col.AggregateFunction.DisplayFormatFormula, col.AggregateFunction.OverallValue), OverallRowNumber = CurrentRowInfoData.LastOverallDataRowNumber, GroupNumber = CurrentRowInfoData.LastGroupNumber }; SharedData.ColumnCellsSummaryData.Add(columnRowSummary); }
private T CachingFullMode(Func <T> valueFactory, ManualResetEvent waitHandle, ref Thread thread) { if (Interlocked.CompareExchange(ref _isValueCreated, 1, 0) == 0) { try { thread = Thread.CurrentThread; GC.KeepAlive(thread); _target = valueFactory.Invoke(); _valueFactory = FuncHelper.GetReturnFunc(_target); return(_target); } catch (Exception exc) { _valueFactory = FuncHelper.GetThrowFunc <T>(exc); throw; } finally { waitHandle.Set(); thread = null; } } else { if (ReferenceEquals(thread, Thread.CurrentThread)) { throw new InvalidOperationException(); } waitHandle.WaitOne(); return(_valueFactory.Invoke()); } }
private T NoneMode(HashSet <Thread> threads, Func <T> valueFactory) { if (Volatile.Read(ref _isValueCreated) != 0) { return(_valueFactory.Invoke()); } try { AddThread(threads); ValueForDebugDisplay = valueFactory(); _valueFactory = FuncHelper.GetReturnFunc(ValueForDebugDisplay); Volatile.Write(ref _isValueCreated, 1); return(ValueForDebugDisplay); } catch (Exception) { Volatile.Write(ref _isValueCreated, 0); throw; } finally { RemoveThread(threads); } }
private void printSummary(Rectangle position, PdfContentByte[] canvases) { var rowSummaryDataObj = getRowSummaryData() ?? string.Empty; var rowSummaryData = FuncHelper.ApplyFormula(_pdfRptCell.SharedData.PdfColumnAttributes.AggregateFunction.DisplayFormatFormula, rowSummaryDataObj); if (!_pdfRptCell.BasicProperties.RunDirection.HasValue) { _pdfRptCell.BasicProperties.RunDirection = PdfRunDirection.LeftToRight; } if (_pdfRptCell.BasicProperties.RunDirection == PdfRunDirection.RightToLeft) { rowSummaryData = rowSummaryData.FixWeakCharacters(); } var formattedValue = rowSummaryData.ToSafeString(); setCellData(rowSummaryDataObj, formattedValue); setMainTableEvents(); var phrase = _pdfRptCell.BasicProperties.PdfFont.FontSelector.Process(_pdfRptCell.RowData.FormattedValue); var alignment = getAggregateValuePosition(position); ColumnText.ShowTextAligned( canvas: canvases[PdfPTable.TEXTCANVAS], alignment: (int)alignment.HorizontalAlignment, phrase: phrase, x: alignment.X, y: ((position.Bottom + position.Top) / 2) - 4, rotation: 0, runDirection: (int)_pdfRptCell.BasicProperties.RunDirection, arabicOptions: 0); }
/// <summary> /// 根据参数构建SQL条件语句(返回SQL条件语句),huhm2008 /// </summary> /// <param name="sqlCmd">源sql语句:如果sqlCmd已存在参数则不追加此参数</param> /// <param name="dbParas">参数</param> /// <returns>返回SQL条件语句,无参数时返回string.empty,否则返回形如: AND UserCode=@UserCode and Password=@Password </returns> public static string BuildParaSqlString(string sqlCmd, DbParameter[] dbParas) { //根据参数取数据 StringBuilder cParaWhere = new StringBuilder(); if (dbParas != null) { foreach (DbParameter para in dbParas) { string paraValue = para.Value == null?"":para.Value.ToString(); if (paraValue.IndexOf(',') < 0) { //构建SQL参数 //if (sqlCmd.IndexOf("@" + TransToColumnName(para.ParameterName) + " ", StringComparison.InvariantCultureIgnoreCase) < 0) if (!Regex.IsMatch(sqlCmd + " ", "@" + TransToColumnName(para.ParameterName) + "[^0-9a-zA-Z]+", RegexOptions.IgnoreCase)) { cParaWhere.Append(" AND " + para.ParameterName + "=@" + TransToColumnName(para.ParameterName)); } } else { //参数值中带有“,”则不构造参数,用SQL字符串构建 //检测是否为Int数组,非Int数组字符串不能添加(有安全漏洞) if (FuncHelper.IsIntArrayString(paraValue)) { cParaWhere.Append(" AND " + para.ParameterName + " IN(" + paraValue + ")"); } } } } return(cParaWhere.ToString()); }
public ConditionalExtendedList(IEnumerable <T> target, IEnumerable <T> append, Func <bool> enumerateTarget, Func <bool> enumerateAppend) { _target = target == null ? ArrayReservoir <T> .EmptyArray : Extensions.WrapAsIList(target); _append = append == null ? ArrayReservoir <T> .EmptyArray : Extensions.WrapAsIList(append); _enumerateTarget = enumerateTarget ?? (null == target ? FuncHelper.GetFallacyFunc() : FuncHelper.GetTautologyFunc()); _enumerateAppend = enumerateAppend ?? (null == append ? FuncHelper.GetFallacyFunc() : FuncHelper.GetTautologyFunc()); }
public bool Dispose(Func <bool> condition) { if (condition == null) { throw new ArgumentNullException("condition"); } Func <bool> temp = condition; return(DisposedConditional ( FuncHelper.GetFallacyFunc(), () => { if (condition.Invoke()) { Dispose(); return true; } else { return false; } } )); }
private string thisPageSummary() { var pageBoundary = CurrentRowInfoData.PagesBoundaries.OrderByDescending(x => x).Take(2).ToList(); if (!pageBoundary.Any()) { return(string.Empty); } int firstRowOfThePage, lastRowOfThePage; if (pageBoundary.Count == 1) { firstRowOfThePage = 1; lastRowOfThePage = pageBoundary[0]; } else { firstRowOfThePage = pageBoundary[1] + 1; lastRowOfThePage = pageBoundary[0]; } var propertyName = _pdfRptCell.SharedData.PdfColumnAttributes.PropertyName; var list = SummaryCellsData.Where(x => x.CellData.PropertyName == propertyName && x.OverallRowNumber >= firstRowOfThePage && x.OverallRowNumber <= lastRowOfThePage) .ToList(); var result = _pdfRptCell.SharedData.PdfColumnAttributes.AggregateFunction.ProcessingBoundary(list); return(FuncHelper.ApplyFormula(_pdfRptCell.SharedData.PdfColumnAttributes.AggregateFunction.DisplayFormatFormula, result)); }
public ContainerContext(IContainerConfiguration configuration, IClassWrapperCreator classWrapperCreator) { Configuration = configuration; ClassWrapperCreator = classWrapperCreator; ITypesHelper typesHelper = new TypesHelper(); var funcHelper = new FuncHelper(); FuncBuilder = new FuncBuilder(); var classCreator = new ClassCreator(funcHelper); var constructorSelector = new ConstructorSelector(); CreationContext = new CreationContext(classCreator, constructorSelector, classWrapperCreator); var implementationTypesCollection = new ImplementationTypesCollection(configuration.GetTypesToScan(), typesHelper); ImplementationCache = new ImplementationCache(); IAbstractionsCollection abstractionsCollection = new AbstractionsCollection(implementationTypesCollection, ImplementationCache); ImplementationConfigurationCache = new ImplementationConfigurationCache(); //l var factory = new AutoAbstractionConfigurationFactory(typesHelper, abstractionsCollection, ImplementationConfigurationCache); AbstractionConfigurationCollection = new AbstractionConfigurationCollection(factory); AbstractionConfigurationCollection.Add(typeof(IContainer), new StupidAbstractionConfiguration(new ContainerImplementationConfiguration())); }
public ResultLogin Login(Model.DB.User model) { ApiResultEnum result = UserDA.Login(ref model, platform); if (result == ApiResultEnum.Success) { string user_token = UserRA.Get(model.id.ToString(), "platform_" + platform); if (string.IsNullOrWhiteSpace(user_token)) { user_token = FuncHelper.GetUniqueString(); Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("platform_" + platform, user_token); dic.Add("name", model.name); dic.Add("status_order", model.status_order.ToString()); dic.Add("role", model.role.ToString()); dic.Add("login_time_" + platform, DateTime.Now.Format()); UserRA.Set(model.id.ToString(), dic); UserRA.SetExpire(model.id.ToString()); } return(new ResultLogin(result, model, model.id + "-" + user_token)); } else { return(new ResultLogin(result, null, null)); } }
public CacheNeedle(Func <T> valueFactory, T target, bool trackResurrection, bool cacheExceptions) : base(target, trackResurrection) { if (valueFactory == null) { throw new ArgumentNullException("valueFactory"); } _valueFactory = valueFactory; if (cacheExceptions) { _valueFactory = () => { try { return(valueFactory.Invoke()); } catch (Exception exc) { _valueFactory = FuncHelper.GetThrowFunc <T>(exc); throw; } }; } _waitHandle = new StructNeedle <ManualResetEventSlim>(new ManualResetEventSlim(false)); }
private T CachingFullMode(Func <T> valueFactory, EventWaitHandle waitHandle, ref Thread thread) { if (Interlocked.CompareExchange(ref _isValueCreated, 1, 0) == 0) { try { thread = Thread.CurrentThread; GC.KeepAlive(thread); ValueForDebugDisplay = valueFactory.Invoke(); _valueFactory = FuncHelper.GetReturnFunc(ValueForDebugDisplay); return(ValueForDebugDisplay); } catch (Exception exc) { _valueFactory = FuncHelper.GetThrowFunc <T>(exc); throw; } finally { waitHandle.Set(); thread = null; } } if (thread == Thread.CurrentThread) { throw new InvalidOperationException(); } waitHandle.WaitOne(); return(_valueFactory.Invoke()); }
public CompositeContainerContext(IContainerConfiguration configuration, IClassWrapperCreator classWrapperCreator, IContainerSelector containerSelector) { this.Configuration = configuration; ClassWrapperCreator = classWrapperCreator; typesHelper = new TypesHelper(); var funcHelper = new FuncHelper(); FuncBuilder = new FuncBuilder(); var classCreator = new ClassCreator(funcHelper); var constructorSelector = new ConstructorSelector(); CreationContext = new CreationContext(classCreator, constructorSelector, classWrapperCreator); var implementationTypesCollection = new ImplementationTypesCollection(configuration, typesHelper); ImplementationCache = new ImplementationCache(); abstractionsCollection = new AbstractionsCollection(implementationTypesCollection, ImplementationCache); ImplementationConfigurationCache = new ImplementationConfigurationCache(); var factory = new AutoAbstractionConfigurationFactory(typesHelper, abstractionsCollection, ImplementationConfigurationCache); compositeCollection = new CompositeCollection(new[] { new AbstractionConfigurationCollection(factory) }, containerSelector); compositeCollection.Add(typeof(IContainer), new StupidAbstractionConfiguration( new ContainerImplementationConfiguration())); }
public ConditionalExtendedList(IEnumerable <T> target, IEnumerable <T> append, Func <bool>?enumerateTarget, Func <bool>?enumerateAppend) { _target = target?.WrapAsIList() ?? ArrayEx.Empty <T>(); _append = append?.WrapAsIList() ?? ArrayEx.Empty <T>(); _enumerateTarget = enumerateTarget ?? (target == null ? FuncHelper.GetFallacyFunc() : FuncHelper.GetTautologyFunc()); _enumerateAppend = enumerateAppend ?? (append == null ? FuncHelper.GetFallacyFunc() : FuncHelper.GetTautologyFunc()); }
public async Task <ListResp <GetRoleItemResp> > GetAuthUserFuncList() { var memIdentityRes = await AdminHelper.GetAuthAdmin(); if (!memIdentityRes.IsSuccess()) { return(new ListResp <GetRoleItemResp>().WithResp(memIdentityRes)); } // 如果是超级管理员直接返回所有 if (memIdentityRes.data.auth_type != PortalAuthorizeType.SuperAdmin) { return(await FuncHelper.GetAuthUserRoleFuncList()); } var sysFunItemsRes = await FuncHelper.GetAllFuncItems(); if (!sysFunItemsRes.IsSuccess()) { return(new ListResp <GetRoleItemResp>().WithResp(sysFunItemsRes)); } var roleItems = sysFunItemsRes.data.Select(item => item.ToRoleItemResp()).ToList(); return(new ListResp <GetRoleItemResp>(roleItems)); }
private string getTotalSummaries() { var row = CurrentRowInfoData.LastRenderedRowNumber; var propertyName = _pdfRptCell.SharedData.PdfColumnAttributes.PropertyName; var result = SummaryCellsData.FirstOrDefault(x => x.CellData.PropertyName == propertyName && x.OverallRowNumber == row); if (result == null) { return(string.Empty); } object data; if (IsGroupingEnabled && (_pdfRptCell.RowData.PdfRowType == RowType.SummaryRow || _pdfRptCell.RowData.PdfRowType == RowType.PreviousPageSummaryRow)) { data = result.GroupAggregateValue; } else { data = result.OverallAggregateValue; } return(FuncHelper.ApplyFormula(_pdfRptCell.SharedData.PdfColumnAttributes.AggregateFunction.DisplayFormatFormula, data)); }
private Lazy(Func <T> valueFactory, LazyThreadSafetyMode mode, bool cacheExceptions) { if (valueFactory == null) { throw new ArgumentNullException(nameof(valueFactory)); } switch (mode) { case LazyThreadSafetyMode.None: if (cacheExceptions) { var threads = new HashSet <Thread>(); _valueFactory = () => CachingNoneMode(threads, valueFactory); } else { var threads = new HashSet <Thread>(); _valueFactory = () => NoneMode(threads, valueFactory); } break; case LazyThreadSafetyMode.PublicationOnly: _valueFactory = PublicationOnlyMode; break; default: /*LazyThreadSafetyMode.ExecutionAndPublication*/ if (cacheExceptions) { Thread? thread = null; ManualResetEvent?manualResetEvent = null; _valueFactory = () => CachingFullMode(valueFactory, ref manualResetEvent, ref thread); } else { Thread? thread = null; ManualResetEvent?manualResetEvent = null; _valueFactory = () => FullMode(valueFactory, ref manualResetEvent, ref thread); } break; } T PublicationOnlyMode() { ValueForDebugDisplay = valueFactory(); if (Interlocked.CompareExchange(ref _isValueCreated, 1, 0) == 0) { _valueFactory = FuncHelper.GetReturnFunc(ValueForDebugDisplay); } return(ValueForDebugDisplay); } }
internal static async Task <Resp> LogOut(UserIdentity user) { // 清楚用户权限相关缓存 await FuncHelper.ClearAuthUserFuncListCache(user); await ClearAdminCache(); return(new Resp(RespTypes.UnLogin, "请登录!")); }
public void Test1(string number1, string number2, string expected) { //Given //When var result = FuncHelper.Sum(number1, number2); //Then Assert.Equal(expected, result); }
private T PublicationOnlyMode(Func <T> valueFactory) { _target = valueFactory(); if (Interlocked.CompareExchange(ref _isValueCreated, 1, 0) == 0) { _valueFactory = FuncHelper.GetReturnFunc(_target); } return(_target); }
private BucketCore(int level) { _childFactory = level == 1 ? FuncHelper.GetDefaultFunc <object>() : () => new BucketCore(_level - 1); _level = level; _arrayFirst = ArrayReservoir <object> .GetArray(_capacity); _arraySecond = ArrayReservoir <object> .GetArray(_capacity); _arrayUse = ArrayReservoir <int> .GetArray(_capacity); }
public HistoryControlVM(QueryItemRepository itemsRepository, IVersionProvider versionProvider, IServiceCacheIntegration serviceCacheIntegration) { _itemsRepository = itemsRepository; _versionProvider = versionProvider; _serviceCacheIntegration = serviceCacheIntegration; RequestItemsCommand = new AsyncCommand(FuncHelper.DebounceAsync(ExecuteRequestItemsAsync, 100), CanExecuteSubmit, this.HandleError); ViewLoadedCommand = new AsyncCommand(OnViewLoadedAsync, CanExecuteSubmit, this.HandleError); OpenScriptCmd = new Command <SearchFilterResultVM>(OpenScript, () => true, HandleError); InitDefaults(); }
public void GroupProgressiveByOverloadDEx() { var src = new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; var r = src.GroupProgressiveBy(i => i > 5, FuncHelper.GetIdentityFunc <int>(), (_, group) => StringEx.Concat(group.ToArray()), null); var rArray = r.ToArray(); Assert.AreEqual(rArray.Length, 2); Assert.AreEqual(rArray[0], "12345"); Assert.AreEqual(rArray[1], "678910"); }
public void GroupByOverloadDEx() { var _src = new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; var r = _src.GroupBy(i => i > 5, FuncHelper.GetIdentityFunc <int>(), (key, group) => StringHelper.Concat(group.ToArray()), null); var _r = r.ToArray(); Assert.AreEqual(_r.Length, 2); Assert.AreEqual(_r[0], "12345"); Assert.AreEqual(_r[1], "678910"); }
public ConditionalExtendedEnumerable(IEnumerable <T> target, IEnumerable <T> append, Func <bool> enumerateTarget, Func <bool> enumerateAppend) : base(target, append) { if (enumerateTarget == null) { throw new ArgumentNullException("enumerateTarget"); } _enumerateTarget = enumerateTarget; _enumerateAppend = enumerateAppend ?? (null == append ? FuncHelper.GetFallacyFunc() : FuncHelper.GetTautologyFunc()); }
private string getText(CellAttributes attributes) { var text = FuncHelper.ApplyFormula(attributes.BasicProperties.DisplayFormatFormula, attributes.RowData.Value); if (!string.IsNullOrEmpty(TextPropertyName)) { text = attributes.RowData.TableRowData.GetSafeStringValueOf(TextPropertyName); } attributes.RowData.FormattedValue = text; return(text); }
/// <summary> /// Custom cell's content template as a PdfPCell. /// </summary> /// <returns>Content as a PdfPCell</returns> public PdfPCell RenderingCell(CellAttributes attributes) { var data = FuncHelper.ApplyFormula(attributes.BasicProperties.DisplayFormatFormula, attributes.RowData.Value); attributes.RowData.FormattedValue = data; var img = _barcode.GetBarcodeImage(data, attributes.SharedData.PdfWriter.DirectContent); return(new PdfPCell(img) { PaddingTop = 5, }); }
public void Order(Order order) { string request_id = FuncHelper.GetUniqueID().ToString(); order.account_id = account_id; order.name = StockInfoBiz.GetStock(order.code).name; order.time_dt = DateTime.Now; OrderRA.Add(order, "O_" + request_id + "_T_" + order.trade_no + "_U_" + order.unit_id + "_F"); JY.Order(new JY.Order(order.code, order.type, order.count, order.price, request_id)); MonitorRA.Increment("account_" + account_id, "order_count"); }
private async Task <ListResp <RoleFunSmallMo> > GetUserAllFuncsNoCache() { var userIdentity = CoreUserContext.Identity; if (userIdentity.auth_type == PortalAuthorizeType.SuperAdmin) { // 如果是超级管理员直接返回所有 var sysFunItemsRes = await FuncHelper.GetAllFuncItems(); if (!sysFunItemsRes.IsSuccess()) { return(new ListResp <RoleFunSmallMo>().WithResp(sysFunItemsRes)); } var roleItems = sysFunItemsRes.data.Select(item => item.ToSmallMo()).ToList(); return(new ListResp <RoleFunSmallMo>(roleItems)); } var userId = userIdentity.id.ToInt64(); var roleIdsRes = await GetUserRoles(userId); if (!roleIdsRes.IsSuccess()) { return(new ListResp <RoleFunSmallMo>().WithResp(roleIdsRes)); } var funcRes = await RoleFuncRep.Instance.GetRoleFuncList(roleIdsRes.data.Select(s => s.id).ToList()); if (!funcRes.IsSuccess()) { return(new ListResp <RoleFunSmallMo>().WithResp(funcRes, "未获取有效角色对应权限信息!")); } var funcItems = funcRes.data; var dir = new Dictionary <string, RoleFunSmallMo>(); foreach (var f in funcItems) { if (!dir.ContainsKey(f.func_code)) { dir.Add(f.func_code, f); continue; } var fValue = dir[f.func_code]; if (f.data_level < fValue.data_level) { fValue.data_level = f.data_level; } } return(new ListResp <RoleFunSmallMo>(dir.Select(d => d.Value).ToList())); }
private T FullMode(Func <T> valueFactory, ref ManualResetEvent?waitHandle, ref Thread?thread) { if (waitHandle == null) { waitHandle = new ManualResetEvent(false); } while (Volatile.Read(ref _isValueCreated) != 1) { var foundThread = Interlocked.CompareExchange(ref thread, Thread.CurrentThread, null); if (foundThread == null) { try { ValueForDebugDisplay = valueFactory.Invoke(); _valueFactory = FuncHelper.GetReturnFunc(ValueForDebugDisplay); Volatile.Write(ref _isValueCreated, 1); return(ValueForDebugDisplay); } finally { Volatile.Write(ref thread, default); waitHandle.Set(); if (Volatile.Read(ref _isValueCreated) == 1) { waitHandle.Close(); } } } if (foundThread == Thread.CurrentThread) { throw new InvalidOperationException(); } if (waitHandle.SafeWaitHandle.IsClosed) { continue; } try { waitHandle.WaitOne(); } catch (ObjectDisposedException exception) { _ = exception; } } return(_valueFactory.Invoke()); }