private void ButtonRefresh_Click(object sender, RoutedEventArgs e) { var isClearCache = CheckBoxClearCache.IsChecked ?? false; new Thread(() => { try { Dispatcher.Invoke(() => settings.Password = ((PasswordBox)((Button)sender).CommandParameter).Password); // PasswordBox doesn't allow 2 way binding, so we have to manually read it settings.Dirty = true; UpdateStatus("Re-initialising data ...", true); InitActions(isClearCache); UpdateStatus("-- Finished re-initialising data ...", false); if (isClearCache) { CrmDataHelper.ClearCache(); } } catch (Exception exception) { PopException(exception); } finally { Dispatcher.Invoke(() => CheckBoxClearCache.IsChecked = false); UpdateStatus("", false); } }).Start(); }
private void ProcessEntityChange() { if (!entityChanged) { return; } var entitySelected = (string)ComboBoxEntities.SelectedItem; new Thread(() => { if (!string.IsNullOrEmpty(entitySelected)) { try { ShowBusy("Getting message list ..."); MessageList = new List <string>(CrmDataHelper.GetMessageNames(entitySelected, Context)); Dispatcher.Invoke(() => ComboBoxMessages.ItemsSource = MessageList); IsInitEntity = true; } catch (Exception exception) { PopException(exception); } finally { HideBusy(); } } entityChanged = false; }).Start(); }
private void LoadAttributes() { string entitySelected = null; string messageSelected = null; Dispatcher.Invoke(() => { entitySelected = (string)ComboBoxEntities.SelectedItem; messageSelected = (string)ComboBoxMessages.SelectedItem; }); if (messageSelected == "Update") { try { ShowBusy("Getting attribute list ..."); AttributeList = new ObservableCollection <string>(CrmDataHelper .GetEntityFieldNames(entitySelected, Context)); AttributesSelectedString = CrmStep.Attributes; } catch (Exception exception) { PopException(exception); } finally { HideBusy(); } } else { AttributesSelectedString = null; } }
private void DialogWindow_Loaded(object sender, RoutedEventArgs e) { DataContext = this; new Thread(() => { try { ShowBusy("Getting user list ..."); UserList = new List <ComboUser>(CrmDataHelper .GetUsers(Context)); ShowBusy("Getting entity list ..."); EntityList = new List <string>(CrmDataHelper .GetEntityNames(Context)); User = CrmStep.UserId == Guid.Empty ? UserList.First() : UserList.First(userQ => userQ.Id == CrmStep.UserId); Entity = string.IsNullOrEmpty(Entity) ? "none" : Entity; Dispatcher.Invoke(() => ComboBoxEntities.Focus()); } catch (Exception exception) { PopException(exception); } finally { HideBusy(); } }).Start(); }
private void ButtonAddImage_Click(object sender, RoutedEventArgs e) { var step = (CrmTypeStep)ListTypeSteps.SelectedItem; var newImage = new CrmStepImage { Step = step }; new Thread(() => { try { UpdateStatus("Getting attribute list ...", true); newImage.AttributeList = new ObservableCollection <string>(CrmDataHelper .GetEntityFieldNames(step.Entity, context)); UpdateStatus("-- Finished getting attribute list.", false); } catch (Exception exception) { PopException(exception); } finally { UpdateStatus("", false); } StepImage dialogue = null; Dispatcher.Invoke(() => { dialogue = new StepImage(newImage, context); dialogue.ShowDialog(); }); try { if (dialogue.IsUpdate) { assemblyRegistration.CreateStepImage(newImage); Dispatcher.Invoke(() => step.Children.Add(newImage)); } } catch (Exception exception) { PopException(exception); } finally { HideBusy(); } }).Start(); }
private void ListTypeSteps_SelectionChanged(object sender, SelectionChangedEventArgs e) { var step = (CrmTypeStep)ListTypeSteps.SelectedItem; new Thread(() => { if (step != null) { IsTypeStepSelected = true; // don't fetch from CRM if updated once (caching) if (!step.IsUpdated) { try { UpdateStatus("Updating type step info ...", true); step.UpdateInfo(context); UpdateStatus("-- Finished updating type step info.", false); } catch (Exception exception) { PopException(exception); } finally { UpdateStatus("", false); } } IsAddImageAllowed = (step.Message == "Create" && step.Stage == SdkMessageProcessingStep.Enums.Stage.Postoperation) || (step.Message != "Create" && !string.IsNullOrEmpty(CrmDataHelper.GetMessagePropertyName(step.Message, step.Entity))); } else { IsAddImageAllowed = false; } // update UI UpdateListBindingToEntityChildren(step, ListStepImages); }).Start(); }
private void ButtonEditImage_Click(object sender, RoutedEventArgs e) { var step = (CrmTypeStep)ListTypeSteps.SelectedItem; var image = (CrmStepImage)ListStepImages.SelectedItem; new Thread(() => { try { UpdateStatus("Getting attribute list ...", true); image.AttributeList = new ObservableCollection <string>(CrmDataHelper .GetEntityFieldNames(step.Entity, context)); UpdateStatus("-- Finished getting attribute list.", false); if (!image.IsUpdated) { UpdateStatus("Updating image info ...", true); // only basic info exists in the image when it is loaded through the step class image.UpdateInfo(context); UpdateStatus("-- Finished updating image info.", false); } } catch (Exception exception) { PopException(exception); } finally { UpdateStatus("", false); } var clone = image.Clone <CrmStepImage>(); StepImage dialogue = null; Dispatcher.Invoke(() => { dialogue = new StepImage(clone, context); dialogue.ShowDialog(); }); try { if (dialogue.IsUpdate) { assemblyRegistration.UpdateStepImage(clone); Dispatcher.Invoke(() => { step.Children.Remove(image); step.Children.Add(clone); }); } } catch (Exception exception) { PopException(exception); } finally { HideBusy(); } }).Start(); }
public void Execute(IServiceProvider serviceProvider) { ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService)); IPluginExecutionContext context = (IPluginExecutionContext) serviceProvider.GetService(typeof(IPluginExecutionContext)); tracingService.Trace("Entered in R"); if (context != null) { //tracingService.Trace(context) } if (context.Depth > 1) { tracingService.Trace("depth"); return; } //Entity entity = context.PostEntityImages["PostImage"]; if (context.PostEntityImages.Contains("PostImage") && context.PostEntityImages["PostImage"] is Entity) { Entity entity = (Entity)context.PostEntityImages["PostImage"]; if (entity.LogicalName != "poad_customaddress") { return; } IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory)); IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId); try { CrmDataHelper objHelper = new CrmDataHelper(); Guid accountId = Guid.Empty; Guid contactid = Guid.Empty; Guid addressId = Guid.Empty; int addressNumber = 0; int objectTypeCode = 0; bool blnupdateaddressnumber = false; Entity customAddressObject; if (entity.Contains(CustomAddressAttributes.poad_addressnumber) && entity[CustomAddressAttributes.poad_addressnumber] != null) { addressNumber = (int)entity[CustomAddressAttributes.poad_addressnumber]; } if (entity.Contains(CustomAddressAttributes.poad_customerid) && entity[CustomAddressAttributes.poad_customerid] != null) { EntityReference customer = ((EntityReference)entity[CustomAddressAttributes.poad_customerid]); if (customer.LogicalName == "contact") { objectTypeCode = 2; } else if (customer.LogicalName == "account") { objectTypeCode = 1; } addressId = objHelper.GetAddressId(service, addressNumber, customer.Id); if (addressNumber == 0) { addressNumber = objHelper.GetMaxAddressNumber(service, tracingService, customer.Id, objectTypeCode); blnupdateaddressnumber = true; } } //else if(entity.Contains(CustomAddressAttributes.poad_contactid) && entity[CustomAddressAttributes.poad_contactid] != null) //{ // objectTypeCode = 2; // contactid = ((EntityReference)entity[CustomAddressAttributes.poad_contactid]).Id; // addressId = objHelper.GetAddressId(service, addressNumber, contactid); // if (addressNumber == 0) // { // addressNumber = objHelper.GetMaxAddressNumber(service, tracingService, contactid, objectTypeCode); // blnupdateaddressnumber = true; // } //} tracingService.Trace("Object Type code" + objectTypeCode); tracingService.Trace("ADdress number::" + addressNumber); if (objectTypeCode != 1 && objectTypeCode != 2) { return; } if (addressNumber == 0) { return; } tracingService.Trace("message" + context.MessageName); if (context.MessageName == "Create" || context.MessageName == "Update") { if (addressId == Guid.Empty) { customAddressObject = CreateAddressObject(entity, objectTypeCode, addressNumber); service.Create(customAddressObject); } else { customAddressObject = CreateAddressObject(entity, objectTypeCode, addressNumber); customAddressObject.Id = addressId; service.Update(customAddressObject); } } if (context.MessageName == "Create" && blnupdateaddressnumber == true) { entity[CustomAddressAttributes.poad_addressnumber] = addressNumber; service.Update(entity); } } catch (Exception ex) { tracingService.Trace("HandleCustom OOB Address: {0}", ex.ToString()); throw; } //catch (FaultException<OrganizationServiceFault> ex) //{ // throw new InvalidPluginExecutionException("An error occurred in HandleCustomAddress.", ex); //} } }
public void Execute(IServiceProvider serviceProvider) { ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService)); IPluginExecutionContext context = (IPluginExecutionContext) serviceProvider.GetService(typeof(IPluginExecutionContext)); tracingService.Trace("Entered in CustomAddress"); if (context != null) { //tracingService.Trace(context) } if (context.Depth > 1) { tracingService.Trace("depth is greter than 1 returned"); return; } //Entity entity = context.PostEntityImages["PostImage"]; if (context.PostEntityImages.Contains("PostImage") && context.PostEntityImages["PostImage"] is Entity) { Entity entity = (Entity)context.PostEntityImages["PostImage"]; IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory)); IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId); try { CrmDataHelper objHelper = new CrmDataHelper(); Guid customerAddressId = Guid.Empty; Guid parentId; int addressNumber; int objectTypeCode; Entity customAddressObject; EntityCollection addresscollection = objHelper.GetCustomerAddress(service, entity.Id); if (entity.LogicalName == "contact") { objectTypeCode = 2; } else { objectTypeCode = 1; } foreach (Entity e in addresscollection.Entities) { addressNumber = (int)e[AddressAttributes.addressnumber]; tracingService.Trace("Object Type code" + objectTypeCode); tracingService.Trace("message" + context.MessageName); parentId = ((EntityReference)e[AddressAttributes.parentid]).Id; customerAddressId = objHelper.GetParentIdCustomerAddress(service, addressNumber, entity.Id, objectTypeCode); if (context.MessageName == "Create" || context.MessageName == "Update") { if (customerAddressId == Guid.Empty) { customAddressObject = CreateCustomerAddressObject(e, objectTypeCode, entity, addressNumber, service, tracingService); service.Create(customAddressObject); } else { customAddressObject = CreateCustomerAddressObject(e, objectTypeCode, entity, addressNumber, service, tracingService); customAddressObject.Id = customerAddressId; service.Update(customAddressObject); } } } tracingService.Trace("check adress"); if (objectTypeCode == 1 && entity.Attributes.Contains(AddressAttributes.gk_shiptoaddresstype) && entity.Attributes[AddressAttributes.gk_shiptoaddresstype] != null) { tracingService.Trace("Address3"); addressNumber = 3; customerAddressId = objHelper.GetParentIdCustomerAddress(service, addressNumber, entity.Id, objectTypeCode); if (customerAddressId == Guid.Empty) { tracingService.Trace("createaddress3"); customAddressObject = CreateCustomerAddressObject(null, objectTypeCode, entity, addressNumber, service, tracingService); service.Create(customAddressObject); } else { tracingService.Trace("updateaddress3"); customAddressObject = CreateCustomerAddressObject(null, objectTypeCode, entity, addressNumber, service, tracingService); customAddressObject.Id = customerAddressId; service.Update(customAddressObject); } } } catch (Exception ex) { tracingService.Trace("HandleCustomAddress: {0}", ex.ToString()); throw; } //catch (FaultException<OrganizationServiceFault> ex) //{ // throw new InvalidPluginExecutionException("An error occurred in HandleCustomAddress.", ex); //} } }