private async Task PerformExportDescriptionToFile(Guid idChart, Func <Task <IOrganizationServiceExtented> > getService)
        {
            if (!this.IsControlsEnabled)
            {
                return;
            }

            ToggleControls(false, Properties.OutputStrings.CreatingEntityDescription);

            var service = await getService();

            if (service != null)
            {
                var repository = new SavedQueryVisualizationRepository(service);

                var chart = await repository.GetByIdAsync(idChart, ColumnSetInstances.AllColumns);

                var description = await EntityDescriptionHandler.GetEntityDescriptionAsync(chart, service.ConnectionData);

                string filePath = await CreateDescriptionFileAsync(service.ConnectionData, chart.PrimaryEntityTypeCode, chart.Name, EntityFileNameFormatter.Headers.EntityDescription, description);

                this._iWriteToOutput.PerformAction(service.ConnectionData, filePath);
            }

            ToggleControls(true, Properties.OutputStrings.CreatingEntityDescriptionCompleted);
        }
        private async Task PerformExportXmlToFile(Guid idChart, Func <Task <IOrganizationServiceExtented> > getService, string fieldName, string fieldTitle)
        {
            if (!this.IsControlsEnabled)
            {
                return;
            }

            ToggleControls(false, Properties.OutputStrings.ExportingXmlFieldToFileFormat1, fieldTitle);

            var service = await getService();

            if (service != null)
            {
                var repository = new SavedQueryVisualizationRepository(service);

                var chart = await repository.GetByIdAsync(idChart, ColumnSetInstances.AllColumns);

                string xmlContent = chart.GetAttributeValue <string>(fieldName);

                string filePath = await CreateFileAsync(service.ConnectionData, chart.PrimaryEntityTypeCode, chart.Name, fieldTitle, xmlContent);

                if (!File.Exists(filePath))
                {
                    this._iWriteToOutput.WriteToOutput(null, Properties.OutputStrings.InConnectionEntityFieldIsEmptyFormat4, service.ConnectionData.Name, SavedQueryVisualization.Schema.EntityLogicalName, chart.Name, fieldTitle);
                    this._iWriteToOutput.ActivateOutputWindow(null);
                }

                this._iWriteToOutput.PerformAction(service.ConnectionData, filePath);
            }

            ToggleControls(true, Properties.OutputStrings.ExportingXmlFieldToFileCompletedFormat1, fieldName);
        }
        private void FillChartsFromCustomization(ICollection <SolutionComponent> result, EntityMetadata metaData, XElement elementEntity)
        {
            var repository = new SavedQueryVisualizationRepository(_source.Service);

            var elements = elementEntity.XPathSelectElements("./Visualizations/visualization/savedqueryvisualizationid");

            foreach (var item in elements)
            {
                if (string.IsNullOrEmpty(item.Value) || !Guid.TryParse(item.Value, out var idChart))
                {
                    continue;
                }

                var entity = repository.GetById(idChart, ColumnSetInstances.None);

                if (entity != null)
                {
                    var component = new SolutionComponent()
                    {
                        ComponentType = new OptionSetValue((int)ComponentType.SavedQueryVisualization),

                        ObjectId = entity.Id,

                        RootComponentBehaviorEnum = SolutionComponent.Schema.OptionSets.rootcomponentbehavior.Include_Subcomponents_0,
                    };

                    result.Add(component);
                }
            }
        }
