private async Task CheckingPluginImagesRequiredComponents(ConnectionData connectionData, CommonConfiguration commonConfig) { if (connectionData == null) { this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.NoCurrentCRMConnection); return; } StringBuilder content = new StringBuilder(); content.AppendLine(this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.ConnectingToCRM)); content.AppendLine(this._iWriteToOutput.WriteToOutput(connectionData, connectionData.GetConnectionDescription())); // Подключаемся к CRM. var service = await QuickConnection.ConnectAsync(connectionData); if (service == null) { this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.ConnectionFailedFormat1, connectionData.Name); return; } content.AppendLine(this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.CurrentServiceEndpointFormat1, service.CurrentServiceEndpoint)); var repository = new PluginSearchRepository(service); var repositoryImage = new SdkMessageProcessingStepImageRepository(service); var listImages = await repositoryImage.GetAllImagesAsync(); var queryImages = listImages .OrderBy(image => image.Contains("sdkmessageprocessingstep.eventhandler") ? (image.GetAttributeValue<AliasedValue>("sdkmessageprocessingstep.eventhandler").Value as EntityReference).Name : "Null") .ThenBy(image => image.PrimaryObjectTypeCodeName) .ThenBy(image => image.SecondaryObjectTypeCodeName) .ThenBy(image => image.Contains("sdkmessageprocessingstep.sdkmessageid") ? (image.GetAttributeValue<AliasedValue>("sdkmessageprocessingstep.sdkmessageid").Value as EntityReference).Name : "Null", new MessageComparer()) .ThenBy(image => image.Contains("sdkmessageprocessingstep.stage") ? (image.GetAttributeValue<AliasedValue>("sdkmessageprocessingstep.stage").Value as OptionSetValue).Value : 0) .ThenBy(image => image.Contains("sdkmessageprocessingstep.mode") ? (image.GetAttributeValue<AliasedValue>("sdkmessageprocessingstep.mode").Value as OptionSetValue).Value : 0) .ThenBy(image => image.Contains("sdkmessageprocessingstep.rank") ? (int)image.GetAttributeValue<AliasedValue>("sdkmessageprocessingstep.rank").Value : 0) .ThenBy(image => image.FormattedValues.ContainsKey("sdkmessageprocessingstep.statuscode") ? image.FormattedValues["sdkmessageprocessingstep.statuscode"] : "") .ThenBy(image => image.FormattedValues.ContainsKey(SdkMessageProcessingStepImage.Schema.Attributes.imagetype) ? image.FormattedValues[SdkMessageProcessingStepImage.Schema.Attributes.imagetype] : "") .ThenBy(image => image.Name) .ThenBy(image => image.EntityAlias) .ThenBy(image => image.Attributes1StringsSorted) ; EntityMetadataRepository repositoryMetadata = new EntityMetadataRepository(service); var dependencyRepository = new DependencyRepository(service); var listMetaData = await repositoryMetadata.GetEntitiesWithAttributesAsync(); var dictEntity = new Dictionary<Guid, EntityMetadata>(); var dictAttribute = new Dictionary<Guid, AttributeMetadata>(); foreach (var metaEntity in listMetaData) { dictEntity.Add(metaEntity.MetadataId.Value, metaEntity); foreach (var metaAttribute in metaEntity.Attributes) { dictAttribute.Add(metaAttribute.MetadataId.Value, metaAttribute); } } bool hasInfo = false; foreach (var image in queryImages) { var listRequired = await dependencyRepository.GetRequiredComponentsAsync((int)ComponentType.SdkMessageProcessingStepImage, image.Id); var stepEntities = GetSetEntites(image); var stepAttributes = GetSetImageAttributes(image); var componentsEntities = GetSetComponentsEntites(listRequired, dictEntity); var componentsAttributes = GetSetComponentsAttributes(listRequired, dictAttribute); bool entitiesIsSame = stepEntities.SequenceEqual(componentsEntities); bool attributesIsSame = stepAttributes.SequenceEqual(componentsAttributes); string pluginType = image.Contains("sdkmessageprocessingstep.eventhandler") ? (image.GetAttributeValue<AliasedValue>("sdkmessageprocessingstep.eventhandler").Value as EntityReference).Name : "Null"; string sdkMessage = image.Contains("sdkmessageprocessingstep.sdkmessageid") ? (image.GetAttributeValue<AliasedValue>("sdkmessageprocessingstep.sdkmessageid").Value as EntityReference).Name : "Null"; int stage = image.Contains("sdkmessageprocessingstep.stage") ? (image.GetAttributeValue<AliasedValue>("sdkmessageprocessingstep.stage").Value as OptionSetValue).Value : 0; int mode = image.Contains("sdkmessageprocessingstep.mode") ? (image.GetAttributeValue<AliasedValue>("sdkmessageprocessingstep.mode").Value as OptionSetValue).Value : 0; int rank = image.Contains("sdkmessageprocessingstep.rank") ? (int)image.GetAttributeValue<AliasedValue>("sdkmessageprocessingstep.rank").Value : 0; string status = image.FormattedValues.ContainsKey("sdkmessageprocessingstep.statuscode") ? image.FormattedValues["sdkmessageprocessingstep.statuscode"] : ""; if (!entitiesIsSame || !attributesIsSame) { hasInfo = true; if (content.Length > 0) { content.AppendLine().AppendLine().AppendLine(); } //handler.SetHeader("PluginType", "Primary Entity", "Secondary Entity", "Message", "Stage", "Rank", "Status", "ImageType", "Name", "EntityAlias", "Attributes"); content.AppendFormat("{0} Primary {1} Secondary {2} Message {3} Stage {4} Rank {5} Status {6} ImageType {7} Name {8} EntityAlias {9} Attributes {10}" , pluginType , image.PrimaryObjectTypeCodeName , image.SecondaryObjectTypeCodeName , sdkMessage , SdkMessageProcessingStepRepository.GetStageName(stage, mode) , rank.ToString() , status , image.FormattedValues[SdkMessageProcessingStepImage.Schema.Attributes.imagetype] , image.Name , image.EntityAlias , image.Attributes1StringsSorted ).AppendLine(); if (!entitiesIsSame) { content.AppendLine("Conflict in entites."); content.Append("Entities in plugin step description"); if (stepEntities.Count > 0) { content.AppendLine(":"); foreach (var item in stepEntities) { content.AppendFormat(" {0}", item).AppendLine(); } } else { content.AppendLine(" are empty."); } content.Append("Entities in required components"); if (componentsEntities.Count > 0) { content.AppendLine(":"); foreach (var item in componentsEntities) { content.AppendFormat(" {0}", item).AppendLine(); } } else { content.AppendLine(" are empty."); } } if (!attributesIsSame) { content.AppendLine("Conflict in attributes."); content.Append("Attributes in plugin step description"); if (componentsEntities.Count > 0) { content.AppendLine(":"); foreach (var item in stepAttributes) { content.AppendFormat(" {0}", item).AppendLine(); } } else { content.AppendLine(" are empty."); } content.Append("Attributes in required components"); if (componentsAttributes.Count > 0) { content.AppendLine(":"); foreach (var item in componentsAttributes) { content.AppendFormat(" {0}", item).AppendLine(); } } else { content.AppendLine(" are empty."); } } } } if (!hasInfo) { content.AppendLine(this._iWriteToOutput.WriteToOutput(connectionData, "No conflicts were found.")); } string fileName = string.Format("{0}.Checking Plugin Images Required Components at {1}.txt", connectionData.Name, DateTime.Now.ToString("yyyy.MM.dd HH-mm-ss")); 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 = Path.Combine(commonConfig.FolderForExport, FileOperations.RemoveWrongSymbols(fileName)); File.WriteAllText(filePath, content.ToString(), new UTF8Encoding(false)); this._iWriteToOutput.WriteToOutput(connectionData, "Created file with Checking Plugin Images Required Components: {0}", filePath); this._iWriteToOutput.PerformAction(service.ConnectionData, filePath); }
private async Task CheckingPluginStepsRequiredComponents(ConnectionData connectionData, CommonConfiguration commonConfig) { if (connectionData == null) { this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.NoCurrentCRMConnection); return; } StringBuilder content = new StringBuilder(); content.AppendLine(this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.ConnectingToCRM)); content.AppendLine(this._iWriteToOutput.WriteToOutput(connectionData, connectionData.GetConnectionDescription())); // Подключаемся к CRM. var service = await QuickConnection.ConnectAsync(connectionData); if (service == null) { this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.ConnectionFailedFormat1, connectionData.Name); return; } content.AppendLine(this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.CurrentServiceEndpointFormat1, service.CurrentServiceEndpoint)); var repository = new PluginSearchRepository(service); var search = await repository.FindAllAsync(new List<PluginStage>(), string.Empty, string.Empty, string.Empty); var querySteps = search.SdkMessageProcessingStep .OrderBy(ent => ent.EventHandler.Name) .ThenBy(ent => ent.PrimaryObjectTypeCodeName) .ThenBy(ent => ent.SdkMessageId.Name, new MessageComparer()) .ThenBy(ent => ent.Stage.Value) .ThenBy(ent => ent.Mode.Value) .ThenBy(ent => ent.Rank) .ThenBy(ent => ent.Name) ; EntityMetadataRepository repositoryMetadata = new EntityMetadataRepository(service); DependencyRepository dependencyRepository = new DependencyRepository(service); var listMetaData = await repositoryMetadata.GetEntitiesWithAttributesAsync(); var dictEntity = new Dictionary<Guid, EntityMetadata>(); var dictAttribute = new Dictionary<Guid, AttributeMetadata>(); bool hasInfo = false; foreach (var metaEntity in listMetaData) { dictEntity.Add(metaEntity.MetadataId.Value, metaEntity); foreach (var metaAttribute in metaEntity.Attributes) { dictAttribute.Add(metaAttribute.MetadataId.Value, metaAttribute); } } foreach (var step in querySteps) { var listRequired = await dependencyRepository.GetRequiredComponentsAsync((int)ComponentType.SdkMessageProcessingStep, step.Id); var stepEntities = GetSetEntites(step); var stepAttributes = GetSetStepAttributes(step); var componentsEntities = GetSetComponentsEntites(listRequired, dictEntity); var componentsAttributes = GetSetComponentsAttributes(listRequired, dictAttribute); bool entitiesIsSame = stepEntities.SequenceEqual(componentsEntities); bool attributesIsSame = stepAttributes.SequenceEqual(componentsAttributes); if (!entitiesIsSame || !attributesIsSame) { if (content.Length > 0) { content.AppendLine().AppendLine().AppendLine(); } content.AppendFormat("{0} Primary {1} Secondary {2} Message {3} Stage {4} Rank {5} Status {6} FilteringAttributes {7}", step.EventHandler?.Name ?? "Unknown" , step.PrimaryObjectTypeCodeName , step.SecondaryObjectTypeCodeName , step.SdkMessageId?.Name ?? "Unknown" , SdkMessageProcessingStepRepository.GetStageName(step.Stage.Value, step.Mode.Value) , step.Rank.ToString() , step.FormattedValues[SdkMessageProcessingStep.Schema.Attributes.statuscode] , step.FilteringAttributesStringsSorted ).AppendLine(); if (!entitiesIsSame) { hasInfo = true; content.AppendLine("Conflict in entites."); content.Append("Entities in plugin step description"); if (stepEntities.Count > 0) { content.AppendLine(":"); foreach (var item in stepEntities) { content.AppendFormat(" {0}", item).AppendLine(); } } else { content.AppendLine(" are empty."); } content.Append("Entities in required components"); if (componentsEntities.Count > 0) { content.AppendLine(":"); foreach (var item in componentsEntities) { content.AppendFormat(" {0}", item).AppendLine(); } } else { content.AppendLine(" are empty."); } } if (!attributesIsSame) { hasInfo = true; content.AppendLine("Conflict in attributes."); content.Append("Attributes in plugin step description"); if (componentsEntities.Count > 0) { content.AppendLine(":"); foreach (var item in stepAttributes) { content.AppendFormat(" {0}", item).AppendLine(); } } else { content.AppendLine(" are empty."); } content.Append("Attributes in required components"); if (componentsAttributes.Count > 0) { content.AppendLine(":"); foreach (var item in componentsAttributes) { content.AppendFormat(" {0}", item).AppendLine(); } } else { content.AppendLine(" are empty."); } } } } if (!hasInfo) { content.AppendLine(this._iWriteToOutput.WriteToOutput(connectionData, "No conflicts were found.")); } string fileName = string.Format("{0}.Checking Plugin Steps Required Components at {1}.txt", connectionData.Name, DateTime.Now.ToString("yyyy.MM.dd HH-mm-ss")); 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 = Path.Combine(commonConfig.FolderForExport, FileOperations.RemoveWrongSymbols(fileName)); File.WriteAllText(filePath, content.ToString(), new UTF8Encoding(false)); this._iWriteToOutput.WriteToOutput(connectionData, "Created file with Checking Plugin Steps Required Components: {0}", filePath); this._iWriteToOutput.PerformAction(service.ConnectionData, filePath); }