Esempio n. 1
0
        private void ExecuteCrmAddresses(IExtendedPluginContext context)
        {
            // Account is used here, but since all Entities have the same exact field names, this works just fine
            var target = context.GetTarget <Entity>();

            switch (target.LogicalName)
            {
            case Contact.EntityLogicalName:
                RemoveFormatting(target, Contact.Fields.Address3_Telephone1);
                RemoveFormatting(target, Contact.Fields.Address3_Telephone2);
                RemoveFormatting(target, Contact.Fields.Address3_Telephone3);
                RemoveFormatting(target, Contact.Fields.MobilePhone);
                break;

            case Lead.EntityLogicalName:
            case SystemUser.EntityLogicalName:
                RemoveFormatting(target, Contact.Fields.MobilePhone);
                break;
            }

            RemoveFormatting(target, Account.Fields.Address1_Telephone1);
            RemoveFormatting(target, Account.Fields.Address1_Telephone2);
            RemoveFormatting(target, Account.Fields.Address1_Telephone3);
            RemoveFormatting(target, Account.Fields.Address2_Telephone1);
            RemoveFormatting(target, Account.Fields.Address2_Telephone2);
            RemoveFormatting(target, Account.Fields.Address2_Telephone3);
        }
Esempio n. 2
0
 /// <summary>
 /// Method that gets called in the finally block of the Execute
 /// </summary>
 /// <param name="context">The context.</param>
 protected virtual void PostExecute(IExtendedPluginContext context)
 {
     if (context.TracingService is IMaxLengthTracingService maxLengthService)
     {
         maxLengthService.RetraceMaxLength();
     }
 }
Esempio n. 3
0
 /// <summary>
 /// Gets the context information.
 /// </summary>
 /// <returns></returns>
 public static string GetContextInfo(this IExtendedPluginContext context)
 {
     return
         ("**** Context Info ****" + Environment.NewLine +
          "Plugin: " + context.PluginTypeName + Environment.NewLine +
          "* Registered Event *" + Environment.NewLine + context.Event.ToString("   ") + Environment.NewLine +
          context.ToStringDebug());
 }
Esempio n. 4
0
        private void ExecuteCrmPhoneNumber(IExtendedPluginContext context)
        {
            // Account is used here, but since all Entities have the same exact field names, this works just fine
            var target = context.GetTarget <Entity>();

            RemoveFormatting(target, Account.Fields.Telephone1);
            RemoveFormatting(target, Account.Fields.Telephone2);
            RemoveFormatting(target, Account.Fields.Telephone3);

            ExecuteCrmAddresses(context);
        }
Esempio n. 5
0
 /// <summary>
 /// Cast the Target to the given Entity Type T.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <returns></returns>
 public static T GetTarget <T>(this IExtendedPluginContext context) where T : Entity
 {
     // Obtain the target business entity from the input parmameters.
     try
     {
         return(((IPluginExecutionContext)context).GetTarget <T>());
     }
     catch (Exception ex)
     {
         context.LogException(ex);
     }
     return(null);
 }
Esempio n. 6
0
        /// <summary>
        /// Allows Plugin to trigger itself.  Delete Messge Types always return False since you can't delete something twice, all other message types return true if the execution key is found in the shared parameters.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        protected virtual bool PreventRecursiveCall(IExtendedPluginContext context)
        {
            if (context.Event.Message == MessageType.Delete)
            {
                return(false);
            }

            var key = $"{context.PluginTypeName}|{context.Event.MessageName}|{context.Event.Stage}|{context.PrimaryEntityId}";

            if (context.GetFirstSharedVariable <int>(key) > 0)
            {
                return(true);
            }

            context.SharedVariables.Add(key, 1);
            return(false);
        }
        protected override void ExecuteInternal(IExtendedPluginContext context)
        {
            // Get the Target
            var contact = context.GetTarget <Contact>();

            if (string.IsNullOrWhiteSpace(contact.Address1_Line1))
            {
                // Address not updated, no need to update Account
                return;
            }

            using (var crm = new CrmContext(context.OrganizationService))
            {
                var accounts = crm.AccountSet.Where(a => a.PrimaryContactId.Id == contact.Id);
                foreach (var account in accounts)
                {
                    UpdateAccountAddress(context.OrganizationService, account.Id, contact);
                }
            }
        }
 /// <summary>
 /// Defalt execution method for the plugin
 /// </summary>
 /// <param name="context"><see href="IExtendedPluginContext" /> object for the current plug-in.</param>
 public abstract void ExecutePlugin(IExtendedPluginContext context);
Esempio n. 9
0
 /// <summary>
 /// Determines whether a shared variable exists that specifies that the plugin or the plugin and specifc message type should be prevented from executing.
 /// This is used in conjunction with PreventPluginHandlerExecution
 /// </summary>
 /// <returns></returns>
 public static bool HasPluginHandlerExecutionBeenPrevented(this IExtendedPluginContext context)
 {
     return(context.HasPluginHandlerExecutionBeenPreventedInternal(context.Event, GetPreventPluginHandlerSharedVariableName(context.PluginTypeName)));
 }
Esempio n. 10
0
 protected override void ExecuteInternal(IExtendedPluginContext context)
 {
     throw new InvalidOperationException("Should Never Get Called!");
 }
Esempio n. 11
0
 public override void ExecutePlugin(IExtendedPluginContext context)
 {
     // Plugin logic
 }
 /// <summary>
 /// Methods that gets called in the finally block of the Execute
 /// </summary>
 /// <param name="context">The context.</param>
 protected virtual void PostExecute(IExtendedPluginContext context)
 {
 }