Exemplo n.º 1
0
        private async Task ExecuteExportAssembly(string folder, Guid idAssembly, string name)
        {
            var service = await GetService();

            if (service == null)
            {
                return;
            }

            ToggleControls(service.ConnectionData, false, Properties.OutputStrings.ExportingPluginAssemblyBodyBinaryFormat1, name);

            var repository = new PluginAssemblyRepository(service);

            var assembly = await repository.GetAssemblyByIdRetrieveRequestAsync(idAssembly, new ColumnSet(PluginAssembly.Schema.Attributes.content));

            string fileName = EntityFileNameFormatter.GetPluginAssemblyFileName(service.ConnectionData.Name, name, "Content", FileExtension.dll);
            string filePath = Path.Combine(folder, FileOperations.RemoveWrongSymbols(fileName));

            var array = Convert.FromBase64String(assembly.Content);

            File.WriteAllBytes(filePath, array);

            this._iWriteToOutput.WriteToOutput(service.ConnectionData, Properties.OutputStrings.InConnectionEntityFieldExportedToFormat5, service.ConnectionData.Name, PluginAssembly.Schema.EntityLogicalName, name, "Content", filePath);

            if (File.Exists(filePath))
            {
                if (_commonConfig.DefaultFileAction != FileAction.None)
                {
                    this._iWriteToOutput.SelectFileInFolder(service.ConnectionData, filePath);
                }
            }

            ToggleControls(service.ConnectionData, true, Properties.OutputStrings.ExportingPluginAssemblyBodyBinaryCompletedFormat1, name);
        }
        private void FillSolutionComponentFromSchemaName(ICollection <SolutionComponent> result, string schemaName, int?behavior)
        {
            if (string.IsNullOrEmpty(schemaName))
            {
                return;
            }

            var match = _regexSchemaName.Match(schemaName);

            if (match.Success && match.Groups.Count == 5)
            {
                string name                 = match.Groups[1].Value;
                string versionString        = match.Groups[2].Value;
                string cultureString        = match.Groups[3].Value;
                string publicKeyTokenString = match.Groups[4].Value;

                if (!string.IsNullOrEmpty(name) &&
                    !string.IsNullOrEmpty(versionString) &&
                    !string.IsNullOrEmpty(cultureString) &&
                    !string.IsNullOrEmpty(publicKeyTokenString)
                    )
                {
                    var repository = new PluginAssemblyRepository(_service);

                    var entity = repository.FindAssemblyByFullName(name, versionString, cultureString, publicKeyTokenString, new ColumnSet(false));

                    if (entity != null)
                    {
                        FillSolutionComponentInternal(result, entity.Id, behavior);

                        return;
                    }
                }
            }
        }
Exemplo n.º 3
0
        private async void mIUpdatePluginAssembly_Click(object sender, RoutedEventArgs e)
        {
            var entity = GetSelectedEntity();

            if (entity == null)
            {
                return;
            }

            var service = await GetService();

            if (service == null)
            {
                return;
            }

            var repository = new PluginAssemblyRepository(service);

            var assembly = await repository.GetAssemblyByIdRetrieveRequestAsync(entity.Id);

            WindowHelper.OpenPluginAssemblyUpdateWindow(
                this._iWriteToOutput
                , service
                , assembly
                , null
                );
        }
        private async void mIUpdatePluginAssembly_Click(object sender, RoutedEventArgs e)
        {
            var entity = GetSelectedEntity();

            if (entity == null)
            {
                return;
            }

            var service = await GetService();

            var repository = new PluginAssemblyRepository(service);

            var assembly = await repository.GetAssemblyByIdRetrieveRequestAsync(entity.Id);

            System.Threading.Thread worker = new System.Threading.Thread(() =>
            {
                try
                {
                    var form = new WindowPluginAssembly(_iWriteToOutput, service, assembly, null, null);

                    form.ShowDialog();
                }
                catch (Exception ex)
                {
                    DTEHelper.WriteExceptionToOutput(null, ex);
                }
            });

            worker.SetApartmentState(System.Threading.ApartmentState.STA);

            worker.Start();
        }
