Esempio n. 1
0
        private async Task ShowExistingPluginTypes()
        {
            if (!this.IsControlsEnabled)
            {
                return;
            }

            var service = await GetService();

            ToggleControls(service.ConnectionData, false, Properties.WindowStatusStrings.LoadingPluginTypes);

            this._itemsSource.Clear();

            string textName = string.Empty;

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

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

            try
            {
                if (service != null)
                {
                    var repository = new PluginTypeRepository(service);
                    list = await repository.GetPluginTypesAsync(textName
                                                                , new ColumnSet
                                                                (
                                                                    PluginType.Schema.Attributes.typename
                                                                    , PluginType.Schema.Attributes.name
                                                                    , PluginType.Schema.Attributes.friendlyname
                                                                    , PluginType.Schema.Attributes.assemblyname
                                                                    , PluginType.Schema.Attributes.workflowactivitygroupname
                                                                    , PluginType.Schema.Attributes.customworkflowactivityinfo
                                                                    , PluginType.Schema.Attributes.description
                                                                    , PluginType.Schema.Attributes.ismanaged
                                                                    , PluginType.Schema.Attributes.isworkflowactivity
                                                                    , PluginType.Schema.Attributes.pluginassemblyid
                                                                )
                                                                );
                }
            }
            catch (Exception ex)
            {
                this._iWriteToOutput.WriteErrorToOutput(service.ConnectionData, ex);
            }

            LoadPluginTypes(list);

            ToggleControls(service.ConnectionData, true, Properties.WindowStatusStrings.LoadingPluginTypesCompletedFormat1, list.Count());
        }
        public async Task <string> CreateDescriptionAsync(Guid idPluginAssembly, string name, DateTime now)
        {
            var content = new StringBuilder();

            var allTypes = await _repType.GetPluginTypesAsync(idPluginAssembly);

            var allSteps = await _repStep.GetAllStepsByPluginAssemblyAsync(idPluginAssembly);

            var allImages = await _repImage.GetImagesByPluginAssemblyAsync(idPluginAssembly);

            var allSecure = await _repSecure.GetAllSdkMessageProcessingStepSecureConfigAsync();

            content.AppendLine(_connectionInfo).AppendLine();
            content.AppendFormat("Description for PluginAssembly '{0}' at {1}", name, now.ToString("G", System.Globalization.CultureInfo.CurrentCulture)).AppendLine();

            content
            .AppendLine()
            .AppendLine("Plugin Types");

            foreach (var pluginType in allTypes.OrderBy(e => e.TypeName))
            {
                content.AppendLine(pluginType.TypeName);
            }

            content
            .AppendLine()
            .AppendLine("Plugin Types Descriptions");

            foreach (var pluginType in allTypes.OrderBy(e => e.TypeName))
            {
                var desc = await PluginTypeDescriptionHandler.CreateDescriptionAsync(pluginType.PluginTypeId.Value
                                                                                     , allSteps.Where(s => s.EventHandler.Id == pluginType.PluginTypeId.Value)
                                                                                     , allImages
                                                                                     , allSecure
                                                                                     );

                if (!string.IsNullOrEmpty(desc))
                {
                    content.AppendFormat("Plugin Steps for PluginType '{0}'", pluginType.TypeName).AppendLine();

                    content.AppendLine(desc).AppendLine();
                }
            }

            return(content.ToString());
        }
        private async Task LoadLocalAssemblyAsync(string assemblyPath)
        {
            this.Dispatcher.Invoke(() =>
            {
                _assemblyLoad = null;

                _listLocalAssembly.Clear();
                _listMissingCrm.Clear();

                txtBLoadedAssemblyPath.Text           = string.Empty;
                txtBLoadedAssemblyName.Text           = string.Empty;
                txtBLoadedAssemblyVersion.Text        = string.Empty;
                txtBLoadedAssemblyCulture.Text        = string.Empty;
                txtBLoadedAssemblyPublicKeyToken.Text = string.Empty;
            });

            if (string.IsNullOrEmpty(assemblyPath) ||
                !File.Exists(assemblyPath)
                )
            {
                UpdateStatus(Properties.OutputStrings.FileNotExists);
                return;
            }

            if (!IsControlsEnabled)
            {
                return;
            }

            ToggleControls(false, Properties.OutputStrings.LoadingAssemblyFromPathFormat1, assemblyPath);

            AssemblyReaderResult assemblyCheck = null;

            using (var reader = new AssemblyReader())
            {
                assemblyCheck = reader.ReadAssembly(assemblyPath);
            }

            if (assemblyCheck == null)
            {
                ToggleControls(true, Properties.OutputStrings.LoadingAssemblyFromPathFailedFormat1, assemblyPath);
                return;
            }

            assemblyCheck.Content = File.ReadAllBytes(assemblyPath);

            this._assemblyLoad     = assemblyCheck;
            cmBAssemblyToLoad.Text = this._assemblyLoad.FilePath;

            txtBLoadedAssemblyPath.Text           = this._assemblyLoad.FilePath;
            txtBLoadedAssemblyName.Text           = this._assemblyLoad.Name;
            txtBLoadedAssemblyVersion.Text        = this._assemblyLoad.Version;
            txtBLoadedAssemblyCulture.Text        = this._assemblyLoad.Culture;
            txtBLoadedAssemblyPublicKeyToken.Text = this._assemblyLoad.PublicKeyToken;

            var fileInfo = new FileInfo(assemblyPath);

            txtBLoadedAssemblyDateModified.Text = fileInfo.LastWriteTime.ToString(EntityFileNameFormatter.dateFormatYearMonthDayHourMinuteSecond);

            if (PluginAssembly.Id == Guid.Empty)
            {
                txtBFileNameOnServer.Text = this._assemblyLoad.FileName;
            }

            txtBWorkflowActivityGroupName.Text = string.Format("{0} ({1})", this._assemblyLoad.Name, this._assemblyLoad.Version);

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

            if (this.PluginAssembly != null && this.PluginAssembly.Id != Guid.Empty)
            {
                var repositoryType = new PluginTypeRepository(_service);
                var pluginTypes    = await repositoryType.GetPluginTypesAsync(this.PluginAssembly.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);
            var workflowOnlyInCrm = crmWorkflows.Except(assemblyWorkflows, StringComparer.InvariantCultureIgnoreCase);

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

            List <PluginTreeViewItem> listLocalAssembly = new List <PluginTreeViewItem>();
            List <PluginTreeViewItem> listMissingCrm    = new List <PluginTreeViewItem>();

            foreach (var pluginTypeName in pluginsOnlyInLocalAssembly.OrderBy(s => s))
            {
                var nodeType = new PluginTreeViewItem(ComponentType.PluginType)
                {
                    Name  = pluginTypeName,
                    Image = _imagePluginType,
                };

                listLocalAssembly.Add(nodeType);
            }

            foreach (var pluginTypeName in workflowOnlyInLocalAssembly.OrderBy(s => s))
            {
                var nodeType = new PluginTreeViewItem(ComponentType.PluginType)
                {
                    Name  = pluginTypeName,
                    Image = _imageWorkflowActivity,

                    IsWorkflowActivity = true,
                };

                listLocalAssembly.Add(nodeType);
            }

            foreach (var pluginTypeName in pluginsOnlyInCrm.OrderBy(s => s))
            {
                var nodeType = new PluginTreeViewItem(ComponentType.PluginType)
                {
                    Name  = pluginTypeName,
                    Image = _imagePluginType,
                };

                listMissingCrm.Add(nodeType);
            }

            foreach (var pluginTypeName in workflowOnlyInCrm.OrderBy(s => s))
            {
                var nodeType = new PluginTreeViewItem(ComponentType.PluginType)
                {
                    Name  = pluginTypeName,
                    Image = _imageWorkflowActivity,

                    IsWorkflowActivity = true,
                };

                listMissingCrm.Add(nodeType);
            }

            this.Dispatcher.Invoke(() =>
            {
                foreach (var item in listLocalAssembly)
                {
                    _listLocalAssembly.Add(item);
                }
                this.trVPluginTreeNew.UpdateLayout();

                foreach (var item in listMissingCrm)
                {
                    _listMissingCrm.Add(item);
                }
                this.trVPluginTreeMissing.UpdateLayout();
            });

            ToggleControls(true, Properties.OutputStrings.LoadingAssemblyFromPathCompletedFormat1, assemblyPath);
        }
        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);
        }
