Exemple #1
0
        static internal void Main(string[] args)
        {
            try
            {
                var cmdLineArgs = StartupUtils.CommandLineArguments.Parse(args);
                var locale      = Dynamo.Applications.StartupUtils.SetLocale(cmdLineArgs);
                var model       = Dynamo.Applications.StartupUtils.MakeModel(true);
                var runner      = new CommandLineRunner(model);
                runner.Run(cmdLineArgs);
            }
            catch (Exception e)
            {
                try
                {
                    DynamoModel.IsCrashing = true;
                    InstrumentationLogger.LogException(e);
                    StabilityTracking.GetInstance().NotifyCrash();
                }
                catch
                {
                }

                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
            }
        }
Exemple #2
0
        public static void Main(string[] args)
        {
            DynamoViewModel viewModel = null;

            try
            {
                var cmdLineArgs = CommandLineArguments.FromArguments(args);

                if (!string.IsNullOrEmpty(cmdLineArgs.Locale))
                {
                    // Change the application locale, if a locale information is supplied.
                    Thread.CurrentThread.CurrentUICulture = new CultureInfo(cmdLineArgs.Locale);
                    Thread.CurrentThread.CurrentCulture   = new CultureInfo(cmdLineArgs.Locale);
                }

                MakeStandaloneAndRun(cmdLineArgs.CommandFilePath, out viewModel);
            }
            catch (Exception e)
            {
                try
                {
#if DEBUG
                    // Display the recorded command XML when the crash happens,
                    // so that it maybe saved and re-run later
                    if (viewModel != null)
                    {
                        viewModel.SaveRecordedCommand.Execute(null);
                    }
#endif

                    DynamoModel.IsCrashing = true;
                    InstrumentationLogger.LogException(e);
                    StabilityTracking.GetInstance().NotifyCrash();

                    if (viewModel != null)
                    {
                        // Show the unhandled exception dialog so user can copy the
                        // crash details and report the crash if she chooses to.
                        viewModel.Model.OnRequestsCrashPrompt(null,
                                                              new CrashPromptArgs(e.Message + "\n\n" + e.StackTrace));

                        // Give user a chance to save (but does not allow cancellation)
                        viewModel.Exit(allowCancel: false);
                    }
                }
                catch
                {
                }

                Debug.WriteLine(e.Message);
                Debug.WriteLine(e.StackTrace);
            }
        }
Exemple #3
0
        public Result ExecuteCommand(DynamoRevitCommandData commandData)
        {
            HandleDebug(commandData);

            InitializeCore(commandData);

            try
            {
                extCommandData   = commandData;
                shouldShowUi     = CheckJournalForUiDisplay(extCommandData);
                isAutomationMode = CheckJournalForAutomationMode(extCommandData);

                UpdateSystemPathForProcess();

                // create core data models
                revitDynamoModel = InitializeCoreModel(extCommandData);
                dynamoViewModel  = InitializeCoreViewModel(revitDynamoModel);

                revitDynamoModel.Logger.Log("SYSTEM", string.Format("Environment Path:{0}", Environment.GetEnvironmentVariable("PATH")));

                // handle initialization steps after RevitDynamoModel is created.
                revitDynamoModel.HandlePostInitialization();

                // show the window
                if (shouldShowUi)
                {
                    InitializeCoreView().Show();
                }

                TryOpenAndExecuteWorkspace(extCommandData);

                // Disable the Dynamo button to prevent a re-run
                DynamoRevitApp.DynamoButtonEnabled = false;
            }
            catch (Exception ex)
            {
                // notify instrumentation
                InstrumentationLogger.LogException(ex);
                StabilityTracking.GetInstance().NotifyCrash();

                MessageBox.Show(ex.ToString());

                DynamoRevitApp.DynamoButtonEnabled = true;

                return(Result.Failed);
            }

            return(Result.Succeeded);
        }
