private async Task LoadPluginConfiguration(string filePath, Action <PluginDescription> setter, TextBox textBox)
        {
            if (!this.IsControlsEnabled)
            {
                return;
            }

            textBox.Text = string.Empty;

            ToggleControls(false, Properties.WindowStatusStrings.LoadingPluginConfiguration);

            if (string.IsNullOrEmpty(filePath))
            {
                return;
            }

            if (!File.Exists(filePath))
            {
                return;
            }

            PluginDescription pluginDescription = null;

            try
            {
                pluginDescription = await PluginDescription.LoadAsync(filePath);
            }
            catch (Exception ex)
            {
                _iWriteToOutput.WriteErrorToOutput(null, ex);

                pluginDescription = null;
            }

            setter(pluginDescription);

            this._allEntities = null;

            textBox.Dispatcher.Invoke(() =>
            {
                if (pluginDescription != null)
                {
                    textBox.Text = filePath;
                }
                else
                {
                    textBox.Text = string.Empty;
                }
            });

            ToggleControls(true, Properties.WindowStatusStrings.LoadingPluginConfigurationCompleted);

            ShowExistingAssemblies();
        }
Esempio n. 2
0
        private async Task <IOrganizationServiceExtented> GetService()
        {
            ConnectionData connectionData = null;

            cmBCurrentConnection.Dispatcher.Invoke(() =>
            {
                connectionData = cmBCurrentConnection.SelectedItem as ConnectionData;
            });

            if (connectionData == null)
            {
                return(null);
            }

            if (_connectionCache.ContainsKey(connectionData.ConnectionId))
            {
                return(_connectionCache[connectionData.ConnectionId]);
            }

            ToggleControls(connectionData, false, string.Empty);

            _iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.ConnectingToCRM);
            _iWriteToOutput.WriteToOutput(connectionData, connectionData.GetConnectionDescription());

            try
            {
                var service = await QuickConnection.ConnectAsync(connectionData);

                if (service != null)
                {
                    _iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.CurrentServiceEndpointFormat1, service.CurrentServiceEndpoint);

                    _connectionCache[connectionData.ConnectionId] = service;

                    return(service);
                }
                else
                {
                    _iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.ConnectionFailedFormat1, connectionData.Name);
                }
            }
            catch (Exception ex)
            {
                _iWriteToOutput.WriteErrorToOutput(connectionData, ex);
            }
            finally
            {
                ToggleControls(connectionData, true, string.Empty);
            }

            return(null);
        }
        private async Task LoadPluginConfiguration(string filePath)
        {
            if (!this.IsControlsEnabled)
            {
                return;
            }

            this._itemsSource.Clear();

            txtBFilePath.Text = string.Empty;

            if (string.IsNullOrEmpty(filePath))
            {
                return;
            }

            if (!File.Exists(filePath))
            {
                return;
            }

            ToggleControls(false, Properties.WindowStatusStrings.LoadingPluginConfiguration);

            try
            {
                this._pluginDescription = await PluginDescription.LoadAsync(filePath);
            }
            catch (Exception ex)
            {
                _iWriteToOutput.WriteErrorToOutput(null, ex);

                this._pluginDescription = null;
            }

            txtBFilePath.Dispatcher.Invoke(() =>
            {
                if (this._pluginDescription != null)
                {
                    txtBFilePath.Text = filePath;
                }
                else
                {
                    txtBFilePath.Text = string.Empty;
                }
            });

            ToggleControls(true, Properties.WindowStatusStrings.LoadingPluginConfigurationCompleted);

            ShowExistingPluginTypes();
        }
        protected static string GetPluginConfigurationFilePath(IWriteToOutput iWriteToOutput)
        {
            string selectedPath = string.Empty;

            var thread = new Thread(() =>
            {
                try
                {
                    var openFileDialog1 = new Microsoft.Win32.OpenFileDialog
                    {
                        Filter           = "Plugin Configuration (.xml)|*.xml",
                        FilterIndex      = 1,
                        RestoreDirectory = true
                    };

                    if (openFileDialog1.ShowDialog().GetValueOrDefault())
                    {
                        selectedPath = openFileDialog1.FileName;
                    }
                }
                catch (Exception ex)
                {
                    iWriteToOutput.WriteErrorToOutput(null, ex);
                }
            });

            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();

            thread.Join();

            return(selectedPath);
        }
