Skip to content
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
6 changes: 5 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -651,4 +651,8 @@ dotnet_diagnostic.CS8981.severity = none
[src/Dataverse/**]
dotnet_diagnostic.CA1510.severity = none
dotnet_diagnostic.CA1307.severity = none
dotnet_diagnostic.MA0009.severity = none # With data that comes from Dataverse we will not worry about Denial of service attacks
dotnet_diagnostic.MA0009.severity = none # With data that comes from Dataverse we will not worry about Denial of service attacks

[src/Dataverse/AdhocJobs/Jobs/**]
dotnet_diagnostic.MA0048.severity = none # Job files use top-level statements which generate a Program class, not matching file name
dotnet_diagnostic.CA1812.severity = none # Same reason - generated Program class appears never instantiated
2 changes: 1 addition & 1 deletion XrmBedrock.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<Project Path="src/Shared/NetCoreContext/NetCoreContext.csproj" />
</Folder>
<Folder Name="/src/Dataverse/">
<Project Path="src/Dataverse/ConsoleJobs/ConsoleJobs.csproj" />
<Project Path="src/Dataverse/AdhocJobs/AdhocJobs.csproj" />
<Project Path="src/Dataverse/Plugins/Plugins.csproj" />
<Project Path="src/Dataverse/PluginsNetCore/PluginsNetCore.csproj" />
<Project Path="src/Dataverse/SharedPluginLogic/SharedPluginLogic.shproj" />
Expand Down
14 changes: 14 additions & 0 deletions src/Dataverse/AdhocJobs/AdhocJobs.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<Features>FileBasedProgram</Features>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="DataverseConnection" Version="1.1.1" />
<PackageReference Include="Azure.Identity" Version="1.13.2" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="9.0.4" />
</ItemGroup>

<Import Project="..\..\Shared\SharedContext\SharedContext.projitems" Label="Shared" />
</Project>
10 changes: 10 additions & 0 deletions src/Dataverse/AdhocJobs/JobContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Microsoft.Xrm.Sdk;
using SharedContext.Dao;

namespace AdhocJobs;

public record JobContext(
IOrganizationService OrgService,
DataverseAccessObject Dao,
Uri DataverseUri,
IServiceProvider Services);
48 changes: 48 additions & 0 deletions src/Dataverse/AdhocJobs/JobSetup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using Azure.Identity;
using DataverseConnection;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Xrm.Sdk;
using SharedContext.Dao;

namespace AdhocJobs;

public static class JobSetup
{
#pragma warning disable S1075 // URIs should not be hardcoded
private const string DefaultUri = "https://YOUR-ENV.crm4.dynamics.com";
#pragma warning restore S1075 // URIs should not be hardcoded

public static JobContext Initialize(string[] args)
{
return Initialize(args, null);
}

public static JobContext Initialize(string[] args, Action<IServiceCollection>? configureServices)
{
ArgumentNullException.ThrowIfNull(args);
var dataverseUri = args.Length > 0 ? new Uri(args[0]) : new Uri(DefaultUri);

var services = new ServiceCollection();
services.AddLogging(builder => builder.AddConsole());
services.AddDataverseWithOrganizationServices(options =>
{
// Swap with whatever fits you. This uses the token from az login
options.TokenCredential = new AzureCliCredential();
options.DataverseUrl = dataverseUri.ToString();
});

configureServices?.Invoke(services);

var sp = services.BuildServiceProvider();
var orgService = sp.GetRequiredService<IOrganizationService>();
var logger = sp.GetRequiredService<ILoggerFactory>().CreateLogger("BatchJob");
var dao = new DataverseAccessObject(orgService, logger);

var ctx = new JobContext(orgService, dao, dataverseUri, sp);

logger.LogInformation($"Connected to {ctx.DataverseUri}");

return ctx;
}
}
14 changes: 14 additions & 0 deletions src/Dataverse/AdhocJobs/Jobs/ExampleJob.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#:package DataverseConnection@1.1.1
#:package Azure.Identity@1.13.2
#:project ../AdhocJobs.csproj
#:property PublishAot=false

using AdhocJobs;

var ctx = JobSetup.Initialize(args);

var accounts = ctx.Dao.RetrieveList(xrm => xrm.AccountSet)
.Select(a => new { a.AccountId, a.Name })
.ToList();

Console.WriteLine($"Found {accounts.Count} accounts");
20 changes: 0 additions & 20 deletions src/Dataverse/ConsoleJobs/App.config

This file was deleted.

25 changes: 0 additions & 25 deletions src/Dataverse/ConsoleJobs/ConsoleJobs.csproj

This file was deleted.

147 changes: 0 additions & 147 deletions src/Dataverse/ConsoleJobs/Helpers/CsvHelper.cs

This file was deleted.

12 changes: 0 additions & 12 deletions src/Dataverse/ConsoleJobs/Helpers/HeaderAttribute.cs

This file was deleted.

29 changes: 0 additions & 29 deletions src/Dataverse/ConsoleJobs/Jobs/ExampleJob.cs

This file was deleted.

8 changes: 0 additions & 8 deletions src/Dataverse/ConsoleJobs/Jobs/IJob.cs

This file was deleted.

Loading