/// <summary> /// Get default setting for given profile type. /// </summary> /// <param name="profile"> /// The code cleanup profile to use. /// </param> /// <param name="profileType"> /// Determine if it is a full or reformat <see cref="CodeCleanup.DefaultProfileType"/>. /// </param> public void SetDefaultSetting(CodeCleanupProfile profile, CodeCleanup.DefaultProfileType profileType) { // Default option are set in the constructors. OrderingOptions orderingOptions = new OrderingOptions(); profile.SetSetting(OrderingDescriptor, orderingOptions); LayoutOptions layoutOptions = new LayoutOptions(); profile.SetSetting(LayoutDescriptor, layoutOptions); DocumentationOptions documentationOptions = new DocumentationOptions(); profile.SetSetting(DocumentationDescriptor, documentationOptions); SpacingOptions spacingOptions = new SpacingOptions(); profile.SetSetting(SpacingDescriptor, spacingOptions); ReadabilityOptions readabilityOptions = new ReadabilityOptions(); profile.SetSetting(ReadabilityDescriptor, readabilityOptions); MaintainabilityOptions maintainabilityOptions = new MaintainabilityOptions(); profile.SetSetting(MaintainabilityDescriptor, maintainabilityOptions); }
private void OrderPropertyIndexerAndEventDeclarations(OrderingOptions options, ICSharpFile file) { foreach (ICSharpNamespaceDeclaration namespaceDeclaration in file.NamespaceDeclarations) { this.ProcessTypeDeclarations(options, namespaceDeclaration.TypeDeclarations); } this.ProcessTypeDeclarations(options, file.TypeDeclarations); }
/// <summary> /// Run the OrderingRules Fix. /// </summary> /// <param name="options"> /// OrderingOptions for the Fix. /// </param> /// <param name="file"> /// File that the fix will be performed on. /// </param> public void Execute(OrderingOptions options, ICSharpFile file) { StyleCopTrace.In(options, file); OrderUsings(options, file); this.OrderPropertyIndexerAndEventDeclarations(options, file); StyleCopTrace.Out(); }
private void ProcessTypeDeclarations(OrderingOptions options, IEnumerable <ICSharpTypeDeclaration> typeDeclarations) { foreach (ICSharpTypeDeclaration typeDeclaration in typeDeclarations) { foreach (ICSharpTypeMemberDeclaration memberDeclaration in typeDeclaration.MemberDeclarations) { ProcessMemberDeclarations(memberDeclaration, options); } this.ProcessNestedTypeDeclarations(options, typeDeclaration.NestedTypeDeclarations); } }
/// <summary> /// The execute transaction inner. /// </summary> /// <param name="solution"> /// The solution. /// </param> /// <param name="textControl"> /// The text control. /// </param> public override void ExecuteTransactionInner(ISolution solution, ITextControl textControl) { ICSharpFile file = Utils.GetCSharpFile(solution, textControl); OrderingOptions options = new OrderingOptions { AlphabeticalUsingDirectives = AlphabeticalUsingsStyle.Alphabetical, ExpandUsingDirectives = ExpandUsingsStyle.FullyQualify }; // Fixes SA1208, SA1209, SA1210, SA1211 new OrderingRules().Execute(options, file); }
/// <summary> /// Process clean-up on file. /// </summary> /// <param name="projectFile"> /// The project file to process. /// </param> /// <param name="range"> /// The range marker to process. /// </param> /// <param name="profile"> /// The code cleanup settings to use. /// </param> /// <param name="canIncrementalUpdate"> /// Determines whether we can incrementally update. /// </param> /// <param name="progressIndicator"> /// The progress indicator. /// </param> public void Process( IProjectFile projectFile, IPsiRangeMarker range, CodeCleanupProfile profile, out bool canIncrementalUpdate, JB::JetBrains.Application.Progress.IProgressIndicator progressIndicator) { StyleCopTrace.In(projectFile, range, profile, progressIndicator); canIncrementalUpdate = true; if (projectFile == null) { return; } if (!this.IsAvailable(projectFile)) { return; } ISolution solution = projectFile.GetSolution(); PsiManagerImpl psiManager = PsiManagerImpl.GetInstance(solution); ICSharpFile file = psiManager.GetPsiFile(projectFile, PsiLanguageType.GetByProjectFile(projectFile)) as ICSharpFile; if (file == null) { return; } DocumentationOptions documentationOptions = profile.GetSetting(DocumentationDescriptor); LayoutOptions layoutOptions = profile.GetSetting(LayoutDescriptor); MaintainabilityOptions maintainabilityOptions = profile.GetSetting(MaintainabilityDescriptor); OrderingOptions orderingOptions = profile.GetSetting(OrderingDescriptor); ReadabilityOptions readabilityOptions = profile.GetSetting(ReadabilityDescriptor); SpacingOptions spacingOptions = profile.GetSetting(SpacingDescriptor); // Process the file for all the different Code Cleanups we have here // we do them in a very specific order. Do not change it. new ReadabilityRules().Execute(readabilityOptions, file); new MaintainabilityRules().Execute(maintainabilityOptions, file); new DocumentationRules().Execute(documentationOptions, file); new LayoutRules().Execute(layoutOptions, file); new SpacingRules().Execute(spacingOptions, file); new OrderingRules().Execute(orderingOptions, file); StyleCopTrace.Out(); }
/// <summary> /// Processes all the cleanup. /// </summary> /// <param name="profile"> /// The current profile to use. /// </param> /// <param name="file"> /// The file to clean. /// </param> private void InternalProcess(CodeCleanupProfile profile, ICSharpFile file) { DocumentationOptions documentationOptions = profile.GetSetting(DocumentationDescriptor); LayoutOptions layoutOptions = profile.GetSetting(LayoutDescriptor); MaintainabilityOptions maintainabilityOptions = profile.GetSetting(MaintainabilityDescriptor); OrderingOptions orderingOptions = profile.GetSetting(OrderingDescriptor); ReadabilityOptions readabilityOptions = profile.GetSetting(ReadabilityDescriptor); SpacingOptions spacingOptions = profile.GetSetting(SpacingDescriptor); // Process the file for all the different Code Cleanups we have here // we do them in a very specific order. Do not change it. new ReadabilityRules(this.shellLocks).Execute(readabilityOptions, file); new MaintainabilityRules().Execute(maintainabilityOptions, file); new DocumentationRules().Execute(documentationOptions, file); new LayoutRules().Execute(layoutOptions, file); new SpacingRules().Execute(spacingOptions, file); new OrderingRules().Execute(orderingOptions, file); }
/// <summary> /// Orders the files usings statements. /// </summary> /// <param name="options"> /// The options to use. /// </param> /// <param name="file"> /// The file to process. /// </param> public static void OrderUsings(OrderingOptions options, ICSharpFile file) { AlphabeticalUsingsStyle organiseUsingsFormatOption = options.AlphabeticalUsingDirectives; ExpandUsingsStyle expandUsingsFormatOption = options.ExpandUsingDirectives; // Exit if both options are to ignore if (organiseUsingsFormatOption == AlphabeticalUsingsStyle.Ignore && expandUsingsFormatOption == ExpandUsingsStyle.Ignore) { return; } foreach (ICSharpNamespaceDeclaration namespaceDeclaration in file.NamespaceDeclarations) { ProcessImports(namespaceDeclaration.Imports, organiseUsingsFormatOption, expandUsingsFormatOption, namespaceDeclaration); } ProcessImports(file.Imports, organiseUsingsFormatOption, expandUsingsFormatOption, file); }
private static void ProcessMemberDeclarations(IDeclaration declaration, OrderingOptions options) { bool propertyAccessorsMustFollowOrder = options.SA1212PropertyAccessorsMustFollowOrder; bool eventAccessorsMustFollowOrder = options.SA1213EventAccessorsMustFollowOrder; if (declaration is IIndexerDeclaration && propertyAccessorsMustFollowOrder) { CheckAccessorOrder(declaration as IIndexerDeclaration); } else if (declaration is IPropertyDeclaration && propertyAccessorsMustFollowOrder) { CheckAccessorOrder(declaration as IPropertyDeclaration); } else if (declaration is IEventDeclaration && eventAccessorsMustFollowOrder) { CheckAccessorOrder(declaration as IEventDeclaration); } }
public IActionResult GetAnimals([FromQuery] PagingOptions pagingOptions, [FromQuery] OrderingOptions <AnimalOrderType> orderingOptions, bool?includeArchived = false) { Logger.LogInformation($"Requesting {pagingOptions.PageSize} animals from page {pagingOptions.PageNumber}..."); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var filter = new AnimalSummaryFilter { IncludeArchived = includeArchived }; var animals = _animalSummaryService.SearchPaged(filter, pagingOptions, orderingOptions); return(Ok(animals)); }
public virtual Task <IOrderedQueryable <TEntity> > GetByCondition(Expression <Func <TEntity, bool> > filter, OrderingOptions <TEntity, int> orderingOptions = null) { var ordOptions = orderingOptions ?? OrderingOptions <TEntity, int> .Create(); if (filter == null) { if (ordOptions.Direction == OrderingDirection.Ascend) { return(Task.FromResult(_dataSet.OrderBy(ordOptions.Order))); } return(Task.FromResult(_dataSet.OrderByDescending(ordOptions.Order))); } if (ordOptions.Direction == OrderingDirection.Ascend) { return(Task.FromResult(_dataSet.Where(filter).OrderBy(ordOptions.Order))); } return(Task.FromResult(_dataSet.Where(filter).OrderByDescending(ordOptions.Order))); }
// get paging model /// <summary> /// If pageSize is 0 - returns the whole dataset /// </summary> /// <param name="filter"></param> /// <param name="pageNumber"></param> /// <param name="pageSize"></param> /// <param name="orderingOptions"></param> /// <returns></returns> public async Task <PagingModel <TDto> > GetByCondition(TFilter filter, int pageNumber, int pageSize, OrderingOptions <TEntity, int> orderingOptions = null) { if (pageNumber < 1) { throw new ArgumentException(nameof(pageNumber)); } if (pageSize < 0) { throw new ArgumentException(nameof(pageSize)); } // this is sync operation anyway var data = DataProvider.GetByCondition(GenerateExpression(filter), orderingOptions).Result; var count = await data.CountAsync(); if (pageSize == 0) { return(new PagingModel <TDto>(count, count, 1) { PageData = await data.Skip(0) .Take(count) .Select(x => Mapper.Map <TDto>(x)) .ToArrayAsync() }); } return(new PagingModel <TDto>(count, pageSize, pageNumber) { PageData = await data.Skip((pageNumber - 1) *pageSize) .Take(pageSize) .Select(x => Mapper.Map <TDto>(x)) .ToArrayAsync() }); }
/// <summary> /// Order an <see cref="IQueryable"/> of <see cref="AnimalSummary"/> items according /// to the <paramref name="orderingOptions"/>. /// </summary> /// <param name="query">The <see cref="IQueryable"/> of <see cref="AnimalSummary"/> items.</param> /// <param name="orderingOptions">Options for ordering the result set.</param> /// <returns>The <see cref="IOrderedQueryable"/> of <see cref="AnimalSummary"/> items.</returns> public static IOrderedQueryable <AnimalSummary> Order(this IQueryable <AnimalSummary> query, OrderingOptions <AnimalOrderType>?orderingOptions) { if (orderingOptions == null) { return(query.OrderBy(animal => animal.Number)); } return(orderingOptions.Direction == ListSortDirection.Ascending ? query.OrderBy(GetOrderKeyExpression(orderingOptions.Property)) : query.OrderByDescending(GetOrderKeyExpression(orderingOptions.Property))); }
/// <inheritdoc/> public IPagedData <AnimalSummary> SearchPaged(IQueryableFilter <AnimalSummary> filter, IPagingOptions pagingOptions, OrderingOptions <AnimalOrderType>?orderingOptions = null) { return(dbContext.Animals .SelectAnimalSummaries() .FilterOnObject(filter) .Order(orderingOptions) .Paginate(pagingOptions)); }