Esempio n. 1
0
        private async Task DeleteSolution(IWriteToOutput iWriteToOutput, Solution solution)
        {
            if (solution.Id == Guid.Empty)
            {
                return;
            }

            try
            {
                iWriteToOutput.WriteToOutput(_service.ConnectionData, Properties.OutputStrings.DeletingSolutionFormat1, solution.UniqueName);
                await _service.DeleteAsync(solution.LogicalName, solution.Id);

                solution.Id = Guid.Empty;
            }
            catch (Exception ex)
            {
                iWriteToOutput.WriteErrorToOutput(_service.ConnectionData, ex, Properties.OutputStrings.DeletingSolutionFailedFormat1, solution.UniqueName);
            }
        }
        private async Task PerformSaveClick()
        {
            string messageName     = cmBMessageName.Text?.Trim();
            string primaryEntity   = cmBPrimaryEntity.Text?.Trim();
            string secondaryEntity = cmBSecondaryEntity.Text?.Trim();

            if (string.IsNullOrEmpty(messageName))
            {
                MessageBox.Show(Properties.MessageBoxStrings.MessageNameIsEmpty, Properties.MessageBoxStrings.ErrorTitle, MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            if (!int.TryParse(txtBExecutionOrder.Text.Trim(), out int rank))
            {
                string text = string.Format(Properties.MessageBoxStrings.TextCannotBeParsedToIntFormat1, txtBExecutionOrder.Text);
                MessageBox.Show(text, Properties.MessageBoxStrings.ErrorTitle, MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            if (string.IsNullOrEmpty(primaryEntity))
            {
                primaryEntity = "none";
            }
            if (string.IsNullOrEmpty(secondaryEntity))
            {
                secondaryEntity = "none";
            }

            var messageFilterCount = _filters.Count(f =>
                                                    string.Equals(f.SdkMessageId.Name, messageName, StringComparison.InvariantCultureIgnoreCase) &&
                                                    string.Equals(f.PrimaryObjectTypeCode, primaryEntity, StringComparison.InvariantCultureIgnoreCase) &&
                                                    string.Equals(f.SecondaryObjectTypeCode, secondaryEntity, StringComparison.InvariantCultureIgnoreCase)
                                                    );

            if (messageFilterCount != 1)
            {
                string text = string.Format(Properties.MessageBoxStrings.MessageFilterNotFindedForMessageNameAndEntitiesFormat3, messageName, primaryEntity, secondaryEntity);
                MessageBox.Show(text, Properties.MessageBoxStrings.ErrorTitle, MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            var messageFilter = _filters.Single(f =>
                                                string.Equals(f.SdkMessageId.Name, messageName, StringComparison.InvariantCultureIgnoreCase) &&
                                                string.Equals(f.PrimaryObjectTypeCode, primaryEntity, StringComparison.InvariantCultureIgnoreCase) &&
                                                string.Equals(f.SecondaryObjectTypeCode, secondaryEntity, StringComparison.InvariantCultureIgnoreCase)
                                                );

            this.Step.Name        = txtBName.Text.Trim();
            this.Step.Description = txtBDescription.Text.Trim();

            this.Step.SdkMessageFilterId = messageFilter.ToEntityReference();
            this.Step.SdkMessageId       = messageFilter.SdkMessageId;

            this.Step.Rank          = rank;
            this.Step.Configuration = txtBUnSecureConfiguration.Text.Trim();

            var stage            = GetStage();
            var invocationsource = GetInvocationSource();

            this.Step.Stage = new OptionSetValue(stage);

            if (stage == (int)SdkMessageProcessingStep.Schema.OptionSets.stage.Post_operation_40)
            {
                var mode = GetMode();

                this.Step.Mode = new OptionSetValue(mode);

                if (mode == (int)SdkMessageProcessingStep.Schema.OptionSets.mode.Asynchronous_1)
                {
                    this.Step.AsyncAutoDelete = chBDeleteAsyncOperationIfSuccessful.IsChecked.GetValueOrDefault();
                }
                else
                {
                    this.Step.AsyncAutoDelete = false;
                }
            }
            else
            {
                this.Step.Mode            = new OptionSetValue((int)SdkMessageProcessingStep.Schema.OptionSets.mode.Synchronous_0);
                this.Step.AsyncAutoDelete = false;
            }

            if (!messageFilter.Availability.HasValue || messageFilter.Availability == (int)SdkMessageFilter.Schema.OptionSets.availability.Both)
            {
                var supporteddeployment = GetDeployment();

                this.Step.SupportedDeployment = new OptionSetValue(supporteddeployment);
            }
            else if (messageFilter.Availability == (int)SdkMessageFilter.Schema.OptionSets.availability.Server)
            {
                this.Step.SupportedDeployment = new OptionSetValue((int)SdkMessageProcessingStep.Schema.OptionSets.supporteddeployment.Server_Only_0);
            }
            else if (messageFilter.Availability == (int)SdkMessageFilter.Schema.OptionSets.availability.Client)
            {
                this.Step.SupportedDeployment = new OptionSetValue((int)SdkMessageProcessingStep.Schema.OptionSets.supporteddeployment.Microsoft_Dynamics_365_Client_for_Outlook_Only_1);
            }

#pragma warning disable CS0612 // Type or member is obsolete
            this.Step.InvocationSource = new OptionSetValue(invocationsource);
#pragma warning restore CS0612 // Type or member is obsolete

            if (string.Equals(messageFilter.SdkMessageId.Name, "Update", StringComparison.InvariantCultureIgnoreCase))
            {
                this.Step.FilteringAttributes = txtBFilteringBAttributes.Text.Trim();
            }
            else
            {
                this.Step.FilteringAttributes = string.Empty;
            }

            this.Step.ImpersonatingUserId = _impersonatingUser;

            string          secureConfig   = txtBSecureConfiguration.Text.Trim();
            EntityReference configToDelete = null;

            if (string.IsNullOrEmpty(secureConfig))
            {
                if (this.Step.SdkMessageProcessingStepSecureConfigId != null)
                {
                    configToDelete = this.Step.SdkMessageProcessingStepSecureConfigId;

                    this.Step.SdkMessageProcessingStepSecureConfigId = null;
                }
            }
            else
            {
                SdkMessageProcessingStepSecureConfig config = new SdkMessageProcessingStepSecureConfig()
                {
                    SecureConfig = secureConfig,
                };

                if (this.Step.SdkMessageProcessingStepSecureConfigId != null)
                {
                    config.Id = this.Step.SdkMessageProcessingStepSecureConfigId.Id;
                }

                ToggleControls(false, Properties.WindowStatusStrings.UpdatingSdkMessageProcessingStepSecureConfigFormat1, _service.ConnectionData.Name);

                try
                {
                    config.Id = await _service.UpsertAsync(config);

                    ToggleControls(true, Properties.WindowStatusStrings.UpdatingSdkMessageProcessingStepSecureConfigCompletedFormat1, _service.ConnectionData.Name);
                }
                catch (Exception ex)
                {
                    ToggleControls(true, Properties.WindowStatusStrings.UpdatingSdkMessageProcessingStepSecureConfigFailedFormat1, _service.ConnectionData.Name);

                    _iWriteToOutput.WriteErrorToOutput(_service.ConnectionData, ex);
                    _iWriteToOutput.ActivateOutputWindow(_service.ConnectionData);
                }

                if (config.Id != Guid.Empty)
                {
                    this.Step.SdkMessageProcessingStepSecureConfigId = config.ToEntityReference();
                }
            }

            ToggleControls(false, Properties.WindowStatusStrings.UpdatingSdkMessageProcessingStepFormat1, _service.ConnectionData.Name);

            try
            {
                this.Step.Id = await _service.UpsertAsync(this.Step);

                if (configToDelete != null)
                {
                    ToggleControls(false, Properties.WindowStatusStrings.DeletingSdkMessageProcessingStepSecureConfigFormat1, _service.ConnectionData.Name);

                    try
                    {
                        await _service.DeleteAsync(configToDelete.LogicalName, configToDelete.Id);

                        ToggleControls(true, Properties.WindowStatusStrings.DeletingSdkMessageProcessingStepSecureConfigCompletedFormat1, _service.ConnectionData.Name);
                    }
                    catch (Exception ex)
                    {
                        ToggleControls(true, Properties.WindowStatusStrings.DeletingSdkMessageProcessingStepSecureConfigFailedFormat1, _service.ConnectionData.Name);

                        _iWriteToOutput.WriteErrorToOutput(_service.ConnectionData, ex);
                        _iWriteToOutput.ActivateOutputWindow(_service.ConnectionData);
                    }
                }

                ToggleControls(true, Properties.WindowStatusStrings.UpdatingSdkMessageProcessingStepCompletedFormat1, _service.ConnectionData.Name);

                this.DialogResult = true;

                this.Close();
            }
            catch (Exception ex)
            {
                ToggleControls(true, Properties.WindowStatusStrings.UpdatingSdkMessageProcessingStepFailedFormat1, _service.ConnectionData.Name);

                _iWriteToOutput.WriteErrorToOutput(_service.ConnectionData, ex);
                _iWriteToOutput.ActivateOutputWindow(_service.ConnectionData);
            }
        }