Esempio n. 5
0
        private async Task PerformSaveClick()
        {
            var imageType = GetImageType();

            this.Image.Name                 = txtBName.Text.Trim();
            this.Image.EntityAlias          = txtBEntityAlias.Text.Trim();
            this.Image.MessagePropertyName  = cmBMessagePropertyName.Text?.Trim() ?? string.Empty;
            this.Image.RelatedAttributeName = txtBRelatedAttributeName.Text.Trim();
            this.Image.Description          = txtBDescription.Text.Trim();

            this.Image.Attributes1 = txtBAttributes.Text.Trim();

            this.Image.ImageType = new OptionSetValue(imageType);

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

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

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

                this.DialogResult = true;

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

                _iWriteToOutput.WriteErrorToOutput(_service.ConnectionData, ex);
                _iWriteToOutput.ActivateOutputWindow(_service.ConnectionData);
            }
        }
        private async Task LoadPluginConfiguration(string filePath)
        {
            if (!this.IsControlsEnabled)
            {
                return;
            }

            txtBFilePath.Text = string.Empty;

            if (string.IsNullOrEmpty(filePath))
            {
                return;
            }

            if (!File.Exists(filePath))
            {
                return;
            }

            try
            {
                this._pluginDescription = await PluginDescription.LoadAsync(filePath);
            }
            catch (Exception ex)
            {
                _iWriteToOutput.WriteErrorToOutput(null, ex);

                this._pluginDescription = null;
            }

            txtBFilePath.Dispatcher.Invoke(() =>
            {
                if (this._pluginDescription != null)
                {
                    txtBFilePath.Text = filePath;
                }
                else
                {
                    txtBFilePath.Text = string.Empty;
                }
            });

            ShowExistingPlugins();
        }
Esempio n. 7
0
        private async Task RetrieveEntityInformation()
        {
            try
            {
                ToggleControls(false, Properties.WindowStatusStrings.GettingEntityMetadataFormat1, _entityName);

                var repositoryEntityMetadata = new EntityMetadataRepository(_service);

                this._entityMetadata = await repositoryEntityMetadata.GetEntityMetadataAsync(_entityName);

                ToggleControls(true, Properties.WindowStatusStrings.GettingEntityMetadataCompletedFormat1, _entityName);

                FilterEntityAttributes(null);
            }
            catch (Exception ex)
            {
                _iWriteToOutput.WriteErrorToOutput(_service.ConnectionData, ex);
            }
        }