Exemplo n.º 5
0
        private async Task PerformDownloadBinaryContent(Guid pluginAssemblyId, string assemblyName, Func <Task <IOrganizationServiceExtented> > getService)
        {
            ToggleControls(false, Properties.WindowStatusStrings.ExportingPluginAssemblyBodyBinaryFormat1, assemblyName);

            var service = await getService();

            if (service != null)
            {
                var repository = new PluginAssemblyRepository(service);

                var assembly = await repository.GetAssemblyByIdRetrieveRequestAsync(pluginAssemblyId, new ColumnSet(PluginAssembly.Schema.Attributes.content));

                string fileName = EntityFileNameFormatter.GetPluginAssemblyFileName(service.ConnectionData.Name, assembly.Name, "Content", "dll");
                string filePath = Path.Combine(_commonConfig.FolderForExport, FileOperations.RemoveWrongSymbols(fileName));

                var array = Convert.FromBase64String(assembly.Content);

                File.WriteAllBytes(filePath, array);

                this._iWriteToOutput.WriteToOutput(service.ConnectionData, Properties.OutputStrings.EntityFieldExportedToFormat5, service.ConnectionData.Name, PluginAssembly.Schema.EntityLogicalName, assembly.Name, "Content", filePath);

                if (File.Exists(filePath))
                {
                    if (_commonConfig.DefaultFileAction != FileAction.None)
                    {
                        this._iWriteToOutput.SelectFileInFolder(service.ConnectionData, filePath);
                    }
                }
            }

            ToggleControls(true, Properties.WindowStatusStrings.ExportingPluginAssemblyBodyBinaryCompletedFormat1, assemblyName);
        }
Exemplo n.º 6
0
        private async Task PerformExportEntityDescriptionToFileAsync(Guid pluginAssemblyId, string assemblyName, Func <Task <IOrganizationServiceExtented> > getService)
        {
            if (!this.IsControlsEnabled)
            {
                return;
            }

            ToggleControls(false, Properties.WindowStatusStrings.CreatingEntityDescription);

            var service = await getService();

            if (service != null)
            {
                var repository = new PluginAssemblyRepository(service);

                var assembly = await repository.GetAssemblyByIdRetrieveRequestAsync(pluginAssemblyId, new ColumnSet(true));

                var description = await EntityDescriptionHandler.GetEntityDescriptionAsync(assembly, EntityFileNameFormatter.PluginAssemblyIgnoreFields, service.ConnectionData);

                string filePath = await CreateDescriptionFileAsync(service.ConnectionData, assembly.Name, EntityFileNameFormatter.Headers.EntityDescription, description);

                this._iWriteToOutput.PerformAction(service.ConnectionData, filePath);
            }

            ToggleControls(true, Properties.WindowStatusStrings.CreatingEntityDescriptionCompleted);
        }
Exemplo n.º 7
0
        private async Task PerformExportEntityDescription(string folder, Guid idPluginAssembly, string name)
        {
            var service = await GetService();

            if (service == null)
            {
                return;
            }

            ToggleControls(service.ConnectionData, false, Properties.OutputStrings.CreatingEntityDescription);

            var repository = new PluginAssemblyRepository(service);

            var assembly = await repository.GetAssemblyByIdRetrieveRequestAsync(idPluginAssembly);

            string fileName = EntityFileNameFormatter.GetPluginAssemblyFileName(service.ConnectionData.Name, name, EntityFileNameFormatter.Headers.EntityDescription, FileExtension.txt);
            string filePath = Path.Combine(folder, FileOperations.RemoveWrongSymbols(fileName));

            await EntityDescriptionHandler.ExportEntityDescriptionAsync(filePath, assembly, service.ConnectionData);

            this._iWriteToOutput.WriteToOutput(service.ConnectionData, Properties.OutputStrings.InConnectionExportedEntityDescriptionFormat3
                                               , service.ConnectionData.Name
                                               , assembly.LogicalName
                                               , filePath);

            this._iWriteToOutput.PerformAction(service.ConnectionData, filePath);

            ToggleControls(service.ConnectionData, true, Properties.OutputStrings.CreatingEntityDescriptionCompleted);
        }
Exemplo n.º 8
0
        private async Task PerformExportAssemblyDescriptionToFileAsync(Guid idAssembly, string assemblyName, Func <Task <IOrganizationServiceExtented> > getService)
        {
            if (!this.IsControlsEnabled)
            {
                return;
            }

            ToggleControls(false, Properties.WindowStatusStrings.CreatingPluginAssebmltyDescriptionFormat1, assemblyName);

            var service = await getService();

            if (service != null)
            {
                var repository = new PluginAssemblyRepository(service);

                var assembly = await repository.GetAssemblyByIdRetrieveRequestAsync(idAssembly, new ColumnSet(PluginAssembly.Schema.Attributes.name));

                PluginAssemblyDescriptionHandler handler = new PluginAssemblyDescriptionHandler(service, service.ConnectionData.GetConnectionInfo());

                string description = await handler.CreateDescriptionAsync(assembly.Id, assembly.Name, DateTime.Now);

                string filePath = await CreateDescriptionFileAsync(service.ConnectionData, assembly.Name, "Description", description);

                this._iWriteToOutput.PerformAction(service.ConnectionData, filePath);
            }

            ToggleControls(true, Properties.WindowStatusStrings.CreatingPluginAssebmltyDescriptionCompletedFormat1, assemblyName);
        }
