private async Task PerformExportXmlToFile(string folder, Guid idPluginType, string typeName, string fieldName, string fieldTitle) { if (!this.IsControlsEnabled) { return; } var service = await GetService(); ToggleControls(service.ConnectionData, false, Properties.WindowStatusStrings.ExportingXmlFieldToFileFormat1, fieldTitle); try { var repository = new PluginTypeRepository(service); var pluginType = await repository.GetByIdAsync(idPluginType, new ColumnSet(fieldName)); string xmlContent = pluginType.GetAttributeValue <string>(fieldName); string filePath = await CreateFileAsync(folder, typeName, fieldTitle, xmlContent); this._iWriteToOutput.PerformAction(service.ConnectionData, filePath); ToggleControls(service.ConnectionData, true, Properties.WindowStatusStrings.ExportingXmlFieldToFileCompletedFormat1, fieldName); } catch (Exception ex) { _iWriteToOutput.WriteErrorToOutput(service.ConnectionData, ex); ToggleControls(service.ConnectionData, true, Properties.WindowStatusStrings.ExportingXmlFieldToFileFailedFormat1, fieldName); } }
private void FillSolutionComponentFromSchemaName(ICollection <SolutionComponent> result, string pluginTypeName, int?behavior) { if (string.IsNullOrEmpty(pluginTypeName)) { return; } var match = _regexSchemaName.Match(pluginTypeName); if (match.Success && match.Groups.Count == 6) { string name = match.Groups[1].Value; string assemblyName = match.Groups[2].Value; string versionString = match.Groups[3].Value; string cultureString = match.Groups[4].Value; string publicKeyTokenString = match.Groups[5].Value; if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(versionString) && !string.IsNullOrEmpty(cultureString) && !string.IsNullOrEmpty(publicKeyTokenString) ) { var repository = new PluginTypeRepository(_service); var entity = repository.FindTypeByFullName(name, assemblyName, versionString, cultureString, publicKeyTokenString, ColumnSetInstances.None); if (entity != null) { FillSolutionComponentInternal(result, entity.Id, behavior); } } } }
private async Task PerformExportEntityDescription(string folder, Guid idPluginType, string name) { var service = await GetService(); if (service == null) { return; } ToggleControls(service.ConnectionData, false, Properties.OutputStrings.CreatingEntityDescription); string fileName = EntityFileNameFormatter.GetPluginTypeFileName(service.ConnectionData.Name, name, EntityFileNameFormatter.Headers.EntityDescription); string filePath = Path.Combine(folder, FileOperations.RemoveWrongSymbols(fileName)); var repository = new PluginTypeRepository(service); var pluginType = await repository.GetPluginTypeByIdAsync(idPluginType); await EntityDescriptionHandler.ExportEntityDescriptionAsync(filePath, pluginType, service.ConnectionData); this._iWriteToOutput.WriteToOutput(service.ConnectionData, Properties.OutputStrings.InConnectionExportedEntityDescriptionFormat3 , service.ConnectionData.Name , pluginType.LogicalName , filePath); this._iWriteToOutput.PerformAction(service.ConnectionData, filePath); ToggleControls(service.ConnectionData, true, Properties.OutputStrings.CreatingEntityDescriptionCompleted); }
public PluginAssemblyDescriptionHandler(IOrganizationServiceExtented service, string connectionInfo) { this._service = service; this._connectionInfo = connectionInfo; this._repType = new PluginTypeRepository(service); this._repStep = new SdkMessageProcessingStepRepository(service); this._repImage = new SdkMessageProcessingStepImageRepository(service); this._repSecure = new SdkMessageProcessingStepSecureConfigRepository(service); }
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); }
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> 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); }
private async Task <Tuple <bool, PluginType> > GetPluginTypeByAttribute(IOrganizationServiceExtented service, CommonConfiguration commonConfig, string pluginTypeName) { var repositoryPluginType = new PluginTypeRepository(service); var pluginType = await repositoryPluginType.FindPluginTypeAsync(pluginTypeName); if (pluginType == null) { this._iWriteToOutput.WriteToOutput(service.ConnectionData, Properties.OutputStrings.InConnectionPluginTypeWasNotFoundFormat2, service.ConnectionData.Name, pluginTypeName); this._iWriteToOutput.ActivateOutputWindow(service.ConnectionData); WindowHelper.OpenPluginTypeExplorer(_iWriteToOutput, service, commonConfig); } return(Tuple.Create(pluginType != null, pluginType)); }
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); } } }
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); }
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()); }
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); }
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); } }
private async Task AddingPluginStepForType(ConnectionData connectionData, CommonConfiguration commonConfig, string pluginTypeName) { if (string.IsNullOrEmpty(pluginTypeName)) { this._iWriteToOutput.WriteToOutput(connectionData, "PluginType Name is empty."); return; } var service = await ConnectAndWriteToOutputAsync(connectionData); if (service == null) { return; } var repository = new PluginTypeRepository(service); var pluginType = await repository.FindPluginTypeAsync(pluginTypeName); if (pluginType == null) { pluginType = await repository.FindPluginTypeByLikeNameAsync(pluginTypeName); } if (pluginType == null) { this._iWriteToOutput.WriteToOutput(connectionData, "PluginType not founded by name {0}.", pluginTypeName); WindowHelper.OpenPluginTypeExplorer( this._iWriteToOutput , service , commonConfig , pluginTypeName ); return; } this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.GettingMessages); var repositoryFilters = new SdkMessageFilterRepository(service); List <SdkMessageFilter> filters = await repositoryFilters.GetAllAsync(new ColumnSet(SdkMessageFilter.Schema.Attributes.sdkmessageid, SdkMessageFilter.Schema.Attributes.primaryobjecttypecode, SdkMessageFilter.Schema.Attributes.secondaryobjecttypecode, SdkMessageFilter.Schema.Attributes.availability)); this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.GettingMessagesCompleted); var step = new SdkMessageProcessingStep() { EventHandler = pluginType.ToEntityReference(), }; System.Threading.Thread worker = new System.Threading.Thread(() => { try { var form = new WindowSdkMessageProcessingStep(_iWriteToOutput, service, filters, step); form.ShowDialog(); } catch (Exception ex) { DTEHelper.WriteExceptionToOutput(null, ex); } }); worker.SetApartmentState(System.Threading.ApartmentState.STA); worker.Start(); }