Esempio n. 1
0
        private void miOptions_Click(object sender, RoutedEventArgs e)
        {
            var fileGenerationOptions = FileGenerationConfiguration.GetFileGenerationOptions();

            this._optionsControl.BindFileGenerationOptions(fileGenerationOptions);

            this._optionsPopup.IsOpen = true;
            this._optionsPopup.Child.Focus();
        }
Esempio n. 2
0
        /// <summary>
        /// Constructor.
        /// </summary>
        public FileGenerator(Composition SourceComposition, ExternalLanguageDeclaration Language, FileGenerationConfiguration NewConfiguration)
        {
            this.SourceComposition = SourceComposition;
            this.Language          = Language;

            if (NewConfiguration == null)
            {
                NewConfiguration = new FileGenerationConfiguration();
            }

            this.Configuration = NewConfiguration;
        }
        private async Task CopingToClipboardSystemFormCurrentTabsAndSections(IOrganizationServiceExtented service, CommonConfiguration commonConfig, JavaScriptObjectType jsObjectType, string entityName, Guid formId, int formType)
        {
            var repositorySystemForm = new SystemFormRepository(service);

            var systemForm = await repositorySystemForm.GetByIdAsync(formId, ColumnSetInstances.AllColumns);

            string formXml = systemForm.FormXml;

            if (string.IsNullOrEmpty(formXml))
            {
                this._iWriteToOutput.WriteToOutput(service.ConnectionData, Properties.OutputStrings.InConnectionEntityFieldIsEmptyFormat4, service.ConnectionData.Name, SystemForm.Schema.EntityLogicalName, systemForm.Name, SystemForm.Schema.Headers.formxml);
                this._iWriteToOutput.ActivateOutputWindow(service.ConnectionData);
                return;
            }

            try
            {
                var fileGenerationOptions = FileGenerationConfiguration.GetFileGenerationOptions();

                var config = new CreateFileJavaScriptConfiguration(fileGenerationOptions);

                var doc = XElement.Parse(formXml);

                var descriptor = new SolutionComponentDescriptor(service);

                descriptor.SetSettings(commonConfig);

                var handler = new FormDescriptionHandler(descriptor, new DependencyRepository(service));

                FormInformation formInfo = handler.GetFormInformation(doc);

                var stringBuilder = new StringBuilder();

                using (var writer = new StringWriter(stringBuilder))
                {
                    var handlerCreate = new CreateFormTabsJavaScriptHandler(writer, config, jsObjectType, service);

                    handlerCreate.WriteContentOnlyForm(formInfo);
                }

                ClipboardHelper.SetText(stringBuilder.ToString().Trim(' ', '\r', '\n'));

                this._iWriteToOutput.WriteToOutput(service.ConnectionData, Properties.OutputStrings.CopyingEntityJavaScriptContentOnFormCompletedFormat2, systemForm.ObjectTypeCode, systemForm.Name);
                this._iWriteToOutput.ActivateOutputWindow(service.ConnectionData);

                service.TryDispose();
            }
            catch (Exception ex)
            {
                this._iWriteToOutput.WriteErrorToOutput(service.ConnectionData, ex);
            }
        }
        public WindowFileGenerationConfiguration(FileGenerationConfiguration config)
        {
            InitializeComponent();

            SetInputLanguageEnglish();

            this._config = config;

            foreach (var solutionFilePath in _config.FileGenerationOptionsCollection.Keys.OrderBy(s => s))
            {
                _sourceOptions.Add(new ListViewItem(solutionFilePath, _config.FileGenerationOptionsCollection[solutionFilePath]));
            }

            lstVwOptions.ItemsSource = _sourceOptions;
        }
        protected override void OnClosed(EventArgs e)
        {
            base.OnClosed(e);

            FileGenerationConfiguration.SaveConfiguration();

            GetSelectedConnection()?.Save();

            BindingOperations.ClearAllBindings(cmBCurrentConnection);

            cmBCurrentConnection.Items.DetachFromSourceCollection();

            cmBCurrentConnection.DataContext = null;
            cmBCurrentConnection.ItemsSource = null;
        }
