/// <summary> /// Returns true if <paramref name="a"/> and <paramref name="b"/> are equal. /// </summary> /// <param name="a">The first object</param> /// <param name="b">The second object</param> /// <returns>true if <paramref name="a"/> and <paramref name="b"/> are equal.</returns> public static bool AreEqual(EntityReference a, EntityReference b) { if (a == null && b == null) { return(true); } if (a != null || b != null) { return(false); } if (a.Equals(b)) { return(true); } if (a.Id != b.Id) { return(false); } if (!string.Equals(a.LogicalName, b.LogicalName)) { return(false); } if (!AreEqual(a.KeyAttributes, b.KeyAttributes)) { return(false); } return(true); }
public bool IsCurrentSiteMapNode(EntityReference entityReference) { if (entityReference == null) { return(false); } var currentNode = CurrentSiteMapNode as CrmSiteMapNode; return(currentNode != null && currentNode.Entity != null && entityReference.Equals(currentNode.Entity.ToEntityReference())); }
public decimal getFactor_UnitConversion(EntityReference product, EntityReference fromunit, EntityReference tounit, bool unitshipping = true) { decimal factor = 1; if (!fromunit.Equals(tounit)) { string xml = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'> <entity name='bsd_unitconversions'> <attribute name='bsd_factor' /> <filter type='and'> <condition attribute='bsd_product' operator='eq' uitype='product' value='" + product.Id + @"' /> <condition attribute='bsd_fromunit' operator='eq' uitype='uom' value='" + fromunit.Id + @"' /> <condition attribute='bsd_tounit' operator='eq' uitype='uom' value='" + tounit.Id + @"' /> <condition attribute='statecode' operator='eq' value='0' /> </filter> </entity> </fetch>"; EntityCollection unitconversion = myService.FetchXml(xml); if (unitconversion.Entities.Any()) { factor = (decimal)unitconversion.Entities.FirstOrDefault()["bsd_factor"]; } else { if (unitshipping) { throw new Exception("Shipping Unit Conversion has not been defined !"); } else { throw new Exception("Unit Conversion has not been defined !"); } } } return(factor); }
public override bool Equals(object obj) { EntityReference reference = this; return(reference.Equals(obj)); }
/// <summary> /// Main method /// </summary> /// <param name="serviceProvider">Service Provider</param> public void Execute(IServiceProvider serviceProvider) { if (serviceProvider == null) { return; } ITracingService tracer = (ITracingService)serviceProvider.GetService(typeof(ITracingService)); IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext)); IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory)); IOrganizationService service = factory.CreateOrganizationService(context.UserId); try { EntityReference currentRecordReference = (EntityReference)context.InputParameters["Target"]; if (currentRecordReference.Equals(null) || currentRecordReference.LogicalName != Model.CRMMarketingList.LOGICAL_NAME) { tracer.Trace("Does not contain target or logical name is different."); return; } Entity currentRecord = service.Retrieve(currentRecordReference.LogicalName, currentRecordReference.Id, new ColumnSet(Model.CRMMarketingList.ATTR_MAILCHIMP_MARKETING_LIST_ID, Model.CRMMarketingList.ATTR_CREATED_FROM_CODE)); string mailChimpMarketingListID = string.Empty; if (string.IsNullOrEmpty(currentRecord.GetAttributeValue <string>(Model.CRMMarketingList.ATTR_MAILCHIMP_MARKETING_LIST_ID))) { tracer.Trace("Mail chimp marketing list ID is not present"); throw new InvalidPluginExecutionException("Mail chimp marketing list ID is not present"); } else { mailChimpMarketingListID = currentRecord.GetAttributeValue <string>(Model.CRMMarketingList.ATTR_MAILCHIMP_MARKETING_LIST_ID); } string targetEntity = this.GetMemberType(currentRecord.GetAttributeValue <OptionSetValue>(Model.CRMMarketingList.ATTR_CREATED_FROM_CODE).Value.ToString()); EntityCollection members = null; switch (targetEntity) { case "account": tracer.Trace("Marketing List is of type Account and Account dors not contains Email Address. Thus it will not be synched to Mail Chimp"); throw new InvalidPluginExecutionException("Marketing List is of type Account and Account dors not contains Email Address. Thus it will not be synched to Mail Chimp"); case "contact": tracer.Trace("Retrieve Contact Members"); members = this.RetrieveMembers(service, currentRecord, tracer, "contact", "contactid"); break; case "lead": tracer.Trace("Retrieve Lead Members"); members = this.RetrieveMembers(service, currentRecord, tracer, "lead", "leadid"); break; default: break; } if (members == null) { //// No members retrieved tracer.Trace("No members retrieved"); throw new InvalidPluginExecutionException("No members retrieved. Kindly add members with Email address present"); } else { //// Create a json object for all the members tracer.Trace("Create a json object for all the members"); string jsonData = CreateBatchJSON(mailChimpMarketingListID, members, tracer); //// Call to Web Service tracer.Trace("Call to Web Service "); this.CallBatchCreateWebService(tracer, service, jsonData, currentRecord.Id); } } catch (FaultException <OrganizationServiceFault> ex) { throw new InvalidPluginExecutionException("An error occurred in the Follow up Plugin plug-in.", ex); } catch (Exception ex) { tracer.Trace("Message: {0}", ex.ToString()); throw; } }
/// <summary> /// Main method /// </summary> /// <param name="serviceProvider">Service Provider</param> public void Execute(IServiceProvider serviceProvider) { if (serviceProvider == null) { return; } ITracingService tracer = (ITracingService)serviceProvider.GetService(typeof(ITracingService)); context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext)); IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory)); IOrganizationService service = factory.CreateOrganizationService(context.UserId); try { EntityReference currentRecordReference = (EntityReference)context.InputParameters["Target"]; if (currentRecordReference.Equals(null) || currentRecordReference.LogicalName != Model.MailChimpSync.LOGICAL_NAME) { tracer.Trace("target record: " + currentRecordReference.LogicalName.ToString()); tracer.Trace("Does not contain target or logical name is different."); return; } //// Retrieve the mail chimp sync record Entity currentRecord = service.Retrieve(currentRecordReference.LogicalName, currentRecordReference.Id, new ColumnSet(Model.MailChimpSync.ATTR_BATCHID, Model.MailChimpSync.ATTR_MARKETING_LIST)); string batchId = string.Empty; Guid marketingListId = Guid.Empty; if (string.IsNullOrEmpty(currentRecord.GetAttributeValue <string>(Model.MailChimpSync.ATTR_BATCHID))) { tracer.Trace("Mail chimp Sync Batch ID is not present"); throw new InvalidPluginExecutionException("Mail chimp Sync Batch ID is not present"); } else { batchId = currentRecord.GetAttributeValue <string>(Model.MailChimpSync.ATTR_BATCHID); } if ((currentRecord.GetAttributeValue <EntityReference>(Model.MailChimpSync.ATTR_MARKETING_LIST)) != null) { marketingListId = currentRecord.GetAttributeValue <EntityReference>(Model.MailChimpSync.ATTR_MARKETING_LIST).Id; } string getBatchResponseJSON = string.Empty; Entity mailChimpconfig = null; mailChimpconfig = this.RetrieveMailChimpConfiguration(tracer, service); string username = string.Empty; string password = string.Empty; string api = string.Empty; string basicURL = string.Empty; if (mailChimpconfig.Contains(Model.MailChimpConfiguration.ATTR_APIKEY)) { api = mailChimpconfig.Attributes[Model.MailChimpConfiguration.ATTR_APIKEY].ToString(); tracer.Trace("API key present" + api); } if (mailChimpconfig.Contains(Model.MailChimpConfiguration.ATTR_MAILCHIMPURL)) { basicURL = mailChimpconfig.Attributes[Model.MailChimpConfiguration.ATTR_MAILCHIMPURL].ToString(); tracer.Trace("URL present" + basicURL); } if (mailChimpconfig.Contains(Model.MailChimpConfiguration.ATTR_MAILCHIMP_USERNAME)) { username = mailChimpconfig.Attributes[Model.MailChimpConfiguration.ATTR_MAILCHIMP_USERNAME].ToString(); tracer.Trace("UserName present" + username); } if (mailChimpconfig.Contains(Model.MailChimpConfiguration.ATTR_MAILCHIMP_PASSWORD)) { password = mailChimpconfig.Attributes[Model.MailChimpConfiguration.ATTR_MAILCHIMP_PASSWORD].ToString(); tracer.Trace("Password present" + password); } //// Call the web service using (WebClientEx client = new WebClientEx()) { string authorizationKey = string.Empty; authorizationKey = Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes(string.Format(CultureInfo.InvariantCulture, "{0}:{1}", username, api))); basicURL = basicURL + "/" + batchId; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(basicURL); request.Accept = "application/json"; request.Method = "GET"; request.Headers.Add("Authorization", "Basic " + authorizationKey); using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) using (Stream stream = response.GetResponseStream()) using (StreamReader reader = new StreamReader(stream)) { getBatchResponseJSON = reader.ReadToEnd(); } } tracer.Trace("createBatchResponse :" + getBatchResponseJSON); Model.MailChimpContactCreateBatchResponse createBatchResponse = GetInfoFromJSON(getBatchResponseJSON); UpdateMailChimpSyncRecord(createBatchResponse, tracer, service, currentRecord.Id); } catch (FaultException <OrganizationServiceFault> ex) { throw new InvalidPluginExecutionException("An error occurred in the Follow up Plugin plug-in.", ex); } catch (Exception ex) { tracer.Trace("Message: {0}", ex.ToString()); throw; } }
/// <summary> /// Filters tax records by basic cover (Peril) and orders results by 'valid until' date. /// </summary> /// <param name="taxes"></param> /// <param name="basicCoverRef"></param> /// <returns></returns> public static IEnumerable <Tax> ForBasicCover(this IEnumerable <Tax> taxes, EntityReference basicCoverRef) { return(taxes.Where(t => basicCoverRef.Equals(t.BasicCoverRef)) .OrderBy(t => t.ValidUntil, Tax.DateComparer)); }
/// <summary> /// Filters tax records by regulatory class and orders results by 'valid until' date. /// </summary> /// <param name="taxes"></param> /// <param name="regulatoryClassRef"></param> /// <returns></returns> public static IEnumerable <Tax> ForRegulatoryClass(this IEnumerable <Tax> taxes, EntityReference regulatoryClassRef) { return(taxes.Where(t => regulatoryClassRef.Equals(t.RegulatoryClassRef)) .OrderBy(t => t.ValidUntil, Tax.DateComparer)); }
/// <summary> /// Implements inequality between two <see cref="EntityReference"/>s /// </summary> /// <param name="x">The first <see cref="EntityReference"/> to compare</param> /// <param name="y">The second <see cref="EntityReference"/> to compare</param> /// <returns><c>false</c> if the first <see cref="EntityReference"/> matches the second <see cref="EntityReference"/>, or <c>true</c> otherwise</returns> public static bool NotEqual(EntityReference x, EntityReference y) { return(!x.Equals(y)); }