private async Task PerformExportXmlToFileAsync(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.ExportingXmlFieldToFileFormat1, fieldTitle); try { var repository = new CustomControlRepository(service); var customControl = await repository.GetByIdAsync(idCustomControl, new ColumnSet(fieldName)); string xmlContent = customControl.GetAttributeValue <string>(fieldName); if (!string.IsNullOrEmpty(xmlContent)) { if (string.Equals(fieldName, CustomControl.Schema.Attributes.manifest, StringComparison.InvariantCultureIgnoreCase)) { xmlContent = ContentCoparerHelper.FormatXmlByConfiguration(xmlContent, _commonConfig, _xmlOptions , schemaName: AbstractDynamicCommandXsdSchemas.SchemaManifest , customControlId: idCustomControl ); } else if (string.Equals(fieldName, CustomControl.Schema.Attributes.clientjson, StringComparison.InvariantCultureIgnoreCase)) { xmlContent = ContentCoparerHelper.FormatJson(xmlContent); } } string filePath = await CreateFileAsync(folder, idCustomControl, name, fieldTitle, extension, xmlContent); this._iWriteToOutput.PerformAction(service.ConnectionData, filePath); ToggleControls(service.ConnectionData, true, Properties.WindowStatusStrings.ExportingXmlFieldToFileCompletedFormat1, fieldName); } catch (Exception ex) { _iWriteToOutput.WriteErrorToOutput(service.ConnectionData, ex); ToggleControls(service.ConnectionData, true, Properties.WindowStatusStrings.ExportingXmlFieldToFileFailedFormat1, fieldName); } }
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); } }