Exemple #1
0
        private async Task CreateGlobalOptionSetsCSharpFile(Func <Task <IOrganizationServiceExtented> > getService, IEnumerable <OptionSetMetadata> optionSets)
        {
            if (!this.IsControlsEnabled)
            {
                return;
            }

            if (optionSets == null)
            {
                return;
            }

            var service = await getService();

            if (service == null)
            {
                return;
            }

            _commonConfig.CheckFolderForExportExists(_iWriteToOutput);

            string optionSetsName = string.Join(",", optionSets.Select(o => o.Name).OrderBy(s => s));

            this._iWriteToOutput.WriteToOutputStartOperation(null, Properties.OperationNames.CreatingFileWithGlobalOptionSetsFormat1, optionSetsName);

            ToggleControls(false, Properties.OutputStrings.CreatingFileForOptionSetsFormat1, optionSetsName);

            try
            {
                string filePath = CreateFileNameCSharp(optionSets, service.ConnectionData);

                var fileGenerationOptions = FileGenerationConfiguration.GetFileGenerationOptions();

                var config = CreateFileCSharpConfiguration.CreateForSchemaGlobalOptionSet(fileGenerationOptions);

                var stringBuilder = new StringBuilder();

                using (var stringWriter = new StringWriter(stringBuilder))
                {
                    var descriptor = new SolutionComponentDescriptor(service);

                    var handler = new CreateGlobalOptionSetsFileCSharpHandler(stringWriter, service, descriptor, config);

                    await handler.CreateFileAsync(optionSets);
                }

                File.WriteAllText(filePath, stringBuilder.ToString(), new UTF8Encoding(false));

                this._iWriteToOutput.WriteToOutput(service.ConnectionData, Properties.OutputStrings.InConnectionCreatedGlobalOptionSetMetadataFileFormat3, service.ConnectionData.Name, optionSetsName, filePath);

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

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

                ToggleControls(true, Properties.OutputStrings.CreatingFileForOptionSetsFailedFormat1, optionSetsName);
            }

            this._iWriteToOutput.WriteToOutputEndOperation(null, Properties.OperationNames.CreatingFileWithGlobalOptionSetsFormat1, optionSetsName);
        }
