/// <summary> /// Выполнение обновления содержания и публикация. /// </summary> public void UpdateContentAndPublish() { if (_Elements.Count == 0) { this._iWriteToOutput.WriteToOutput(_service.ConnectionData, Properties.OutputStrings.NothingToPublish); return; } this._iWriteToOutput.WriteToOutput(_service.ConnectionData, "Updating WebResources content..."); UpdateContent(); this._iWriteToOutput.WriteToOutput(_service.ConnectionData, "Publishing WebResources..."); PublishActionsRepository repository = new PublishActionsRepository(_service); repository.PublishWebResources(_Elements.Keys); FormatTextTableHandler table = new FormatTextTableHandler(); table.SetHeader("WebResourceName", "WebResourceType"); foreach (var element in this._Elements.Values.OrderBy(e => e.WebResource.Name)) { element.WebResource.FormattedValues.TryGetValue(WebResource.Schema.Attributes.webresourcetype, out var webresourcetype); table.AddLine(element.WebResource.Name, webresourcetype); } this._iWriteToOutput.WriteToOutput(_service.ConnectionData, "Published web-resources: {0}", this._Elements.Values.Count); var lines = table.GetFormatedLines(false); lines.ForEach(item => _iWriteToOutput.WriteToOutput(_service.ConnectionData, " {0}", item)); }
private async Task PublishEntityAsync(IEnumerable <string> entityNames) { if (!this.IsControlsEnabled) { return; } var service = await GetService(); var entityNamesOrdered = string.Join(",", entityNames.OrderBy(s => s)); this._iWriteToOutput.WriteToOutputStartOperation(service.ConnectionData, Properties.OperationNames.PublishingEntitiesFormat2, service.ConnectionData.Name, entityNamesOrdered); ToggleControls(service.ConnectionData, false, Properties.WindowStatusStrings.PublishingEntitiesFormat2, service.ConnectionData.Name, entityNamesOrdered); try { var repository = new PublishActionsRepository(service); await repository.PublishEntitiesAsync(entityNames); ToggleControls(service.ConnectionData, true, Properties.WindowStatusStrings.PublishingEntitiesCompletedFormat2, service.ConnectionData.Name, entityNamesOrdered); } catch (Exception ex) { _iWriteToOutput.WriteErrorToOutput(service.ConnectionData, ex); ToggleControls(service.ConnectionData, true, Properties.WindowStatusStrings.PublishingEntitiesFailedFormat2, service.ConnectionData.Name, entityNamesOrdered); } this._iWriteToOutput.WriteToOutputEndOperation(service.ConnectionData, Properties.OperationNames.PublishingEntitiesFormat2, service.ConnectionData.Name, entityNamesOrdered); }
private async Task PublishOptionSetAsync(string optionSetName) { if (string.IsNullOrEmpty(optionSetName)) { return; } if (!this.IsControlsEnabled) { return; } var service = await GetService(); this._iWriteToOutput.WriteToOutputStartOperation(service.ConnectionData, Properties.OperationNames.PublishingOptionSetFormat2, service.ConnectionData.Name, optionSetName); ToggleControls(service.ConnectionData, false, Properties.WindowStatusStrings.PublishingOptionSetFormat2, service.ConnectionData.Name, optionSetName); try { var repository = new PublishActionsRepository(service); await repository.PublishOptionSetsAsync(new[] { optionSetName }); ToggleControls(service.ConnectionData, true, Properties.WindowStatusStrings.PublishingOptionSetCompletedFormat2, service.ConnectionData.Name, optionSetName); } catch (Exception ex) { _iWriteToOutput.WriteErrorToOutput(service.ConnectionData, ex); ToggleControls(service.ConnectionData, true, Properties.WindowStatusStrings.PublishingOptionSetFailedFormat2, service.ConnectionData.Name, optionSetName); } this._iWriteToOutput.WriteToOutputEndOperation(service.ConnectionData, Properties.OperationNames.PublishingOptionSetFormat2, service.ConnectionData.Name, optionSetName); }
private async void miPublishApplicationRibbon_Click(object sender, RoutedEventArgs e) { if (!this.IsControlsEnabled) { return; } var service = await GetService(); this._iWriteToOutput.WriteToOutputStartOperation(service.ConnectionData, Properties.OperationNames.PublishingApplicationRibbonFormat1, service.ConnectionData.Name); ToggleControls(service.ConnectionData, false, Properties.WindowStatusStrings.PublishingApplicationRibbonFormat1, service.ConnectionData.Name); try { var repository = new PublishActionsRepository(service); await repository.PublishApplicationRibbonAsync(); ToggleControls(service.ConnectionData, true, Properties.WindowStatusStrings.PublishingApplicationRibbonCompletedFormat1, service.ConnectionData.Name); } catch (Exception ex) { _iWriteToOutput.WriteErrorToOutput(service.ConnectionData, ex); ToggleControls(service.ConnectionData, true, Properties.WindowStatusStrings.PublishingApplicationRibbonFailedFormat1, service.ConnectionData.Name); } this._iWriteToOutput.WriteToOutputEndOperation(service.ConnectionData, Properties.OperationNames.PublishingApplicationRibbonFormat1, service.ConnectionData.Name); }
private async Task PerformPublishEntityAsync(string folder, Guid idSavedQueryVisualization, string entityName, string name) { if (!this.IsControlsEnabled) { return; } var service = await GetService(); if (service == null) { return; } this._iWriteToOutput.WriteToOutputStartOperation(service.ConnectionData, Properties.OperationNames.PublishingEntitiesFormat2, service.ConnectionData.Name, entityName); ToggleControls(service.ConnectionData, false, Properties.OutputStrings.InConnectionPublishingEntitiesFormat2, service.ConnectionData.Name, entityName); try { var repository = new PublishActionsRepository(service); await repository.PublishEntitiesAsync(new[] { entityName }); ToggleControls(service.ConnectionData, true, Properties.OutputStrings.InConnectionPublishingEntitiesCompletedFormat2, service.ConnectionData.Name, entityName); } catch (Exception ex) { _iWriteToOutput.WriteErrorToOutput(service.ConnectionData, ex); ToggleControls(service.ConnectionData, true, Properties.OutputStrings.InConnectionPublishingEntitiesFailedFormat2, service.ConnectionData.Name, entityName); } this._iWriteToOutput.WriteToOutputEndOperation(service.ConnectionData, Properties.OperationNames.PublishingEntitiesFormat2, service.ConnectionData.Name, entityName); }
private async Task PublishingAllAsync(IOrganizationServiceExtented service) { using (service.Lock()) { try { _iWriteToOutput.WriteToOutput(service.ConnectionData , Properties.OutputStrings.PublishingAllFormat2 , service.ConnectionData.Name , DateTime.Now.ToString("G", System.Globalization.CultureInfo.CurrentCulture) ); var repository = new PublishActionsRepository(service); await repository.PublishAllXmlAsync(); _iWriteToOutput.WriteToOutput(service.ConnectionData , Properties.OutputStrings.PublishingAllCompletedFormat2 , service.ConnectionData.Name , DateTime.Now.ToString("G", System.Globalization.CultureInfo.CurrentCulture) ); } catch (Exception ex) { _iWriteToOutput.WriteErrorToOutput(service.ConnectionData, ex); _iWriteToOutput.WriteToOutput(service.ConnectionData , Properties.OutputStrings.PublishingAllFailedFormat2 , service.ConnectionData.Name , DateTime.Now.ToString("G", System.Globalization.CultureInfo.CurrentCulture) ); } } }
private async Task PerformPublishSiteMap(string folder, Guid idSiteMap, string name, string nameUnique) { var service = await GetService(); if (service == null) { return; } this._iWriteToOutput.WriteToOutputStartOperation(service.ConnectionData, Properties.OperationNames.PublishingSiteMapFormat3, service.ConnectionData.Name, name, idSiteMap.ToString()); ToggleControls(service.ConnectionData, false, Properties.OutputStrings.InConnectionPublishingSiteMapFormat3, service.ConnectionData.Name, name, idSiteMap.ToString()); try { var repository = new PublishActionsRepository(service); await repository.PublishSiteMapsAsync(new[] { idSiteMap }); ToggleControls(service.ConnectionData, true, Properties.OutputStrings.InConnectionPublishingSiteMapCompletedFormat3, service.ConnectionData.Name, name, idSiteMap.ToString()); } catch (Exception ex) { _iWriteToOutput.WriteErrorToOutput(service.ConnectionData, ex); ToggleControls(service.ConnectionData, true, Properties.OutputStrings.InConnectionPublishingSiteMapFailedFormat3, service.ConnectionData.Name, name, idSiteMap.ToString()); } this._iWriteToOutput.WriteToOutputEndOperation(service.ConnectionData, Properties.OperationNames.PublishingSiteMapFormat3, service.ConnectionData.Name, name, idSiteMap.ToString()); }
private async Task UpdateSiteMapXml(IOrganizationServiceExtented service, CommonConfiguration commonConfig, XDocument doc, string filePath, SiteMap siteMap) { string fieldTitle = SiteMap.Schema.Headers.sitemapxml; { string siteMapXml = siteMap.SiteMapXml; if (!string.IsNullOrEmpty(siteMapXml)) { commonConfig.CheckFolderForExportExists(this._iWriteToOutput); string fileNameBackUp = EntityFileNameFormatter.GetSiteMapFileName(service.ConnectionData.Name, siteMap.SiteMapNameUnique, siteMap.Id, fieldTitle + " BackUp", FileExtension.xml); string filePathBackUp = Path.Combine(commonConfig.FolderForExport, FileOperations.RemoveWrongSymbols(fileNameBackUp)); try { siteMapXml = ContentComparerHelper.FormatXmlByConfiguration( siteMapXml , commonConfig , XmlOptionsControls.SiteMapXmlOptions , schemaName: AbstractDynamicCommandXsdSchemas.SiteMapXmlSchema , siteMapUniqueName: siteMap.SiteMapNameUnique ?? string.Empty ); File.WriteAllText(filePathBackUp, siteMapXml, new UTF8Encoding(false)); this._iWriteToOutput.WriteToOutput(service.ConnectionData, Properties.OutputStrings.InConnectionEntityFieldExportedToFormat5, service.ConnectionData.Name, SiteMap.Schema.EntityLogicalName, siteMap.SiteMapNameUnique, fieldTitle, filePathBackUp); } catch (Exception ex) { this._iWriteToOutput.WriteErrorToOutput(service.ConnectionData, ex); } } else { this._iWriteToOutput.WriteToOutput(service.ConnectionData, Properties.OutputStrings.InConnectionEntityFieldIsEmptyFormat4, service.ConnectionData.Name, SiteMap.Schema.EntityLogicalName, siteMap.SiteMapNameUnique, fieldTitle); this._iWriteToOutput.ActivateOutputWindow(service.ConnectionData); } } var newText = doc.ToString(SaveOptions.DisableFormatting); var updateEntity = new SiteMap { Id = siteMap.Id }; updateEntity.Attributes[SiteMap.Schema.Attributes.sitemapxml] = newText; await service.UpdateAsync(updateEntity); _iWriteToOutput.WriteToOutput(service.ConnectionData, Properties.OutputStrings.InConnectionPublishingSiteMapFormat3, service.ConnectionData.Name, siteMap.SiteMapName, siteMap.Id.ToString()); var repositoryPublish = new PublishActionsRepository(service); await repositoryPublish.PublishSiteMapsAsync(new[] { siteMap.Id }); service.TryDispose(); }
private async Task UpdateWebResourceDependencyXml(IOrganizationServiceExtented service, CommonConfiguration commonConfig, XDocument doc, string filePath, WebResource webResource) { { string fieldTitle = WebResource.Schema.Headers.dependencyxml; string dependencyXml = webResource.DependencyXml; if (!string.IsNullOrEmpty(dependencyXml)) { commonConfig.CheckFolderForExportExists(this._iWriteToOutput); string fileNameBackUp = EntityFileNameFormatter.GetWebResourceFileName(service.ConnectionData.Name, webResource.Name, fieldTitle + " BackUp", FileExtension.xml); string filePathBackUp = Path.Combine(commonConfig.FolderForExport, FileOperations.RemoveWrongSymbols(fileNameBackUp)); try { dependencyXml = ContentComparerHelper.FormatXmlByConfiguration( dependencyXml , commonConfig , XmlOptionsControls.WebResourceDependencyXmlOptions , schemaName: AbstractDynamicCommandXsdSchemas.WebResourceDependencyXmlSchema , webResourceName: webResource.Name ); File.WriteAllText(filePathBackUp, dependencyXml, new UTF8Encoding(false)); this._iWriteToOutput.WriteToOutput(service.ConnectionData, Properties.OutputStrings.InConnectionEntityFieldExportedToFormat5, service.ConnectionData.Name, WebResource.Schema.EntityLogicalName, webResource.Name, fieldTitle, filePathBackUp); } catch (Exception ex) { this._iWriteToOutput.WriteErrorToOutput(service.ConnectionData, ex); } } else { this._iWriteToOutput.WriteToOutput(service.ConnectionData, Properties.OutputStrings.InConnectionEntityFieldIsEmptyFormat4, service.ConnectionData.Name, WebResource.Schema.EntityLogicalName, webResource.Name, fieldTitle); this._iWriteToOutput.ActivateOutputWindow(service.ConnectionData); } } var newText = doc.ToString(SaveOptions.DisableFormatting); var updateEntity = new WebResource { Id = webResource.Id }; updateEntity.Attributes[WebResource.Schema.Attributes.dependencyxml] = newText; await service.UpdateAsync(updateEntity); var repositoryPublish = new PublishActionsRepository(service); _iWriteToOutput.WriteToOutput(service.ConnectionData, Properties.OutputStrings.InConnectionPublishingWebResourceFormat2, service.ConnectionData.Name, webResource.Name); await repositoryPublish.PublishWebResourcesAsync(new[] { webResource.Id }); service.TryDispose(); }
private async Task PerformEntityEditor(string folder, Guid idSiteMap, string name, string nameUnique) { var service = await GetService(); var repositoryPublish = new PublishActionsRepository(service); _commonConfig.Save(); WindowHelper.OpenEntityEditor(_iWriteToOutput, service, _commonConfig, SiteMap.EntityLogicalName, idSiteMap); }
private async Task PerformEntityEditor(string folder, Guid idSavedQueryVisualization, string entityName, string name) { var service = await GetService(); if (service == null) { return; } _commonConfig.Save(); var repositoryPublish = new PublishActionsRepository(service); WindowHelper.OpenEntityEditor(_iWriteToOutput, service, _commonConfig, SavedQueryVisualization.EntityLogicalName, idSavedQueryVisualization); }
private async Task PublishingAllAsync(IOrganizationServiceExtented service) { try { var repository = new PublishActionsRepository(service); await repository.PublishAllXmlAsync(); _iWriteToOutput.WriteToOutput(service.ConnectionData, Properties.OutputStrings.PublishingAllCompletedFormat1, service.ConnectionData.Name); } catch (Exception ex) { _iWriteToOutput.WriteErrorToOutput(service.ConnectionData, ex); _iWriteToOutput.WriteToOutput(service.ConnectionData, Properties.OutputStrings.PublishingAllFailedFormat1, service.ConnectionData.Name); } }
private async void btnPublishEntity_Click(object sender, RoutedEventArgs e) { PluginTreeViewItem nodeItem = GetItemFromRoutedDataContext <PluginTreeViewItem>(e); if (nodeItem == null || !nodeItem.EntityLogicalName.IsValidEntityName() ) { return; } if (!this.IsControlsEnabled) { return; } var service = await GetService(); if (service == null) { return; } var entityName = nodeItem.EntityLogicalName; this._iWriteToOutput.WriteToOutputStartOperation(service.ConnectionData, Properties.OperationNames.PublishingEntitiesFormat2, service.ConnectionData.Name, entityName); ToggleControls(service.ConnectionData, false, Properties.OutputStrings.InConnectionPublishingEntitiesFormat2, service.ConnectionData.Name, entityName); try { var repository = new PublishActionsRepository(service); await repository.PublishEntitiesAsync(new[] { entityName }); ToggleControls(service.ConnectionData, true, Properties.OutputStrings.InConnectionPublishingEntitiesCompletedFormat2, service.ConnectionData.Name, entityName); } catch (Exception ex) { _iWriteToOutput.WriteErrorToOutput(service.ConnectionData, ex); ToggleControls(service.ConnectionData, true, Properties.OutputStrings.InConnectionPublishingEntitiesFailedFormat2, service.ConnectionData.Name, entityName); } this._iWriteToOutput.WriteToOutputEndOperation(service.ConnectionData, Properties.OperationNames.PublishingEntitiesFormat2, service.ConnectionData.Name, entityName); }
private async Task PublishingAllAsync(ConnectionData connectionData) { if (connectionData == null) { this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.NoCurrentCRMConnection); return; } this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.ConnectingToCRM); this._iWriteToOutput.WriteToOutput(connectionData, connectionData.GetConnectionDescription()); 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); try { var repository = new PublishActionsRepository(service); await repository.PublishAllXmlAsync(); _iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.PublishingAllCompletedFormat1, connectionData.Name); } catch (Exception ex) { _iWriteToOutput.WriteErrorToOutput(connectionData, ex); _iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.PublishingAllFailedFormat1, connectionData.Name); } }
private async Task IncludingReferencesToDependencyXml(IOrganizationServiceExtented service, List <SelectedFile> selectedFiles) { TupleList <SelectedFile, WebResource> list = new TupleList <SelectedFile, WebResource>(); // Репозиторий для работы с веб-ресурсами WebResourceRepository webResourceRepository = new WebResourceRepository(service); bool allForOther = false; var groups = selectedFiles.GroupBy(sel => sel.Extension); foreach (var gr in groups) { var names = gr.Select(sel => sel.FriendlyFilePath).ToArray(); var dict = webResourceRepository.FindMultiple(gr.Key, names); foreach (var selectedFile in gr) { if (!File.Exists(selectedFile.FilePath)) { this._iWriteToOutput.WriteToOutput(service.ConnectionData, "File not founded: {0}", selectedFile.FilePath); continue; } this._iWriteToOutput.WriteToOutput(service.ConnectionData, "Try to find web-resource by name: {0}. Searching...", selectedFile.Name); string key = selectedFile.FriendlyFilePath.ToLower(); var contentFile = Convert.ToBase64String(File.ReadAllBytes(selectedFile.FilePath)); var webresource = WebResourceRepository.FindWebResourceInDictionary(dict, key, gr.Key); if (webresource != null) { this._iWriteToOutput.WriteToOutput(service.ConnectionData, "WebResource founded by name. WebResourceId: {0} Name: {1}", webresource.Id, webresource.Name); } if (webresource == null) { if (selectedFile.FileName.StartsWith(service.ConnectionData.Name + ".")) { string newFileName = selectedFile.FileName.Replace(service.ConnectionData.Name + ".", string.Empty); string newFilePath = Path.Combine(Path.GetDirectoryName(selectedFile.FilePath), newFileName); var newSelectedFile = new SelectedFile(newFilePath, selectedFile.SolutionDirectoryPath); var newDict = webResourceRepository.FindMultiple(newSelectedFile.Extension, new[] { newSelectedFile.FriendlyFilePath }); webresource = WebResourceRepository.FindWebResourceInDictionary(newDict, newSelectedFile.FriendlyFilePath.ToLower(), newSelectedFile.Extension); if (webresource != null) { this._iWriteToOutput.WriteToOutput(service.ConnectionData, "WebResource founded by name with Connection Prefix. WebResourceId: {0} Name: {1}", webresource.Id, webresource.Name); } } } if (webresource == null) { this._iWriteToOutput.WriteToOutput(service.ConnectionData, "WebResource not founded by name. FileName: {0}. Open linking dialog...", selectedFile.Name); Guid?webId = service.ConnectionData.GetLastLinkForFile(selectedFile.FriendlyFilePath); bool?dialogResult = null; Guid?selectedWebResourceId = null; var t = new Thread(() => { try { var form = new Views.WindowWebResourceSelectOrCreate(this._iWriteToOutput, service, selectedFile, webId); form.ShowCreateButton(allForOther); dialogResult = form.ShowDialog(); allForOther = form.ForAllOther; selectedWebResourceId = form.SelectedWebResourceId; } catch (Exception ex) { DTEHelper.WriteExceptionToOutput(service.ConnectionData, ex); } }); t.SetApartmentState(ApartmentState.STA); t.Start(); t.Join(); if (string.IsNullOrEmpty(service.ConnectionData?.LastSelectedSolutionsUniqueName?.FirstOrDefault())) { allForOther = false; } service.ConnectionData.Save(); if (dialogResult.GetValueOrDefault()) { if (selectedWebResourceId.HasValue) { webresource = await webResourceRepository.GetByIdAsync(selectedWebResourceId.Value); } else { this._iWriteToOutput.WriteToOutput(service.ConnectionData, "!Warning. WebResource not linked. name: {0}.", selectedFile.Name); } } else { this._iWriteToOutput.WriteToOutput(service.ConnectionData, "Updating Content and Publishing was cancelled."); return; } } if (webresource != null) { // Запоминается файл service.ConnectionData.AddMapping(webresource.Id, selectedFile.FriendlyFilePath); list.Add(selectedFile, webresource); } } } //Сохранение настроек после публикации service.ConnectionData.Save(); if (!list.Any()) { return; } List <WebResource> webResourceToPublish = new List <WebResource>(); PublishActionsRepository repository = new PublishActionsRepository(service); await repository.PublishWebResourcesAsync(webResourceToPublish.Select(e => e.Id)); }
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(); }
private async Task <string> TrasnferAudit() { StringBuilder content = new StringBuilder(); await _comparerSource.InitializeConnection(_iWriteToOutput, content, "Connection CRM Source.", "Connection CRM Target."); string operation = string.Format(Properties.OperationNames.TransferingAuditFormat2, ConnectionSource.Name, ConnectionTarget.Name); content.AppendLine(_iWriteToOutput.WriteToOutputStartOperation(null, operation)); var repositorySource = new EntityMetadataRepository(_comparerSource.Service1); var repositoryTarget = new EntityMetadataRepository(_comparerSource.Service2); var taskSource = repositorySource.GetEntitiesWithAttributesForAuditAsync(); var taskTarget = repositoryTarget.GetEntitiesWithAttributesForAuditAsync(); var listEntityMetadataSource = await taskSource; content.AppendLine(_iWriteToOutput.WriteToOutput(null, "Entities in {0}: {1}", ConnectionSource.Name, listEntityMetadataSource.Count())); var listEntityMetadataTarget = await taskTarget; content.AppendLine(_iWriteToOutput.WriteToOutput(null, "Entities in {0}: {1}", ConnectionTarget.Name, listEntityMetadataTarget.Count())); var commonEntityMetadata = new List <LinkedEntities <EntityMetadata> >(); foreach (var entityMetadata1 in listEntityMetadataSource.OrderBy(e => e.LogicalName)) { { var entityMetadata2 = listEntityMetadataTarget.FirstOrDefault(e => string.Equals(e.LogicalName, entityMetadata1.LogicalName, StringComparison.InvariantCultureIgnoreCase)); if (entityMetadata2 != null) { commonEntityMetadata.Add(new LinkedEntities <EntityMetadata>(entityMetadata1, entityMetadata2)); continue; } } } HashSet <string> entitiesToPublish = new HashSet <string>(); var entitiesToEnableAudit = commonEntityMetadata.Where( e => e.Entity1.IsAuditEnabled != null && e.Entity1.IsAuditEnabled.Value && e.Entity2.IsAuditEnabled != null && e.Entity2.IsAuditEnabled.CanBeChanged && e.Entity2.IsAuditEnabled.Value == false ).ToList(); if (entitiesToEnableAudit.Any()) { content .AppendLine() .AppendFormat("Enabling Audit on Entities: {0}", entitiesToEnableAudit.Count) .AppendLine(); foreach (var entityLink in entitiesToEnableAudit.OrderBy(e => e.Entity1.LogicalName)) { content.AppendLine(_tabSpacer + entityLink.Entity1.LogicalName); entitiesToPublish.Add(entityLink.Entity1.LogicalName); try { entityLink.Entity2.IsAuditEnabled.Value = true; await repositoryTarget.UpdateEntityMetadataAsync(entityLink.Entity2); } catch (Exception ex) { var desc = DTEHelper.GetExceptionDescription(ex); content.AppendLine(desc); } } } bool first = true; foreach (var entityLink in commonEntityMetadata.OrderBy(e => e.Entity1.LogicalName)) { var query = from source in entityLink.Entity1.Attributes join target in entityLink.Entity2.Attributes on source.LogicalName equals target.LogicalName where source.IsAuditEnabled != null && string.IsNullOrEmpty(source.AttributeOf) && string.IsNullOrEmpty(target.AttributeOf) && source.IsAuditEnabled.Value && target.IsAuditEnabled != null && target.IsAuditEnabled.CanBeChanged && target.IsAuditEnabled.Value == false orderby target.LogicalName select target; foreach (var attribute in query) { if (first) { content .AppendLine() .AppendLine("Enabling Audit on Attributes:") .AppendLine(); first = false; } content .AppendFormat(_tabSpacer + "{0}.{1}", attribute.EntityLogicalName, attribute.LogicalName) .AppendLine(); entitiesToPublish.Add(attribute.EntityLogicalName); try { attribute.IsAuditEnabled.Value = true; await repositoryTarget.UpdateAttributeMetadataAsync(attribute); } catch (Exception ex) { var desc = DTEHelper.GetExceptionDescription(ex); content.AppendLine(desc); } } } if (entitiesToPublish.Any()) { content .AppendLine() .AppendFormat("Publish Entities: {0}", entitiesToPublish.Count) .AppendLine(); foreach (var item in entitiesToPublish.OrderBy(s => s)) { content.AppendLine(_tabSpacer + item); } var repositoryPublish = new PublishActionsRepository(_comparerSource.Service2); try { await repositoryPublish.PublishEntitiesAsync(entitiesToPublish); } catch (Exception ex) { var desc = DTEHelper.GetExceptionDescription(ex); content.AppendLine(desc); } } content.AppendLine().AppendLine().AppendLine(_iWriteToOutput.WriteToOutputEndOperation(null, operation)); string fileName = string.Format("OrgTransfer Audit from {0} to {1} at {2}.txt" , this.ConnectionSource.Name , this.ConnectionTarget.Name , DateTime.Now.ToString("yyyy.MM.dd HH-mm-ss")); string filePath = Path.Combine(_folder, FileOperations.RemoveWrongSymbols(fileName)); File.WriteAllText(filePath, content.ToString(), new UTF8Encoding(false)); return(filePath); }
private async Task PerformUpdateEntityField(string folder, Guid idSavedQueryVisualization, string entityName, string name, string fieldName, string fieldTitle) { if (!this.IsControlsEnabled) { return; } var service = await GetService(); if (service == null) { return; } ToggleControls(service.ConnectionData, false, Properties.OutputStrings.InConnectionUpdatingFieldFormat2, service.ConnectionData.Name, fieldName); try { var repository = new SavedQueryVisualizationRepository(service); var savedQueryVisualization = await repository.GetByIdAsync(idSavedQueryVisualization, new ColumnSet(fieldName)); string xmlContent = savedQueryVisualization.GetAttributeValue <string>(fieldName); { if (ContentComparerHelper.TryParseXml(xmlContent, out var doc)) { xmlContent = doc.ToString(); } } string filePath = await CreateFileAsync(folder, entityName, 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.OutputStrings.InConnectionUpdatingFieldFailedFormat2, service.ConnectionData.Name, fieldName); return; } newText = ContentComparerHelper.RemoveInTextAllCustomXmlAttributesAndNamespaces(newText); { if (ContentComparerHelper.TryParseXml(newText, out var doc)) { newText = doc.ToString(SaveOptions.DisableFormatting); } } var updateEntity = new SavedQueryVisualization { Id = idSavedQueryVisualization }; updateEntity.Attributes[fieldName] = newText; await service.UpdateAsync(updateEntity); UpdateStatus(service.ConnectionData, Properties.OutputStrings.InConnectionPublishingEntitiesFormat2, service.ConnectionData.Name, entityName); { var repositoryPublish = new PublishActionsRepository(service); await repositoryPublish.PublishEntitiesAsync(new[] { entityName }); } ToggleControls(service.ConnectionData, true, Properties.OutputStrings.InConnectionUpdatingFieldCompletedFormat2, service.ConnectionData.Name, fieldName); } catch (Exception ex) { _iWriteToOutput.WriteErrorToOutput(service.ConnectionData, ex); ToggleControls(service.ConnectionData, true, Properties.OutputStrings.InConnectionUpdatingFieldFailedFormat2, service.ConnectionData.Name, fieldName); } }
private async Task UpdateSystemFormXml(IOrganizationServiceExtented service, CommonConfiguration commonConfig, XDocument doc, string filePath, SystemForm systemForm) { { string fieldTitle = SystemForm.Schema.Headers.formxml; string formXml = systemForm.FormXml; if (!string.IsNullOrEmpty(formXml)) { commonConfig.CheckFolderForExportExists(this._iWriteToOutput); string fileNameBackUp = EntityFileNameFormatter.GetSystemFormFileName(service.ConnectionData.Name, systemForm.ObjectTypeCode, systemForm.Name, fieldTitle + " BackUp", FileExtension.xml); string filePathBackUp = Path.Combine(commonConfig.FolderForExport, FileOperations.RemoveWrongSymbols(fileNameBackUp)); try { formXml = ContentComparerHelper.FormatXmlByConfiguration( formXml , commonConfig , XmlOptionsControls.FormXmlOptions , schemaName: AbstractDynamicCommandXsdSchemas.FormXmlSchema , formId: systemForm.Id , entityName: systemForm.ObjectTypeCode ); File.WriteAllText(filePathBackUp, formXml, new UTF8Encoding(false)); this._iWriteToOutput.WriteToOutput(service.ConnectionData, Properties.OutputStrings.InConnectionEntityFieldExportedToFormat5, service.ConnectionData.Name, SystemForm.Schema.EntitySchemaName, systemForm.Name, fieldTitle, filePathBackUp); } catch (Exception ex) { this._iWriteToOutput.WriteErrorToOutput(service.ConnectionData, ex); } } else { this._iWriteToOutput.WriteToOutput(service.ConnectionData, Properties.OutputStrings.InConnectionEntityFieldIsEmptyFormat4, service.ConnectionData.Name, SystemForm.Schema.EntitySchemaName, systemForm.Name, fieldTitle); this._iWriteToOutput.ActivateOutputWindow(service.ConnectionData); } } var newText = doc.ToString(SaveOptions.DisableFormatting); var updateEntity = new SystemForm { Id = systemForm.Id, }; updateEntity.Attributes[SystemForm.Schema.Attributes.formxml] = newText; await service.UpdateAsync(updateEntity); var repositoryPublish = new PublishActionsRepository(service); _iWriteToOutput.WriteToOutput(service.ConnectionData, Properties.OutputStrings.InConnectionPublishingSystemFormFormat3, service.ConnectionData.Name, systemForm.ObjectTypeCode, systemForm.Name); await repositoryPublish.PublishDashboardsAsync(new[] { systemForm.Id }); if (systemForm.ObjectTypeCode.IsValidEntityName()) { _iWriteToOutput.WriteToOutput(service.ConnectionData, Properties.OutputStrings.InConnectionPublishingEntitiesFormat2, service.ConnectionData.Name, systemForm.ObjectTypeCode); await repositoryPublish.PublishEntitiesAsync(new[] { systemForm.ObjectTypeCode }); } service.TryDispose(); }
private async Task PerformUpdateEntityField(string folder, Guid idSiteMap, string name, string nameUnique, string fieldName, string fieldTitle) { if (!this.IsControlsEnabled) { return; } var service = await GetService(); if (service == null) { return; } ToggleControls(service.ConnectionData, false, Properties.OutputStrings.InConnectionUpdatingFieldFormat2, service.ConnectionData.Name, fieldName); try { var repository = new SiteMapRepository(service); var sitemap = await repository.GetByIdAsync(idSiteMap, new ColumnSet(fieldName)); string xmlContent = sitemap.GetAttributeValue <string>(fieldName); await CreateFileAsync(folder, name, nameUnique, idSiteMap, 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.OutputStrings.InConnectionUpdatingFieldCanceledFormat2, service.ConnectionData.Name, fieldName); return; } } newText = ContentComparerHelper.RemoveInTextAllCustomXmlAttributesAndNamespaces(newText); UpdateStatus(service.ConnectionData, Properties.OutputStrings.ValidatingXmlForFieldFormat1, fieldName); if (!ContentComparerHelper.TryParseXmlDocument(newText, out var doc)) { ToggleControls(service.ConnectionData, true, Properties.OutputStrings.TextIsNotValidXml); _iWriteToOutput.ActivateOutputWindow(service.ConnectionData); return; } bool validateResult = await SiteMapRepository.ValidateXmlDocumentAsync(service.ConnectionData, _iWriteToOutput, doc); if (!validateResult) { var dialogResult = MessageBoxResult.Cancel; this.Dispatcher.Invoke(() => { dialogResult = MessageBox.Show(Properties.MessageBoxStrings.ContinueOperation, Properties.MessageBoxStrings.QuestionTitle, MessageBoxButton.OKCancel, MessageBoxImage.Question); }); if (dialogResult != MessageBoxResult.OK) { ToggleControls(service.ConnectionData, true, Properties.OutputStrings.ValidatingXmlForFieldFailedFormat1, fieldName); _iWriteToOutput.ActivateOutputWindow(service.ConnectionData); return; } } newText = doc.ToString(SaveOptions.DisableFormatting); var updateEntity = new SiteMap { Id = idSiteMap }; updateEntity.Attributes[fieldName] = newText; await service.UpdateAsync(updateEntity); UpdateStatus(service.ConnectionData, Properties.OutputStrings.InConnectionPublishingSiteMapFormat3, service.ConnectionData.Name, name, idSiteMap.ToString()); { var repositoryPublish = new PublishActionsRepository(service); await repositoryPublish.PublishSiteMapsAsync(new[] { idSiteMap }); } ToggleControls(service.ConnectionData, true, Properties.OutputStrings.InConnectionUpdatingFieldCompletedFormat2, service.ConnectionData.Name, fieldName); } catch (Exception ex) { _iWriteToOutput.WriteErrorToOutput(service.ConnectionData, ex); ToggleControls(service.ConnectionData, true, Properties.OutputStrings.InConnectionUpdatingFieldFailedFormat2, service.ConnectionData.Name, fieldName); } }