Skip to content

Commit

Permalink
Feature GetAllEntityMetadatas in the Rappen.XTB.Helper is now used …
Browse files Browse the repository at this point in the history
…instead of my own metadata loading
  • Loading branch information
rappen committed Aug 4, 2022
1 parent 34a96ac commit 9e86aaa
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 59 deletions.
2 changes: 1 addition & 1 deletion FetchXmlBuilder/FXBInterfaces.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public void ShowSettings()
}
else
{
LoadEntities(ConnectionDetail);
LoadEntities();
}
}
SaveSetting();
Expand Down
62 changes: 6 additions & 56 deletions FetchXmlBuilder/FXBMetadata.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using McTools.Xrm.Connection;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Messages;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Metadata;
using Microsoft.Xrm.Sdk.Query;
using Rappen.XRM.Helpers.Extensions;
using Rappen.XTB.FetchXmlBuilder.Settings;
using Rappen.XTB.Helpers.Extensions;
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -205,7 +204,7 @@ internal void LoadEntityDetails(string entityName, Action detailsLoaded, bool as
WorkAsync(new WorkAsyncInfo($"Loading {name}...",
(eventargs) =>
{
eventargs.Result = MetadataExtensions.LoadEntityDetails(Service, entityName);
eventargs.Result = XRM.Helpers.Extensions.MetadataExtensions.LoadEntityDetails(Service, entityName);
})
{
PostWorkCallBack = (completedargs) =>
Expand All @@ -222,7 +221,7 @@ internal void LoadEntityDetails(string entityName, Action detailsLoaded, bool as
{
try
{
var resp = MetadataExtensions.LoadEntityDetails(Service, entityName);
var resp = XRM.Helpers.Extensions.MetadataExtensions.LoadEntityDetails(Service, entityName);
LoadEntityDetailsCompleted(entityName, resp, null, update);
}
catch (Exception e)
Expand Down Expand Up @@ -280,61 +279,12 @@ private static bool CheckMetadata(OwnershipTypes[] options, OwnershipTypes? meta
return true;
}

private void LoadEntities(ConnectionDetail connectionDetail)
private void LoadEntities()
{
working = true;
entities = null;
entityShitList = new List<string>();
WorkAsync(new WorkAsyncInfo
{
Message = "Loading entities...",
Work = (worker, eventargs) =>
{
EnableControls(false);
if (settings.TryMetadataCache && connectionDetail.MetadataCacheLoader != null)
{ // Try cache metadata
if (connectionDetail.MetadataCache != null)
{ // Already cached
eventargs.Result = connectionDetail.MetadataCache;
}
else if (settings.WaitUntilMetadataLoaded)
{ // Load the cache until done
eventargs.Result = connectionDetail.MetadataCacheLoader.ConfigureAwait(false).GetAwaiter().GetResult()?.EntityMetadata;
}
else
{ // Load the cache in background
connectionDetail.MetadataCacheLoader.ContinueWith(task =>
{ // Waiting for loaded
SetAfterEntitiesLoaded(task.Result?.EntityMetadata);
});
}
}
else
{ // Load as usual, the old way
eventargs.Result = Service.LoadEntities(connectionDetail.OrganizationMajorVersion, connectionDetail.OrganizationMinorVersion);
}
},
PostWorkCallBack = (completedargs) =>
{
if (completedargs.Error != null)
{
ShowErrorDialog(completedargs.Error, "Load Entities");
}
else
{
if (completedargs.Result is RetrieveMetadataChangesResponse meta)
{
SetAfterEntitiesLoaded(meta.EntityMetadata);
}
else if (completedargs.Result is IEnumerable<EntityMetadata> entitiesmeta)
{
SetAfterEntitiesLoaded(entitiesmeta);
}
}
SetAfterEntitiesLoaded(null);
}
});
this.GetAllEntityMetadatas(SetAfterEntitiesLoaded, settings.TryMetadataCache, settings.WaitUntilMetadataLoaded);
}

private void SetAfterEntitiesLoaded(IEnumerable<EntityMetadata> newEntityMetadata)
Expand Down
2 changes: 1 addition & 1 deletion FetchXmlBuilder/FetchXmlBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ private void FetchXmlBuilder_ConnectionUpdated(object sender, ConnectionUpdatedE
{
if (!working)
{
LoadEntities(e.ConnectionDetail);
LoadEntities();
}
}
else
Expand Down

1 comment on commit 9e86aaa

@rappen
Copy link
Owner Author

@rappen rappen commented on 9e86aaa Aug 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.