Esempio n. 8
0
        private static async Task <bool> TestConnect(ConnectionData connectionData, IWriteToOutput iWriteToOutput)
        {
            iWriteToOutput.ActivateOutputWindow(connectionData);

            iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.ConnectingToCRM);

            iWriteToOutput.WriteToOutput(connectionData, connectionData.GetConnectionDescription());

            try
            {
                var service = ConnectInternal(
                    connectionData
                    , true
                    , out OrganizationDetail organizationDetail
                    );

                if (service != null)
                {
                    {
                        WhoAmIResponse whoresponse = (WhoAmIResponse)service.Execute(new WhoAmIRequest());

                        iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.WhoAmIRequestExecutedSuccessfully);

                        iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.QuickConnectionOrganizationIdFormat1, whoresponse.OrganizationId);
                        iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.QuickConnectionBusinessUnitIdFormat1, whoresponse.BusinessUnitId);
                        iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.QuickConnectionUserIdFormat1, whoresponse.UserId);
                    }

                    var result = new OrganizationServiceExtentedProxy(service, connectionData);

                    await LoadOrganizationDataAsync(result, organizationDetail);

                    iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.CurrentServiceEndpointFormat1, result.CurrentServiceEndpoint);

                    iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.SuccessfullyConnectedFormat1, connectionData.Name);

                    return(true);
                }
                else
                {
                    iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.ConnectionFailedFormat1, connectionData.Name);

                    return(false);
                }
            }
            catch (Exception ex)
            {
                iWriteToOutput.WriteErrorToOutput(connectionData, ex);

                iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.ConnectionFailedFormat1, connectionData.Name);

                return(false);
            }
        }
        private static async Task <bool> TestConnect(ConnectionData connectionData, IWriteToOutput iWriteToOutput, System.Windows.Window window)
        {
            iWriteToOutput.ActivateOutputWindow(connectionData, window);

            iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.ConnectingToCRM);

            iWriteToOutput.WriteToOutput(connectionData, connectionData.GetConnectionDescription());

            try
            {
                var connectionResult = await ConnectInternal(connectionData, true);

                OrganizationServiceProxy serviceProxy       = connectionResult.Item1;
                OrganizationDetail       organizationDetail = connectionResult.Item2;
                string currentServiceEndpoint = GetServiceManagementEndpoint(connectionData.ConnectionId);

                if (serviceProxy != null)
                {
                    using (var serviceProxyExt = new OrganizationServiceExtentedProxy(serviceProxy, connectionData, currentServiceEndpoint))
                    {
                        var whoAmIResponse = await serviceProxyExt.ExecuteAsync <WhoAmIResponse>(new WhoAmIRequest());

                        iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.WhoAmIRequestExecutedSuccessfully);

                        iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.QuickConnectionOrganizationIdFormat1, whoAmIResponse.OrganizationId);
                        iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.QuickConnectionBusinessUnitIdFormat1, whoAmIResponse.BusinessUnitId);
                        iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.QuickConnectionUserIdFormat1, whoAmIResponse.UserId);

                        await LoadOrganizationDataAsync(serviceProxyExt, organizationDetail, whoAmIResponse);

                        iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.CurrentServiceEndpointFormat1, serviceProxyExt.CurrentServiceEndpoint);
                    }

                    iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.SuccessfullyConnectedFormat1, connectionData.Name);

                    return(true);
                }
                else
                {
                    iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.ConnectionFailedFormat1, connectionData.Name);

                    return(false);
                }
            }
            catch (Exception ex)
            {
                iWriteToOutput.WriteErrorToOutput(connectionData, ex);

                iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.ConnectionFailedFormat1, connectionData.Name);

                return(false);
            }
        }
        private static bool ValidateXmlDocument(ConnectionData connectionData, IWriteToOutput iWriteToOutput, XDocument doc)
        {
            ContentComparerHelper.ClearRoot(doc);

            XmlSchemaSet schemas = new XmlSchemaSet();

            {
                var schemasResources = AbstractDynamicCommandXsdSchemas.GetXsdSchemas(AbstractDynamicCommandXsdSchemas.WebResourceDependencyXmlSchema);

                if (schemasResources != null)
                {
                    foreach (var fileName in schemasResources)
                    {
                        Uri uri = FileOperations.GetSchemaResourceUri(fileName);
                        StreamResourceInfo info = Application.GetResourceStream(uri);

                        using (StreamReader reader = new StreamReader(info.Stream))
                        {
                            schemas.Add(string.Empty, XmlReader.Create(reader));
                        }
                    }
                }
            }

            List <ValidationEventArgs> errors = new List <ValidationEventArgs>();

            doc.Validate(schemas, (o, e) =>
            {
                errors.Add(e);
            });

            if (errors.Count > 0)
            {
                iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.TextIsNotValidForFieldFormat1, AbstractDynamicCommandXsdSchemas.WebResourceDependencyXmlSchema);

                foreach (var item in errors)
                {
                    iWriteToOutput.WriteToOutput(connectionData, string.Empty);
                    iWriteToOutput.WriteToOutput(connectionData, string.Empty);
                    iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.XmlValidationMessageFormat2, item.Severity, item.Message);
                    iWriteToOutput.WriteErrorToOutput(connectionData, item.Exception);
                }

                iWriteToOutput.ActivateOutputWindow(connectionData);
            }

            return(errors.Count == 0);
        }
Esempio n. 11
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 PublishingAllAsync(ConnectionData connectionData)
        {
            if (connectionData == null)
            {
                this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.NoCurrentCRMConnection);
                return;
            }

            this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.ConnectingToCRM);

            this._iWriteToOutput.WriteToOutput(connectionData, connectionData.GetConnectionDescription());

            var service = await QuickConnection.ConnectAsync(connectionData);

            if (service == null)
            {
                _iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.ConnectionFailedFormat1, connectionData.Name);
                return;
            }

            this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.CurrentServiceEndpointFormat1, service.CurrentServiceEndpoint);

            try
            {
                var repository = new PublishActionsRepository(service);

                await repository.PublishAllXmlAsync();

                _iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.PublishingAllCompletedFormat1, connectionData.Name);
            }
            catch (Exception ex)
            {
                _iWriteToOutput.WriteErrorToOutput(connectionData, ex);

                _iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.PublishingAllFailedFormat1, connectionData.Name);
            }
        }