Exemplo n.º 9
0
        private async Task ShowExistingPluginAssemblies()
        {
            if (!this.IsControlsEnabled)
            {
                return;
            }

            ConnectionData connectionData = GetSelectedConnection();

            ToggleControls(connectionData, false, Properties.OutputStrings.LoadingPluginAssemblies);

            string textName = string.Empty;

            txtBFilter.Dispatcher.Invoke(() =>
            {
                this._itemsSource.Clear();
                textName = txtBFilter.Text.Trim().ToLower();
            });

            IEnumerable <PluginAssembly> list = Enumerable.Empty <PluginAssembly>();

            try
            {
                var service = await GetService();

                if (service != null)
                {
                    var repository = new PluginAssemblyRepository(service);
                    list = await repository.GetPluginAssembliesAsync(textName
                                                                     , new ColumnSet
                                                                     (
                                                                         PluginAssembly.Schema.Attributes.name
                                                                         , PluginAssembly.Schema.Attributes.version
                                                                         , PluginAssembly.Schema.Attributes.culture
                                                                         , PluginAssembly.Schema.Attributes.publickeytoken
                                                                         , PluginAssembly.Schema.Attributes.iscustomizable
                                                                         , PluginAssembly.Schema.Attributes.ismanaged
                                                                         , PluginAssembly.Schema.Attributes.ishidden
                                                                         , PluginAssembly.Schema.Attributes.username
                                                                         , PluginAssembly.Schema.Attributes.ispasswordset
                                                                         , PluginAssembly.Schema.Attributes.authtype
                                                                         , PluginAssembly.Schema.Attributes.isolationmode
                                                                         , PluginAssembly.Schema.Attributes.sourcetype
                                                                         , PluginAssembly.Schema.Attributes.description
                                                                         , PluginAssembly.Schema.Attributes.path
                                                                         , PluginAssembly.Schema.Attributes.url
                                                                     )
                                                                     );
                }
            }
            catch (Exception ex)
            {
                this._iWriteToOutput.WriteErrorToOutput(connectionData, ex);
            }

            LoadPluginAssemblies(list);

            ToggleControls(connectionData, true, Properties.OutputStrings.LoadingPluginAssembliesCompletedFormat1, list.Count());
        }
