コード例 #1
0
 public virtual void PostAddMember(Guid mkList, Guid member, ConnectionHelper ch)
 {
 }
コード例 #2
0
 public virtual void PreAddListMembers(Guid mkList, Guid[] members, ConnectionHelper ch)
 {
 }
コード例 #3
0
 public virtual void PreWinOpportunity(Entity opportunity, ConnectionHelper helper)
 {
 }
コード例 #4
0
 public virtual void PostLoseOpportunity(Entity opportunity, ConnectionHelper helper)
 {
 }
コード例 #5
0
 public virtual void PreDelete(EntityReference moniker, ConnectionHelper helper)
 {
 }
コード例 #6
0
 public virtual void PostDisassociate(EntityReferenceCollection coll, EntityReference moniker, ConnectionHelper helper)
 {
 }
コード例 #7
0
 public virtual void PostSetSate(EntityReference moniker, ConnectionHelper helper)
 {
 }
コード例 #8
0
 public virtual void PreAssign(EntityReference moniker, ConnectionHelper helper)
 {
 }
コード例 #9
0
 public virtual void PreUpdate(Entity entity, ConnectionHelper helper)
 {
 }
コード例 #10
0
 public virtual void PostCreate(Entity entity, ConnectionHelper helper)
 {
 }
コード例 #11
0
 public virtual void PrevalidateCreate(Entity entity, ConnectionHelper helper)
 {
 }
コード例 #12
0
 public virtual void PrevalidateUpdate(Entity entity, ConnectionHelper ch)
 {
 }