Esempio n. 13
0
        private void tSBLoadFromFile_Click(object sender, RoutedEventArgs e)
        {
            if (!IsControlsEnabled)
            {
                return;
            }

            string selectedPath = string.Empty;
            var    t            = new Thread(() =>
            {
                try
                {
                    var openFileDialog1 = new Microsoft.Win32.OpenFileDialog
                    {
                        Filter           = "ConnectionData (.xml)|*.xml",
                        FilterIndex      = 1,
                        RestoreDirectory = true
                    };

                    if (openFileDialog1.ShowDialog().GetValueOrDefault())
                    {
                        selectedPath = openFileDialog1.FileName;
                    }
                }
                catch (Exception ex)
                {
                    _iWriteToOutput.WriteErrorToOutput(null, ex);
                    _iWriteToOutput.ActivateOutputWindow(null, this);
                }
            });

            t.SetApartmentState(ApartmentState.STA);
            t.Start();

            t.Join();

            if (string.IsNullOrEmpty(selectedPath))
            {
                return;
            }

            ConnectionData connectionData = null;

            try
            {
                connectionData = ConnectionData.GetFromPath(selectedPath);
            }
            catch (Exception ex)
            {
                _iWriteToOutput.WriteErrorToOutput(null, ex);
                _iWriteToOutput.ActivateOutputWindow(null, this);

                connectionData = null;
            }

            if (connectionData == null)
            {
                return;
            }

            connectionData.User = this._crmConfig.Users.FirstOrDefault(u => u.UserId == connectionData.UserId);

            if (this._crmConfig.Connections.Any(c => c.ConnectionId == connectionData.ConnectionId) ||
                this._crmConfig.ArchiveConnections.Any(c => c.ConnectionId == connectionData.ConnectionId) ||
                connectionData.ConnectionId == Guid.Empty
                )
            {
                connectionData.ConnectionId = Guid.NewGuid();
            }

            var form = new WindowCrmConnectionCard(_iWriteToOutput, connectionData, _crmConfig.Users);

            if (form.ShowDialog().GetValueOrDefault())
            {
                this.Dispatcher.Invoke(() =>
                {
                    connectionData.Save();
                    connectionData.ConnectionConfiguration = this._crmConfig;
                    connectionData.LoadIntellisenseAsync();
                    connectionData.StartWatchFile();
                    this._crmConfig.Connections.Add(connectionData);
                });
            }

            UpdateCurrentConnectionInfo();

            this._crmConfig.Save();
        }
        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);
            }
        }
        private async Task RetrieveEntityInformation()
        {
            try
            {
                ToggleControls(false, Properties.WindowStatusStrings.GettingEntityMetadataFormat1, _entityName);

                var repositoryEntityMetadata = new EntityMetadataRepository(_service);

                this._entityMetadata = await repositoryEntityMetadata.GetEntityMetadataWithAttributesAsync(_entityName);

                ToggleControls(true, Properties.WindowStatusStrings.GettingEntityMetadataCompletedFormat1, _entityName);

                if (this._entityMetadata != null)
                {
                    if (_entityId != Guid.Empty)
                    {
                        ToggleControls(false, Properties.WindowStatusStrings.GettingEntityFormat1, _entityId);

                        var repositoryGeneric = new GenericRepository(_service, this._entityMetadata);

                        this._entityInstance = await repositoryGeneric.GetEntityByIdAsync(_entityId, new ColumnSet(true));

                        ToggleControls(true, Properties.WindowStatusStrings.GettingEntityCompletedFormat1, _entityId);

                        if (this._entityInstance != null)
                        {
                            base.SwitchEntityDatesToLocalTime(new[] { this._entityInstance });

                            SetWindowTitle(string.Format("Edit Entity {0} - {1}", _entityName, _entityId));

                            this.Dispatcher.Invoke(() =>
                            {
                                btnSaveAsCopyEntity.IsEnabled  = true;
                                btnSaveAsCopyEntity.Visibility = Visibility.Visible;
                            });

                            this._attributeChecker = a => a.IsValidForUpdate.GetValueOrDefault() && !_ignoredAttributes.Contains(a.LogicalName);

                            foreach (var attributeValue in this._entityInstance.Attributes.OrderBy(a => a.Key))
                            {
                                var attributeMetadata = this._entityMetadata.Attributes.FirstOrDefault(a => string.Equals(a.LogicalName, attributeValue.Key, StringComparison.InvariantCultureIgnoreCase));

                                if (attributeMetadata != null &&
                                    string.IsNullOrEmpty(attributeMetadata.AttributeOf) &&
                                    _attributeChecker(attributeMetadata)
                                    )
                                {
                                    UserControl control = null;

                                    this.Dispatcher.Invoke(() =>
                                    {
                                        control = _controlFactory.CreateControlForAttribute(_service, false, this._entityMetadata, attributeMetadata, _entityInstance, attributeValue.Value);
                                    });

                                    if (control != null)
                                    {
                                        _listAttributeControls.Add(control);
                                    }
                                }
                            }
                        }
                        else
                        {
                            SetWindowTitle(string.Format("Create Entity {0} - {1}", _entityName, _entityId));
                        }
                    }
                    else
                    {
                        SetWindowTitle(string.Format("Create Entity {0}", _entityName));
                    }
                }

                FilterEntityAttributes(null);
            }
            catch (Exception ex)
            {
                _iWriteToOutput.WriteErrorToOutput(_service.ConnectionData, ex);
            }
        }
        private async Task RetrieveEntityInformation()
        {
            try
            {
                ToggleControls(false, Properties.WindowStatusStrings.GettingEntityMetadataFormat1, _entityName);

                var repositoryEntityMetadata = new EntityMetadataRepository(_service);

                this._entityMetadata = await repositoryEntityMetadata.GetEntityMetadataWithAttributesAsync(_entityName);

                ToggleControls(true, Properties.WindowStatusStrings.GettingEntityMetadataCompletedFormat1, _entityName);

                if (this._entityMetadata != null &&
                    this._entityMetadata.Attributes != null
                    )
                {
                    var stateCodeAttributeMetadata  = this._entityMetadata.Attributes.OfType <StateAttributeMetadata>().FirstOrDefault();
                    var statusCodeAttributeMetadata = this._entityMetadata.Attributes.OfType <StatusAttributeMetadata>().FirstOrDefault();

                    if (stateCodeAttributeMetadata != null &&
                        stateCodeAttributeMetadata.OptionSet != null &&
                        stateCodeAttributeMetadata.OptionSet.Options != null &&
                        statusCodeAttributeMetadata != null &&
                        statusCodeAttributeMetadata.OptionSet != null &&
                        statusCodeAttributeMetadata.OptionSet.Options != null
                        )
                    {
                        foreach (var statusCodeOption in statusCodeAttributeMetadata
                                 .OptionSet
                                 .Options
                                 .OfType <StatusOptionMetadata>()
                                 .OrderBy(o => o.State)
                                 .ThenBy(o => o.Value)
                                 )
                        {
                            var stateCodeOption = stateCodeAttributeMetadata.OptionSet.Options.OfType <StateOptionMetadata>().FirstOrDefault(o => o.Value == statusCodeOption.State);

                            if (stateCodeOption != null)
                            {
                                string stateName  = CreateFileHandler.GetLocalizedLabel(stateCodeOption.Label);
                                string statusName = CreateFileHandler.GetLocalizedLabel(statusCodeOption.Label);

                                _sourceStatusCodes.Add(new StatusCodeViewItem(
                                                           stateCodeOption.Value.Value
                                                           , stateName

                                                           , statusCodeOption.Value.Value
                                                           , statusName

                                                           , stateCodeOption.Label
                                                           , statusCodeOption.Label

                                                           , statusCodeOption
                                                           ));
                            }
                        }
                    }
                }

                FilterStatusCodes();
            }
            catch (Exception ex)
            {
                _iWriteToOutput.WriteErrorToOutput(_service.ConnectionData, ex);
            }
        }
        private async Task PerformSaveClick()
        {
            if (_assemblyLoad == null)
            {
                return;
            }

            if (_listMissingCrm.Count > 0)
            {
                return;
            }

            string workflowActivityGroupName = txtBWorkflowActivityGroupName.Text.Trim();

            var updateAssembly = new PluginAssembly();

            if (PluginAssembly.PluginAssemblyId.HasValue)
            {
                updateAssembly.Id = PluginAssembly.PluginAssemblyId.Value;
                updateAssembly.PluginAssemblyId = PluginAssembly.PluginAssemblyId;
            }
            else
            {
                updateAssembly.Name = _assemblyLoad.Name;
            }

            updateAssembly.Description = txtBDescription.Text.Trim();

            var isolationMode = GetIsolationMode();
            var sourceType    = GetSourceType();

            updateAssembly.IsolationMode  = new Microsoft.Xrm.Sdk.OptionSetValue(isolationMode);
            updateAssembly.SourceType     = new Microsoft.Xrm.Sdk.OptionSetValue(sourceType);
            updateAssembly.Version        = _assemblyLoad.Version;
            updateAssembly.Culture        = _assemblyLoad.Culture;
            updateAssembly.PublicKeyToken = _assemblyLoad.PublicKeyToken;

            if (sourceType == (int)PluginAssembly.Schema.OptionSets.sourcetype.Database_0 &&
                _assemblyLoad.Content != null &&
                _assemblyLoad.Content.Length > 0
                )
            {
                updateAssembly.Content = Convert.ToBase64String(_assemblyLoad.Content);
            }

            if (sourceType == (int)PluginAssembly.Schema.OptionSets.sourcetype.Disk_1)
            {
                updateAssembly.Path = txtBFileNameOnServer.Text.Trim();
            }
            else
            {
                updateAssembly.Path = string.Empty;
            }

            var listToRegister = _listLocalAssembly.Where(p => p.IsChecked).ToList();

            _service.ConnectionData.AddAssemblyMapping(_assemblyLoad.Name, _assemblyLoad.FilePath);
            _service.ConnectionData.Save();

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

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

                if (listToRegister.Any())
                {
                    var assemblyRef = this.PluginAssembly.ToEntityReference();

                    ToggleControls(false, Properties.WindowStatusStrings.RegisteringNewPluginTypesFormat2, _service.ConnectionData.Name, listToRegister.Count);

                    foreach (var pluginType in listToRegister)
                    {
                        var pluginTypeEntity = new PluginType()
                        {
                            Name         = pluginType.Name,
                            TypeName     = pluginType.Name,
                            FriendlyName = pluginType.Name,

                            PluginAssemblyId = assemblyRef,
                        };

                        if (pluginType.IsWorkflowActivity)
                        {
                            pluginTypeEntity.WorkflowActivityGroupName = workflowActivityGroupName;
                        }

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

                        try
                        {
                            pluginTypeEntity.Id = await _service.CreateAsync(pluginTypeEntity);

                            ToggleControls(true, Properties.WindowStatusStrings.RegisteringPluginTypeCompletedFormat2, _service.ConnectionData.Name, pluginType);
                        }
                        catch (Exception ex)
                        {
                            ToggleControls(true, Properties.WindowStatusStrings.RegisteringPluginTypeFailedFormat2, _service.ConnectionData.Name, pluginType);

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

                    ToggleControls(true, Properties.WindowStatusStrings.RegisteringNewPluginTypesCompletedFormat2, _service.ConnectionData.Name, listToRegister.Count);
                }

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

                this.DialogResult = true;

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

                _iWriteToOutput.WriteErrorToOutput(_service.ConnectionData, ex);
                _iWriteToOutput.ActivateOutputWindow(_service.ConnectionData);
            }
        }
Esempio n. 18
0
        private string ParseJavaScriptCode()
        {
            JavaScriptParser parser = new JavaScriptParser();

            var prog = parser.Parse(this._javaScriptCode);

            var engine = new Engine();

            bool resultFillParameters = FillParameters(engine, prog, out var varName);

            bool executed = false;

            int count = 0;

            while (!executed && count < 1000)
            {
                try
                {
                    engine.Execute(prog);

                    executed = true;
                }
                catch (Jint.Runtime.JavaScriptException ex)
                {
                    count++;

                    bool exceptionHandled = false;

                    if (ex.Error.IsObject())
                    {
                        var obj = ex.Error.AsObject();

                        if (string.Equals(obj.Class, "Error", StringComparison.InvariantCultureIgnoreCase))
                        {
                            var name    = obj.GetOwnProperty("name");
                            var message = obj.GetOwnProperty("message");

                            if (name != null && message != null && name.Value.IsString() && message.Value.IsString())
                            {
                                var nameValue    = name.Value.AsString();
                                var messageValue = message.Value.AsString();

                                exceptionHandled = HandleException(engine, nameValue, messageValue);
                            }
                        }
                    }

                    if (!exceptionHandled)
                    {
                        _iWriteToOutput.WriteErrorToOutput(null, ex);

                        executed = false;

                        break;
                    }
                }
                catch (Exception ex)
                {
                    _iWriteToOutput.WriteErrorToOutput(null, ex);

                    executed = false;

                    break;
                }
            }

            string result = string.Empty;

            if (executed)
            {
                var lastVar = engine.Global.GetOwnProperty(varName);

                if (lastVar != null)
                {
                    result = lastVar.Value.AsString();

                    if (!string.IsNullOrEmpty(result))
                    {
                        var commonConfig = Model.CommonConfiguration.Get();

                        result = ContentComparerHelper.FormatXmlByConfiguration(
                            result
                            , commonConfig
                            , XmlOptionsControls.SavedQueryXmlOptions
                            , schemaName: Commands.AbstractDynamicCommandXsdSchemas.FetchSchema
                            );
                    }
                }
            }

            return(result);
        }
Esempio n. 19
0
        private async Task RetrieveEntityInformation()
        {
            try
            {
                foreach (var entity in _entityCollection)
                {
                    ToggleControls(false, Properties.WindowStatusStrings.FilteringEntityInstanceAttributesFormat2, _entityMetadata.LogicalName, entity.Id);

                    foreach (var attributeKey in entity.Attributes.Keys.ToList())
                    {
                        var attributeMetadata = _entityMetadata.Attributes.FirstOrDefault(a => string.Equals(attributeKey, a.LogicalName, StringComparison.InvariantCultureIgnoreCase));

                        if (attributeMetadata == null)
                        {
                            if (_cacheMessageEntityAttributeNotExists.Add(attributeKey))
                            {
                                this._iWriteToOutput.WriteToOutput(_service.ConnectionData, Properties.OutputStrings.EntityAttributeNotExistsInConnectionFormat3, _entityMetadata.LogicalName, attributeKey, _service.ConnectionData.Name);
                            }

                            entity.Attributes.Remove(attributeKey);
                            continue;
                        }

                        if (!attributeMetadata.IsValidForCreate.GetValueOrDefault() &&
                            !attributeMetadata.IsValidForUpdate.GetValueOrDefault()
                            )
                        {
                            entity.Attributes.Remove(attributeKey);
                            continue;
                        }

                        if (entity.Attributes[attributeKey] != null &&
                            entity.Attributes[attributeKey] is EntityReference entityReference &&
                            attributeMetadata is LookupAttributeMetadata lookupAttributeMetadata &&
                            !_dictLookupMapping.ContainsKey(entityReference)
                            )
                        {
                            var targetEntityMetadata = await GetEntityMetadata(entityReference.LogicalName);

                            if (targetEntityMetadata == null)
                            {
                                entity.Attributes.Remove(attributeKey);
                                continue;
                            }

                            EntityReference targetEntityReference = null;

                            var repositoryGeneric = new GenericRepository(_service, targetEntityMetadata);

                            ColumnSet columnSet = new ColumnSet(false);

                            if (!string.IsNullOrEmpty(targetEntityMetadata.PrimaryNameAttribute))
                            {
                                columnSet.AddColumn(targetEntityMetadata.PrimaryNameAttribute);
                            }

                            if (targetEntityReference == null)
                            {
                                ToggleControls(false, Properties.WindowStatusStrings.TryingToFindEntityByIdFormat2, entityReference.LogicalName, entityReference.Id);

                                var targetEntity = await repositoryGeneric.GetEntityByIdAsync(entityReference.Id, columnSet);

                                if (targetEntity != null)
                                {
                                    targetEntityReference = targetEntity.ToEntityReference();

                                    if (!string.IsNullOrEmpty(targetEntityMetadata.PrimaryNameAttribute) &&
                                        targetEntity.Attributes.ContainsKey(targetEntityMetadata.PrimaryNameAttribute) &&
                                        targetEntity.Attributes[targetEntityMetadata.PrimaryNameAttribute] != null &&
                                        targetEntity.Attributes[targetEntityMetadata.PrimaryNameAttribute] is string entityReferenceName
                                        )
                                    {
                                        targetEntityReference.Name = entityReferenceName;
                                    }

                                    ToggleControls(true, Properties.WindowStatusStrings.TryingToFindEntityByIdFoundedFormat2, entityReference.LogicalName, entityReference.Id);
                                }
                                else
                                {
                                    ToggleControls(true, Properties.WindowStatusStrings.TryingToFindEntityByIdNotFoundedFormat2, entityReference.LogicalName, entityReference.Id);
                                }
                            }

                            if (targetEntityReference == null &&
                                !string.IsNullOrEmpty(targetEntityMetadata.PrimaryNameAttribute) &&
                                !string.IsNullOrEmpty(entityReference.Name)
                                )
                            {
                                ToggleControls(false, Properties.WindowStatusStrings.TryingToFindEntityByNameFormat4, entityReference.LogicalName, entityReference.Id, targetEntityMetadata.PrimaryNameAttribute, entityReference.Name);

                                var targetEntity = await repositoryGeneric.GetEntityByNameFieldAsync(entityReference.Name, columnSet);

                                if (targetEntity != null)
                                {
                                    targetEntityReference = targetEntity.ToEntityReference();

                                    if (targetEntity.Attributes.ContainsKey(targetEntityMetadata.PrimaryNameAttribute) &&
                                        targetEntity.Attributes[targetEntityMetadata.PrimaryNameAttribute] != null &&
                                        targetEntity.Attributes[targetEntityMetadata.PrimaryNameAttribute] is string entityReferenceName
                                        )
                                    {
                                        targetEntityReference.Name = entityReferenceName;
                                    }

                                    ToggleControls(true, Properties.WindowStatusStrings.TryingToFindEntityByNameFoundedFormat4, entityReference.LogicalName, entityReference.Id, targetEntityMetadata.PrimaryNameAttribute, entityReference.Name);
                                }
                                else
                                {
                                    ToggleControls(true, Properties.WindowStatusStrings.TryingToFindEntityByNameNotFoundedFormat4, entityReference.LogicalName, entityReference.Id, targetEntityMetadata.PrimaryNameAttribute, entityReference.Name);
                                }
                            }

                            EntityReferenceMappingControl control = null;

                            this.Dispatcher.Invoke(() =>
                            {
                                control = new EntityReferenceMappingControl(_service, lookupAttributeMetadata, entityReference, targetEntityReference);
                            });

                            _dictLookupMapping.Add(entityReference, control);
                            _listLookupMappingControls.Add(control);
                        }
                    }

                    ToggleControls(true, Properties.WindowStatusStrings.FilteringEntityInstanceAttributesCompletedFormat2, _entityMetadata.LogicalName, entity.Id);
                }

                this.lstVwLookupMapping.Dispatcher.Invoke(() =>
                {
                    int index = 0;

                    foreach (var item in _listLookupMappingControls.OrderBy(a => a.AttributeMetadata.LogicalName))
                    {
                        if (item is UserControl control)
                        {
                            var itemRowDef = new RowDefinition()
                            {
                                Height = new GridLength(10, GridUnitType.Auto),
                            };

                            lstVwLookupMapping.RowDefinitions.Add(itemRowDef);

                            control.VerticalAlignment   = VerticalAlignment.Stretch;
                            control.HorizontalAlignment = HorizontalAlignment.Stretch;

                            Grid.SetRow(control, index);
                            lstVwLookupMapping.Children.Add(control);

                            index++;
                        }
                    }
                });
            }
            catch (Exception ex)
            {
                _iWriteToOutput.WriteErrorToOutput(_service.ConnectionData, ex);
            }
        }