Exemplo n.º 10
0
        private async Task PerformShowingDifferenceEntityDescriptionAsync(LinkedEntities <PluginAssembly> linked, bool showAllways)
        {
            if (!this.IsControlsEnabled)
            {
                return;
            }

            ToggleControls(false, Properties.WindowStatusStrings.ShowingDifferenceEntityDescription);

            try
            {
                var service1 = await GetService1();

                var service2 = await GetService2();

                if (service1 != null && service2 != null)
                {
                    var repository1 = new PluginAssemblyRepository(service1);
                    var repository2 = new PluginAssemblyRepository(service2);

                    var assembly1 = await repository1.GetAssemblyByIdRetrieveRequestAsync(linked.Entity1.Id, new ColumnSet(true));

                    var assembly2 = await repository2.GetAssemblyByIdRetrieveRequestAsync(linked.Entity2.Id, new ColumnSet(true));

                    var desc1 = await EntityDescriptionHandler.GetEntityDescriptionAsync(assembly1, EntityFileNameFormatter.PluginAssemblyIgnoreFields);

                    var desc2 = await EntityDescriptionHandler.GetEntityDescriptionAsync(assembly2, EntityFileNameFormatter.PluginAssemblyIgnoreFields);

                    if (showAllways || desc1 != desc2)
                    {
                        string filePath1 = await CreateDescriptionFileAsync(service1.ConnectionData, assembly1.Name, EntityFileNameFormatter.Headers.EntityDescription, desc1);

                        string filePath2 = await CreateDescriptionFileAsync(service2.ConnectionData, assembly2.Name, EntityFileNameFormatter.Headers.EntityDescription, desc2);

                        if (File.Exists(filePath1) && File.Exists(filePath2))
                        {
                            this._iWriteToOutput.ProcessStartProgramComparer(filePath1, filePath2, Path.GetFileName(filePath1), Path.GetFileName(filePath2));
                        }
                        else
                        {
                            this._iWriteToOutput.PerformAction(service1.ConnectionData, filePath1);

                            this._iWriteToOutput.PerformAction(service2.ConnectionData, filePath2);
                        }
                    }
                }

                ToggleControls(true, Properties.WindowStatusStrings.ShowingDifferenceEntityDescriptionCompleted);
            }
            catch (Exception ex)
            {
                _iWriteToOutput.WriteErrorToOutput(null, ex);

                ToggleControls(true, Properties.WindowStatusStrings.ShowingDifferenceEntityDescriptionFailed);
            }
        }
        public async Task <string> RegisterPluginsForAssemblyAsync(string folder, Model.Backup.PluginAssembly assembly)
        {
            if (_service.ConnectionData.IsReadOnly)
            {
                return(null);
            }

            string fileName = string.Format("{0}.Plugin Register Operation at {1}.txt"
                                            , _service.ConnectionData.Name
                                            , EntityFileNameFormatter.GetDateString()
                                            );

            string filePath = Path.Combine(folder, FileOperations.RemoveWrongSymbols(fileName));

            StringBuilder log = new StringBuilder();

            var repositoryAssembly   = new PluginAssemblyRepository(_service);
            var repositoryType       = new PluginTypeRepository(_service);
            var repositoryMessage    = new SdkMessageRepository(_service);
            var repositoryFilter     = new SdkMessageFilterRepository(_service);
            var repositorySystemUser = new SystemUserRepository(_service);

            var entAssembly = await repositoryAssembly.FindAssemblyAsync(assembly.Name);

            if (entAssembly != null)
            {
                log.AppendFormat("Assembly {0} founded in CRM with ID {1}", assembly.Name, entAssembly.Id).AppendLine();

                foreach (var pluginType in assembly.PluginTypes)
                {
                    var entPluginType = await repositoryType.FindPluginTypeAsync(pluginType.TypeName);

                    if (entPluginType == null)
                    {
                        log.AppendFormat("Plugin Type {0} not founded in CRM.", pluginType.TypeName).AppendLine();
                        continue;
                    }

                    log.AppendFormat("Plugin Type {0} founded in CRM with ID {1}", pluginType.TypeName, entPluginType.Id).AppendLine();

                    foreach (var step in pluginType.PluginSteps)
                    {
                        await RegisterSingleStep(log, repositoryMessage, repositoryFilter, repositorySystemUser, entPluginType, step);
                    }
                }
            }
            else
            {
                log.AppendFormat("Assembly {0} not founded in CRM.", assembly.Name).AppendLine();
            }

            File.WriteAllText(filePath, log.ToString(), new UTF8Encoding(false));

            return(filePath);
        }
        public async Task <string> RegisterPluginsForPluginStepAsync(string folder, string assemblyName, string pluginType, Nav.Common.VSPackages.CrmDeveloperHelper.Model.Backup.PluginStep step)
        {
            if (_service.ConnectionData.IsReadOnly)
            {
                return(null);
            }

            string fileName = string.Format("{0}.Plugin Register Operation at {1}.txt"
                                            , _service.ConnectionData.Name
                                            , DateTime.Now.ToString("yyyy.MM.dd HH-mm-ss")
                                            );

            string filePath = Path.Combine(folder, FileOperations.RemoveWrongSymbols(fileName));

            StringBuilder log = new StringBuilder();

            var repositoryAssembly   = new PluginAssemblyRepository(_service);
            var repositoryType       = new PluginTypeRepository(_service);
            var repositoryMessage    = new SdkMessageRepository(_service);
            var repositoryFilter     = new SdkMessageFilterRepository(_service);
            var repositorySystemUser = new SystemUserRepository(_service);

            var entAssembly = await repositoryAssembly.FindAssemblyAsync(assemblyName);

            if (entAssembly != null)
            {
                log.AppendFormat("Assembly {0} founded in CRM with ID {1}", assemblyName, entAssembly.Id).AppendLine();

                var entPluginType = await repositoryType.FindPluginTypeAsync(pluginType);

                if (entPluginType != null)
                {
                    log.AppendFormat("Plugin Type {0} founded in CRM with ID {1}", pluginType, entPluginType.Id).AppendLine();

                    await RegisterSingleStep(log, repositoryMessage, repositoryFilter, repositorySystemUser, entPluginType, step);
                }
                else
                {
                    log.AppendFormat("Plugin Type {0} not founded in CRM.", pluginType).AppendLine();
                }
            }
            else
            {
                log.AppendFormat("Assembly {0} not founded in CRM.", assemblyName).AppendLine();
            }

            File.WriteAllText(filePath, log.ToString(), new UTF8Encoding(false));

            return(filePath);
        }
Exemplo n.º 13
0
        private async Task UpdatingPluginAssembliesInWindow(ConnectionData connectionData, CommonConfiguration commonConfig, List <EnvDTE.Project> projectList)
        {
            if (projectList == null || !projectList.Any(p => !string.IsNullOrEmpty(p.Name)))
            {
                this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.AssemblyNameIsEmpty);
                return;
            }

            var service = await ConnectAndWriteToOutputAsync(connectionData);

            if (service == null)
            {
                return;
            }

            var repositoryAssembly = new PluginAssemblyRepository(service);

            foreach (var project in projectList)
            {
                var assembly = await repositoryAssembly.FindAssemblyAsync(project.Name);

                if (assembly == null)
                {
                    assembly = await repositoryAssembly.FindAssemblyByLikeNameAsync(project.Name);
                }

                if (assembly == null)
                {
                    this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.PluginAssemblyNotFoundedByNameFormat1, project.Name);

                    WindowHelper.OpenPluginAssemblyExplorer(
                        this._iWriteToOutput
                        , service
                        , commonConfig
                        , project.Name
                        );
                }
                else
                {
                    WindowHelper.OpenPluginAssemblyUpdateWindow(
                        this._iWriteToOutput
                        , service
                        , assembly
                        , project
                        );
                }
            }
        }
