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
3 changes: 2 additions & 1 deletion .claude/settings.local.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"Bash(cat:*)",
"Bash(dotnet build:*)",
"Bash(dotnet test:*)",
"Bash(dotnet pack:*)"
"Bash(dotnet pack:*)",
"Bash(find:*)"
]
}
}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,6 @@ docs/tools/FSharp.Formatting.svclog
/XrmMockup/tools/Signature/delegate.snk
/tools/XrmContext/EnvInfo.config
/src/MetadataGen/XrmMockupTest.csproj

# Claude temp files
tmpclaude-*-cwd
2 changes: 1 addition & 1 deletion Tools/Tools.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Xrm.Sdk.Workflow, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.CrmSdk.Workflow.9.0.2.23\lib\net462\Microsoft.Xrm.Sdk.Workflow.dll</HintPath>
<HintPath>..\packages\Microsoft.CrmSdk.Workflow.9.0.2.60\lib\net462\Microsoft.Xrm.Sdk.Workflow.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Xrm.Tooling.Connector, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
Expand Down
2 changes: 1 addition & 1 deletion Tools/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<package id="Microsoft.Bcl.AsyncInterfaces" version="8.0.0" targetFramework="net462" />
<package id="Microsoft.CrmSdk.CoreAssemblies" version="9.0.2.59" targetFramework="net462" />
<package id="Microsoft.CrmSdk.Deployment" version="9.0.2.23" targetFramework="net462" />
<package id="Microsoft.CrmSdk.Workflow" version="9.0.2.23" targetFramework="net462" />
<package id="Microsoft.CrmSdk.Workflow" version="9.0.2.60" targetFramework="net462" />
<package id="Microsoft.CrmSdk.XrmTooling.CoreAssembly" version="9.1.0.51" targetFramework="net462" />
<package id="Microsoft.IdentityModel.Clients.ActiveDirectory" version="3.19.8" targetFramework="net462" />
<package id="Microsoft.Rest.ClientRuntime" version="2.3.20" targetFramework="net462" />
Expand Down
2 changes: 2 additions & 0 deletions XrmMockup.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
<File Path=".github/workflows/release.yml" />
<File Path="README.md" />
<File Path="RELEASE_NOTES.md" />
<File Path="scripts/Pack-Local.ps1" />
<File Path="scripts/Set-VersionFromChangelog.ps1" />
</Folder>
<Folder Name="/Solution Items/">
<File Path=".gitignore" />
Expand Down
8 changes: 6 additions & 2 deletions scripts/Pack-Local.ps1
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
param(
[string]$Output = "./nupkg"
)

# Local pack script for XrmMockup packages
# Sets versions from changelogs and creates NuGet packages locally

Expand All @@ -13,5 +17,5 @@
dotnet build --configuration Release

# Pack specific projects (not the entire solution to avoid legacy project errors)
dotnet pack ./src/XrmMockup365/XrmMockup365.csproj --configuration Release --no-build --output ./nupkg
dotnet pack ./src/MetadataGen/MetadataGenerator.Tool/MetadataGenerator.Tool.csproj --configuration Release --no-build --output ./nupkg
dotnet pack ./src/XrmMockup365/XrmMockup365.csproj --configuration Release --no-build --output $Output
dotnet pack ./src/MetadataGen/MetadataGenerator.Tool/MetadataGenerator.Tool.csproj --configuration Release --no-build --output $Output
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="NSubstitute" Version="5.3.0" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0">
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
73 changes: 30 additions & 43 deletions src/XrmMockup365/Core.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using DG.Tools.XrmMockup.Database;
using DG.Tools.XrmMockup.Database;
using DG.Tools.XrmMockup.Internal;
using DG.Tools.XrmMockup.Serialization;
using DG.Tools.XrmMockup.Online;
using XrmPluginCore.Enums;
using Microsoft.Crm.Sdk.Messages;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Client;
using Microsoft.Xrm.Sdk.Messages;
using Microsoft.Xrm.Sdk.Metadata;
using Microsoft.Xrm.Sdk.Organization;
Expand Down Expand Up @@ -59,7 +59,7 @@ internal class Core : IXrmMockupExtension
private XrmDb db;
private Dictionary<string, Snapshot> snapshots;
private Dictionary<string, Type> entityTypeMap = new Dictionary<string, Type>();
private OrganizationServiceProxy OnlineProxy;
private IOnlineDataService OnlineDataService;
private int baseCurrencyPrecision;
private FormulaFieldEvaluator FormulaFieldEvaluator { get; set; }
private List<string> systemAttributeNames;
Expand All @@ -79,7 +79,7 @@ public Core(XrmMockupSettings Settings, MetadataSkeleton metadata, List<Entity>
SecurityRoles = SecurityRoles,
BaseCurrency = metadata.BaseOrganization.GetAttributeValue<EntityReference>("basecurrencyid"),
BaseCurrencyPrecision = metadata.BaseOrganization.GetAttributeValue<int>("pricingdecimalprecision"),
OnlineProxy = null,
OnlineDataService = null,
EntityTypeMap = new Dictionary<string, Type>()
};

