如果有人感兴趣,最后的片段如下所示:
var context = new XrmFakedContext { UsePipelineSimulation = true };
context.RegisterPluginStep<Foo, Account>("Create", ProcessingStepStage.Postoperation);
var organizationService = context.GetOrganizationService();
organizationService.Create(new Account { LogicalName = "account" });
实体元数据(全部)必须考虑如下:
[EntityLogicalNameAttribute("account")]
public class Account : Entity
{
[AttributeLogicalName("name")]
public string Name { get; set; }
public int EntityTypeCode;
public Account()
{
this.EntityTypeCode = 1;
}
}
包括仅限系统的元数据:
[EntityLogicalName("plugintype")]
public class PluginType : Entity
{
[AttributeLogicalName("plugintypeid")]
public Guid PluginTypeId { get; set; }
[AttributeLogicalName("name")]
public string Name { get; set; }
[AttributeLogicalName("typename")]
public string TypeName { get; set; }
[AttributeLogicalName("assemblyname")]
public string AssemblyName { get; set; }
[AttributeLogicalName("major")]
public int Major { get; set; }
[AttributeLogicalName("minor")]
public int Minor { get; set; }
[AttributeLogicalName("version")]
public string Version { get; set; }
}
[EntityLogicalName("sdkmessage")]
public class SdkMessage : Entity
{
[AttributeLogicalName("sdkmessageid")]
public Guid SdkMessageId { get; set; }
[AttributeLogicalName("name")]
public string Name { get; set; }
}
[EntityLogicalName("sdkmessagefilter")]
public class SdkMessageFilter : Entity
{
[AttributeLogicalName("sdkmessagefilterid")]
public Guid SdkMessageFilterId { get; set; }
[AttributeLogicalName("primaryobjecttypecode")]
public int PrimaryObjectTypeCode { get; set; }
}
[EntityLogicalName("sdkmessageprocessingstep")]
public class SdkMessageProcessingStep : Entity
{
[AttributeLogicalName("configuration")]
public string Configuration { get; set; }
[AttributeLogicalName("eventhandler")]
public EntityReference EventHandler { get; set; }
[AttributeLogicalName("sdkmessageid")]
public EntityReference SdkMessageId { get; set; }
[AttributeLogicalName("sdkmessagefilterid")]
public EntityReference SdkMessageFilterId { get; set; }
[AttributeLogicalName("filteringattributes")]
public string FilteringAttributes { get; set; }
[AttributeLogicalName("mode")]
public OptionSetValue Mode { get; set; }
[AttributeLogicalName("stage")]
public OptionSetValue Stage { get; set; }
[AttributeLogicalName("rank")]
public int Rank { get; set; }
}