Exemplo n.º 14
0
        private async Task ComparingAssemblyAndCrmSolution(ConnectionData connectionData, CommonConfiguration commonConfig, string projectName, string defaultOutputFilePath)
        {
            if (string.IsNullOrEmpty(projectName))
            {
                this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.AssemblyNameIsEmpty);
                return;
            }

            var service = await ConnectAndWriteToOutputAsync(connectionData);

            if (service == null)
            {
                return;
            }

            var repositoryAssembly = new PluginAssemblyRepository(service);

            var assembly = await repositoryAssembly.FindAssemblyAsync(projectName);

            if (assembly == null)
            {
                assembly = await repositoryAssembly.FindAssemblyByLikeNameAsync(projectName);
            }

            if (assembly == null)
            {
                this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.PluginAssemblyNotFoundedByNameFormat1, projectName);

                WindowHelper.OpenPluginAssemblyExplorer(
                    this._iWriteToOutput
                    , service
                    , commonConfig
                    , projectName
                    );

                return;
            }

            commonConfig.CheckFolderForExportExists(this._iWriteToOutput);

            string filePath = await CreateFileWithAssemblyComparing(commonConfig.FolderForExport, service, assembly.Id, assembly.Name, defaultOutputFilePath);

            this._iWriteToOutput.PerformAction(service.ConnectionData, filePath);
        }
Exemplo n.º 15
0
        private async Task BuildingProjectAndUpdatingPluginAssembly(ConnectionData connectionData, CommonConfiguration commonConfig, List <EnvDTE.Project> projectList, bool registerPlugins)
        {
            if (projectList == null || !projectList.Any(p => !string.IsNullOrEmpty(p.Name)))
            {
                this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.AssemblyNameIsEmpty);
                return;
            }

            var service = await ConnectAndWriteToOutputAsync(connectionData);

            if (service == null)
            {
                return;
            }

            var repositoryAssembly = new PluginAssemblyRepository(service);
            var repositoryType     = new PluginTypeRepository(service);

            foreach (var project in projectList)
            {
                string operation = string.Format(registerPlugins ? Properties.OperationNames.BuildingProjectAndUpdatingPluginAssemblyFormat2 : Properties.OperationNames.BuildingProjectUpdatingPluginAssemblyRegisteringPluginsFormat2
                                                 , connectionData?.Name
                                                 , project.Name
                                                 );

                this._iWriteToOutput.WriteToOutputStartOperation(connectionData, operation);

                try
                {
                    await BuildProjectUpdatePluginAssembly(connectionData, commonConfig, service, repositoryAssembly, repositoryType, project, registerPlugins);
                }
                catch (Exception ex)
                {
                    this._iWriteToOutput.WriteErrorToOutput(connectionData, ex);
                }
                finally
                {
                    this._iWriteToOutput.WriteToOutputEndOperation(connectionData, operation);
                }
            }
        }
Exemplo n.º 16
0
        private async Task ComparingAssemblyAndCrmSolution(ConnectionData connectionData, CommonConfiguration commonConfig, string projectName, string defaultOutputFilePath)
        {
            if (connectionData == null)
            {
                this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.NoCurrentCRMConnection);
                return;
            }

            if (string.IsNullOrEmpty(projectName))
            {
                this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.AssemblyNameIsEmpty);
                return;
            }

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

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

            // Подключаемся к CRM.
            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);

            var repositoryAssembly = new PluginAssemblyRepository(service);

            var assembly = await repositoryAssembly.FindAssemblyAsync(projectName);

            if (assembly == null)
            {
                assembly = await repositoryAssembly.FindAssemblyByLikeNameAsync(projectName);
            }

            if (assembly == null)
            {
                this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.PluginAssemblyNotFoundedByNameFormat1, projectName);

                WindowHelper.OpenPluginAssemblyWindow(
                    this._iWriteToOutput
                    , service
                    , commonConfig
                    , projectName
                    );

                return;
            }

            if (string.IsNullOrEmpty(commonConfig.FolderForExport))
            {
                _iWriteToOutput.WriteToOutput(null, Properties.OutputStrings.FolderForExportIsEmpty);
                commonConfig.FolderForExport = FileOperations.GetDefaultFolderForExportFilePath();
            }
            else if (!Directory.Exists(commonConfig.FolderForExport))
            {
                _iWriteToOutput.WriteToOutput(null, Properties.OutputStrings.FolderForExportDoesNotExistsFormat1, commonConfig.FolderForExport);
                commonConfig.FolderForExport = FileOperations.GetDefaultFolderForExportFilePath();
            }

            string filePath = await CreateFileWithAssemblyComparing(commonConfig.FolderForExport, service, assembly.Id, assembly.Name, defaultOutputFilePath);

            this._iWriteToOutput.PerformAction(service.ConnectionData, filePath);
        }
