Esempio n. 1
0
        private void OnItemContextMenuInvokeHandler(object sender, EventArgs e)
        {
            try
            {
                var menuCommand = sender as MenuCommand;

                if (menuCommand == null)
                {
                    return;
                }

                if (menuCommand.CommandID.ID == PkgCmdIDList.cmdidEdmMenuAbout)
                {
                    _aboutHandler.ShowDialog();
                    return;
                }

                if (_dte2.SelectedItems.Count != 1)
                {
                    return;
                }

                try
                {
                    Type systemContextType;
                    var  context = DiscoverUserContextType(out systemContextType);

                    if (context != null)
                    {
                        if (menuCommand.CommandID.ID == PkgCmdIDList.cmdidDebugView)
                        {
                            _modelAnalyzerHandler.GenerateDebugView(context);
                        }
                        else if (menuCommand.CommandID.ID == PkgCmdIDList.cmdidDgmlView)
                        {
                            _modelAnalyzerHandler.GenerateDgml(context);
                        }
                    }
                }
                catch (TargetInvocationException ex)
                {
                    var innerException = ex.InnerException;

                    var remoteStackTraceString =
                        typeof(Exception).GetField("_remoteStackTraceString", BindingFlags.Instance | BindingFlags.NonPublic)
                        ?? typeof(Exception).GetField("remote_stack_trace", BindingFlags.Instance | BindingFlags.NonPublic);
                    remoteStackTraceString.SetValue(innerException, innerException.StackTrace + "$$RethrowMarker$$");

                    EnvDteHelper.ShowMessage("An error occurred: " + Environment.NewLine + innerException.ToString());
                }
            }
            catch (Exception ex)
            {
                EnvDteHelper.ShowMessage("An error occurred: " + Environment.NewLine + ex.ToString());
            }
        }
        private void OnProjectContextMenuInvokeHandler(object sender, EventArgs e)
        {
            var menuCommand = sender as MenuCommand;

            if (menuCommand == null || _dte2.SelectedItems.Count != 1)
            {
                return;
            }

            var project = _dte2.SelectedItems.Item(1).Project;

            if (project == null)
            {
                return;
            }

            if (menuCommand.CommandID.ID == PkgCmdIDList.cmdidReverseEngineerCodeFirst)
            {
                _reverseEngineerHandler.ReverseEngineerCodeFirst(project);
            }
            else if (menuCommand.CommandID.ID == PkgCmdIDList.cmdidReverseEngineerDgml)
            {
                _reverseEngineerHandler.GenerateServerDgmlFiles();
            }
            else if (menuCommand.CommandID.ID == PkgCmdIDList.cmdidDgmlNuget)
            {
                _modelAnalyzerHandler.InstallDgmlNuget(project);
            }
            else if (menuCommand.CommandID.ID == PkgCmdIDList.cmdidDgmlBuild)
            {
                var path = LocateProjectAssemblyPath(project);
                if (path != null)
                {
                    _modelAnalyzerHandler.GenerateDgml(path, project);
                }
            }
            else if (menuCommand.CommandID.ID == PkgCmdIDList.cmdidAbout)
            {
                _aboutHandler.ShowDialog();
            }
        }