-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Dataverse sample code modernization #767
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
4d294a2
Add migration infrastructure for legacy to modern .NET 6+ sample upgrade
phecke f85cd08
Phase 2: Begin pilot migration with Audit category (partial)
phecke 6b1e2b5
Phase 2: Complete Audit category migration (2 of 2 samples)
phecke 7dab0f6
Add DuplicateDetection category with 3 migrated samples
phecke 829ee4d
Add Queues category with 8 scaffolded samples (3 implemented, 5 in pr…
phecke a96e127
Complete Queues category - all 8 samples fully implemented
phecke 3693968
Complete comprehensive documentation for all 8 Queue samples
phecke 3ad2795
Phase 3: Add Query category with 3 initial samples
phecke c27441d
Phase 3: Add 4 more Query samples (FetchXML focus)
phecke 56e3d25
Phase 3: Complete Query category - all 14 samples migrated
phecke 7349f35
Phase 3: Complete CRUD category - all 7 samples migrated
phecke dd8c60e
Phase 3 Batch 2: Complete Activities and Relationships categories - 2…
phecke b26eb99
Merge branch 'master' into sample-migration-infrastructure
phecke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| { | ||
| "permissions": { | ||
| "allow": [ | ||
| "Bash(dir:*)", | ||
| "Bash(dir /s /b \"C:\\\\GitHub\\\\microsoft\\\\PowerApps-Samples\\\\dataverse\\\\orgsvc\\\\CSharp-NETCore\")", | ||
| "Bash(findstr:*)", | ||
| "Bash(ls:*)", | ||
| "Bash(git checkout:*)", | ||
| "Bash(git add:*)", | ||
| "Bash(git commit:*)", | ||
| "Bash(pwsh:*)", | ||
| "Bash(dotnet sln:*)", | ||
| "Bash(dotnet new:*)", | ||
| "Bash(dotnet build:*)" | ||
| ] | ||
| } | ||
| } | ||
23 changes: 23 additions & 0 deletions
23
dataverse/orgsvc/CSharp-NETCore/Activities/BookAppointment/BookAppointment.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>net6.0</TargetFramework> | ||
| <RootNamespace>PowerPlatform.Dataverse.CodeSamples</RootNamespace> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Content Include="..\appsettings.json" Link="appsettings.json"> | ||
| <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
| </Content> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.1" /> | ||
| <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" /> | ||
| <PackageReference Include="Microsoft.PowerPlatform.Dataverse.Client" Version="1.1.14" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
164 changes: 164 additions & 0 deletions
164
dataverse/orgsvc/CSharp-NETCore/Activities/BookAppointment/Program.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,164 @@ | ||
| using Microsoft.Crm.Sdk.Messages; | ||
| using Microsoft.Extensions.Configuration; | ||
| using Microsoft.PowerPlatform.Dataverse.Client; | ||
| using Microsoft.Xrm.Sdk; | ||
|
|
||
| namespace PowerPlatform.Dataverse.CodeSamples | ||
| { | ||
| /// <summary> | ||
| /// Demonstrates how to book or schedule an appointment using the BookRequest message. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// This sample shows how to create and book an appointment using the BookRequest message, | ||
| /// which validates that the appointment can be scheduled and creates it in the system. | ||
| /// | ||
| /// Set the appropriate Url and Username values for your test | ||
| /// environment in the appsettings.json file before running this program. | ||
| /// </remarks> | ||
| class Program | ||
| { | ||
| private static readonly List<EntityReference> entityStore = new(); | ||
|
|
||
| #region Sample Methods | ||
|
|
||
| /// <summary> | ||
| /// Sets up sample data required for the demonstration | ||
| /// </summary> | ||
| private static void Setup(ServiceClient service) | ||
| { | ||
| // No setup required for this sample | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Demonstrates how to book an appointment using BookRequest | ||
| /// </summary> | ||
| private static void Run(ServiceClient service) | ||
| { | ||
| Console.WriteLine("Booking an appointment..."); | ||
|
|
||
| // Get the current user information | ||
| var userRequest = new WhoAmIRequest(); | ||
| var userResponse = (WhoAmIResponse)service.Execute(userRequest); | ||
|
|
||
| // Create the ActivityParty instance. | ||
| var party = new Entity("activityparty") | ||
| { | ||
| ["partyid"] = new EntityReference("systemuser", userResponse.UserId) | ||
| }; | ||
|
|
||
| // Create the appointment instance. | ||
| var appointment = new Entity("appointment") | ||
| { | ||
| ["subject"] = "Test Appointment", | ||
| ["description"] = "Test Appointment created using the BookRequest Message.", | ||
| ["scheduledstart"] = DateTime.Now.AddHours(1), | ||
| ["scheduledend"] = DateTime.Now.AddHours(2), | ||
| ["location"] = "Office", | ||
| ["requiredattendees"] = new EntityCollection(new List<Entity> { party }), | ||
| ["organizer"] = new EntityCollection(new List<Entity> { party }) | ||
| }; | ||
|
|
||
| // Use the Book request message. | ||
| var book = new BookRequest | ||
| { | ||
| Target = appointment | ||
| }; | ||
| var booked = (BookResponse)service.Execute(book); | ||
| Guid appointmentId = booked.ValidationResult.ActivityId; | ||
|
|
||
| // Add to entityStore for cleanup | ||
| entityStore.Add(new EntityReference("appointment", appointmentId)); | ||
|
|
||
| // Verify that the appointment has been scheduled. | ||
| if (appointmentId != Guid.Empty) | ||
| { | ||
| Console.WriteLine("Successfully booked appointment: {0}", appointment["subject"]); | ||
| Console.WriteLine("Appointment ID: {0}", appointmentId); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Cleans up sample data created during execution | ||
| /// </summary> | ||
| private static void Cleanup(ServiceClient service, bool deleteCreatedRecords) | ||
| { | ||
| if (deleteCreatedRecords && entityStore.Count > 0) | ||
| { | ||
| Console.WriteLine("\nDeleting {0} created record(s)...", entityStore.Count); | ||
| foreach (var entityRef in entityStore) | ||
| { | ||
| service.Delete(entityRef.LogicalName, entityRef.Id); | ||
| } | ||
| Console.WriteLine("Records deleted."); | ||
| } | ||
| } | ||
|
|
||
| #endregion | ||
|
|
||
| #region Application Setup | ||
|
|
||
| /// <summary> | ||
| /// Contains the application's configuration settings. | ||
| /// </summary> | ||
| IConfiguration Configuration { get; } | ||
|
|
||
| /// <summary> | ||
| /// Constructor. Loads the application configuration settings from a JSON file. | ||
| /// </summary> | ||
| Program() | ||
| { | ||
| // Get the path to the appsettings file. If the environment variable is set, | ||
| // use that file path. Otherwise, use the runtime folder's settings file. | ||
| string? path = Environment.GetEnvironmentVariable("DATAVERSE_APPSETTINGS"); | ||
| if (path == null) path = "appsettings.json"; | ||
|
|
||
| // Load the app's configuration settings from the JSON file. | ||
| Configuration = new ConfigurationBuilder() | ||
| .AddJsonFile(path, optional: false, reloadOnChange: true) | ||
| .Build(); | ||
| } | ||
|
|
||
| static void Main(string[] args) | ||
| { | ||
| Program app = new(); | ||
|
|
||
| // Create a Dataverse service client using the default connection string. | ||
| ServiceClient serviceClient = | ||
| new(app.Configuration.GetConnectionString("default")); | ||
|
|
||
| if (!serviceClient.IsReady) | ||
| { | ||
| Console.WriteLine("Failed to connect to Dataverse."); | ||
| Console.WriteLine("Error: {0}", serviceClient.LastError); | ||
| return; | ||
| } | ||
|
|
||
| Console.WriteLine("Connected to Dataverse."); | ||
| Console.WriteLine(); | ||
|
|
||
| bool deleteCreatedRecords = true; | ||
|
|
||
| try | ||
| { | ||
| Setup(serviceClient); | ||
| Run(serviceClient); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| Console.WriteLine("An error occurred:"); | ||
| Console.WriteLine(ex.Message); | ||
| } | ||
| finally | ||
| { | ||
| Cleanup(serviceClient, deleteCreatedRecords); | ||
|
|
||
| Console.WriteLine(); | ||
| Console.WriteLine("Press any key to exit."); | ||
| Console.ReadKey(); | ||
| serviceClient.Dispose(); | ||
| } | ||
| } | ||
|
|
||
| #endregion | ||
| } | ||
| } |
69 changes: 69 additions & 0 deletions
69
dataverse/orgsvc/CSharp-NETCore/Activities/BookAppointment/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| --- | ||
| languages: | ||
| - csharp | ||
| products: | ||
| - power-platform | ||
| - power-apps | ||
| page_type: sample | ||
| description: "Demonstrates how to book or schedule an appointment using the BookRequest message." | ||
| --- | ||
|
|
||
| # Book an Appointment | ||
|
|
||
| Demonstrates how to book or schedule an appointment using the BookRequest message. | ||
|
|
||
| ## What this sample does | ||
|
|
||
| The `BookRequest` message is used to book or schedule an appointment. This validates that the appointment can be scheduled according to the calendars of the required attendees and creates the appointment in the system. | ||
|
|
||
| ## How this sample works | ||
|
|
||
| ### Setup | ||
|
|
||
| This sample requires no setup. It uses the current user as both organizer and attendee. | ||
|
|
||
| ### Run | ||
|
|
||
| The sample demonstrates the following steps: | ||
|
|
||
| 1. Gets the current user information using WhoAmIRequest | ||
| 2. Creates an ActivityParty for the current user | ||
| 3. Creates an appointment entity with: | ||
| - Subject and description | ||
| - Scheduled start and end times | ||
| - Location | ||
| - Required attendees and organizer | ||
| 4. Uses BookRequest to validate and create the appointment | ||
| 5. Verifies the appointment was successfully booked | ||
|
|
||
| ### Cleanup | ||
|
|
||
| The sample deletes the created appointment record by default. | ||
|
|
||
| ## Demonstrates | ||
|
|
||
| - Using `WhoAmIRequest` to get current user information | ||
| - Creating an `ActivityParty` entity to represent appointment participants | ||
| - Using `BookRequest` message to book an appointment | ||
| - Working with appointment scheduling attributes | ||
|
|
||
| ## Sample Output | ||
|
|
||
| ``` | ||
| Connected to Dataverse. | ||
|
|
||
| Booking an appointment... | ||
| Successfully booked appointment: Test Appointment | ||
| Appointment ID: 12345678-1234-1234-1234-123456789012 | ||
|
|
||
| Deleting 1 created record(s)... | ||
| Records deleted. | ||
|
|
||
| Press any key to exit. | ||
| ``` | ||
|
|
||
| ## See also | ||
|
|
||
| [BookRequest Class](https://learn.microsoft.com/dotnet/api/microsoft.crm.sdk.messages.bookrequest) | ||
| [Appointment entities](https://learn.microsoft.com/power-apps/developer/data-platform/appointment-entities) | ||
| [Activity entities](https://learn.microsoft.com/power-apps/developer/data-platform/activity-entities) |
23 changes: 23 additions & 0 deletions
23
dataverse/orgsvc/CSharp-NETCore/Activities/BulkEmail/BulkEmail.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>net6.0</TargetFramework> | ||
| <RootNamespace>PowerPlatform.Dataverse.CodeSamples</RootNamespace> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Content Include="..\appsettings.json" Link="appsettings.json"> | ||
| <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
| </Content> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.1" /> | ||
| <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" /> | ||
| <PackageReference Include="Microsoft.PowerPlatform.Dataverse.Client" Version="1.1.14" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we check in this file?
Or should it be added to .gitignore?