Esempio n. 6
0
        protected override void OnClosed(EventArgs e)
        {
            base.OnClosed(e);

            FileGenerationConfiguration.SaveConfiguration();

            (cmBConnection1.SelectedItem as ConnectionData)?.Save();
            (cmBConnection2.SelectedItem as ConnectionData)?.Save();

            BindingOperations.ClearAllBindings(cmBConnection1);
            cmBConnection1.Items.DetachFromSourceCollection();
            cmBConnection1.DataContext = null;
            cmBConnection1.ItemsSource = null;

            BindingOperations.ClearAllBindings(cmBConnection2);
            cmBConnection2.Items.DetachFromSourceCollection();
            cmBConnection2.DataContext = null;
            cmBConnection2.ItemsSource = null;
        }
        public GeneratorSelectionEditor(Composition SourceComposition)
            : this()
        {
            this.SourceComposition   = SourceComposition;
            this.SourceConfiguration = SourceComposition.CompositeContentDomain.GenerationConfiguration;

            if (this.SourceConfiguration.TargetDirectory.IsAbsent())
            {
                this.SourceConfiguration.TargetDirectory = Path.Combine(AppExec.UserDataDirectory, this.SourceComposition.TechName);
            }

            if (this.SourceConfiguration.Language == null ||
                !this.SourceConfiguration.Language.IsIn(this.SourceComposition.CompositeContentDomain.ExternalLanguages))
            {
                this.SourceConfiguration.Language = SourceComposition.CompositeContentDomain.CurrentExternalLanguage;
            }

            this.CbxLanguage.ItemsSource = SourceComposition.CompositeContentDomain.ExternalLanguages;

            this.DataContext = this.SourceConfiguration;
        }
Esempio n. 8
0
        private void btnLoadConfiguration_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            if (this._fileGenerationOptions == null)
            {
                return;
            }

            string selectedPath = string.Empty;
            var    thread       = new Thread(() =>
            {
                try
                {
                    var openFileDialog1 = new Microsoft.Win32.OpenFileDialog
                    {
                        Filter           = "FileGenerationOptions (.xml)|*.xml",
                        FilterIndex      = 1,
                        RestoreDirectory = true
                    };

                    if (openFileDialog1.ShowDialog().GetValueOrDefault())
                    {
                        selectedPath = openFileDialog1.FileName;
                    }
                }
                catch (Exception ex)
                {
                    DTEHelper.WriteExceptionToOutput(null, ex);
                }
            });

            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();

            thread.Join();

            if (string.IsNullOrEmpty(selectedPath))
            {
                return;
            }

            FileGenerationOptions fileOptionFromDisk = null;

            try
            {
                fileOptionFromDisk = FileGenerationOptions.LoadFromPath(selectedPath);
            }
            catch (Exception ex)
            {
                DTEHelper.WriteExceptionToOutput(null, ex);

                fileOptionFromDisk = null;
            }

            if (fileOptionFromDisk == null)
            {
                return;
            }

            this._fileGenerationOptions.LoadFromDisk(fileOptionFromDisk);

            FileGenerationConfiguration.SaveConfiguration();
        }
Esempio n. 9
0
        private async Task CreateGlobalOptionSetsJavaScriptFile(Func <Task <IOrganizationServiceExtented> > getService, IEnumerable <OptionSetMetadata> optionSets)
        {
            if (!this.IsControlsEnabled)
            {
                return;
            }

            if (optionSets == null || !optionSets.Any())
            {
                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
            {
                var fileGenerationOptions = FileGenerationConfiguration.GetFileGenerationOptions();

                string tabSpacer = fileGenerationOptions.GetTabSpacer();

                var withDependentComponents = fileGenerationOptions.GenerateSchemaGlobalOptionSetsWithDependentComponents;

                var namespaceJavaScript = fileGenerationOptions.NamespaceGlobalOptionSetsJavaScript;

                string filePath = CreateFileNameJavaScript(optionSets, service.ConnectionData);

                var stringBuilder = new StringBuilder();

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

                    var handler = new CreateGlobalOptionSetsFileJavaScriptHandler(stringWriter, service, descriptor, tabSpacer, withDependentComponents, namespaceJavaScript);

                    await handler.CreateFileAsync(optionSets);
                }

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

                var message = string.Empty;

                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);
        }
Esempio n. 10
0
        private async Task PerformComparingJavaScriptFile(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 = CreateFileNameJavaScript(optionSets1, service1.ConnectionData);
                    string filePath2 = CreateFileNameJavaScript(optionSets2, service2.ConnectionData);

                    var fileGenerationOptions = FileGenerationConfiguration.GetFileGenerationOptions();

                    var tabSpacer           = fileGenerationOptions.GetTabSpacer();
                    var constantType        = fileGenerationOptions.GenerateSchemaConstantType;
                    var namespaceJavascript = fileGenerationOptions.NamespaceGlobalOptionSetsJavaScript;

                    var withDependentComponents = fileGenerationOptions.GenerateSchemaGlobalOptionSetsWithDependentComponents;

                    var stringBuilder1 = new StringBuilder();

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

                        var handler1 = new CreateGlobalOptionSetsFileJavaScriptHandler(stringWriter1, service1, descriptor1, tabSpacer, withDependentComponents, namespaceJavascript);

                        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 CreateGlobalOptionSetsFileJavaScriptHandler(stringWriter2, service2, descriptor2, tabSpacer, withDependentComponents, namespaceJavascript);

                                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;
            }

            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);
        }