Exemplo n.º 17
0
        private async Task ShowExistingPluginAssemblies()
        {
            if (!this.IsControlsEnabled)
            {
                return;
            }

            ToggleControls(false, Properties.WindowStatusStrings.LoadingPluginAssemblies);

            this._itemsSource.Clear();

            var textName = string.Empty;

            txtBFilter.Dispatcher.Invoke(() =>
            {
                textName = txtBFilter.Text.Trim().ToLower();
            });

            IEnumerable <LinkedEntities <PluginAssembly> > list = Enumerable.Empty <LinkedEntities <PluginAssembly> >();

            try
            {
                var service1 = await GetService1();

                var service2 = await GetService2();

                if (service1 != null && service2 != null)
                {
                    var columnSet = new ColumnSet(PluginAssembly.Schema.Attributes.pluginassemblyid, PluginAssembly.Schema.Attributes.name);

                    var temp = new List <LinkedEntities <PluginAssembly> >();

                    if (service1.ConnectionData.ConnectionId != service2.ConnectionData.ConnectionId)
                    {
                        var repository1 = new PluginAssemblyRepository(service1);
                        var repository2 = new PluginAssemblyRepository(service2);

                        var task1 = repository1.GetPluginAssembliesAsync(textName, columnSet);
                        var task2 = repository2.GetPluginAssembliesAsync(textName, columnSet);

                        var list1 = await task1;
                        var list2 = await task2;

                        foreach (var assembly1 in list1)
                        {
                            var assembly2 = list2.FirstOrDefault(c => c.Name == assembly1.Name);

                            if (assembly2 == null)
                            {
                                continue;
                            }

                            temp.Add(new LinkedEntities <PluginAssembly>(assembly1, assembly2));
                        }
                    }
                    else
                    {
                        var repository1 = new PluginAssemblyRepository(service1);

                        var task1 = repository1.GetPluginAssembliesAsync(textName, columnSet);

                        var list1 = await task1;

                        foreach (var assembly1 in list1)
                        {
                            temp.Add(new LinkedEntities <PluginAssembly>(assembly1, null));
                        }
                    }

                    list = temp;
                }
            }
            catch (Exception ex)
            {
                this._iWriteToOutput.WriteErrorToOutput(null, ex);
            }

            LoadEntities(list);
        }
        private async Task <Model.Backup.PluginDescription> GetPluginDescription(IOrganizationServiceExtented service)
        {
            var repositoryAssembly = new PluginAssemblyRepository(service);
            var repositoryType     = new PluginTypeRepository(service);

            var repositoryMessage = new SdkMessageRepository(service);
            var repositoryFilter  = new SdkMessageFilterRepository(service);
            var repositorySecure  = new SdkMessageProcessingStepSecureConfigRepository(service);
            var repositoryImage   = new SdkMessageProcessingStepImageRepository(service);

            var repositoryStep = new SdkMessageProcessingStepRepository(service);

            var result = new Model.Backup.PluginDescription();

            result.CreatedOn = DateTime.Now;

            var listAssemblies = await repositoryAssembly.GetAllPluginAssemblisWithStepsAsync();

            var listMessage = await repositoryMessage.GetAllSdkMessageWithStepsAsync();

            var listFilter = await repositoryFilter.GetAllSdkMessageFilterWithStepsAsync();

            var listSecure = await repositorySecure.GetAllSdkMessageProcessingStepSecureConfigAsync();

            foreach (var entAssembly in listAssemblies)
            {
                var assembly = Model.Backup.PluginAssembly.GetObject(entAssembly);

                result.PluginAssemblies.Add(assembly);

                var listTypes = await repositoryType.GetPluginTypesAsync(entAssembly.Id);

                foreach (var entPluginType in listTypes)
                {
                    var pluginType = Model.Backup.PluginType.GetObject(entPluginType);

                    assembly.PluginTypes.Add(pluginType);

                    var listSteps = await repositoryStep.GetPluginStepsByPluginTypeIdAsync(entPluginType.Id);

                    var listStepsToAdd = new List <Model.Backup.PluginStep>();

                    foreach (var entStep in listSteps)
                    {
                        Entities.SdkMessage       entMessage = null;
                        Entities.SdkMessageFilter entFilter  = null;
                        Entities.SdkMessageProcessingStepSecureConfig entSecure = null;

                        var refMessage = entStep.SdkMessageId;
                        if (refMessage != null)
                        {
                            entMessage = listMessage.FirstOrDefault(m => m.SdkMessageId == refMessage.Id);
                        }

                        var refFilter = entStep.SdkMessageFilterId;
                        if (refFilter != null)
                        {
                            entFilter = listFilter.FirstOrDefault(f => f.SdkMessageFilterId == refFilter.Id);
                        }

                        var refSecure = entStep.SdkMessageProcessingStepSecureConfigId;
                        if (refSecure != null)
                        {
                            entSecure = listSecure.FirstOrDefault(s => s.SdkMessageProcessingStepSecureConfigId == refSecure.Id);
                        }

                        var step = Model.Backup.PluginStep.GetObject(entStep, entMessage, entFilter, entSecure);

                        listStepsToAdd.Add(step);

                        var listImages = await repositoryImage.GetStepImagesAsync(entStep.Id);

                        foreach (var entImage in listImages)
                        {
                            var image = Model.Backup.PluginImage.GetObject(entImage);

                            step.PluginImages.Add(image);
                        }
                    }

                    pluginType.PluginSteps.AddRange(
                        listStepsToAdd
                        .OrderBy(step => step.PrimaryEntity)
                        .ThenBy(step => step.SecondaryEntity)
                        .ThenBy(step => step.Message, MessageComparer.Comparer)
                        .ThenBy(step => step.Stage)
                        .ThenBy(step => step.ExecutionOrder)
                        .ThenBy(step => step.Name)
                        .ThenBy(step => step.CreatedOn)
                        );
                }
            }

            return(result);
        }
