示例#1
0
#pragma warning disable VSTHRD100 // Avoid async void methods - ok as an event handler
        private async void Execute(object sender, EventArgs e)
#pragma warning restore VSTHRD100 // Avoid async void methods
        {
            System.Windows.Forms.Cursor previousCursor = System.Windows.Forms.Cursor.Current;
            System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;

            try
            {
                await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

                this.Logger?.RecordFeatureUsage(nameof(AnalyzeCurrentDocumentCommand));

                var dte = await Instance.AsyncPackage.GetServiceAsync <DTE, DTE>();

                var vs = new VisualStudioAbstraction(this.Logger, this.AsyncPackage, dte);

                var filePath = vs.GetActiveDocumentFilePath();

                // Ensure that the open document has been saved so get latest version
                var rdt = new RunningDocumentTable(Package);
                rdt.SaveFileIfDirty(filePath);

                RapidXamlDocumentCache.Invalidate(filePath);
                RapidXamlDocumentCache.TryUpdate(filePath);
            }
            catch (Exception exc)
            {
                this.Logger?.RecordException(exc);
            }
            finally
            {
                System.Windows.Forms.Cursor.Current = previousCursor;
            }
        }
示例#2
0
        public static void SaveFile(this ITextView textView)
        {
            RunningDocumentTable rdt = new RunningDocumentTable(RPackage.Current);
            string filePath          = textView.TextBuffer.GetFilePath();

            rdt.SaveFileIfDirty(filePath);
        }
示例#3
0
        public void EnsureDiagramIsCreated(EFArtifact artifact)
        {
            if (RootElement != null)
            {
                var modelRoot = RootElement as EntityDesignerViewModel;
                if (modelRoot != null)
                {
                    var diagram = modelRoot.GetDiagram();
                    Debug.Assert(diagram != null, "DSL Diagram should have been created by now");

                    if (diagram != null)
                    {
                        Debug.Assert(artifact.DesignerInfo() != null, "artifact.DesignerInfo should not be null");
                        Debug.Assert(artifact.DesignerInfo().Diagrams != null, "artifact.DesignerInfo.Diagrams should not be null");

                        if (artifact.DesignerInfo() != null &&
                            artifact.DesignerInfo().Diagrams != null)
                        {
                            var saveDiagramDocument = false;

                            if (artifact.DesignerInfo().Diagrams.FirstDiagram == null)
                            {
                                // layout is very slow.  Only auto-layout if less than a max number of types
                                if (diagram.ModelElement.EntityTypes.Count < EntityDesignerDiagram.IMPLICIT_AUTO_LAYOUT_CEILING)
                                {
                                    diagram.AutoLayoutDiagram();
                                }

                                try
                                {
                                    EntityDesignerViewModel.RespondToModelChanges = false;
                                    EntityModelToDslModelTranslatorStrategy.CreateDefaultDiagram(modelRoot.EditingContext, diagram);

                                    // Ensure that DSL Diagram and Model Diagram are in sync:
                                    // - Update xref between 2 diagrams
                                    // - Propagetes model diagram info to DSL Diagram.
                                    var modelDiagram = artifact.DesignerInfo().Diagrams.FirstDiagram;
                                    Debug.Assert(modelDiagram != null, "modelDiagram should not be null");
                                    if (modelDiagram != null)
                                    {
                                        ModelTranslatorContextItem.GetEntityModelTranslator(EditingContext)
                                        .SynchronizeSingleDslModelElement(modelRoot, modelDiagram);
                                    }
                                }
                                finally
                                {
                                    EntityDesignerViewModel.RespondToModelChanges = true;
                                }

                                // save the file after adding Diagram element so it won't open as a dirty document
                                saveDiagramDocument = true;
                            }

                            if (saveDiagramDocument)
                            {
                                var rdt = new RunningDocumentTable(ServiceProvider);
                                rdt.SaveFileIfDirty(FileName);
                            }

                            _isDiagramLoaded = true;
                        }
                    }
                }
            }
        }
示例#4
0
#pragma warning disable VSTHRD100 // Avoid async void methods - Allowed as called from event handler.
        private async void Execute(object sender, EventArgs e)