Esempio n. 5
0
        private async Task ShowExistingPluginTypes()
        {
            if (!this.IsControlsEnabled)
            {
                return;
            }

            ConnectionData connectionData = GetSelectedConnection();

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

            string textName           = string.Empty;
            bool?  isWorkflowActivity = null;

            this.Dispatcher.Invoke(() =>
            {
                this._itemsSource.Clear();

                textName = txtBFilter.Text.Trim().ToLower();

                if (cmBIsWorkflowActivity.SelectedItem is bool valueIsWorkflowActivity)
                {
                    isWorkflowActivity = valueIsWorkflowActivity;
                }
            });

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

            try
            {
                var service = await GetService();

                if (service != null)
                {
                    var repository = new PluginTypeRepository(service);
                    list = await repository.GetPluginTypesAsync(textName, isWorkflowActivity
                                                                , new ColumnSet
                                                                (
                                                                    PluginType.Schema.Attributes.typename
                                                                    , PluginType.Schema.Attributes.name
                                                                    , PluginType.Schema.Attributes.friendlyname
                                                                    , PluginType.Schema.Attributes.assemblyname
                                                                    , PluginType.Schema.Attributes.workflowactivitygroupname
                                                                    , PluginType.Schema.Attributes.customworkflowactivityinfo
                                                                    , PluginType.Schema.Attributes.description
                                                                    , PluginType.Schema.Attributes.ismanaged
                                                                    , PluginType.Schema.Attributes.isworkflowactivity
                                                                    , PluginType.Schema.Attributes.pluginassemblyid
                                                                )
                                                                );

                    base.StartGettingSdkMessageFilters(service);
                }
            }
            catch (Exception ex)
            {
                this._iWriteToOutput.WriteErrorToOutput(connectionData, ex);
            }

            this.lstVwPluginTypes.Dispatcher.Invoke(() =>
            {
                foreach (var entity in list
                         .OrderBy(ent => ent.AssemblyName)
                         .ThenBy(ent => ent.TypeName)
                         .ThenBy(ent => ent.FriendlyName)
                         .ThenBy(ent => ent.Id)
                         )
                {
                    var item = new EntityViewItem(entity);

                    this._itemsSource.Add(item);
                }

                if (this.lstVwPluginTypes.Items.Count == 1)
                {
                    this.lstVwPluginTypes.SelectedItem = this.lstVwPluginTypes.Items[0];
                }
            });

            ToggleControls(connectionData, true, Properties.OutputStrings.LoadingPluginTypesCompletedFormat1, list.Count());
        }