Expand All @@ -99,7 +99,7 @@ public Core(XrmMockupSettings Settings, StaticMetadataCache staticCache)
SecurityRoles = staticCache.SecurityRoles,
BaseCurrency = staticCache.BaseCurrency,
BaseCurrencyPrecision = staticCache.BaseCurrencyPrecision,
OnlineProxy = staticCache.OnlineProxy,
OnlineDataService = staticCache.OnlineDataService,
EntityTypeMap = staticCache.EntityTypeMap
};

Expand All @@ -116,10 +116,9 @@ private void InitializeCore(CoreInitializationData initData)
metadata = initData.Metadata;
BaseCurrency = initData.BaseCurrency;
baseCurrencyPrecision = initData.BaseCurrencyPrecision;
OnlineProxy = initData.OnlineProxy;
OnlineDataService = initData.OnlineDataService;
db = new XrmDb(initData.Metadata.EntityMetadata, initData.OnlineDataService);
entityTypeMap = initData.EntityTypeMap;

db = new XrmDb(initData.Metadata.EntityMetadata, initData.OnlineProxy);
EnsureFileAttachmentMetadata();
FileBlockStore = new FileBlockStore();
snapshots = new Dictionary<string, Snapshot>();
Expand Down Expand Up @@ -185,7 +184,7 @@ public static StaticMetadataCache BuildStaticMetadataCache(XrmMockupSettings set
var baseCurrency = metadata.BaseOrganization.GetAttributeValue<EntityReference>("basecurrencyid");
var baseCurrencyPrecision = metadata.BaseOrganization.GetAttributeValue<int>("pricingdecimalprecision");

var onlineProxy = BuildOnlineProxy(settings);
var onlineDataService = BuildOnlineDataService(settings);
var entityTypeMap = new Dictionary<string, Type>();

// Build entity type map for proxy types if enabled
Expand All @@ -194,29 +193,28 @@ public static StaticMetadataCache BuildStaticMetadataCache(XrmMockupSettings set
BuildEntityTypeMap(settings, entityTypeMap);
}

// Note: IPluginMetadata is handled per-instance in the Core constructor
// Note: IPluginMetadata is handled per-instance in the Core constructor
// to avoid modifying the shared cache

return new StaticMetadataCache(metadata, workflows, securityRoles, entityTypeMap,
baseCurrency, baseCurrencyPrecision, onlineProxy);
return new StaticMetadataCache(metadata, workflows, securityRoles, entityTypeMap,
baseCurrency, baseCurrencyPrecision, onlineDataService);
}

private static OrganizationServiceProxy BuildOnlineProxy(XrmMockupSettings settings)
private static IOnlineDataService BuildOnlineDataService(XrmMockupSettings settings)
{
#if DATAVERSE_SERVICE_CLIENT
// Allow injection for testing
if (settings.OnlineDataServiceFactory != null)
{
return settings.OnlineDataServiceFactory();
}

if (settings.OnlineEnvironment.HasValue)
{
var env = settings.OnlineEnvironment.Value;
var orgHelper = new OrganizationHelper(
new Uri(env.uri),
env.providerType,
env.username,
env.password,
env.domain);
var proxy = orgHelper.GetServiceProxy();
if (settings.EnableProxyTypes == true)
proxy.EnableProxyTypes();
return proxy;
return new OnlineDataService(env.Url);
}
#endif
return null;
}

Expand Down Expand Up @@ -427,25 +425,6 @@ internal void EnableProxyTypes(Assembly assembly)
}
}

private OrganizationServiceProxy GetOnlineProxy()
{
if (OnlineProxy == null && settings.OnlineEnvironment.HasValue)
{
var env = settings.OnlineEnvironment.Value;
var orgHelper = new OrganizationHelper(
new Uri(env.uri),
env.providerType,
env.username,
env.password,
env.domain);
this.OnlineProxy = orgHelper.GetServiceProxy();
if (settings.EnableProxyTypes == true)
OnlineProxy.EnableProxyTypes();
}

return OnlineProxy;
}

internal IOrganizationService GetWorkflowService()
{
return ServiceFactory.CreateOrganizationService(null,
Expand Down Expand Up @@ -1121,6 +1100,14 @@ internal void PopulateWith(Entity[] entities)
}
}

/// <summary>
/// Prefills the local database with data from the online service based on the query.
/// </summary>
internal void PrefillDBWithOnlineData(QueryExpression query)
{
db.PrefillDBWithOnlineData(query);
}

internal Dictionary<string, Dictionary<AccessRights, PrivilegeDepth>> GetPrivilege(Guid principleId)
{
return security.GetPrincipalPrivilege(principleId);
Expand Down Expand Up @@ -1356,7 +1343,7 @@ internal void ResetEnvironment()
workflowManager.ResetWorkflows(settings.IncludeAllWorkflows);

pluginManager.ResetPlugins();
this.db = new XrmDb(metadata.EntityMetadata, GetOnlineProxy());
this.db = new XrmDb(metadata.EntityMetadata, OnlineDataService);
EnsureFileAttachmentMetadata();
this.RequestHandlers = GetRequestHandlers(db);
InitializeDB();
Expand Down
Loading
Loading