Exemple #4
0
        public static void Main(string[] args)
        {
            DynamoViewModel viewModel = null;

            try
            {
                var cmdLineArgs = StartupUtils.CommandLineArguments.Parse(args);
                var locale      = Dynamo.Applications.StartupUtils.SetLocale(cmdLineArgs);
                _putenv(locale);

                MakeStandaloneAndRun(cmdLineArgs.CommandFilePath, out viewModel);
            }
            catch (Exception e)
            {
                try
                {
#if DEBUG
                    // Display the recorded command XML when the crash happens,
                    // so that it maybe saved and re-run later
                    if (viewModel != null)
                    {
                        viewModel.SaveRecordedCommand.Execute(null);
                    }
#endif

                    DynamoModel.IsCrashing = true;
                    InstrumentationLogger.LogException(e);
                    StabilityTracking.GetInstance().NotifyCrash();

                    if (viewModel != null)
                    {
                        // Show the unhandled exception dialog so user can copy the
                        // crash details and report the crash if she chooses to.
                        viewModel.Model.OnRequestsCrashPrompt(null,
                                                              new CrashPromptArgs(e.Message + "\n\n" + e.StackTrace));

                        // Give user a chance to save (but does not allow cancellation)
                        viewModel.Exit(allowCancel: false);
                    }
                }
                catch
                {
                }

                Debug.WriteLine(e.Message);
                Debug.WriteLine(e.StackTrace);
            }
        }
Exemple #5
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            HandleDebug(commandData);

            InitializeCore(commandData);

            try
            {
#if ENABLE_DYNAMO_SCHEDULER
                extCommandData = commandData;
                commandData.Application.Idling += OnRevitIdleOnce;
#else
                IdlePromise.ExecuteOnIdleAsync(
                    delegate
                {
                    // create core data models
                    revitDynamoModel = InitializeCoreModel(commandData);
                    dynamoViewModel  = InitializeCoreViewModel(revitDynamoModel);

                    // show the window
                    InitializeCoreView().Show();

                    TryOpenWorkspaceInCommandData(commandData);
                    SubscribeViewActivating(commandData);
                });
#endif
                // Disable the Dynamo button to prevent a re-run
                DynamoRevitApp.DynamoButton.Enabled = false;
            }
            catch (Exception ex)
            {
                // notify instrumentation
                InstrumentationLogger.LogException(ex);
                StabilityTracking.GetInstance().NotifyCrash();

                MessageBox.Show(ex.ToString());

                DynamoRevitApp.DynamoButton.Enabled = true;

                return(Result.Failed);
            }

            return(Result.Succeeded);
        }
Exemple #6
0
        /// <summary>
        ///     A method to deal with unhandle exceptions.  Executes right before Revit crashes.
        ///     Dynamo is still valid at this time, but further work may cause corruption.  Here,
        ///     we run the ExitCommand, allowing the user to save all of their work.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args">Info about the exception</param>
        private static void Dispatcher_UnhandledException(
            object sender, DispatcherUnhandledExceptionEventArgs args)
        {
            args.Handled = true;

            // only handle a single crash per Dynamo sesh, this should be reset in the initial command
            if (handledCrash)
            {
                return;
            }

            handledCrash = true;

            string exceptionMessage = args.Exception.Message;

            try
            {
                InstrumentationLogger.LogException(args.Exception);
                StabilityTracking.GetInstance().NotifyCrash();

                revitDynamoModel.Logger.LogError("Dynamo Unhandled Exception");
                revitDynamoModel.Logger.LogError(exceptionMessage);
            }
            catch { }

            try
            {
                DynamoModel.IsCrashing = true;
                revitDynamoModel.OnRequestsCrashPrompt(
                    revitDynamoModel,
                    new CrashPromptArgs(args.Exception.Message + "\n\n" + args.Exception.StackTrace));
                dynamoViewModel.Exit(false); // don't allow cancellation
            }
            catch { }
            finally
            {
                args.Handled = true;

                // KILLDYNSETTINGS - this is suspect
                revitDynamoModel.Logger.Dispose();
                DynamoRevitApp.DynamoButton.Enabled = true;
            }
        }