コード例 #13
0
        public void Execute(IServiceProvider serviceProvider)
        {
            ConnectionHelper ch = new ConnectionHelper(serviceProvider);

            ch.Messages = new List <string>();

            try
            {
                #region EntityMessage

                Entity entity;

                if (ch.PluginExecutionContext.InputParameters.Contains("Target") &&
                    ch.PluginExecutionContext.InputParameters["Target"] is Entity)
                {
                    entity = ch.PluginExecutionContext.InputParameters["Target"] as Entity;
                    if (ch.PluginExecutionContext.Stage == 10 && ch.PluginExecutionContext.MessageName == "Create")
                    {
                        PrevalidateCreate(entity, ch);
                    }
                    if (ch.PluginExecutionContext.Stage == 40 && ch.PluginExecutionContext.MessageName == "Create")
                    {
                        PostCreate(entity, ch);
                    }
                    if (ch.PluginExecutionContext.Stage == 40 && ch.PluginExecutionContext.MessageName == "Update")
                    {
                        PostUpdate(entity, ch);
                    }
                    if (ch.PluginExecutionContext.Stage == 20 && ch.PluginExecutionContext.MessageName == "Create")
                    {
                        PreCreate(entity, ch);
                    }
                    if (ch.PluginExecutionContext.Stage == 20 && ch.PluginExecutionContext.MessageName == "Update")
                    {
                        PreUpdate(entity, ch);
                    }
                    if (ch.PluginExecutionContext.Stage == 10 && ch.PluginExecutionContext.MessageName == "Update")
                    {
                        PrevalidateUpdate(entity, ch);
                    }
                }

                if (ch.PluginExecutionContext.InputParameters.Contains("Target") &&
                    ch.PluginExecutionContext.InputParameters["Target"] is EntityReference)
                {
                    EntityReference target = ch.PluginExecutionContext.InputParameters["Target"] as EntityReference;
                    ;
                    if (ch.PluginExecutionContext.Stage > 30 && ch.PluginExecutionContext.MessageName == "Delete")
                    {
                        PostDelete(target, ch);
                    }
                    if (ch.PluginExecutionContext.Stage < 30 && ch.PluginExecutionContext.MessageName == "Delete")
                    {
                        PreDelete(target, ch);
                    }
                }

                if (ch.PluginExecutionContext.Stage < 30 && ch.PluginExecutionContext.MessageName == "RetrieveMultiple")
                {
                    PreRetrieveMultiple();
                }
                if (ch.PluginExecutionContext.Stage > 30 && ch.PluginExecutionContext.MessageName == "RetrieveMultiple")
                {
                    PostRetrieveMultiple();
                }

                #endregion

                #region EntityReferenceMessage

                EntityReference moniker;
                if (ch.PluginExecutionContext.InputParameters.Contains("EntityMoniker") &&
                    ch.PluginExecutionContext.InputParameters["EntityMoniker"] is EntityReference)
                {
                    moniker = ch.PluginExecutionContext.InputParameters["EntityMoniker"] as EntityReference;

                    if (ch.PluginExecutionContext.Stage > 30 && (ch.PluginExecutionContext.MessageName == "SetState" || ch.PluginExecutionContext.MessageName == "SetStateDynamicEntity"))
                    {
                        PostSetSate(moniker, ch);
                    }
                    if (ch.PluginExecutionContext.Stage > 30 && ch.PluginExecutionContext.MessageName == "Assign")
                    {
                        PostAssign(moniker, ch);
                    }
                    if (ch.PluginExecutionContext.Stage < 30 && (ch.PluginExecutionContext.MessageName == "SetState" || ch.PluginExecutionContext.MessageName == "SetStateDynamicEntity"))
                    {
                        PreSetState(moniker, ch);
                    }
                    if (ch.PluginExecutionContext.Stage < 30 && ch.PluginExecutionContext.MessageName == "Assign")
                    {
                        PreAssign(moniker, ch);
                    }
                }

                if (ch.PluginExecutionContext.InputParameters.Contains("RelatedEntities") &&
                    ch.PluginExecutionContext.InputParameters["RelatedEntities"] is EntityReferenceCollection &&
                    ch.PluginExecutionContext.InputParameters.Contains("Target") &&
                    ch.PluginExecutionContext.InputParameters["Target"] is EntityReference)
                {
                    EntityReferenceCollection relatedEntities = (EntityReferenceCollection)ch.PluginExecutionContext.InputParameters["RelatedEntities"];
                    moniker = (EntityReference)ch.PluginExecutionContext.InputParameters["Target"];

                    if (ch.PluginExecutionContext.Stage > 30 && (ch.PluginExecutionContext.MessageName == "Associate"))
                    {
                        PostAssociate(relatedEntities, moniker, ch);
                    }
                    if (ch.PluginExecutionContext.Stage > 30 && (ch.PluginExecutionContext.MessageName == "Disassociate"))
                    {
                        PostDisassociate(relatedEntities, moniker, ch);
                    }
                }

                #endregion

                #region OpportunityMessages

                if (ch.PluginExecutionContext.InputParameters.Contains("OpportunityClose") &&
                    ch.PluginExecutionContext.InputParameters["OpportunityClose"] is Entity)
                {
                    Entity target = ch.PluginExecutionContext.InputParameters["OpportunityClose"] as Entity;
                    if (ch.PluginExecutionContext.Stage > 30 && ch.PluginExecutionContext.MessageName == "Lose")
                    {
                        PostLoseOpportunity(target, ch);
                    }
                    if (ch.PluginExecutionContext.Stage < 30 && ch.PluginExecutionContext.MessageName == "Lose")
                    {
                        PreLoseOpportunity(target, ch);
                    }
                    if (ch.PluginExecutionContext.Stage > 30 && ch.PluginExecutionContext.MessageName == "Win")
                    {
                        PostWinOpportunity(target, ch);
                    }
                    if (ch.PluginExecutionContext.Stage < 30 && ch.PluginExecutionContext.MessageName == "Win")
                    {
                        PreWinOpportunity(target, ch);
                    }
                }

                #endregion

                #region MarketingListMessages
                if (ch.PluginExecutionContext.InputParameters.Contains("ListId") &&
                    ch.PluginExecutionContext.InputParameters["ListId"] is Guid &&
                    ch.PluginExecutionContext.InputParameters.Contains("EntityId") &&
                    ch.PluginExecutionContext.InputParameters["EntityId"] is Guid)
                {
                    var mkList = (Guid)ch.PluginExecutionContext.InputParameters["ListId"];
                    var member = (Guid)ch.PluginExecutionContext.InputParameters["EntityId"];

                    if (ch.PluginExecutionContext.Stage > 30 && (ch.PluginExecutionContext.MessageName == "AddMember"))
                    {
                        PostAddMember(mkList, member, ch);
                    }
                    if (ch.PluginExecutionContext.Stage > 30 && (ch.PluginExecutionContext.MessageName == "RemoveMember"))
                    {
                        PostRemoveMember(mkList, member, ch);
                    }
                }

                if (ch.PluginExecutionContext.MessageName == "AddListMembers" &&
                    ch.PluginExecutionContext.InputParameters.Contains("ListId") &&
                    ch.PluginExecutionContext.InputParameters.Contains("MemberIds"))
                {
                    var mkList  = (Guid)ch.PluginExecutionContext.InputParameters["ListId"];
                    var members = (Guid[])ch.PluginExecutionContext.InputParameters["MemberIds"];

                    if (ch.PluginExecutionContext.Stage > 30)
                    {
                        PostAddListMembers(mkList, members, ch);
                    }
                }
                else if (ch.PluginExecutionContext.MessageName == "Update" && ch.PluginExecutionContext.ParentContext != null &&
                         ch.PluginExecutionContext.ParentContext.MessageName == "AddListMembers" &&
                         ch.PluginExecutionContext.ParentContext.InputParameters.Contains("ListId") &&
                         ch.PluginExecutionContext.ParentContext.InputParameters.Contains("MemberIds"))
                {
                    var mkList  = (Guid)ch.PluginExecutionContext.ParentContext.InputParameters["ListId"];
                    var members = (Guid[])ch.PluginExecutionContext.ParentContext.InputParameters["MemberIds"];

                    if (ch.PluginExecutionContext.ParentContext.Stage > 30)
                    {
                        PostAddListMembers(mkList, members, ch);
                    }
                    if (ch.PluginExecutionContext.ParentContext.Stage < 30)
                    {
                        PreAddListMembers(mkList, members, ch);
                    }
                }
                #endregion
            }
            catch (Exception ex)
            {
                #region Exception handling
                string errorMessage = ex.Message;
                string traceText    = string.Empty;
                ch.TracingService.Trace("Context Depth: " + ch.PluginExecutionContext.Depth);
                if (!ch.ThrowError)
                {
                    ch.Messages.Add("CatchBase");
                    ch.Messages.Add("BaseException: " + ex.Message);
                }

                IEnumerator enumer = ch.Messages.GetEnumerator();
                while (enumer.MoveNext())
                {
                    string value = enumer.Current.ToString();
                    traceText += Environment.NewLine + "-" + value;
                    ch.TracingService.Trace(value);
                }

                if (!ch.ThrowError)
                {
                    ch.TracingService.Trace(ex.Message);
                    ch.TracingService.Trace(ex.StackTrace);
                    throw new Exception("An exception has occured. Please see the trace log for further information.",
                                        ex);
                }
                else
                {
                    ch.TracingService.Trace(ex.Message);
                    ch.TracingService.Trace(ex.StackTrace);
                    ch.TracingService.Trace(traceText);

                    throw new InvalidPluginExecutionException(ex.Message);
                }
                #endregion
            }
        }