Starter Execution Method:
public void Execute(IPluginExecutionContext context)
{
string opportunityid = "";
switch(context.MessageName)
{
case "Create":
if (context.OutputParameters.Properties.Contains("id"))
{
opportunityid = context.OutputParameters.Properties["id"].ToString();
}
break;
case "Update":
if (context.InputParameters.Properties.Contains(ParameterName.Target) && context.InputParameters.Properties[ParameterName.Target] is DynamicEntity)
{
DynamicEntity entity = (DynamicEntity)context.InputParameters.Properties[ParameterName.Target];
opportunityid = ((Key)entity.Properties["opportunityid"]).Value.ToString();
}
break;
case "SetState":
if (context.InputParameters.Properties.Contains("EntityMoniker"))
{
if (context.InputParameters.Properties.Contains("State"))
{
entity = (Moniker)context.InputParameters.Properties[ParameterName.EntityMoniker];
opportunityid = entity.Id.ToString();
}
}
break;
case "SetStateDynamicEntity":
if (context.InputParameters.Properties.Contains("EntityMoniker"))
{
if (context.InputParameters.Properties.Contains("State"))
{
entity = (Moniker)context.InputParameters.Properties[ParameterName.EntityMoniker];
opportunityid = entity.Id.ToString();
}
}
break;
case "Win":
opportunityClose = (DynamicEntity)context.InputParameters["OpportunityClose"];
Lookup WonLook = (Lookup)opportunityClose.Properties["opportunityid"];
opportunityid = WonLook.Value.ToString();
break;
case "Lost":
opportunityClose = (DynamicEntity)context.InputParameters["OpportunityClose"];
Lookup LostLook = (Lookup)opportunityClose.Properties["opportunityid"];
opportunityid = LostLook.Value.ToString();
break;
case "Assign":
if (context.InputParameters.Properties.Contains("Assignee") && context.InputParameters.Properties["Assignee"] is SecurityPrincipal)
{
Moniker assignEntity = (Moniker)context.InputParameters.Properties["Target"];
opportunityid = assignEntity.Id.ToString();
}
break;
case "Delete":
if (context.InputParameters.Properties.Contains("Target"))
{
Moniker monikerentity = null;
monikerentity = (Moniker)context.InputParameters.Properties[ParameterName.Target];
opportunityid = monikerentity.Id.ToString();
}
break;
}
}
MessageName Class (CrmHelpers)
AddItem
AddMember
AddMembers
AddMembersByFetchXml
Assign
Book
Clone
CompoundCreate
Create
Delete
DeliverIncoming
DeliverPromote
ExecuteWorkflow
ExecuteWorkflow
GrantAccess
Handle
Lose
Merge
ModifyAccess
RemoveItem
RemoveMember
RemoveMembers
RemoveMembersByFetchXml
Reschedule
Retrieve
RetrieveExchangeRate
RetrieveMultiple
RetrievePrincipalAccess
RetrieveSharedPrincipalsAndAccess
RevokeAccess
Route
Send
SetState
SetStateDynamicEntity
Update
Win
转载于:https://www.cnblogs.com/janmson/archive/2009/05/26/1490405.html