Exemple #7
0
        public CrashPrompt(CrashPromptArgs args, DynamoViewModel dynamoViewModel)
        {
            InitializeComponent();

            productName            = dynamoViewModel.BrandingResourceProvider.ProductName;
            Title                  = string.Format(Wpf.Properties.Resources.CrashPromptDialogTitle, productName);
            txtOverridingText.Text = string.Format(Wpf.Properties.Resources.CrashPromptDialogCrashMessage, productName);

            InstrumentationLogger.LogAnonymousEvent("CrashPrompt", "Stability");
            StabilityTracking.GetInstance().NotifyCrash();

            if (args.HasDetails())
            {
                this.details = args.Details;
                this.CrashDetailsContent.Text = args.Details;
                this.btnDetails.Visibility    = Visibility.Visible;

                InstrumentationLogger.LogPiiInfo("CrashPrompt", args.Details);
            }
            else
            {
                InstrumentationLogger.LogPiiInfo("CrashPrompt", args.Details);
            }

            if (args.IsFilePath())
            {
                folderPath = Path.GetDirectoryName(args.FilePath);
                btnOpenFolder.Visibility = Visibility.Visible;
            }

            if (args.IsDefaultTextOverridden())
            {
                string overridingText = args.OverridingText;

                if (args.IsFilePath())
                {
                    overridingText = overridingText.Replace("[FILEPATH]", args.FilePath);
                }

                ConvertFormattedTextIntoTextblock(this.txtOverridingText, overridingText);
            }
        }
Exemple #8
0
        public CrashPrompt(CrashPromptArgs args)
        {
            InitializeComponent();

            InstrumentationLogger.LogAnonymousEvent("CrashPrompt", "Stability");
            StabilityTracking.GetInstance().NotifyCrash();

            if (args.HasDetails())
            {
                this.details = args.Details;
                this.CrashDetailsContent.Text = args.Details;
                this.btnDetails.Visibility    = Visibility.Visible;

                InstrumentationLogger.LogPiiInfo("CrashPrompt", args.Details);
            }
            else
            {
                InstrumentationLogger.LogPiiInfo("CrashPrompt", args.Details);
            }

            if (args.IsFilePath())
            {
                folderPath = Path.GetDirectoryName(args.FilePath);
                btnOpenFolder.Visibility = Visibility.Visible;
            }

            if (args.IsDefaultTextOverridden())
            {
                string overridingText = args.OverridingText;

                if (args.IsFilePath())
                {
                    overridingText = overridingText.Replace("[FILEPATH]", args.FilePath);
                }

                ConvertFormattedTextIntoTextblock(this.txtOverridingText, overridingText);
            }
        }
Exemple #9
0
        public static void Main(string[] args)
        {
            DynamoViewModel viewModel = null;

            try
            {
                var cmdLineArgs     = CommandLineArguments.FromArguments(args);
                var supportedLocale = new HashSet <string>(new[]
                {
                    "cs-CZ", "de-DE", "en-US", "es-ES", "fr-FR", "it-IT",
                    "ja-JP", "ko-KR", "pl-PL", "pt-BR", "ru-RU", "zh-CN", "zh-TW"
                });
                string libgLocale;

                if (!string.IsNullOrEmpty(cmdLineArgs.Locale))
                {
                    // Change the application locale, if a locale information is supplied.
                    Thread.CurrentThread.CurrentUICulture = new CultureInfo(cmdLineArgs.Locale);
                    Thread.CurrentThread.CurrentCulture   = new CultureInfo(cmdLineArgs.Locale);
                    libgLocale = cmdLineArgs.Locale;
                }
                else
                {
                    // In case no language is specified, libG's locale should be that of the OS.
                    // There is no need to set Dynamo's locale in this case.
                    libgLocale = CultureInfo.InstalledUICulture.ToString();
                }

                // If locale is not supported by Dynamo, default to en-US.
                if (!supportedLocale.Any(s => s.Equals(libgLocale, StringComparison.InvariantCultureIgnoreCase)))
                {
                    libgLocale = "en-US";
                }

                // Change the locale that LibG depends on.
                StringBuilder sb = new StringBuilder("LANGUAGE=");
                sb.Append(libgLocale.Replace("-", "_"));
                _putenv(sb.ToString());

                MakeStandaloneAndRun(cmdLineArgs.CommandFilePath, out viewModel);
            }
            catch (Exception e)
            {
                try
                {
#if DEBUG
                    // Display the recorded command XML when the crash happens,
                    // so that it maybe saved and re-run later
                    if (viewModel != null)
                    {
                        viewModel.SaveRecordedCommand.Execute(null);
                    }
#endif

                    DynamoModel.IsCrashing = true;
                    InstrumentationLogger.LogException(e);
                    StabilityTracking.GetInstance().NotifyCrash();

                    if (viewModel != null)
                    {
                        // Show the unhandled exception dialog so user can copy the
                        // crash details and report the crash if she chooses to.
                        viewModel.Model.OnRequestsCrashPrompt(null,
                                                              new CrashPromptArgs(e.Message + "\n\n" + e.StackTrace));

                        // Give user a chance to save (but does not allow cancellation)
                        viewModel.Exit(allowCancel: false);
                    }
                }
                catch
                {
                }

                Debug.WriteLine(e.Message);
                Debug.WriteLine(e.StackTrace);
            }
        }