Exemplo n.º 19
0
        private async Task UpdatingPluginAssembly(ConnectionData connectionData, CommonConfiguration commonConfig, EnvDTE.Project project, string defaultOutputFilePath)
        {
            if (connectionData == null)
            {
                this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.NoCurrentCRMConnection);
                return;
            }

            if (project == null || string.IsNullOrEmpty(project.Name))
            {
                this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.AssemblyNameIsEmpty);
                return;
            }

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

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

            // Подключаемся к CRM.
            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);

            var repositoryAssembly = new PluginAssemblyRepository(service);

            var assembly = await repositoryAssembly.FindAssemblyAsync(project.Name);

            if (assembly == null)
            {
                assembly = await repositoryAssembly.FindAssemblyByLikeNameAsync(project.Name);
            }

            if (assembly == null)
            {
                this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.PluginAssemblyNotFoundedByNameFormat1, project.Name);

                WindowHelper.OpenPluginAssemblyWindow(
                    this._iWriteToOutput
                    , service
                    , commonConfig
                    , project.Name
                    );

                return;
            }

            System.Threading.Thread worker = new System.Threading.Thread(() =>
            {
                try
                {
                    var form = new WindowPluginAssembly(_iWriteToOutput, service, assembly, defaultOutputFilePath, project);

                    form.ShowDialog();
                }
                catch (Exception ex)
                {
                    DTEHelper.WriteExceptionToOutput(null, ex);
                }
            });

            worker.SetApartmentState(System.Threading.ApartmentState.STA);

            worker.Start();
        }