Ejemplo n.º 4
0
        protected override async Task <List <SavedQueryVisualization> > GetSavedQueryVisualizationAsync(IOrganizationServiceExtented service)
        {
            List <SavedQueryVisualization> result = new List <SavedQueryVisualization>();

            var descriptor = new SolutionComponentDescriptor(service);
            var repository = new SavedQueryVisualizationRepository(service);

            var imageComponents = _solutionImage.Components.Where(c => c.ComponentType == (int)ComponentType.SavedQueryVisualization);

            if (imageComponents.Any())
            {
                var solutionComponents = await descriptor.GetSolutionComponentsListAsync(imageComponents);

                if (solutionComponents.Any())
                {
                    var tempList = await repository.GetListByIdListAsync(solutionComponents.Select(s => s.ObjectId.Value), new ColumnSet(true));

                    result.AddRange(tempList);
                }
            }

            var hashSet = new HashSet <Guid>(result.Select(c => c.Id));

            imageComponents = _solutionImage.Components.Where(c => c.ComponentType == (int)ComponentType.Entity);

            if (imageComponents.Any())
            {
                var solutionComponents = await descriptor.GetSolutionComponentsListAsync(imageComponents);

                if (solutionComponents.Any())
                {
                    var entities = solutionComponents
                                   .Where(c => c.RootComponentBehaviorEnum.GetValueOrDefault(SolutionComponent.Schema.OptionSets.rootcomponentbehavior.Include_Subcomponents_0) == SolutionComponent.Schema.OptionSets.rootcomponentbehavior.Include_Subcomponents_0 &&
                                          c.ObjectId.HasValue)
                                   .Select(e => descriptor.MetadataSource.GetEntityMetadata(e.ObjectId.Value))
                                   .Where(e => e != null)
                                   .Select(e => e.LogicalName)
                                   .ToArray();

                    if (entities.Any())
                    {
                        var tempList = await repository.GetListForEntitiesAsync(entities, new ColumnSet(true));

                        foreach (var item in tempList)
                        {
                            if (hashSet.Add(item.Id))
                            {
                                result.Add(item);
                            }
                        }
                    }
                }
            }

            return(result);
        }
        private async Task PerformShowingDifferenceDescriptionAsync(LinkedEntities <SavedQueryVisualization> linked, bool showAllways)
        {
            if (!this.IsControlsEnabled)
            {
                return;
            }

            ToggleControls(false, Properties.OutputStrings.ShowingDifferenceEntityDescription);

            try
            {
                var service1 = await GetService1();

                var service2 = await GetService2();

                if (service1 != null && service2 != null)
                {
                    var repository1 = new SavedQueryVisualizationRepository(service1);
                    var repository2 = new SavedQueryVisualizationRepository(service2);

                    var chart1 = await repository1.GetByIdAsync(linked.Entity1.Id, ColumnSetInstances.AllColumns);

                    var chart2 = await repository2.GetByIdAsync(linked.Entity2.Id, ColumnSetInstances.AllColumns);

                    var desc1 = await EntityDescriptionHandler.GetEntityDescriptionAsync(chart1);

                    var desc2 = await EntityDescriptionHandler.GetEntityDescriptionAsync(chart2);

                    if (showAllways || desc1 != desc2)
                    {
                        string filePath1 = await CreateDescriptionFileAsync(service1.ConnectionData, chart1.PrimaryEntityTypeCode, chart1.Name, EntityFileNameFormatter.Headers.EntityDescription, desc1);

                        string filePath2 = await CreateDescriptionFileAsync(service2.ConnectionData, chart2.PrimaryEntityTypeCode, chart2.Name, EntityFileNameFormatter.Headers.EntityDescription, desc2);

                        if (File.Exists(filePath1) && File.Exists(filePath2))
                        {
                            await this._iWriteToOutput.ProcessStartProgramComparerAsync(service1.ConnectionData, filePath1, filePath2, Path.GetFileName(filePath1), Path.GetFileName(filePath2), service2.ConnectionData);
                        }
                        else
                        {
                            this._iWriteToOutput.PerformAction(service1.ConnectionData, filePath1);

                            this._iWriteToOutput.PerformAction(service2.ConnectionData, filePath2);
                        }
                    }
                }

                ToggleControls(true, Properties.OutputStrings.ShowingDifferenceEntityDescriptionCompleted);
            }
            catch (Exception ex)
            {
                _iWriteToOutput.WriteErrorToOutput(null, ex);

                ToggleControls(true, Properties.OutputStrings.ShowingDifferenceEntityDescriptionFailed);
            }
        }
        private async Task PerformExportEntityDescription(string folder, Guid idSavedQueryVisualization, string entityName, string name)
        {
            var service = await GetService();

            if (service == null)
            {
                return;
            }

            ToggleControls(service.ConnectionData, false, Properties.OutputStrings.CreatingEntityDescription);

            try
            {
                string fileName = EntityFileNameFormatter.GetSavedQueryVisualizationFileName(service.ConnectionData.Name, entityName, name, EntityFileNameFormatter.Headers.EntityDescription, FileExtension.txt);
                string filePath = Path.Combine(folder, FileOperations.RemoveWrongSymbols(fileName));

                var repository = new SavedQueryVisualizationRepository(service);

                var savedQueryVisualization = await repository.GetByIdAsync(idSavedQueryVisualization, ColumnSetInstances.AllColumns);

                await EntityDescriptionHandler.ExportEntityDescriptionAsync(filePath, savedQueryVisualization, service.ConnectionData);

                this._iWriteToOutput.WriteToOutput(service.ConnectionData, Properties.OutputStrings.InConnectionExportedEntityDescriptionFormat3
                                                   , service.ConnectionData.Name
                                                   , savedQueryVisualization.LogicalName
                                                   , filePath);

                this._iWriteToOutput.PerformAction(service.ConnectionData, filePath);

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

                ToggleControls(service.ConnectionData, true, Properties.OutputStrings.CreatingEntityDescriptionFailed);
            }
        }
        private async Task PerformExportXmlToFile(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.ExportingXmlFieldToFileFormat1, fieldTitle);

            try
            {
                var repository = new SavedQueryVisualizationRepository(service);

                var savedQueryVisualization = await repository.GetByIdAsync(idSavedQueryVisualization, new ColumnSet(fieldName));

                string xmlContent = savedQueryVisualization.GetAttributeValue <string>(fieldName);

                string filePath = await CreateFileAsync(folder, entityName, name, fieldTitle, xmlContent);

                this._iWriteToOutput.PerformAction(service.ConnectionData, filePath);

                ToggleControls(service.ConnectionData, true, Properties.OutputStrings.ExportingXmlFieldToFileCompletedFormat1, fieldName);
            }
            catch (Exception ex)
            {
                _iWriteToOutput.WriteErrorToOutput(service.ConnectionData, ex);

                ToggleControls(service.ConnectionData, true, Properties.OutputStrings.ExportingXmlFieldToFileFailedFormat1, fieldName);
            }
        }
        private async Task PerformShowingDifferenceSingleXmlAsync(LinkedEntities <SavedQueryVisualization> linked, bool showAllways, string fieldName, string fieldTitle)
        {
            if (!this.IsControlsEnabled)
            {
                return;
            }

            ToggleControls(false, Properties.OutputStrings.ShowingDifferenceXmlForFieldFormat1, fieldName);

            try
            {
                var service1 = await GetService1();

                var service2 = await GetService2();

                if (service1 != null && service2 != null)
                {
                    var repository1 = new SavedQueryVisualizationRepository(service1);
                    var repository2 = new SavedQueryVisualizationRepository(service2);

                    var chart1 = await repository1.GetByIdAsync(linked.Entity1.Id, ColumnSetInstances.AllColumns);

                    var chart2 = await repository2.GetByIdAsync(linked.Entity2.Id, ColumnSetInstances.AllColumns);

                    string xml1 = chart1.GetAttributeValue <string>(fieldName);
                    string xml2 = chart2.GetAttributeValue <string>(fieldName);

                    if (showAllways || !ContentComparerHelper.CompareXML(xml1, xml2).IsEqual)
                    {
                        string filePath1 = await CreateFileAsync(service1.ConnectionData, chart1.PrimaryEntityTypeCode, chart1.Name, fieldTitle, xml1);

                        string filePath2 = await CreateFileAsync(service2.ConnectionData, chart2.PrimaryEntityTypeCode, chart2.Name, fieldTitle, xml2);

                        if (!File.Exists(filePath1))
                        {
                            this._iWriteToOutput.WriteToOutput(null, Properties.OutputStrings.InConnectionEntityFieldIsEmptyFormat4, service1.ConnectionData.Name, SavedQueryVisualization.Schema.EntityLogicalName, chart1.Name, fieldTitle);
                            this._iWriteToOutput.ActivateOutputWindow(null);
                        }

                        if (!File.Exists(filePath2))
                        {
                            this._iWriteToOutput.WriteToOutput(null, Properties.OutputStrings.InConnectionEntityFieldIsEmptyFormat4, service2.ConnectionData.Name, SavedQueryVisualization.Schema.EntityLogicalName, chart2.Name, fieldTitle);
                            this._iWriteToOutput.ActivateOutputWindow(null);
                        }

                        if (File.Exists(filePath1) && File.Exists(filePath2))
                        {
                            await this._iWriteToOutput.ProcessStartProgramComparerAsync(service1.ConnectionData, filePath1, filePath2, Path.GetFileName(filePath1), Path.GetFileName(filePath2), service2.ConnectionData);
                        }
                        else
                        {
                            this._iWriteToOutput.PerformAction(service1.ConnectionData, filePath1);

                            this._iWriteToOutput.PerformAction(service2.ConnectionData, filePath2);
                        }
                    }
                }

                ToggleControls(true, Properties.OutputStrings.ShowingDifferenceXmlForFieldCompletedFormat1, fieldName);
            }
            catch (Exception ex)
            {
                _iWriteToOutput.WriteErrorToOutput(null, ex);

                ToggleControls(true, Properties.OutputStrings.ShowingDifferenceXmlForFieldFailedFormat1, fieldName);
            }
        }
        private async Task ShowExistingCharts()
        {
            if (!this.IsControlsEnabled)
            {
                return;
            }

            ToggleControls(false, Properties.OutputStrings.LoadingCharts);

            this.Dispatcher.Invoke(() =>
            {
                this._itemsSource.Clear();
            });

            IEnumerable <LinkedEntities <SavedQueryVisualization> > list = Enumerable.Empty <LinkedEntities <SavedQueryVisualization> >();

            try
            {
                var service1 = await GetService1();

                var service2 = await GetService2();

                if (service1 != null && service2 != null)
                {
                    string entityName = string.Empty;

                    this.Dispatcher.Invoke(() =>
                    {
                        if (!string.IsNullOrEmpty(cmBEntityName.Text) &&
                            cmBEntityName.Items.Contains(cmBEntityName.Text)
                            )
                        {
                            entityName = cmBEntityName.Text.Trim().ToLower();
                        }
                    });

                    string filterEntity = null;

                    if (service1.ConnectionData.IsValidEntityName(entityName) &&
                        service2.ConnectionData.IsValidEntityName(entityName)
                        )
                    {
                        filterEntity = entityName;
                    }

                    var temp = new List <LinkedEntities <SavedQueryVisualization> >();

                    if (service1.ConnectionData.ConnectionId != service2.ConnectionData.ConnectionId)
                    {
                        var repository1 = new SavedQueryVisualizationRepository(service1);
                        var repository2 = new SavedQueryVisualizationRepository(service2);

                        var task1 = repository1.GetListAsync(filterEntity);
                        var task2 = repository2.GetListAsync(filterEntity);

                        var list1 = await task1;
                        var list2 = await task2;

                        foreach (var chart1 in list1)
                        {
                            var chart2 = list2.FirstOrDefault(c => c.Id == chart1.Id);

                            if (chart2 == null)
                            {
                                continue;
                            }

                            temp.Add(new LinkedEntities <SavedQueryVisualization>(chart1, chart2));
                        }
                    }
                    else
                    {
                        var repository1 = new SavedQueryVisualizationRepository(service1);

                        var task1 = repository1.GetListAsync(filterEntity);

                        var list1 = await task1;

                        foreach (var chart1 in list1)
                        {
                            temp.Add(new LinkedEntities <SavedQueryVisualization>(chart1, null));
                        }
                    }

                    list = temp;
                }
            }
            catch (Exception ex)
            {
                this._iWriteToOutput.WriteErrorToOutput(null, ex);
            }

            var textName = string.Empty;

            txtBFilter.Dispatcher.Invoke(() =>
            {
                textName = txtBFilter.Text.Trim().ToLower();
            });

            list = FilterList(list, textName);

            LoadEntities(list);
        }
        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 ShowExistingCharts()
        {
            if (!this.IsControlsEnabled)
            {
                return;
            }

            ConnectionData connectionData = GetSelectedConnection();

            ToggleControls(connectionData, false, Properties.OutputStrings.LoadingCharts);

            string filterEntity = null;

            string entityName = string.Empty;

            this.Dispatcher.Invoke(() =>
            {
                this._itemsSource.Clear();

                if (!string.IsNullOrEmpty(cmBEntityName.Text) &&
                    cmBEntityName.Items.Contains(cmBEntityName.Text)
                    )
                {
                    entityName = cmBEntityName.Text.Trim().ToLower();
                }
            });

            if (connectionData.IsValidEntityName(entityName))
            {
                filterEntity = entityName;
            }

            IEnumerable <SavedQueryVisualization> list = Enumerable.Empty <SavedQueryVisualization>();

            try
            {
                var service = await GetService();

                if (service != null)
                {
                    var repository = new SavedQueryVisualizationRepository(service);

                    list = await repository.GetListAsync(filterEntity, new ColumnSet(
                                                             SavedQueryVisualization.Schema.Attributes.savedqueryvisualizationid
                                                             , SavedQueryVisualization.Schema.Attributes.primaryentitytypecode
                                                             , SavedQueryVisualization.Schema.Attributes.name
                                                             , SavedQueryVisualization.Schema.Attributes.iscustomizable
                                                             ));
                }
            }
            catch (Exception ex)
            {
                this._iWriteToOutput.WriteErrorToOutput(connectionData, ex);
            }

            string textName = string.Empty;

            txtBFilter.Dispatcher.Invoke(() =>
            {
                textName = txtBFilter.Text.Trim().ToLower();
            });

            list = FilterList(list, textName);

            LoadSystemCharts(list);

            ToggleControls(connectionData, true, Properties.OutputStrings.LoadingChartsCompletedFormat1, list.Count());
        }