Exemple #10
0
        public static void Main(string[] args)
        {
            DynamoViewModel viewModel = null;

            try
            {
                // Running Dynamo sandbox with a command file:
                // DynamoSandbox.exe /c "C:\file path\file.xml"
                //
                string commandFilePath = string.Empty;
                for (int i = 0; i < args.Length; ++i)
                {
                    // Looking for '/c'
                    string arg = args[i];
                    if (arg.Length != 2 || (arg[0] != '/'))
                    {
                        continue;
                    }

                    if (arg[1] == 'c' || (arg[1] == 'C'))
                    {
                        // If there's at least one more argument...
                        if (i < args.Length - 1)
                        {
                            commandFilePath = args[i + 1];
                        }
                    }
                }

                MakeStandaloneAndRun(commandFilePath, ref viewModel);
            }
            catch (Exception e)
            {
                try
                {
#if DEBUG
                    // Display the recorded command XML when the crash happens,
                    // so that it maybe saved and re-run later
                    if (viewModel != null)
                    {
                        viewModel.SaveRecordedCommand.Execute(null);
                    }
#endif

                    DynamoModel.IsCrashing = true;
                    InstrumentationLogger.LogException(e);
                    StabilityTracking.GetInstance().NotifyCrash();

                    if (viewModel != null)
                    {
                        // Show the unhandled exception dialog so user can copy the
                        // crash details and report the crash if she chooses to.
                        viewModel.Model.OnRequestsCrashPrompt(null,
                                                              new CrashPromptArgs(e.Message + "\n\n" + e.StackTrace));

                        // Give user a chance to save (but does not allow cancellation)
                        viewModel.Exit(allowCancel: false);
                    }
                }
                catch
                {
                }

                Debug.WriteLine(e.Message);
                Debug.WriteLine(e.StackTrace);
            }
        }
Exemple #11
0
        public void RunApplication(Application app)
        {
            try
            {
                DynamoModel.RequestMigrationStatusDialog += MigrationStatusDialogRequested;

                var model = Dynamo.Applications.StartupUtils.MakeModel(false);

                viewModel = DynamoViewModel.Start(
                    new DynamoViewModel.StartConfiguration()
                {
                    CommandFilePath  = commandFilePath,
                    DynamoModel      = model,
                    Watch3DViewModel = HelixWatch3DViewModel.TryCreateHelixWatch3DViewModel(new Watch3DViewModelStartupParams(model), model.Logger),
                    ShowLogin        = true
                });

                var view = new DynamoView(viewModel);
                view.Loaded += (sender, args) => CloseMigrationWindow();

                app.Run(view);

                DynamoModel.RequestMigrationStatusDialog -= MigrationStatusDialogRequested;
            }

            catch (Exception e)
            {
                try
                {
#if DEBUG
                    // Display the recorded command XML when the crash happens,
                    // so that it maybe saved and re-run later
                    if (viewModel != null)
                    {
                        viewModel.SaveRecordedCommand.Execute(null);
                    }
#endif

                    DynamoModel.IsCrashing = true;
                    InstrumentationLogger.LogException(e);
                    StabilityTracking.GetInstance().NotifyCrash();

                    if (viewModel != null)
                    {
                        // Show the unhandled exception dialog so user can copy the
                        // crash details and report the crash if she chooses to.
                        viewModel.Model.OnRequestsCrashPrompt(null,
                                                              new CrashPromptArgs(e.Message + "\n\n" + e.StackTrace));

                        // Give user a chance to save (but does not allow cancellation)
                        viewModel.Exit(allowCancel: false);
                    }
                }
                catch
                {
                }

                Debug.WriteLine(e.Message);
                Debug.WriteLine(e.StackTrace);
            }
        }