Skip to content

Commit

Permalink
Merge branch 'master' into view-layout
Browse files Browse the repository at this point in the history
  • Loading branch information
rappen committed Aug 4, 2022
2 parents 54544df + 58a4937 commit 3522cb8
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 60 deletions.
18 changes: 18 additions & 0 deletions FetchXmlBuilder/AppCode/WebAPIMetadataProvider.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using MarkMpn.FetchXmlToWebAPI;
using Microsoft.Xrm.Sdk.Metadata;
using System;
using System.Linq;

namespace Rappen.XTB.FetchXmlBuilder.AppCode
{
Expand Down Expand Up @@ -29,5 +30,22 @@ public EntityMetadata GetEntity(string logicalName)

return metadata;
}

public EntityMetadata GetEntity(int otc)
{
if (fetchXmlBuilder.entities == null)
{
throw new Exception("Metadata not loaded");
}

var entity = fetchXmlBuilder.entities.SingleOrDefault(e => e.ObjectTypeCode == otc);

if (entity == null)
{
throw new Exception($"No metadata for entity: {otc}");
}

return GetEntity(entity.LogicalName);
}
}
}
2 changes: 1 addition & 1 deletion FetchXmlBuilder/FXBInterfaces.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,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 @@ -285,61 +284,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 @@ -519,7 +519,7 @@ private void FetchXmlBuilder_ConnectionUpdated(object sender, ConnectionUpdatedE
{
if (!working)
{
LoadEntities(e.ConnectionDetail);
LoadEntities();
}
}
else
Expand Down

0 comments on commit 3522cb8

Please sign in to comment.