Exemplo n.º 20
0
        private async Task BuildProjectUpdatePluginAssembly(
            ConnectionData connectionData
            , CommonConfiguration commonConfig
            , IOrganizationServiceExtented service
            , PluginAssemblyRepository repositoryAssembly
            , PluginTypeRepository repositoryType
            , EnvDTE.Project project
            , bool registerPlugins
            )
        {
            var assembly = await repositoryAssembly.FindAssemblyAsync(project.Name);

            if (assembly == null)
            {
                assembly = await repositoryAssembly.FindAssemblyByLikeNameAsync(project.Name);
            }

            if (assembly == null)
            {
                this._iWriteToOutput.WriteToOutput(service.ConnectionData, Properties.OutputStrings.PluginAssemblyNotFoundedByNameFormat1, project.Name);

                WindowHelper.OpenPluginAssemblyExplorer(
                    this._iWriteToOutput
                    , service
                    , commonConfig
                    , project.Name
                    );

                return;
            }

            this._iWriteToOutput.WriteToOutput(service.ConnectionData, Properties.OutputStrings.BuildingProjectFormat1, project.Name);

            var buildResult = await _iWriteToOutput.BuildProjectAsync(project);

            if (buildResult != 0)
            {
                this._iWriteToOutput.WriteToOutput(service.ConnectionData, Properties.OutputStrings.BuildingProjectFailedFormat1, project.Name);
                return;
            }

            this._iWriteToOutput.WriteToOutput(service.ConnectionData, Properties.OutputStrings.BuildingProjectCompletedFormat1, project.Name);

            string defaultOutputFilePath = PropertiesHelper.GetOutputFilePath(project);

            if (!File.Exists(defaultOutputFilePath))
            {
                this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.FileNotExistsFormat1, defaultOutputFilePath);
                return;
            }

            this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.LoadingAssemblyFromPathFormat1, defaultOutputFilePath);

            AssemblyReaderResult assemblyLoad = null;

            using (var reader = new AssemblyReader())
            {
                assemblyLoad = reader.ReadAssembly(defaultOutputFilePath);
            }

            if (assemblyLoad == null)
            {
                this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.LoadingAssemblyFromPathFailedFormat1, defaultOutputFilePath);
                return;
            }

            assemblyLoad.Content = File.ReadAllBytes(defaultOutputFilePath);

            var crmPlugins   = new HashSet <string>(StringComparer.InvariantCultureIgnoreCase);
            var crmWorkflows = new HashSet <string>(StringComparer.InvariantCultureIgnoreCase);

            var pluginTypes = await repositoryType.GetPluginTypesAsync(assembly.Id);

            foreach (var item in pluginTypes.Where(e => !e.IsWorkflowActivity.GetValueOrDefault()).Select(e => e.TypeName))
            {
                crmPlugins.Add(item);
            }

            foreach (var item in pluginTypes.Where(e => e.IsWorkflowActivity.GetValueOrDefault()).Select(e => e.TypeName))
            {
                crmWorkflows.Add(item);
            }

            HashSet <string> assemblyPlugins   = new HashSet <string>(assemblyLoad.Plugins, StringComparer.InvariantCultureIgnoreCase);
            HashSet <string> assemblyWorkflows = new HashSet <string>(assemblyLoad.Workflows, StringComparer.InvariantCultureIgnoreCase);

            var pluginsOnlyInCrm  = crmPlugins.Except(assemblyPlugins, StringComparer.InvariantCultureIgnoreCase).ToList();
            var workflowOnlyInCrm = crmWorkflows.Except(assemblyWorkflows, StringComparer.InvariantCultureIgnoreCase).ToList();

            if (pluginsOnlyInCrm.Any() || workflowOnlyInCrm.Any())
            {
                if (pluginsOnlyInCrm.Any())
                {
                    this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.PluginTypesExistsOnlyInCRMFormat1, pluginsOnlyInCrm.Count);

                    foreach (var item in pluginsOnlyInCrm.OrderBy(s => s))
                    {
                        this._iWriteToOutput.WriteToOutput(connectionData, _tabspacer + item);
                    }
                }

                if (workflowOnlyInCrm.Any())
                {
                    this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.WorkflowTypesExistsOnlyInCRMFormat1, workflowOnlyInCrm.Count);

                    foreach (var item in workflowOnlyInCrm.OrderBy(s => s))
                    {
                        this._iWriteToOutput.WriteToOutput(connectionData, _tabspacer + item);
                    }
                }

                this._iWriteToOutput.WriteToOutput(service.ConnectionData, Properties.OutputStrings.CannotUpdatePluginAssemblyFormat1, assembly.Name);

                return;
            }

            string workflowActivityGroupName = string.Format("{0} ({1})", assemblyLoad.Name, assemblyLoad.Version);

            service.ConnectionData.AddAssemblyMapping(assemblyLoad.Name, assemblyLoad.FilePath);
            service.ConnectionData.Save();

            this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.UpdatingPluginAssemblyFormat1, service.ConnectionData.Name);

            assembly.Content = Convert.ToBase64String(assemblyLoad.Content);

            try
            {
                await service.UpdateAsync(assembly);

                if (registerPlugins)
                {
                    var pluginsOnlyInLocalAssembly  = assemblyPlugins.Except(crmPlugins, StringComparer.InvariantCultureIgnoreCase);
                    var workflowOnlyInLocalAssembly = assemblyWorkflows.Except(crmWorkflows, StringComparer.InvariantCultureIgnoreCase);

                    if (pluginsOnlyInLocalAssembly.Any() || workflowOnlyInLocalAssembly.Any())
                    {
                        int totalCount = pluginsOnlyInLocalAssembly.Count() + workflowOnlyInLocalAssembly.Count();

                        var assemblyRef = assembly.ToEntityReference();

                        this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.RegisteringNewPluginTypesFormat2, service.ConnectionData.Name, totalCount);

                        await RegisterNewPluginTypes(service, pluginsOnlyInLocalAssembly, assemblyRef, false, workflowActivityGroupName);

                        await RegisterNewPluginTypes(service, workflowOnlyInLocalAssembly, assemblyRef, true, workflowActivityGroupName);

                        this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.RegisteringNewPluginTypesCompletedFormat2, service.ConnectionData.Name, totalCount);
                    }
                }
            }
            catch (Exception ex)
            {
                this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.UpdatingPluginAssemblyFailedFormat1, service.ConnectionData.Name);

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