Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add analyzers and correct warnings #302

Merged
merged 2 commits into from
Apr 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
365 changes: 173 additions & 192 deletions src/.editorconfig

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project>
<PropertyGroup>
<AnalysisMode>All</AnalysisMode>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.9.28">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using HotChocolate;
using System;
using HotChocolate;
using Microsoft.Extensions.Logging;
using Nikcio.UHeadless.Base.Basics.Models;
using Nikcio.UHeadless.Base.Properties.Factories;
Expand Down Expand Up @@ -28,6 +29,8 @@ public class CustomBasicContent : BasicContent<BasicProperty, BasicContentType,

public CustomBasicContent(CreateContent createContent, IPropertyFactory<BasicProperty> propertyFactory, IContentTypeFactory<BasicContentType> contentTypeFactory, IContentFactory<CustomBasicContent> contentFactory, IVariationContextAccessor variationContextAccessor, IPublicAccessService publicAccessService, IContentService contentService, IUmbracoContextAccessor context, ILogger<CustomBasicContent> logger) : base(createContent, propertyFactory, contentTypeFactory, contentFactory, variationContextAccessor)
{
ArgumentNullException.ThrowIfNull(createContent);

_publicAccessService = publicAccessService;
_contentService = contentService;
_context = context;
Expand All @@ -43,15 +46,15 @@ public CustomBasicContent(CreateContent createContent, IPropertyFactory<BasicPro

if (content == null)
{
_logger.LogWarning("Content from content service is null. Id: {contentId}", createContent.Content.Id);
_logger.LogWarning("Content from content service is null. Id: {ContentId}", createContent.Content.Id);
return;
}

PublicAccessEntry? entry = _publicAccessService.GetEntryForContent(content);

if (entry != null)
{
var cache = _context.GetRequiredUmbracoContext();
IUmbracoContext cache = _context.GetRequiredUmbracoContext();

if (cache.Content == null)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using HotChocolate;

namespace Examples.Docs.Content.PublicAccessExample;
Expand All @@ -8,7 +8,7 @@ public class PermissionsModel
{
public PermissionsModel()
{
AccessRules = new List<AccessRuleModel>();
AccessRules = [];
}

[GraphQLDescription("Gets the url to the login page.")]
Expand All @@ -19,4 +19,4 @@ public PermissionsModel()

[GraphQLDescription("Gets the access rules for the restrict public access settings.")]
public List<AccessRuleModel> AccessRules { get; set; }
}
}
7 changes: 5 additions & 2 deletions src/Examples/Docs/PropertyValues/MyPropertyValue.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Nikcio.UHeadless.Base.Properties.Commands;
using System;
using Nikcio.UHeadless.Base.Properties.Commands;
using Nikcio.UHeadless.Base.Properties.Models;

namespace Examples.Docs.PropertyValues;
Expand All @@ -9,7 +10,9 @@ public class MyPropertyValue : PropertyValue

public MyPropertyValue(CreatePropertyValue createPropertyValue) : base(createPropertyValue)
{
var value = createPropertyValue.Property.GetValue(createPropertyValue.Culture);
ArgumentNullException.ThrowIfNull(createPropertyValue);

object? value = createPropertyValue.Property.GetValue(createPropertyValue.Culture);
if (value == null)
{
return;
Expand Down
132 changes: 115 additions & 17 deletions src/Examples/Program.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,119 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
using HotChocolate.Execution.Configuration;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Nikcio.UHeadless.Content.Basics.Queries;
using Nikcio.UHeadless.Content.Extensions;
using Nikcio.UHeadless.Extensions;
using Nikcio.UHeadless.Media.Basics.Queries;
using Nikcio.UHeadless.Media.Extensions;
using Nikcio.UHeadless.Members.Basics.Queries;
using Nikcio.UHeadless.Members.Extensions;
using Umbraco.Cms.Core.DependencyInjection;
using Umbraco.Extensions;

namespace Examples;
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);

public class Program
{
public static void Main(string[] args)
=> CreateHostBuilder(args)
.Build()
.Run();

public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureUmbracoDefaults()
.ConfigureWebHostDefaults(webBuilder =>
builder.CreateUmbracoBuilder()
.AddBackOffice()
.AddWebsite()
.AddDeliveryApi()
.AddComposers()
.AddUHeadless(new()
{
PropertyServicesOptions = new()
{
PropertyMapOptions = new()
{
PropertyMappings = []
},
},
TracingOptions = new()
{
TimestampProvider = null,
TracingPreference = HotChocolate.Execution.Options.TracingPreference.Never,
},
UHeadlessGraphQLOptions = new()
{
GraphQLExtensions = (IRequestExecutorBuilder builder) =>
{
webBuilder.UseStaticWebAssets();
webBuilder.UseStartup<Startup>();
});
builder.AddAuthorization();

builder.UseContentQueries();
builder.AddTypeExtension<BasicContentAllQuery>();
builder.AddTypeExtension<BasicContentAtRootQuery>();
builder.AddTypeExtension<BasicContentByAbsoluteRouteQuery>();
builder.AddTypeExtension<BasicContentByContentTypeQuery>();
builder.AddTypeExtension<BasicContentByGuidQuery>();
builder.AddTypeExtension<BasicContentByIdQuery>();
builder.AddTypeExtension<BasicContentByTagQuery>();
builder.AddTypeExtension<BasicContentDescendantsByAbsoluteRouteQuery>();
builder.AddTypeExtension<BasicContentDescendantsByContentTypeQuery>();
builder.AddTypeExtension<BasicContentDescendantsByGuidQuery>();
builder.AddTypeExtension<BasicContentDescendantsByIdQuery>();

builder.UseMediaQueries();
builder.AddTypeExtension<BasicMediaAtRootQuery>();
builder.AddTypeExtension<BasicMediaByContentTypeQuery>();
builder.AddTypeExtension<BasicMediaByGuidQuery>();
builder.AddTypeExtension<BasicMediaByIdQuery>();

builder.UseMemberQueries();
builder.AddTypeExtension<BasicMembersAllQuery>();
builder.AddTypeExtension<BasicFindMembersByDisplayNameQuery>();
builder.AddTypeExtension<BasicFindMembersByEmailQuery>();
builder.AddTypeExtension<BasicFindMembersByRoleQuery>();
builder.AddTypeExtension<BasicFindMembersByUsernameQuery>();
builder.AddTypeExtension<BasicMemberByEmailQuery>();
builder.AddTypeExtension<BasicMemberByIdQuery>();
builder.AddTypeExtension<BasicMemberByKeyQuery>();
builder.AddTypeExtension<BasicMemberByUsernameQuery>();
builder.AddTypeExtension<BasicMembersByIdQuery>();
return builder;
},
},
})
.Build();

WebApplication app = builder.Build();

await app.BootUmbracoAsync().ConfigureAwait(false);

app.UseAuthentication();
app.UseAuthorization();


app.MapUHeadlessGraphQLEndpoint(new()
{
CorsPolicy = null,
GraphQLPath = "/graphql",
GraphQLServerOptions = new()
{
Tool =
{
Enable = true
}
}
});

app.UseUmbraco()
.WithMiddleware(u =>
{
u.UseBackOffice();
u.UseWebsite();
})
.WithEndpoints(u =>
{
u.UseInstallerEndpoints();
u.UseBackOfficeEndpoints();
u.UseWebsiteEndpoints();
});

await app.RunAsync().ConfigureAwait(false);

public partial class Program
{
private Program()
{

}
}
126 changes: 0 additions & 126 deletions src/Examples/Startup.cs

This file was deleted.

Loading