#pragma warning restore VSTHRD100 // Avoid async void methods
        {
            System.Windows.Forms.Cursor previousCursor = System.Windows.Forms.Cursor.Current;
            System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;

            try
            {
                await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

                this.Logger?.RecordFeatureUsage(nameof(MoveAllHardCodedStringsToResourceFileCommand));

                var dte = await Instance.AsyncPackage.GetServiceAsync <DTE, DTE>();

                var vs = new VisualStudioAbstraction(this.Logger, this.AsyncPackage, dte);

                var filePath = vs.GetActiveDocumentFilePath();

                // Ensure that the open document has been saved or modifications may go wrong
                var rdt = new RunningDocumentTable(Package);
                rdt.SaveFileIfDirty(filePath);

                // Do this as don't have direct snapshot access and want any changes to be processed before making changes
                RapidXamlDocumentCache.TryUpdate(filePath);

                var tags = RapidXamlDocumentCache.ErrorListTags(filePath)
                           .OfType <HardCodedStringTag>()
                           .OrderByDescending(t => t.Span.Start);

                var referenceUids = new Dictionary <Guid, string>();

                vs.StartSingleUndoOperation(StringRes.UI_UndoContextMoveStringsToResourceFile);

                try
                {
                    foreach (var tag in tags)
                    {
                        if (!tag.UidExists && referenceUids.ContainsKey(tag.ElementGuid))
                        {
                            tag.UidExists = true;
                            tag.UidValue  = referenceUids[tag.ElementGuid];
                        }

                        // pass in vs so have the same reference for tracking undo actions
                        var action = new HardCodedStringAction(filePath, null, tag, vs);
                        action.Execute(new CancellationTokenSource().Token);

                        if (tag.UidExists == false && tag.ElementGuid != Guid.Empty && !referenceUids.ContainsKey(tag.ElementGuid))
                        {
                            referenceUids.Add(tag.ElementGuid, tag.UidValue);
                        }
                    }
                }
                finally
                {
                    vs.EndSingleUndoOperation();
                }

                // Update again to force reflecting the changes that were just made.
                RapidXamlDocumentCache.TryUpdate(filePath);
            }
            catch (Exception exc)
            {
                this.Logger?.RecordException(exc);
                throw;
            }
            finally
            {
                System.Windows.Forms.Cursor.Current = previousCursor;
            }
        }
        public void EnsureDiagramIsCreated(EFArtifact artifact)
        {
            if (RootElement != null)
            {
                var modelRoot = RootElement as EntityDesignerViewModel;
                if (modelRoot != null)
                {
                    var diagram = modelRoot.GetDiagram();
                    Debug.Assert(diagram != null, "DSL Diagram should have been created by now");

                    if (diagram != null)
                    {
                        Debug.Assert(artifact.DesignerInfo() != null, "artifact.DesignerInfo should not be null");
                        Debug.Assert(artifact.DesignerInfo().Diagrams != null, "artifact.DesignerInfo.Diagrams should not be null");

                        if (artifact.DesignerInfo() != null
                            && artifact.DesignerInfo().Diagrams != null)
                        {
                            var saveDiagramDocument = false;

                            if (artifact.DesignerInfo().Diagrams.FirstDiagram == null)
                            {
                                // layout is very slow.  Only auto-layout if less than a max number of types
                                if (diagram.ModelElement.EntityTypes.Count < EntityDesignerDiagram.IMPLICIT_AUTO_LAYOUT_CEILING)
                                {
                                    diagram.AutoLayoutDiagram();
                                }

                                try
                                {
                                    EntityDesignerViewModel.RespondToModelChanges = false;
                                    EntityModelToDslModelTranslatorStrategy.CreateDefaultDiagram(modelRoot.EditingContext, diagram);

                                    // Ensure that DSL Diagram and Model Diagram are in sync:
                                    // - Update xref between 2 diagrams
                                    // - Propagetes model diagram info to DSL Diagram.
                                    var modelDiagram = artifact.DesignerInfo().Diagrams.FirstDiagram;
                                    Debug.Assert(modelDiagram != null, "modelDiagram should not be null");
                                    if (modelDiagram != null)
                                    {
                                        ModelTranslatorContextItem.GetEntityModelTranslator(EditingContext)
                                            .SynchronizeSingleDslModelElement(modelRoot, modelDiagram);
                                    }
                                }
                                finally
                                {
                                    EntityDesignerViewModel.RespondToModelChanges = true;
                                }

                                // save the file after adding Diagram element so it won't open as a dirty document
                                saveDiagramDocument = true;
                            }

                            if (saveDiagramDocument)
                            {
                                var rdt = new RunningDocumentTable(ServiceProvider);
                                rdt.SaveFileIfDirty(FileName);
                            }

                            _isDiagramLoaded = true;
                        }
                    }
                }
            }
        }