private string CreateFile(ConnectionData connectionData, string name, Guid id, string fieldTitle, string xmlContent) { string fileName = EntityFileNameFormatter.GetReportFileName(connectionData.Name, name, id, fieldTitle, "xml"); string filePath = Path.Combine(_commonConfig.FolderForExport, FileOperations.RemoveWrongSymbols(fileName)); if (!string.IsNullOrEmpty(xmlContent)) { try { if (ContentCoparerHelper.TryParseXml(xmlContent, out var doc)) { xmlContent = doc.ToString(); } File.WriteAllText(filePath, xmlContent, new UTF8Encoding(false)); this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.EntityFieldExportedToFormat5, connectionData.Name, Report.Schema.EntityLogicalName, name, fieldTitle, filePath); } catch (Exception ex) { this._iWriteToOutput.WriteErrorToOutput(connectionData, ex); } } else { filePath = string.Empty; this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.EntityFieldIsEmptyFormat4, connectionData.Name, Report.Schema.EntityLogicalName, name, fieldTitle); } return(filePath); }
private async Task PerformUpdateEntityField(string folder, Organization organization, string fieldName, string fieldTitle) { if (!this.IsControlsEnabled) { return; } var service = await GetService(); ToggleControls(service.ConnectionData, false, Properties.WindowStatusStrings.UpdatingFieldFormat2, service.ConnectionData.Name, fieldName); try { string xmlContent = organization.GetAttributeValue <string>(fieldName); string filePath = await CreateFileAsync(folder, organization.Name, fieldTitle + " BackUp", xmlContent); var newText = string.Empty; bool?dialogResult = false; this.Dispatcher.Invoke(() => { var form = new WindowTextField("Enter " + fieldTitle, fieldTitle, xmlContent); dialogResult = form.ShowDialog(); newText = form.FieldText; }); if (dialogResult.GetValueOrDefault() == false) { ToggleControls(service.ConnectionData, true, Properties.WindowStatusStrings.UpdatingFieldFailedFormat2, service.ConnectionData.Name, fieldName); return; } newText = ContentCoparerHelper.RemoveAllCustomXmlAttributesAndNamespaces(newText); if (ContentCoparerHelper.TryParseXml(newText, out var doc)) { newText = doc.ToString(SaveOptions.DisableFormatting); } var updateEntity = new Organization { Id = organization.Id }; updateEntity.Attributes[fieldName] = newText; await service.UpdateAsync(updateEntity); organization.Attributes[fieldName] = newText; ToggleControls(service.ConnectionData, true, Properties.WindowStatusStrings.UpdatingFieldCompletedFormat2, service.ConnectionData.Name, fieldName); } catch (Exception ex) { _iWriteToOutput.WriteErrorToOutput(service.ConnectionData, ex); ToggleControls(service.ConnectionData, true, Properties.WindowStatusStrings.UpdatingFieldFailedFormat2, service.ConnectionData.Name, fieldName); } }
protected override void CommandAction(DTEHelper helper) { List <SelectedFile> selectedFiles = helper.GetOpenedFileInCodeWindow(FileOperations.SupportsXmlType).Take(2).ToList(); if (selectedFiles.Count == 1) { string fileText = File.ReadAllText(selectedFiles[0].FilePath); if (ContentCoparerHelper.TryParseXml(fileText, out var doc)) { var attribute = doc.Attribute(Intellisense.Model.IntellisenseContext.IntellisenseContextAttributeSavedQueryId); helper.HandleExplorerSystemSavedQuery(attribute?.Value); } } }
private string CreateFile(string folder, string typeName, string fieldTitle, string xmlContent) { ConnectionData connectionData = null; cmBCurrentConnection.Dispatcher.Invoke(() => { connectionData = cmBCurrentConnection.SelectedItem as ConnectionData; }); if (connectionData == null) { return(null); } string fileName = EntityFileNameFormatter.GetPluginTypeFileName(connectionData.Name, typeName, fieldTitle, "xml"); string filePath = Path.Combine(folder, FileOperations.RemoveWrongSymbols(fileName)); if (!string.IsNullOrEmpty(xmlContent)) { try { if (ContentCoparerHelper.TryParseXml(xmlContent, out var doc)) { xmlContent = doc.ToString(); } File.WriteAllText(filePath, xmlContent, new UTF8Encoding(false)); this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.EntityFieldExportedToFormat5, connectionData.Name, Workflow.Schema.EntityLogicalName, typeName, fieldTitle, filePath); } catch (Exception ex) { this._iWriteToOutput.WriteErrorToOutput(connectionData, ex); } } else { this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.EntityFieldIsEmptyFormat4, connectionData.Name, Workflow.Schema.EntityLogicalName, typeName, fieldTitle); this._iWriteToOutput.ActivateOutputWindow(connectionData); } return(filePath); }
private void ExportEntityXml(string entityName, string filePath) { var request = new OrganizationRequest("RetrieveEntityXml"); request.Parameters["EntityName"] = entityName; var response = _service.Execute(request); if (response.Results.ContainsKey("EntityXml")) { var text = response.Results["EntityXml"].ToString(); if (ContentCoparerHelper.TryParseXml(text, out var doc)) { text = doc.ToString(); } File.WriteAllText(filePath, text, new UTF8Encoding(false)); } }
protected override void CommandAction(DTEHelper helper) { List <SelectedFile> selectedFiles = helper.GetOpenedFileInCodeWindow(FileOperations.SupportsXmlType).Take(2).ToList(); if (selectedFiles.Count == 1) { string siteMapNameUnique = string.Empty; string fileText = File.ReadAllText(selectedFiles[0].FilePath); if (ContentCoparerHelper.TryParseXml(fileText, out var doc)) { var attribute = doc.Attribute(Intellisense.Model.IntellisenseContext.IntellisenseContextAttributeSiteMapNameUnique); if (attribute != null && !string.IsNullOrEmpty(attribute.Value)) { siteMapNameUnique = attribute.Value; } } helper.HandleExplorerSitemap(siteMapNameUnique); } }
private async Task ThreeFileDifferenceReport(SelectedFile selectedFile, string fieldName, string fieldTitle, ConnectionData connectionData1, ConnectionData connectionData2, ShowDifferenceThreeFileType differenceType, CommonConfiguration commonConfig) { if (connectionData1 == null) { this._iWriteToOutput.WriteToOutput(null, Properties.OutputStrings.NoCRMConnection1); return; } if (connectionData2 == null) { this._iWriteToOutput.WriteToOutput(null, Properties.OutputStrings.NoCRMConnection2); return; } if (differenceType == ShowDifferenceThreeFileType.ThreeWay) { if (!File.Exists(selectedFile.FilePath)) { this._iWriteToOutput.WriteToOutput(null, Properties.OutputStrings.FileNotExistsFormat1, selectedFile.FilePath); return; } } if (string.IsNullOrEmpty(fieldName)) { fieldName = Report.Schema.Attributes.originalbodytext; fieldTitle = Report.Schema.Headers.originalbodytext; } this._iWriteToOutput.WriteToOutput(null, Properties.OutputStrings.ConnectingToCRM); this._iWriteToOutput.WriteToOutput(null, string.Empty); this._iWriteToOutput.WriteToOutput(null, connectionData1.GetConnectionDescription()); this._iWriteToOutput.WriteToOutput(null, string.Empty); this._iWriteToOutput.WriteToOutput(null, connectionData2.GetConnectionDescription()); var task1 = QuickConnection.ConnectAsync(connectionData1); var task2 = QuickConnection.ConnectAsync(connectionData2); var service1 = await task1; var service2 = await task2; if (service1 == null) { _iWriteToOutput.WriteToOutput(connectionData1, Properties.OutputStrings.ConnectionFailedFormat1, connectionData1.Name); return; } if (service2 == null) { _iWriteToOutput.WriteToOutput(connectionData2, Properties.OutputStrings.ConnectionFailedFormat1, connectionData2.Name); return; } this._iWriteToOutput.WriteToOutput(null, Properties.OutputStrings.CurrentServiceEndpointConnectionFormat2, connectionData1.Name, service1.CurrentServiceEndpoint); this._iWriteToOutput.WriteToOutput(null, Properties.OutputStrings.CurrentServiceEndpointConnectionFormat2, connectionData2.Name, service2.CurrentServiceEndpoint); // Репозиторий для работы с веб-ресурсами ReportRepository reportRepository1 = new ReportRepository(service1); ReportRepository reportRepository2 = new ReportRepository(service2); var taskReport1 = reportRepository1.FindAsync(selectedFile.FileName); var taskReport2 = reportRepository2.FindAsync(selectedFile.FileName); Report reportEntity1 = await taskReport1; Report reportEntity2 = await taskReport2; if (reportEntity1 != null) { this._iWriteToOutput.WriteToOutput(null, "{0}: Report founded by name.", connectionData1.Name); connectionData1.AddMapping(reportEntity1.Id, selectedFile.FriendlyFilePath); connectionData1.Save(); } else { Guid?reportId = connectionData1.GetLastLinkForFile(selectedFile.FriendlyFilePath); if (reportId.HasValue) { reportEntity1 = await reportRepository1.GetByIdAsync(reportId.Value); if (reportEntity1 != null) { this._iWriteToOutput.WriteToOutput(null, "{0}: Report not founded by name. Last link report is selected for difference.", connectionData1.Name); connectionData1.AddMapping(reportEntity1.Id, selectedFile.FriendlyFilePath); connectionData1.Save(); } } } if (reportEntity2 != null) { this._iWriteToOutput.WriteToOutput(null, "{0}: Report founded by name.", connectionData2.Name); connectionData2.AddMapping(reportEntity2.Id, selectedFile.FriendlyFilePath); connectionData2.Save(); } else { Guid?reportId = connectionData2.GetLastLinkForFile(selectedFile.FriendlyFilePath); if (reportId.HasValue) { reportEntity2 = await reportRepository2.GetByIdAsync(reportId.Value); if (reportEntity2 != null) { this._iWriteToOutput.WriteToOutput(null, "{0}: Report not founded by name. Last link report is selected for difference.", connectionData2.Name); connectionData2.AddMapping(reportEntity2.Id, selectedFile.FriendlyFilePath); connectionData2.Save(); } } } if (!File.Exists(selectedFile.FilePath)) { this._iWriteToOutput.WriteToOutput(null, Properties.OutputStrings.FileNotExistsFormat1, selectedFile.FilePath); } if (reportEntity1 == null) { this._iWriteToOutput.WriteToOutput(null, "{0}: Report not founded in CRM: {1}", connectionData1.Name, selectedFile.FileName); } if (reportEntity2 == null) { this._iWriteToOutput.WriteToOutput(null, "{0}: Report not founded in CRM: {1}", connectionData2.Name, selectedFile.FileName); } string fileLocalPath = selectedFile.FilePath; string fileLocalTitle = selectedFile.FileName; string filePath1 = string.Empty; string fileTitle1 = string.Empty; string filePath2 = string.Empty; string fileTitle2 = string.Empty; if (reportEntity1 != null) { var textReport = reportEntity1.GetAttributeValue <string>(fieldName); if (ContentCoparerHelper.TryParseXml(textReport, out var doc)) { textReport = doc.ToString(); } var reportName = EntityFileNameFormatter.GetReportFileName(connectionData1.Name, reportEntity1.Name, reportEntity1.Id, fieldTitle, selectedFile.Extension); filePath1 = FileOperations.GetNewTempFilePath(Path.GetFileNameWithoutExtension(reportName), selectedFile.Extension); fileTitle1 = connectionData1.Name + "." + selectedFile.FileName + " - " + filePath1; File.WriteAllText(filePath1, textReport, new UTF8Encoding(false)); } if (reportEntity2 != null) { var textReport = reportEntity2.GetAttributeValue <string>(fieldName); if (ContentCoparerHelper.TryParseXml(textReport, out var doc)) { textReport = doc.ToString(); } var reportName = EntityFileNameFormatter.GetReportFileName(connectionData2.Name, reportEntity2.Name, reportEntity2.Id, fieldTitle, selectedFile.Extension); filePath2 = FileOperations.GetNewTempFilePath(Path.GetFileNameWithoutExtension(reportName), selectedFile.Extension); fileTitle1 = connectionData2.Name + "." + selectedFile.FileName + " - " + filePath2; File.WriteAllText(filePath2, textReport, new UTF8Encoding(false)); } switch (differenceType) { case ShowDifferenceThreeFileType.OneByOne: ShowDifferenceOneByOne(commonConfig, fileLocalPath, fileLocalTitle, filePath1, fileTitle1, filePath2, fileTitle2); break; case ShowDifferenceThreeFileType.TwoConnections: this._iWriteToOutput.ProcessStartProgramComparer(filePath1, filePath2, fileTitle1, fileTitle2); break; case ShowDifferenceThreeFileType.ThreeWay: ShowDifferenceThreeWay(commonConfig, fileLocalPath, fileLocalTitle, filePath1, fileTitle1, filePath2, fileTitle2); break; default: break; } }
private async Task DifferenceReport(SelectedFile selectedFile, string fieldName, string fieldTitle, bool isCustom, ConnectionData connectionData, CommonConfiguration commonConfig) { if (connectionData == null) { this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.NoCurrentCRMConnection); return; } if (!File.Exists(selectedFile.FilePath)) { this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.FileNotExistsFormat1, selectedFile.FilePath); return; } if (string.IsNullOrEmpty(fieldName)) { fieldName = Report.Schema.Attributes.originalbodytext; fieldTitle = Report.Schema.Headers.originalbodytext; } 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); // Репозиторий для работы с веб-ресурсами ReportRepository reportRepository = new ReportRepository(service); Report reportEntity = null; if (isCustom) { Guid?reportId = connectionData.GetLastLinkForFile(selectedFile.FriendlyFilePath); bool?dialogResult = null; Guid?selectedReportId = null; string selectedPath = string.Empty; var t = new Thread(() => { try { var form = new Views.WindowReportSelect(this._iWriteToOutput, service, selectedFile, reportId); dialogResult = form.ShowDialog(); selectedReportId = form.SelectedReportId; } catch (Exception ex) { DTEHelper.WriteExceptionToOutput(connectionData, ex); } }); t.SetApartmentState(ApartmentState.STA); t.Start(); t.Join(); if (dialogResult.GetValueOrDefault()) { if (selectedReportId.HasValue) { this._iWriteToOutput.WriteToOutput(connectionData, "Custom report is selected."); reportEntity = await reportRepository.GetByIdAsync(selectedReportId.Value); connectionData.AddMapping(reportEntity.Id, selectedFile.FriendlyFilePath); connectionData.Save(); } else { this._iWriteToOutput.WriteToOutput(connectionData, "!Warning. Report not exists. name: {0}.", selectedFile.Name); } } else { this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.DifferenceWasCancelled); return; } } else { reportEntity = await reportRepository.FindAsync(selectedFile.FileName); if (reportEntity != null) { this._iWriteToOutput.WriteToOutput(connectionData, "Report founded by name."); connectionData.AddMapping(reportEntity.Id, selectedFile.FriendlyFilePath); connectionData.Save(); } else { Guid?reportId = connectionData.GetLastLinkForFile(selectedFile.FriendlyFilePath); if (reportId.HasValue) { reportEntity = await reportRepository.GetByIdAsync(reportId.Value); } if (reportEntity != null) { this._iWriteToOutput.WriteToOutput(connectionData, "Report not founded by name. Last link report is selected for difference."); connectionData.AddMapping(reportEntity.Id, selectedFile.FriendlyFilePath); connectionData.Save(); } else { this._iWriteToOutput.WriteToOutput(connectionData, "Report not founded by name and has not Last link."); this._iWriteToOutput.WriteToOutput(connectionData, "Starting Custom Report selection form."); bool?dialogResult = null; Guid?selectedReportId = null; string selectedPath = string.Empty; var t = new Thread(() => { try { var form = new Views.WindowReportSelect(this._iWriteToOutput, service, selectedFile, reportId); dialogResult = form.ShowDialog(); selectedReportId = form.SelectedReportId; } catch (Exception ex) { DTEHelper.WriteExceptionToOutput(connectionData, ex); } }); t.SetApartmentState(ApartmentState.STA); t.Start(); t.Join(); if (dialogResult.GetValueOrDefault()) { if (selectedReportId.HasValue) { this._iWriteToOutput.WriteToOutput(connectionData, "Custom report is selected."); reportEntity = await reportRepository.GetByIdAsync(selectedReportId.Value); connectionData.AddMapping(reportEntity.Id, selectedFile.FriendlyFilePath); connectionData.Save(); } else { this._iWriteToOutput.WriteToOutput(connectionData, "!Warning. Report not exists. name: {0}.", selectedFile.Name); } } else { this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.DifferenceWasCancelled); return; } } } } if (reportEntity == null) { this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.ReportNotFoundedInConnectionFormat2, connectionData.Name, selectedFile.FileName); return; } var reportName = EntityFileNameFormatter.GetReportFileName(connectionData.Name, reportEntity.Name, reportEntity.Id, fieldTitle, selectedFile.Extension); string temporaryFilePath = FileOperations.GetNewTempFilePath(Path.GetFileNameWithoutExtension(reportName), selectedFile.Extension); var textReport = reportEntity.GetAttributeValue <string>(fieldName); if (ContentCoparerHelper.TryParseXml(textReport, out var doc)) { textReport = doc.ToString(); } File.WriteAllText(temporaryFilePath, textReport, new UTF8Encoding(false)); //DownloadReportDefinitionRequest rdlRequest = new DownloadReportDefinitionRequest //{ // ReportId = reportEntity.Id //}; //DownloadReportDefinitionResponse rdlResponse = (DownloadReportDefinitionResponse)service.Execute(rdlRequest); //using (XmlTextWriter reportDefinitionFile = new XmlTextWriter(temporaryFilePath, System.Text.Encoding.UTF8)) //{ // reportDefinitionFile.WriteRaw(rdlResponse.BodyText); // reportDefinitionFile.Close(); //} this._iWriteToOutput.WriteToOutput(connectionData, "Starting Compare Program for {0} and {1}", selectedFile.FriendlyFilePath, reportName); string file1 = selectedFile.FilePath; string file2 = temporaryFilePath; string fileTitle1 = selectedFile.FileName; string fileTitle2 = connectionData.Name + "." + selectedFile.FileName + " - " + temporaryFilePath; this._iWriteToOutput.ProcessStartProgramComparer(file1, file2, fileTitle1, fileTitle2); }
private async Task PerformUpdateEntityField(string folder, Guid idCustomControl, string name, string fieldName, string fieldTitle, string extension) { if (!this.IsControlsEnabled) { return; } var service = await GetService(); ToggleControls(service.ConnectionData, false, Properties.WindowStatusStrings.UpdatingFieldFormat2, service.ConnectionData.Name, fieldName); try { var repository = new CustomControlRepository(service); var customControl = await repository.GetByIdAsync(idCustomControl, new ColumnSet(fieldName)); string xmlContent = customControl.GetAttributeValue <string>(fieldName); if (string.Equals(fieldName, CustomControl.Schema.Attributes.manifest, StringComparison.InvariantCultureIgnoreCase)) { if (ContentCoparerHelper.TryParseXml(xmlContent, out var tempDoc)) { xmlContent = tempDoc.ToString(); } } else if (string.Equals(fieldName, CustomControl.Schema.Attributes.clientjson, StringComparison.InvariantCultureIgnoreCase)) { xmlContent = ContentCoparerHelper.FormatJson(xmlContent); } { string backUpXmlContent = xmlContent; if (string.Equals(fieldName, CustomControl.Schema.Attributes.manifest, StringComparison.InvariantCultureIgnoreCase)) { backUpXmlContent = ContentCoparerHelper.FormatXmlByConfiguration(backUpXmlContent, _commonConfig, _xmlOptions , schemaName: AbstractDynamicCommandXsdSchemas.SchemaManifest , customControlId: idCustomControl ); } else if (string.Equals(fieldName, CustomControl.Schema.Attributes.clientjson, StringComparison.InvariantCultureIgnoreCase)) { backUpXmlContent = ContentCoparerHelper.FormatJson(backUpXmlContent); } await CreateFileAsync(folder, idCustomControl, name, fieldTitle + " BackUp", extension, backUpXmlContent); } var newText = string.Empty; bool?dialogResult = false; this.Dispatcher.Invoke(() => { var form = new WindowTextField("Enter " + fieldTitle, fieldTitle, xmlContent); dialogResult = form.ShowDialog(); newText = form.FieldText; }); if (dialogResult.GetValueOrDefault() == false) { ToggleControls(service.ConnectionData, true, Properties.WindowStatusStrings.UpdatingFieldCanceledFormat2, service.ConnectionData.Name, fieldName); return; } newText = ContentCoparerHelper.RemoveAllCustomXmlAttributesAndNamespaces(newText); UpdateStatus(service.ConnectionData, Properties.WindowStatusStrings.ValidatingXmlForFieldFormat1, fieldName); if (!ContentCoparerHelper.TryParseXmlDocument(newText, out var doc)) { ToggleControls(service.ConnectionData, true, Properties.WindowStatusStrings.TextIsNotValidXml); _iWriteToOutput.ActivateOutputWindow(service.ConnectionData); return; } newText = doc.ToString(SaveOptions.DisableFormatting); var updateEntity = new CustomControl { Id = idCustomControl }; updateEntity.Attributes[fieldName] = newText; await service.UpdateAsync(updateEntity); ToggleControls(service.ConnectionData, true, Properties.WindowStatusStrings.UpdatingFieldCompletedFormat2, service.ConnectionData.Name, fieldName); } catch (Exception ex) { _iWriteToOutput.WriteErrorToOutput(service.ConnectionData, ex); ToggleControls(service.ConnectionData, true, Properties.WindowStatusStrings.UpdatingFieldFailedFormat2, service.ConnectionData.Name, fieldName); } }
private async Task <string> CheckSystemForms() { StringBuilder content = new StringBuilder(); await _comparerSource.InitializeConnection(_iWriteToOutput, content); string operation = string.Format(Properties.OperationNames.CheckingSystemFormsFormat2, Connection1.Name, Connection2.Name); content.AppendLine(_iWriteToOutput.WriteToOutputStartOperation(null, operation)); FormDescriptionHandler handler1 = new FormDescriptionHandler(ImageBuilder.Descriptor1, new DependencyRepository(_comparerSource.Service1)) { WithManagedInfo = false, WithDependentComponents = false, }; FormDescriptionHandler handler2 = new FormDescriptionHandler(ImageBuilder.Descriptor2, new DependencyRepository(_comparerSource.Service2)) { WithManagedInfo = false, WithDependentComponents = false, }; var task1 = _comparerSource.GetSystemForm1Async(); var task2 = _comparerSource.GetSystemForm2Async(); var list1 = await task1; content.AppendLine(_iWriteToOutput.WriteToOutput(null, Properties.OrganizationComparerStrings.SystemFormsInConnectionFormat2, Connection1.Name, list1.Count)); var list2 = await task2; content.AppendLine(_iWriteToOutput.WriteToOutput(null, Properties.OrganizationComparerStrings.SystemFormsInConnectionFormat2, Connection2.Name, list2.Count)); if (!list1.Any() && !list2.Any()) { _iWriteToOutput.WriteToOutput(null, Properties.OrganizationComparerStrings.ThereIsNothingToCompare); _iWriteToOutput.WriteToOutputEndOperation(null, operation); return(null); } FormatTextTableHandler tableOnlyExistsIn1 = new FormatTextTableHandler(); tableOnlyExistsIn1.SetHeader("Entity", "Type", "Name", "IsManaged", "Id"); FormatTextTableHandler tableOnlyExistsIn2 = new FormatTextTableHandler(); tableOnlyExistsIn2.SetHeader("Entity", "Type", "Name", "IsManaged", "Id"); var dictDifference = new Dictionary <Tuple <string, string, string, string>, List <string> >(); var commonList = new List <LinkedEntities <SystemForm> >(); foreach (var form1 in list1) { { var form2 = list2.FirstOrDefault(form => form.Id == form1.Id); if (form2 != null) { commonList.Add(new LinkedEntities <SystemForm>(form1, form2)); continue; } } var entityName1 = form1.ObjectTypeCode; var name1 = form1.Name; string typeName1 = form1.FormattedValues[SystemForm.Schema.Attributes.type]; tableOnlyExistsIn1.AddLine(entityName1, typeName1, name1, form1.IsManaged.ToString(), form1.Id.ToString()); this.ImageBuilder.AddComponentSolution1((int)ComponentType.SystemForm, form1.Id); } foreach (var form2 in list2) { { var form1 = list1.FirstOrDefault(form => form.Id == form2.Id); if (form1 != null) { continue; } } var entityName2 = form2.ObjectTypeCode; var name2 = form2.Name; string typeName2 = form2.FormattedValues[SystemForm.Schema.Attributes.type]; tableOnlyExistsIn2.AddLine(entityName2, typeName2, name2, form2.IsManaged.ToString(), form2.Id.ToString()); this.ImageBuilder.AddComponentSolution2((int)ComponentType.SystemForm, form2.Id); } { var reporter = new ProgressReporter(_iWriteToOutput, commonList.Count, 5, "Processing Common Forms"); foreach (var form in commonList) { reporter.Increase(); FormatTextTableHandler tabDiff = new FormatTextTableHandler(); tabDiff.SetHeader("Attribute", "Organization", "Value"); { List <string> fieldsToCompare = new List <string>() { //SystemForm.Schema.Attributes.ancestorformid SystemForm.Schema.Attributes.canbedeleted , SystemForm.Schema.Attributes.componentstate , SystemForm.Schema.Attributes.description , SystemForm.Schema.Attributes.formactivationstate , SystemForm.Schema.Attributes.formpresentation //, SystemForm.Schema.Attributes.formxml //, SystemForm.Schema.Attributes.formxmlmanaged , SystemForm.Schema.Attributes.introducedversion , SystemForm.Schema.Attributes.isairmerged , SystemForm.Schema.Attributes.iscustomizable , SystemForm.Schema.Attributes.isdefault //, SystemForm.Schema.Attributes.ismanaged , SystemForm.Schema.Attributes.istabletenabled , SystemForm.Schema.Attributes.name , SystemForm.Schema.Attributes.objecttypecode //, SystemForm.Schema.Attributes.organizationid //, SystemForm.Schema.Attributes.overwritetime //, SystemForm.Schema.Attributes.publishedon //, SystemForm.Schema.Attributes.solutionid //, SystemForm.Schema.Attributes.supportingsolutionid , SystemForm.Schema.Attributes.type , SystemForm.Schema.Attributes.version , SystemForm.Schema.Attributes.versionnumber }; foreach (var fieldName in fieldsToCompare) { if (ContentCoparerHelper.IsEntityDifferentInField(form.Entity1, form.Entity2, fieldName)) { var str1 = EntityDescriptionHandler.GetAttributeString(form.Entity1, fieldName, Connection1); var str2 = EntityDescriptionHandler.GetAttributeString(form.Entity2, fieldName, Connection2); tabDiff.AddLine(fieldName, Connection1.Name, str1); tabDiff.AddLine(fieldName, Connection2.Name, str2); } } } string typeName1 = form.Entity1.FormattedValues[SystemForm.Schema.Attributes.type]; string typeName2 = form.Entity2.FormattedValues[SystemForm.Schema.Attributes.type]; { List <string> fieldsToCompare = new List <string>() { SystemForm.Schema.Attributes.formxml }; foreach (var fieldName in fieldsToCompare) { string formXml1 = form.Entity1.GetAttributeValue <string>(fieldName) ?? string.Empty; string formXml2 = form.Entity2.GetAttributeValue <string>(fieldName) ?? string.Empty; if (!ContentCoparerHelper.CompareXML(formXml1, formXml2).IsEqual) { string descReason = string.Empty; if (ContentCoparerHelper.TryParseXml(formXml1, out var doc1) && ContentCoparerHelper.TryParseXml(formXml2, out var doc2)) { string desc1 = await handler1.GetFormDescriptionAsync(doc1, form.Entity1.ObjectTypeCode, form.Entity1.Id, form.Entity1.Name, typeName1); string desc2 = await handler2.GetFormDescriptionAsync(doc2, form.Entity2.ObjectTypeCode, form.Entity2.Id, form.Entity2.Name, typeName2); if (!string.Equals(desc1, desc2)) { var compare = ContentCoparerHelper.CompareText(desc1.ToLower(), desc2.ToLower()); if (compare.IsEqual) { descReason = "InCase"; } else { descReason = compare.GetCompareDescription(); } } } string formReason = string.Empty; { if (ContentCoparerHelper.TryParseXml(formXml1, out var docCorrected1) && ContentCoparerHelper.TryParseXml(formXml2, out var docCorrected2) ) { handler1.ReplaceRoleToRoleTemplates(docCorrected1); handler2.ReplaceRoleToRoleTemplates(docCorrected2); if (ContentCoparerHelper.CompareXML(docCorrected1.ToString(), docCorrected2.ToString()).IsEqual) { formReason = string.Empty; } else { var compare = ContentCoparerHelper.CompareXML(docCorrected1.ToString().ToLower(), docCorrected2.ToString().ToLower(), true); if (compare.IsEqual) { formReason = "InCase"; } else { formReason = compare.GetCompareDescription(); } } } else { var compare = ContentCoparerHelper.CompareXML(formXml1.ToLower(), formXml2.ToLower(), true); if (compare.IsEqual) { formReason = "InCase"; } else { formReason = compare.GetCompareDescription(); } } } if (!string.IsNullOrEmpty(formReason)) { tabDiff.AddLine(fieldName, string.Empty, string.Format(Properties.OrganizationComparerStrings.FieldDifferenceReasonFormat3, Connection1.Name, Connection2.Name, formReason)); } if (!string.IsNullOrEmpty(descReason)) { tabDiff.AddLine(fieldName + "Description", string.Empty, string.Format(Properties.OrganizationComparerStrings.FieldDifferenceReasonFormat3, Connection1.Name, Connection2.Name, descReason)); } } } } if (tabDiff.Count > 0) { var diff = tabDiff.GetFormatedLines(false); this.ImageBuilder.AddComponentDifferent((int)ComponentType.SystemForm, form.Entity1.Id, form.Entity2.Id, string.Join(Environment.NewLine, diff)); var entityName1 = form.Entity1.ObjectTypeCode; var name1 = form.Entity1.Name; dictDifference.Add(Tuple.Create(entityName1, typeName1, name1, form.Entity1.Id.ToString()), diff); } } } if (tableOnlyExistsIn1.Count > 0) { content .AppendLine() .AppendLine() .AppendLine() .AppendLine(new string('-', 150)) .AppendLine() .AppendLine(); content.AppendLine().AppendLine().AppendFormat("System Forms ONLY EXISTS in {0}: {1}", Connection1.Name, tableOnlyExistsIn1.Count); tableOnlyExistsIn1.GetFormatedLines(true).ForEach(e => content.AppendLine().Append((tabSpacer + e).TrimEnd())); } if (tableOnlyExistsIn2.Count > 0) { content .AppendLine() .AppendLine() .AppendLine() .AppendLine(new string('-', 150)) .AppendLine() .AppendLine(); content.AppendLine().AppendLine().AppendFormat("System Forms ONLY EXISTS in {0}: {1}", Connection2.Name, tableOnlyExistsIn2.Count); tableOnlyExistsIn2.GetFormatedLines(true).ForEach(e => content.AppendLine().Append((tabSpacer + e).TrimEnd())); } if (dictDifference.Count > 0) { content .AppendLine() .AppendLine() .AppendLine() .AppendLine(new string('-', 150)) .AppendLine() .AppendLine(); content.AppendLine().AppendLine().AppendFormat("System Forms DIFFERENT in {0} and {1}: {2}", Connection1.Name, Connection2.Name, dictDifference.Count); FormatTextTableHandler tableDifference = new FormatTextTableHandler(); tableDifference.SetHeader("Entity", "Type", "Name", "Id"); foreach (var template in dictDifference) { tableDifference.CalculateLineLengths(template.Key.Item1, template.Key.Item2, template.Key.Item3, template.Key.Item4); } foreach (var template in dictDifference .OrderBy(w => w.Key.Item1) .ThenBy(w => w.Key.Item2) .ThenBy(w => w.Key.Item3) .ThenBy(w => w.Key.Item4) ) { content.AppendLine().Append(tabSpacer + tableDifference.FormatLine(template.Key.Item1, template.Key.Item2, template.Key.Item3, template.Key.Item4)); foreach (var str in template.Value) { content.AppendLine().Append(tabSpacer + tabSpacer + str); } } } if (tableOnlyExistsIn2.Count == 0 && tableOnlyExistsIn1.Count == 0 && dictDifference.Count == 0 ) { content.AppendLine("No difference in System Forms."); } content.AppendLine().AppendLine().AppendLine(_iWriteToOutput.WriteToOutputEndOperation(null, operation)); string fileName = EntityFileNameFormatter.GetDifferenceConnectionsForFieldFileName(_OrgOrgName, "System Forms"); string filePath = Path.Combine(_folder, FileOperations.RemoveWrongSymbols(fileName)); File.WriteAllText(filePath, content.ToString(), new UTF8Encoding(false)); await SaveOrganizationDifferenceImage(); return(filePath); }