private async Task StartGettingSiteMaps() { try { var service = await GetServiceAsync(); if (service == null) { return; } _siteMapIntellisenseData.ClearData(); if (Version.TryParse(_connectionData.OrganizationVersion, out var organizationVersion)) { string version = "365.8.2"; switch (organizationVersion.Major) { case 5: version = "2011"; break; case 6: version = "2013"; break; case 7: if (organizationVersion.Minor == 0) { version = "2015"; } else { version = "2015SP1"; } break; case 8: if (organizationVersion.Minor == 0) { version = "2016"; } else if (organizationVersion.Minor == 1) { version = "2016SP1"; } else { version = "365.8.2"; } break; } Uri uri = FileOperations.GetSiteMapResourceUri(version); StreamResourceInfo info = Application.GetResourceStream(uri); var doc = XDocument.Load(info.Stream); _siteMapIntellisenseData.LoadDataFromSiteMap(doc); info.Stream.Dispose(); } { var repository = new SitemapRepository(service); var listSiteMaps = await repository.GetListAsync(new ColumnSet(SiteMap.Schema.Attributes.sitemapxml)); foreach (var item in listSiteMaps) { if (string.IsNullOrEmpty(item.SiteMapXml)) { continue; } if (ContentCoparerHelper.TryParseXmlDocument(item.SiteMapXml, out var doc)) { _siteMapIntellisenseData.LoadDataFromSiteMap(doc); } } } if (service.ConnectionData.OrganizationId.HasValue) { var repository = new OrganizationRepository(service); var organization = await repository.GetByIdAsync(service.ConnectionData.OrganizationId.Value, new ColumnSet(Organization.Schema.Attributes.referencesitemapxml, Organization.Schema.Attributes.sitemapxml)); if (organization != null) { if (!string.IsNullOrEmpty(organization.ReferenceSiteMapXml)) { if (ContentCoparerHelper.TryParseXmlDocument(organization.ReferenceSiteMapXml, out var doc)) { _siteMapIntellisenseData.LoadDataFromSiteMap(doc); } } if (!string.IsNullOrEmpty(organization.SiteMapXml)) { if (ContentCoparerHelper.TryParseXmlDocument(organization.SiteMapXml, out var doc)) { _siteMapIntellisenseData.LoadDataFromSiteMap(doc); } } } } { var repository = new SystemFormRepository(service); var listSystemForms = await repository.GetListByTypeAsync((int)SystemForm.Schema.OptionSets.type.Dashboard_0, new ColumnSet(SystemForm.Schema.Attributes.objecttypecode, SystemForm.Schema.Attributes.name, SystemForm.Schema.Attributes.description)); _siteMapIntellisenseData.LoadDashboards(listSystemForms); } } catch (Exception ex) { DTEHelper.WriteExceptionToLog(ex); } finally { lock (_syncObjectTaskGettingSiteMapInformation) { _taskGettingSiteMapInformation = null; } } }
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 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 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); } }