Esempio n. 6
0
        public async Task <string> CreateFileWithAssemblyComparing(string folder, IOrganizationServiceExtented service, Guid idPluginAssembly, string assemblyName, string defaultOutputFilePath)
        {
            var repositoryType = new PluginTypeRepository(service);

            var task = repositoryType.GetPluginTypesAsync(idPluginAssembly);

            string        assemblyPath = service.ConnectionData.GetLastAssemblyPath(assemblyName);
            List <string> lastPaths    = service.ConnectionData.GetAssemblyPaths(assemblyName).ToList();

            if (!string.IsNullOrEmpty(defaultOutputFilePath) &&
                !lastPaths.Contains(defaultOutputFilePath, StringComparer.InvariantCultureIgnoreCase)
                )
            {
                lastPaths.Insert(0, defaultOutputFilePath);
            }

            bool isSuccess = false;

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

                    if (!string.IsNullOrEmpty(assemblyPath))
                    {
                        openFileDialog1.InitialDirectory = Path.GetDirectoryName(assemblyPath);
                        openFileDialog1.FileName         = Path.GetFileName(assemblyPath);
                    }
                    else if (!string.IsNullOrEmpty(defaultOutputFilePath))
                    {
                        openFileDialog1.InitialDirectory = Path.GetDirectoryName(defaultOutputFilePath);
                        openFileDialog1.FileName         = Path.GetFileName(defaultOutputFilePath);
                    }

                    if (lastPaths.Any())
                    {
                        openFileDialog1.CustomPlaces = new List <Microsoft.Win32.FileDialogCustomPlace>(lastPaths.Select(p => new Microsoft.Win32.FileDialogCustomPlace(Path.GetDirectoryName(p))));
                    }

                    if (openFileDialog1.ShowDialog() == true)
                    {
                        isSuccess    = true;
                        assemblyPath = openFileDialog1.FileName;
                    }
                }
                catch (Exception ex)
                {
                    DTEHelper.WriteExceptionToOutput(service.ConnectionData, ex);
                }
            });

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

            t.Join();

            if (!isSuccess)
            {
                return(string.Empty);
            }

            string filePath = string.Empty;

            service.ConnectionData.AddAssemblyMapping(assemblyName, assemblyPath);
            service.ConnectionData.Save();

            AssemblyReaderResult assemblyCheck = null;

            using (var reader = new AssemblyReader())
            {
                assemblyCheck = reader.ReadAssembly(assemblyPath);
            }

            if (assemblyCheck == null)
            {
                return(string.Empty);
            }

            var pluginTypes = await task;

            var crmPlugins   = new HashSet <string>(pluginTypes.Where(e => !e.IsWorkflowActivity.GetValueOrDefault()).Select(e => e.TypeName), StringComparer.InvariantCultureIgnoreCase);
            var crmWorkflows = new HashSet <string>(pluginTypes.Where(e => e.IsWorkflowActivity.GetValueOrDefault()).Select(e => e.TypeName), StringComparer.InvariantCultureIgnoreCase);

            var content = new StringBuilder();

            content.AppendLine(service.ConnectionData.GetConnectionInfo()).AppendLine();
            content.AppendFormat("Description for PluginAssembly '{0}' at {1}", assemblyName, DateTime.Now.ToString("G", System.Globalization.CultureInfo.CurrentCulture)).AppendLine();

            content.AppendFormat("Local Assembly '{0}'", assemblyPath).AppendLine();

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

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

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



            FillInformation(content, "Plugins ONLY in Crm Assembly {0}", pluginsOnlyInCrm);
            FillInformation(content, "Workflows ONLY in Crm Assembly {0}", workflowOnlyInCrm);
            FillInformation(content, "Plugins ONLY in Local Assembly {0}", pluginsOnlyInLocalAssembly);
            FillInformation(content, "Workflows ONLY in Local Assembly {0}", workflowOnlyInLocalAssembly);

            if (!pluginsOnlyInCrm.Any() &&
                !workflowOnlyInCrm.Any() &&
                !pluginsOnlyInLocalAssembly.Any() &&
                !workflowOnlyInLocalAssembly.Any()
                )
            {
                content.AppendLine().AppendLine().AppendLine();

                content.AppendLine("No difference in Assemblies.");
            }

            FillInformation(content, "Plugins in Crm Assembly {0}", crmPlugins);
            FillInformation(content, "Workflows in Crm Assembly {0}", crmWorkflows);
            FillInformation(content, "Plugins in Local Assembly {0}", assemblyPlugins);
            FillInformation(content, "Workflows in Local Assembly {0}", assemblyWorkflows);

            string fileName = EntityFileNameFormatter.GetPluginAssemblyFileName(service.ConnectionData.Name, assemblyName, "Comparing", "txt");

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

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

            this._iWriteToOutput.WriteToOutput(service.ConnectionData, "Assembly {0} Comparing exported to {1}", assemblyName, filePath);
            this._iWriteToOutput.WriteToOutputFilePathUri(service.ConnectionData, filePath);

            return(filePath);
        }
Esempio n. 7
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);
            }
        }