Ejemplo n.º 1
0
        private void CreateNewFileDialog()
        {
            var dialog = new NewFileDialog {
                IsVisible = true
            };

            _imGuiManager.AddElement(dialog);

            dialog.CreateFileRequested += (sender, args) =>
            {
                try
                {
                    _scriptManager.CreateNewScript(dialog.FileName?.Trim(), dialog.SelectedLanguage);
                }
                catch (InvalidOperationException exception)
                {
                    dialog.ErrorText = exception.Message;
                    return;
                }
                catch (Exception exception)
                {
                    dialog.ErrorText = $"Exception: {exception}";
                    return;
                }

                _imGuiManager.RemoveElement(dialog);
                SettingsIo.Save(_appSettings);
                _onScreenLogger.Clear();
            };

            dialog.PropertyChanged += (sender, args) =>
            {
                switch (args.PropertyName)
                {
                case nameof(NewFileDialog.CloseRequested):
                    _imGuiManager.RemoveElement(dialog);
                    break;
                }
            };
        }
Ejemplo n.º 2
0
        public GraphedItems CheckForNewGraphedItems()
        {
            if (_lastScriptChangedEventFiredAt > _lastProcessedScriptChangedEvent)
            {
                // Only actually read the latest script file contents after a period of time since the
                // last change event fired.  This prevents reading while it's still being written, and should
                // help with file lock contention.
                var lastFiredAtTicks = _lastScriptChangedEventFiredAt;
                var lastFiredAt      = new DateTime(lastFiredAtTicks);
                if ((DateTime.Now - lastFiredAt).TotalMilliseconds > 200)
                {
                    var contents = TryLoadFileContents();
                    if (contents != null)
                    {
                        Interlocked.Exchange(ref _lastProcessedScriptChangedEvent, lastFiredAtTicks);

                        try
                        {
                            _onScreenLogger.Clear();
                            return(_scriptRunner.RunScript(contents));
                        }
                        catch (ScriptException exception)
                        {
                            var content = "Failed to run script:\n\n";

                            if (exception.ShowStackTrace)
                            {
                                // ReSharper disable once PossibleNullReferenceException
                                content += exception.InnerException.ToString();
                            }
                            else
                            {
                                // ReSharper disable once PossibleNullReferenceException
                                content += $"{exception.Message}: {exception.InnerException.Message}";
                            }

                            _onScreenLogger.LogMessage(content);
                        }
                        catch (PointConversionException exception)
                        {
                            _onScreenLogger.LogMessage(exception.Message);
                        }
                        catch (Exception exception)
                        {
                            _onScreenLogger.LogMessage($"Failed to run script:\n\n{exception}");
                        }
                    }
                }
            }

            return(null);
        }