Exemple #2
0
        private async Task PerformComparingCSharpFiles(IEnumerable <OptionSetMetadata> optionSets1, IEnumerable <OptionSetMetadata> optionSets2)
        {
            if (optionSets1 == null || optionSets2 == null)
            {
                return;
            }

            if (!optionSets1.Any() || !optionSets2.Any())
            {
                return;
            }

            if (!this.IsControlsEnabled)
            {
                return;
            }

            var service1 = await GetService1();

            var service2 = await GetService2();

            if (service1 == null || service2 == null)
            {
                return;
            }

            _commonConfig.CheckFolderForExportExists(_iWriteToOutput);

            string optionSetsName = string.Join(",", optionSets1.Select(o => o.Name).OrderBy(s => s));

            if (service1 != null && service2 != null)
            {
                this._iWriteToOutput.WriteToOutputStartOperation(null, Properties.OperationNames.CreatingFileWithGlobalOptionSetsFormat1, optionSetsName);

                ToggleControls(false, Properties.OutputStrings.CreatingFileForOptionSetsForConnectionsFormat3, service1.ConnectionData.Name, service2.ConnectionData.Name, optionSetsName);

                try
                {
                    string filePath1 = CreateFileNameCSharp(optionSets1, service1.ConnectionData);
                    string filePath2 = CreateFileNameCSharp(optionSets2, service2.ConnectionData);

                    var fileGenerationOptions = FileGenerationConfiguration.GetFileGenerationOptions();

                    var config = CreateFileCSharpConfiguration.CreateForSchemaGlobalOptionSet(fileGenerationOptions);

                    var stringBuilder1 = new StringBuilder();

                    using (var stringWriter1 = new StringWriter(stringBuilder1))
                    {
                        var descriptor1 = new SolutionComponentDescriptor(service1);

                        var handler1 = new CreateGlobalOptionSetsFileCSharpHandler(stringWriter1, service1, descriptor1, config);

                        var task1 = handler1.CreateFileAsync(optionSets1);

                        if (service1.ConnectionData.ConnectionId != service2.ConnectionData.ConnectionId)
                        {
                            var stringBuilder2 = new StringBuilder();

                            using (var stringWriter2 = new StringWriter(stringBuilder2))
                            {
                                var descriptor2 = new SolutionComponentDescriptor(service2);

                                var handler2 = new CreateGlobalOptionSetsFileCSharpHandler(stringWriter2, service2, descriptor2, config);

                                await handler2.CreateFileAsync(optionSets2);
                            }

                            File.WriteAllText(filePath2, stringBuilder2.ToString(), new UTF8Encoding(false));
                        }

                        await task1;
                    }

                    File.WriteAllText(filePath1, stringBuilder1.ToString(), new UTF8Encoding(false));

                    this._iWriteToOutput.WriteToOutput(null, Properties.OutputStrings.InConnectionCreatedGlobalOptionSetMetadataFileFormat3, service1.ConnectionData.Name, optionSetsName, filePath1);

                    if (service1.ConnectionData.ConnectionId != service2.ConnectionData.ConnectionId)
                    {
                        this._iWriteToOutput.WriteToOutput(null, Properties.OutputStrings.InConnectionCreatedGlobalOptionSetMetadataFileFormat3, service2.ConnectionData.Name, optionSetsName, filePath2);
                    }

                    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.CreatingFileForOptionSetsForConnectionsCompletedFormat3, service1.ConnectionData.Name, service2.ConnectionData.Name, optionSetsName);
                }
                catch (Exception ex)
                {
                    _iWriteToOutput.WriteErrorToOutput(null, ex);

                    ToggleControls(true, Properties.OutputStrings.CreatingFileForOptionSetsForConnectionsFailedFormat3, service1.ConnectionData.Name, service2.ConnectionData.Name, optionSetsName);
                }

                this._iWriteToOutput.WriteToOutputEndOperation(null, Properties.OperationNames.CreatingFileWithGlobalOptionSetsFormat1, optionSetsName);
            }
        }
        private async Task CreateJavaScriptFile(IEnumerable <OptionSetMetadata> optionSets)
        {
            if (optionSets == null)
            {
                return;
            }

            if (!this.IsControlsEnabled)
            {
                return;
            }

            string folder = txtBFolder.Text.Trim();

            if (string.IsNullOrEmpty(folder))
            {
                _iWriteToOutput.WriteToOutput(null, Properties.OutputStrings.FolderForExportIsEmpty);
                folder = FileOperations.GetDefaultFolderForExportFilePath();
            }
            else if (!Directory.Exists(folder))
            {
                _iWriteToOutput.WriteToOutput(null, Properties.OutputStrings.FolderForExportDoesNotExistsFormat1, folder);
                folder = FileOperations.GetDefaultFolderForExportFilePath();
            }

            var service = await GetService();

            string optionSetsName = string.Join(",", optionSets.Select(o => o.Name).OrderBy(s => s));

            this._iWriteToOutput.WriteToOutputStartOperation(service.ConnectionData, Properties.OperationNames.CreatingFileWithGlobalOptionSetsFormat1, optionSetsName);

            ToggleControls(service.ConnectionData, false, Properties.WindowStatusStrings.CreatingFileForOptionSetsFormat1, optionSetsName);

            try
            {
                string fileName = CreateGlobalOptionSetsFileCSharpHandler.CreateFileNameJavaScript(service.ConnectionData, optionSets, this._selectedItem != null);

                string filePath = Path.Combine(folder, fileName);

                if (_isJavaScript && !string.IsNullOrEmpty(_filePath))
                {
                    filePath = _filePath;
                }

                using (var writer = new StreamWriter(filePath, false, new UTF8Encoding(false)))
                {
                    var handler = new CreateGlobalOptionSetsFileJavaScriptHandler(
                        writer
                        , service
                        , _iWriteToOutput
                        , _commonConfig.GetTabSpacer()
                        , _commonConfig.GenerateSchemaGlobalOptionSetsWithDependentComponents
                        );

                    await handler.CreateFileAsync(optionSets);
                }

                if (this._selectedItem != null)
                {
                    if (_selectedItem.ProjectItem != null)
                    {
                        _selectedItem.ProjectItem.ProjectItems.AddFromFileCopy(filePath);

                        _selectedItem.ProjectItem.ContainingProject.Save();
                    }
                    else if (_selectedItem.Project != null)
                    {
                        _selectedItem.Project.ProjectItems.AddFromFile(filePath);

                        _selectedItem.Project.Save();
                    }
                }

                this._iWriteToOutput.WriteToOutput(service.ConnectionData, Properties.OutputStrings.CreatedGlobalOptionSetMetadataFileForConnectionFormat3, service.ConnectionData.Name, optionSetsName, filePath);

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

                ToggleControls(service.ConnectionData, true, Properties.WindowStatusStrings.CreatingFileForOptionSetsCompletedFormat1, optionSetsName);
            }
            catch (Exception ex)
            {
                _iWriteToOutput.WriteErrorToOutput(service.ConnectionData, ex);

                ToggleControls(service.ConnectionData, true, Properties.WindowStatusStrings.CreatingFileForOptionSetsFailedFormat1, optionSetsName);
            }

            this._iWriteToOutput.WriteToOutputEndOperation(service.ConnectionData, Properties.OperationNames.CreatingFileWithGlobalOptionSetsFormat1, optionSetsName);
        }
