Ejemplo n.º 1
0
        protected override void CommandAction(DTEHelper helper)
        {
            EnvDTE.Document document = helper.GetOpenedDocumentInCodeWindow(FileOperations.SupportsXmlType);

            if (document == null)
            {
                return;
            }

            var objTextDoc = document.Object(nameof(EnvDTE.TextDocument));

            if (objTextDoc != null && objTextDoc is EnvDTE.TextDocument textDocument)
            {
                string text = textDocument.StartPoint.CreateEditPoint().GetText(textDocument.EndPoint);

                if (!string.IsNullOrEmpty(text))
                {
                    if (ContentComparerHelper.TryParseXmlDocument(text, out var doc))
                    {
                        string docRootName = doc.Root.Name.ToString();

                        var schemasResources = AbstractDynamicCommandXsdSchemas.GetXsdSchemasByRootName(docRootName);

                        if (schemasResources != null)
                        {
                            ContentComparerHelper.ReplaceXsdSchemaInDocument(document, schemasResources);
                        }
                    }
                }
            }
        }
        protected override void CommandAction(DTEHelper helper)
        {
            var document = helper.GetOpenedDocumentInCodeWindow(FileOperations.SupportsXmlType);

            if (document != null)
            {
                var objTextDoc = document.Object(nameof(EnvDTE.TextDocument));
                if (objTextDoc != null &&
                    objTextDoc is EnvDTE.TextDocument textDocument
                    )
                {
                    string text = textDocument.StartPoint.CreateEditPoint().GetText(textDocument.EndPoint);

                    if (!string.IsNullOrEmpty(text))
                    {
                        if (ContentComparerHelper.TryParseXmlDocument(text, out var doc))
                        {
                            string docRootName = doc.Root.Name.ToString();

                            if (string.Equals(docRootName, AbstractDynamicCommandXsdSchemas.SiteMapXmlRoot, StringComparison.InvariantCultureIgnoreCase))
                            {
                                helper.HandleSiteMapDifferenceCommand(null, doc, document.FullName);
                            }
                            else if (string.Equals(docRootName, AbstractDynamicCommandXsdSchemas.RibbonDiffXmlRoot, StringComparison.InvariantCultureIgnoreCase))
                            {
                                helper.HandleRibbonDiffXmlDifferenceCommand(null, doc, document.FullName);
                            }
                            else if (string.Equals(docRootName, AbstractDynamicCommandXsdSchemas.RibbonXmlRoot, StringComparison.InvariantCultureIgnoreCase))
                            {
                                helper.HandleRibbonDifferenceCommand(null, doc, document.FullName);
                            }
                            else if (string.Equals(docRootName, AbstractDynamicCommandXsdSchemas.FetchRoot, StringComparison.InvariantCultureIgnoreCase) ||
                                     string.Equals(docRootName, AbstractDynamicCommandXsdSchemas.GridRoot, StringComparison.InvariantCultureIgnoreCase) ||
                                     string.Equals(docRootName, AbstractDynamicCommandXsdSchemas.ColumnSetRoot, StringComparison.InvariantCultureIgnoreCase)
                                     )
                            {
                                helper.HandleSavedQueryDifferenceCommand(null, doc, document.FullName);
                            }
                            else if (string.Equals(docRootName, AbstractDynamicCommandXsdSchemas.FormXmlRoot, StringComparison.InvariantCultureIgnoreCase))
                            {
                                helper.HandleSystemFormDifferenceCommand(null, doc, document.FullName);
                            }
                            else if (doc.Root.Name == AbstractDynamicCommandXsdSchemas.WorkflowActivityRoot)
                            {
                                helper.HandleWorkflowDifferenceCommand(null, doc, document.FullName);
                            }
                            else if (string.Equals(docRootName, AbstractDynamicCommandXsdSchemas.WebResourceDependencyXmlRoot, StringComparison.InvariantCultureIgnoreCase))
                            {
                                helper.HandleWebResourceDependencyXmlDifferenceCommand(null, doc, document.FullName);
                            }
                            else if (string.Equals(docRootName, AbstractDynamicCommandXsdSchemas.PluginTypeCustomWorkflowActivityInfoRoot, StringComparison.InvariantCultureIgnoreCase))
                            {
                                helper.HandlePluginTypeCustomWorkflowActivityInfoShowDifferenceCommand(null, doc, document.FullName);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        protected override void CommandAction(DTEHelper helper)
        {
            var document = helper.GetOpenedDocumentInCodeWindow(FileOperations.SupportsXmlType);

            if (document != null)
            {
                var objTextDoc = document.Object("TextDocument");
                if (objTextDoc != null &&
                    objTextDoc is EnvDTE.TextDocument textDocument
                    )
                {
                    string text = textDocument.StartPoint.CreateEditPoint().GetText(textDocument.EndPoint);

                    if (!string.IsNullOrEmpty(text))
                    {
                        if (ContentComparerHelper.TryParseXmlDocument(text, out var doc))
                        {
                            string docRootName = doc.Root.Name.ToString();

                            if (string.Equals(docRootName, AbstractDynamicCommandXsdSchemas.RootSiteMap, StringComparison.InvariantCultureIgnoreCase))
                            {
                                helper.HandleSiteMapUpdateCommand(null, doc, document.FullName);
                            }
                            else if (string.Equals(docRootName, AbstractDynamicCommandXsdSchemas.RootRibbonDiffXml, StringComparison.InvariantCultureIgnoreCase))
                            {
                                helper.HandleRibbonDiffXmlUpdateCommand(null, doc, document.FullName);
                            }
                            else if (string.Equals(docRootName, AbstractDynamicCommandXsdSchemas.RootFetch, StringComparison.InvariantCultureIgnoreCase) ||
                                     string.Equals(docRootName, AbstractDynamicCommandXsdSchemas.RootGrid, StringComparison.InvariantCultureIgnoreCase) ||
                                     string.Equals(docRootName, AbstractDynamicCommandXsdSchemas.RootColumnSet, StringComparison.InvariantCultureIgnoreCase)
                                     )
                            {
                                helper.HandleSavedQueryUpdateCommand(null, doc, document.FullName);
                            }
                            else if (string.Equals(docRootName, AbstractDynamicCommandXsdSchemas.RootForm, StringComparison.InvariantCultureIgnoreCase))
                            {
                                helper.HandleSystemFormUpdateCommand(null, doc, document.FullName);
                            }
                            else if (doc.Root.Name == AbstractDynamicCommandXsdSchemas.RootActivity)
                            {
                                helper.HandleWorkflowUpdateCommand(null, doc, document.FullName);
                            }
                            else if (string.Equals(docRootName, AbstractDynamicCommandXsdSchemas.RootWebResourceDependencies, StringComparison.InvariantCultureIgnoreCase))
                            {
                                helper.HandleWebResourceDependencyXmlUpdateCommand(null, doc, document.FullName);
                            }
                        }
                    }
                }
            }
        }
        private async Task PerformUpdateEntityField(string folder, Guid idCustomControl, string name, string fieldName, string fieldTitle, FileExtension extension)
        {
            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 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 (ContentComparerHelper.TryParseXml(xmlContent, out var tempDoc))
                    {
                        xmlContent = tempDoc.ToString();
                    }
                }
                else if (string.Equals(fieldName, CustomControl.Schema.Attributes.clientjson, StringComparison.InvariantCultureIgnoreCase))
                {
                    xmlContent = ContentComparerHelper.FormatJson(xmlContent);
                }

                {
                    string backUpXmlContent = xmlContent;

                    if (string.Equals(fieldName, CustomControl.Schema.Attributes.manifest, StringComparison.InvariantCultureIgnoreCase))
                    {
                        backUpXmlContent = ContentComparerHelper.FormatXmlByConfiguration(
                            backUpXmlContent
                            , _commonConfig
                            , XmlOptionsControls.CustomControlXmlOptions
                            , schemaName: AbstractDynamicCommandXsdSchemas.ManifestSchema
                            , customControlId: idCustomControl
                            );
                    }
                    else if (string.Equals(fieldName, CustomControl.Schema.Attributes.clientjson, StringComparison.InvariantCultureIgnoreCase))
                    {
                        backUpXmlContent = ContentComparerHelper.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.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;
                }

                newText = doc.ToString(SaveOptions.DisableFormatting);

                var updateEntity = new CustomControl
                {
                    Id = idCustomControl
                };
                updateEntity.Attributes[fieldName] = newText;

                await service.UpdateAsync(updateEntity);

                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);
            }
        }
Ejemplo n.º 5
0
        private async Task PerformUpdateApplicationRibbonDiffXml()
        {
            if (!this.IsControlsEnabled)
            {
                return;
            }

            var service = await GetService();

            if (service == null)
            {
                return;
            }

            this._iWriteToOutput.WriteToOutputStartOperation(service.ConnectionData, Properties.OperationNames.UpdatingApplicationRibbonDiffXmlFormat1, service.ConnectionData.Name);

            ToggleControls(service.ConnectionData, false, Properties.OutputStrings.InConnectionUpdatingApplicationRibbonDiffXmlFormat1, 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.OutputStrings.InConnectionUpdatingApplicationRibbonDiffXmlCanceledFormat1, service.ConnectionData.Name);
                    return;
                }
            }

            newText = ContentComparerHelper.RemoveInTextAllCustomXmlAttributesAndNamespaces(newText);

            UpdateStatus(service.ConnectionData, Properties.OutputStrings.ValidatingApplicationRibbonDiffXml);

            if (!ContentComparerHelper.TryParseXmlDocument(newText, out var doc))
            {
                ToggleControls(service.ConnectionData, true, Properties.OutputStrings.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.OutputStrings.ValidatingApplicationRibbonDiffXmlFailed);
                    return;
                }
            }

            var repositoryPublisher = new PublisherRepository(service);
            var publisherDefault    = await repositoryPublisher.GetDefaultPublisherAsync();

            if (publisherDefault == null)
            {
                ToggleControls(service.ConnectionData, true, Properties.OutputStrings.NotFoundedDefaultPublisher);
                _iWriteToOutput.ActivateOutputWindow(service.ConnectionData);
                return;
            }

            var repositoryRibbonCustomization = new RibbonCustomizationRepository(service);

            var ribbonCustomization = await repositoryRibbonCustomization.FindApplicationRibbonCustomizationAsync();

            if (ribbonCustomization == null)
            {
                ToggleControls(service.ConnectionData, true, Properties.OutputStrings.NotFoundedApplicationRibbonRibbonCustomization);
                _iWriteToOutput.ActivateOutputWindow(service.ConnectionData);
                return;
            }

            try
            {
                await repositoryRibbonCustomization.PerformUpdateRibbonDiffXml(_iWriteToOutput, _commonConfig, doc, null, ribbonCustomization);

                ToggleControls(service.ConnectionData, true, Properties.OutputStrings.InConnectionUpdatingApplicationRibbonDiffXmlCompletedFormat1, service.ConnectionData.Name);
            }
            catch (Exception ex)
            {
                this._iWriteToOutput.WriteErrorToOutput(service.ConnectionData, ex);

                ToggleControls(service.ConnectionData, true, Properties.OutputStrings.InConnectionUpdatingApplicationRibbonDiffXmlFailedFormat1, 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();

            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);
            }
        }
Ejemplo n.º 7
0
        private async Task StartGettingSiteMaps()
        {
            try
            {
                var service = await GetServiceAsync();

                if (service == null)
                {
                    return;
                }

                _connectionData.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);

                    _connectionData.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 (ContentComparerHelper.TryParseXmlDocument(item.SiteMapXml, out var doc))
                        {
                            _connectionData.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 (ContentComparerHelper.TryParseXmlDocument(organization.ReferenceSiteMapXml, out var doc))
                            {
                                _connectionData.SiteMapIntellisenseData.LoadDataFromSiteMap(doc);
                            }
                        }

                        if (!string.IsNullOrEmpty(organization.SiteMapXml))
                        {
                            if (ContentComparerHelper.TryParseXmlDocument(organization.SiteMapXml, out var doc))
                            {
                                _connectionData.SiteMapIntellisenseData.LoadDataFromSiteMap(doc);
                            }
                        }
                    }
                }

                {
                    var repository = new SystemFormRepository(service);

                    var listSystemForms = await repository.GetListByTypeAsync((int)SystemForm.Schema.OptionSets.type.Dashboard_0
                                                                              , new ColumnSet
                                                                              (
                                                                                  SystemForm.Schema.EntityPrimaryIdAttribute
                                                                                  , SystemForm.Schema.Attributes.objecttypecode
                                                                                  , SystemForm.Schema.Attributes.name
                                                                                  , SystemForm.Schema.Attributes.description
                                                                              )
                                                                              );

                    _connectionData.SiteMapIntellisenseData.LoadDashboards(listSystemForms);
                }

                _connectionData.SiteMapIntellisenseData.Save();

                this._nextLoadFileDate = DateTime.Now.AddMinutes(_loadPeriodInMinutes);
            }
            catch (Exception ex)
            {
                DTEHelper.WriteExceptionToLog(ex);
            }
            finally
            {
                lock (_syncObjectTaskGettingSiteMapInformation)
                {
                    _taskGettingSiteMapInformation = null;
                }
            }
        }