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); } }
private async Task PerformUpdateApplicationRibbonDiffXml() { if (!this.IsControlsEnabled) { return; } var service = await GetService(); this._iWriteToOutput.WriteToOutputStartOperation(service.ConnectionData, Properties.OperationNames.UpdatingApplicationRibbonDiffXmlFormat1, service.ConnectionData.Name); ToggleControls(service.ConnectionData, false, Properties.WindowStatusStrings.UpdatingApplicationRibbonDiffXmlFormat1, service.ConnectionData.Name); var newText = string.Empty; { bool?dialogResult = false; var title = "Application RibbonDiffXml"; this.Dispatcher.Invoke(() => { var form = new WindowTextField("Enter " + title, title, string.Empty); dialogResult = form.ShowDialog(); newText = form.FieldText; }); if (dialogResult.GetValueOrDefault() == false) { ToggleControls(service.ConnectionData, true, Properties.WindowStatusStrings.UpdatingApplicationRibbonDiffXmlCanceledFormat1, service.ConnectionData.Name); return; } } newText = ContentCoparerHelper.RemoveAllCustomXmlAttributesAndNamespaces(newText); UpdateStatus(service.ConnectionData, Properties.WindowStatusStrings.ValidatingApplicationRibbonDiffXml); if (!ContentCoparerHelper.TryParseXmlDocument(newText, out var doc)) { ToggleControls(service.ConnectionData, true, Properties.WindowStatusStrings.TextIsNotValidXml); _iWriteToOutput.ActivateOutputWindow(service.ConnectionData); return; } bool validateResult = await RibbonCustomizationRepository.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.WindowStatusStrings.ValidatingApplicationRibbonDiffXmlFailed); return; } } var repositoryPublisher = new PublisherRepository(service); var publisherDefault = await repositoryPublisher.GetDefaultPublisherAsync(); if (publisherDefault == null) { ToggleControls(service.ConnectionData, true, Properties.WindowStatusStrings.NotFoundedDefaultPublisher); _iWriteToOutput.ActivateOutputWindow(service.ConnectionData); return; } var repositoryRibbonCustomization = new RibbonCustomizationRepository(service); var ribbonCustomization = await repositoryRibbonCustomization.FindApplicationRibbonCustomizationAsync(); if (ribbonCustomization == null) { ToggleControls(service.ConnectionData, true, Properties.WindowStatusStrings.NotFoundedApplicationRibbonRibbonCustomization); _iWriteToOutput.ActivateOutputWindow(service.ConnectionData); return; } try { await repositoryRibbonCustomization.PerformUpdateRibbonDiffXml(_iWriteToOutput, _commonConfig, doc, null, ribbonCustomization); ToggleControls(service.ConnectionData, true, Properties.WindowStatusStrings.UpdatingApplicationRibbonDiffXmlCompletedFormat1, service.ConnectionData.Name); } catch (Exception ex) { this._iWriteToOutput.WriteErrorToOutput(service.ConnectionData, ex); ToggleControls(service.ConnectionData, true, Properties.WindowStatusStrings.UpdatingApplicationRibbonDiffXmlFailedFormat1, service.ConnectionData.Name); } this._iWriteToOutput.WriteToOutputEndOperation(service.ConnectionData, Properties.OperationNames.UpdatingApplicationRibbonDiffXmlFormat1, service.ConnectionData.Name); }
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 PerformUpdateEntityField(string folder, Guid idSiteMap, string name, string nameUnique, string fieldName, string fieldTitle) { if (!this.IsControlsEnabled) { return; } var service = await GetService(); ToggleControls(service.ConnectionData, false, Properties.WindowStatusStrings.UpdatingFieldFormat2, 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.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; } 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.WindowStatusStrings.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.WindowStatusStrings.PublishingSiteMapFormat3, service.ConnectionData.Name, name, idSiteMap.ToString()); { var repositoryPublish = new PublishActionsRepository(service); await repositoryPublish.PublishSiteMapsAsync(new[] { idSiteMap }); } 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); } }