Exemple #1
0
        public async Task <IActionResult> AddTranslation(AddTranslationViewModel model)
        {
            if (ModelState.IsValid)
            {
                var template = await _ctx.FindTemplateAsync(model.TemplateId);

                if (template == null)
                {
                    return(NotFound());
                }

                template.Translations.Add(new Translation
                {
                    Language        = model.Language,
                    SubjectTemplate = model.SubjectTemplate,
                    BodyTemplate    = model.BodyTemplate
                });

                await _ctx.SaveChangesAsync();

                return(RedirectToAction(nameof(Details), new { id = model.TemplateId }));
            }

            return(View(model));
        }
Exemple #2
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            var wnd         = new MainWindow();
            var projFactory = new ProjectsFactoryFromSolutionFile();
            var vm          = new AddTranslationViewModel(projFactory, wnd);

            wnd.DataContext = vm;
            wnd.ShowDialog();
        }
Exemple #3
0
        public async Task <IActionResult> AddTranslation(Guid id)
        {
            var model = await AddTranslationViewModel.LoadAsync(_ctx, id);

            if (model != null)
            {
                return(View(model));
            }

            return(NotFound());
        }
Exemple #4
0
        private async Task ExecuteAsync(object sender, EventArgs e)
        {
            _logger.Info("Starting command of adding translation.");

            var textManager = (VsTextManager)await _serviceProvider.GetServiceAsync(typeof(SVsTextManager));

            Assumes.Present(textManager);
            var componentModel = (SComponentModel)await _serviceProvider.GetServiceAsync(typeof(SComponentModel));

            Assumes.Present(componentModel);

            IVsTextView  view;
            IWpfTextView wpfTextView;
            ITextEdit    edit = null;

            try
            {
                int result = (textManager as IVsTextManager2).GetActiveView2(1, null, (uint)_VIEWFRAMETYPE.vftCodeWindow, out view);
                _logger.Debug("Successfully created " + nameof(IVsTextView));
                // Cast IVsTextView to IWpfTextView, so we can modify text of the file.
                wpfTextView = (componentModel as IComponentModel).GetService <IVsEditorAdaptersFactoryService>().GetWpfTextView(view);
                _logger.Debug("Successfully created " + nameof(IWpfTextView));
                // IMPORTANT MOMENT: here we create ITextEdit object, which, in case of a failure,
                // may hang whole visual studio (thus, preventing from saving unsaved work,
                // see catch(InvalidOperationException)).
                edit = wpfTextView.TextBuffer.CreateEdit();
                _logger.Info($"Successfully executed {nameof(wpfTextView.TextBuffer.CreateEdit)} and created {nameof(ITextEdit)} object.");

                IVsHierarchy hierarchy  = null;
                string       csProjPath = null;

                var selection = wpfTextView.Selection;

                var startPosition = selection.Start.Position.Position;
                var endPosition   = selection.End.Position.Position;
                var span          = new Span(startPosition, endPosition - startPosition);

                var textToReplace = wpfTextView.TextBuffer.CurrentSnapshot.GetText(span).Trim(' ').Trim('"');

                var translationWindow = new AddTranslationWindow();
                var vm = new AddTranslationViewModel(new ProjectItemsFactory(_serviceProvider), translationWindow);
                translationWindow.DataContext = vm;

                translationWindow.ShowDialog();

                if (translationWindow.DialogResult != null && !translationWindow.DialogResult.Value)
                {
                    _logger.Info("Anulowano dodawanie tłumaczenia!");
                    return;
                }
#warning TO UNCOMMENT
                // edit.Replace(span, translationWindow.TranslationName);
                edit.Apply();
            }
            catch (InvalidOperationException ioe)
            {
                MessageBox.Show("This should not happen, but it happened. Please, do not click anything," +
                                " just save the file in order to not loose any work, then close the file.\nError:\n" + ioe);
                _logger.Fatal("Fatal exception during translation command..", ioe);
                if (ioe.InnerException != null)
                {
                    _logger.Fatal("Fatal inner exception.", ioe);
                }
                return;
            }
            catch (Exception ex)
            {
                MessageBox.Show($"The translation extension reported an exception:\n{ex}");
                _logger.Error("Exception during translation command.", ex);
                if (ex.InnerException != null)
                {
                    _logger.Info(ex.InnerException.ToString());
                }
                return;
            }
            finally
            {
                edit?.Dispose();
            }
        }