Exemple #4
0
        private string CreateFileNameCSharp(IEnumerable <OptionSetMetadata> optionSets, ConnectionData connection)
        {
            string fileName = CreateGlobalOptionSetsFileCSharpHandler.CreateFileNameCSharp(connection, optionSets, false);

            return(Path.Combine(_commonConfig.FolderForExport, fileName));
        }
        private async Task CreateJavaScriptFile(IEnumerable <OptionSetMetadata> optionSets)
        {
            if (optionSets == null)
            {
                return;
            }

            if (!this.IsControlsEnabled)
            {
                return;
            }

            var service = await GetService();

            if (service == null)
            {
                return;
            }

            string folder = txtBFolder.Text.Trim();

            folder = CorrectFolderIfEmptyOrNotExists(_iWriteToOutput, folder);

            string optionSetsName = string.Join(",", optionSets.Select(o => o.Name).OrderBy(s => s));

            this._iWriteToOutput.WriteToOutputStartOperation(service.ConnectionData, Properties.OperationNames.CreatingFileWithGlobalOptionSetsFormat1, optionSetsName);

            ToggleControls(service.ConnectionData, false, Properties.OutputStrings.CreatingFileForOptionSetsFormat1, optionSetsName);

            try
            {
                string fileName = CreateGlobalOptionSetsFileCSharpHandler.CreateFileNameJavaScript(service.ConnectionData, optionSets, this._selectedItem != null);

                string filePath = Path.Combine(folder, fileName);

                if (_isJavaScript && !string.IsNullOrEmpty(_filePath))
                {
                    filePath = _filePath;
                }

                var fileGenerationOptions = FileGenerationConfiguration.GetFileGenerationOptions();

                var stringBuilder = new StringBuilder();

                using (var stringWriter = new StringWriter(stringBuilder))
                {
                    SolutionComponentDescriptor descriptor = new SolutionComponentDescriptor(service);

                    var handler = new CreateGlobalOptionSetsFileJavaScriptHandler(
                        stringWriter
                        , service
                        , descriptor
                        , fileGenerationOptions.GetTabSpacer()
                        , fileGenerationOptions.GenerateSchemaGlobalOptionSetsWithDependentComponents
                        , fileGenerationOptions.NamespaceGlobalOptionSetsJavaScript
                        );

                    await handler.CreateFileAsync(optionSets);
                }

                File.WriteAllText(filePath, stringBuilder.ToString(), new UTF8Encoding(false));

                AddFileToVSProject(_selectedItem, filePath);

                this._iWriteToOutput.WriteToOutput(service.ConnectionData, Properties.OutputStrings.InConnectionCreatedGlobalOptionSetMetadataFileFormat3, service.ConnectionData.Name, optionSetsName, filePath);

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

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

                ToggleControls(service.ConnectionData, true, Properties.OutputStrings.CreatingFileForOptionSetsFailedFormat1, optionSetsName);
            }

            this._iWriteToOutput.WriteToOutputEndOperation(service.ConnectionData, Properties.OperationNames.CreatingFileWithGlobalOptionSetsFormat1, optionSetsName);
        }