private void GetCurrentSavedQueryXml(IOrganizationServiceExtented service, CommonConfiguration commonConfig, XDocument doc, string filePath, SavedQuery savedQuery) { string fieldName = SavedQueryRepository.GetFieldNameByXmlRoot(doc.Root.Name.ToString()); string fieldTitle = SavedQueryRepository.GetFieldTitleByXmlRoot(doc.Root.Name.ToString()); string xmlContent = savedQuery.GetAttributeValue <string>(fieldName); if (string.IsNullOrEmpty(xmlContent)) { this._iWriteToOutput.WriteToOutput(service.ConnectionData, Properties.OutputStrings.InConnectionEntityFieldIsEmptyFormat4, service.ConnectionData.Name, SavedQuery.Schema.EntityLogicalName, savedQuery.Name, fieldTitle); this._iWriteToOutput.ActivateOutputWindow(service.ConnectionData); return; } commonConfig.CheckFolderForExportExists(this._iWriteToOutput); string currentFileName = EntityFileNameFormatter.GetSavedQueryFileName(service.ConnectionData.Name, savedQuery.ReturnedTypeCode, savedQuery.Name, fieldTitle, FileExtension.xml); string currentFilePath = Path.Combine(commonConfig.FolderForExport, FileOperations.RemoveWrongSymbols(currentFileName)); try { File.WriteAllText(currentFilePath, xmlContent, new UTF8Encoding(false)); this._iWriteToOutput.WriteToOutput(service.ConnectionData, Properties.OutputStrings.InConnectionEntityFieldExportedToFormat5, service.ConnectionData.Name, SavedQuery.Schema.EntityLogicalName, savedQuery.Name, fieldTitle, currentFilePath); this._iWriteToOutput.PerformAction(service.ConnectionData, currentFilePath); } catch (Exception ex) { this._iWriteToOutput.WriteErrorToOutput(service.ConnectionData, ex); service.TryDispose(); } }
private async Task <bool> ValidateDocumentSavedQueryXml(ConnectionData connectionData, XDocument doc) { string fieldName = SavedQueryRepository.GetFieldNameByXmlRoot(doc.Root.Name.ToString()); string fieldTitle = SavedQueryRepository.GetFieldTitleByXmlRoot(doc.Root.Name.ToString()); this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.ValidatingXmlForFieldFormat1, fieldTitle); ContentComparerHelper.ClearRoot(doc); bool validateResult = await SavedQueryRepository.ValidateXmlDocumentAsync(connectionData, _iWriteToOutput, doc, fieldTitle); if (!validateResult) { this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.ValidatingXmlForFieldFailedFormat1, fieldTitle); _iWriteToOutput.ActivateOutputWindow(connectionData); var dialogResult = MessageBoxResult.Cancel; var thread = new Thread(() => { dialogResult = MessageBox.Show(Properties.MessageBoxStrings.ContinueOperation, Properties.MessageBoxStrings.QuestionTitle, MessageBoxButton.OKCancel, MessageBoxImage.Question); }); thread.SetApartmentState(ApartmentState.STA); thread.Start(); thread.Join(); if (dialogResult != MessageBoxResult.OK) { return(false); } } return(true); }
private async Task DifferenceSavedQueryXml(IOrganizationServiceExtented service, CommonConfiguration commonConfig, XDocument doc, string filePath, SavedQuery savedQuery) { string fieldName = SavedQueryRepository.GetFieldNameByXmlRoot(doc.Root.Name.ToString()); string fieldTitle = SavedQueryRepository.GetFieldTitleByXmlRoot(doc.Root.Name.ToString()); string xmlContent = savedQuery.GetAttributeValue <string>(fieldName); string fileTitle2 = EntityFileNameFormatter.GetSavedQueryFileName(service.ConnectionData.Name, savedQuery.ReturnedTypeCode, savedQuery.Name, fieldTitle, FileExtension.xml); string filePath2 = FileOperations.GetNewTempFilePath(Path.GetFileNameWithoutExtension(fileTitle2), Path.GetExtension(fileTitle2)); if (string.IsNullOrEmpty(xmlContent)) { this._iWriteToOutput.WriteToOutput(service.ConnectionData, Properties.OutputStrings.InConnectionEntityFieldIsEmptyFormat4, service.ConnectionData.Name, SavedQuery.Schema.EntityLogicalName, savedQuery.Name, fieldTitle); this._iWriteToOutput.ActivateOutputWindow(service.ConnectionData); return; } try { xmlContent = ContentComparerHelper.FormatXmlByConfiguration( xmlContent , commonConfig , XmlOptionsControls.SavedQueryXmlOptions , schemaName: AbstractDynamicCommandXsdSchemas.FetchSchema , savedQueryId: savedQuery.Id , entityName: savedQuery.ReturnedTypeCode ); File.WriteAllText(filePath2, xmlContent, new UTF8Encoding(false)); this._iWriteToOutput.WriteToOutput(service.ConnectionData, Properties.OutputStrings.InConnectionEntityFieldExportedToFormat5, service.ConnectionData.Name, SavedQuery.Schema.EntityLogicalName, savedQuery.Name, fieldTitle, filePath2); } catch (Exception ex) { this._iWriteToOutput.WriteErrorToOutput(service.ConnectionData, ex); } string fileLocalPath = filePath; string fileLocalTitle = Path.GetFileName(filePath); await this._iWriteToOutput.ProcessStartProgramComparerAsync(service.ConnectionData, fileLocalPath, filePath2, fileLocalTitle, fileTitle2); service.TryDispose(); }
private async Task UpdateSavedQueryXml(IOrganizationServiceExtented service, CommonConfiguration commonConfig, XDocument doc, string filePath, SavedQuery savedQuery) { string fieldName = SavedQueryRepository.GetFieldNameByXmlRoot(doc.Root.Name.ToString()); string fieldTitle = SavedQueryRepository.GetFieldTitleByXmlRoot(doc.Root.Name.ToString()); if (string.Equals(fieldName, SavedQuery.Schema.Attributes.layoutxml, StringComparison.InvariantCulture) && !string.IsNullOrEmpty(savedQuery.ReturnedTypeCode) ) { var entityData = service.ConnectionData.GetEntityIntellisenseData(savedQuery.ReturnedTypeCode); if (entityData != null && entityData.ObjectTypeCode.HasValue) { XAttribute attr = doc.Root.Attribute("object"); if (attr != null) { attr.Value = entityData.ObjectTypeCode.ToString(); } } } { string xmlContent = savedQuery.GetAttributeValue <string>(fieldName); if (!string.IsNullOrEmpty(xmlContent)) { commonConfig.CheckFolderForExportExists(this._iWriteToOutput); string fileNameBackUp = EntityFileNameFormatter.GetSavedQueryFileName(service.ConnectionData.Name, savedQuery.ReturnedTypeCode, savedQuery.Name, fieldTitle + " BackUp", FileExtension.xml); string filePathBackUp = Path.Combine(commonConfig.FolderForExport, FileOperations.RemoveWrongSymbols(fileNameBackUp)); try { xmlContent = ContentComparerHelper.FormatXmlByConfiguration( xmlContent , commonConfig , XmlOptionsControls.SavedQueryXmlOptions , schemaName: AbstractDynamicCommandXsdSchemas.FetchSchema , savedQueryId: savedQuery.Id , entityName: savedQuery.ReturnedTypeCode ); File.WriteAllText(filePathBackUp, xmlContent, new UTF8Encoding(false)); this._iWriteToOutput.WriteToOutput(service.ConnectionData, Properties.OutputStrings.InConnectionEntityFieldExportedToFormat5, service.ConnectionData.Name, SavedQuery.Schema.EntityLogicalName, savedQuery.Name, fieldTitle, filePathBackUp); } catch (Exception ex) { this._iWriteToOutput.WriteErrorToOutput(service.ConnectionData, ex); } } else { this._iWriteToOutput.WriteToOutput(service.ConnectionData, Properties.OutputStrings.InConnectionEntityFieldIsEmptyFormat4, service.ConnectionData.Name, SavedQuery.Schema.EntityLogicalName, savedQuery.Name, fieldTitle); this._iWriteToOutput.ActivateOutputWindow(service.ConnectionData); } } var newText = doc.ToString(SaveOptions.DisableFormatting); if (string.Equals(fieldName, SavedQuery.Schema.Attributes.fetchxml, StringComparison.InvariantCulture)) { try { _iWriteToOutput.WriteToOutput(service.ConnectionData, Properties.OutputStrings.ExecutingValidateSavedQueryRequest); var request = new ValidateSavedQueryRequest() { FetchXml = newText, QueryType = savedQuery.QueryType.GetValueOrDefault() }; service.Execute(request); } catch (Exception ex) { this._iWriteToOutput.WriteErrorToOutput(service.ConnectionData, ex); } } _iWriteToOutput.WriteToOutput(service.ConnectionData, Properties.OutputStrings.SavingEntityFormat1, savedQuery.LogicalName); _iWriteToOutput.WriteToOutputEntityInstance(service.ConnectionData, savedQuery.LogicalName, savedQuery.Id); var updateEntity = new SavedQuery { Id = savedQuery.Id, }; updateEntity.Attributes[fieldName] = newText; await service.UpdateAsync(updateEntity); _iWriteToOutput.WriteToOutput(service.ConnectionData, Properties.OutputStrings.SavingEntityCompletedFormat1, savedQuery.LogicalName); _iWriteToOutput.WriteToOutput(service.ConnectionData, Properties.OutputStrings.InConnectionPublishingEntitiesFormat2, service.ConnectionData.Name, savedQuery.ReturnedTypeCode); { var repositoryPublish = new PublishActionsRepository(service); await repositoryPublish.PublishEntitiesAsync(new[] { savedQuery.ReturnedTypeCode }); } service.TryDispose(); }