Ejemplo n.º 1
0
        public void ShowWPF()
        {
            try
            {
                if (scriptEditorThread is null || !scriptEditorThread.IsAlive)
                {
                    var           handler         = new ScriptRunnerHandler();
                    ExternalEvent externalEvent   = ExternalEvent.Create(handler);
                    var           assembliesToRef = new List <Assembly>
                    {
                        typeof(object).Assembly, //mscorlib
                        typeof(Autodesk.Revit.UI.UIApplication).Assembly,
                        typeof(Autodesk.Revit.DB.Document).Assembly,
                        Assembly.Load("RoslynPad.Roslyn.Windows"),
                        Assembly.Load("RoslynPad.Editor.Windows")
                    };

                    var namespaces = new List <string>
                    {
                        "Autodesk.Revit.UI",
                        "Autodesk.Revit.DB",
                        "Autodesk.Revit.DB.Structure",
                        "System",
                        "System.Collections.Generic",
                        "System.IO",
                        "System.Linq"
                    };

                    var roslynHost = new RevitRoslynHost(
                        additionalAssemblies: assembliesToRef,
                        references: RoslynHostReferences.NamespaceDefault.With(typeNamespaceImports: new[] { typeof(UIApplication), typeof(Autodesk.Revit.DB.Document), typeof(Dictionary <,>), typeof(System.Linq.Enumerable), typeof(ScriptGlobals) }),
                        disabledDiagnostics: ImmutableArray.Create("CS1701", "CS1702", "CS0518"));

                    var document = new RoslynEditorViewModel(roslynHost, externalEvent, handler);

                    scriptEditorThread = new Thread(new ThreadStart(() =>
                    {
                        SynchronizationContext.SetSynchronizationContext(
                            new DispatcherSynchronizationContext(
                                Dispatcher.CurrentDispatcher));

                        scriptEditor         = new RoslynEditor(document);
                        handler.Progress     = new Progress <string>(message => document.Result += message + Environment.NewLine);
                        scriptEditor.Closed += (s, e) => Dispatcher.CurrentDispatcher.InvokeShutdown();
                        scriptEditor.Show();
                        Dispatcher.Run();
                    }));

                    scriptEditorThread.SetApartmentState(ApartmentState.STA);
                    scriptEditorThread.IsBackground = true;
                    scriptEditorThread.Start();
                }
            }
            catch (Exception ex)
            {
                TaskDialog.Show("Error", ex.Message);
                //throw;
            }
        }
Ejemplo n.º 2
0
 private void OnRun()
 {
     Text = GetCode();
     RoslynEditorViewModel.Run(this);
 }
Ejemplo n.º 3
0
 private void OnClose()
 {
     RoslynEditorViewModel.Close(this);
 }
Ejemplo n.º 4
0
 private void OnSaveAs(object parameter)
 {
     Text = GetCode();
     RoslynEditorViewModel.Save(this, true);
 }
Ejemplo n.º 5
0
 public DocumentViewModel(RoslynEditorViewModel roslynEditorViewModel)
 {
     RoslynEditorViewModel = roslynEditorViewModel;
     IsDirty = true;
     Title   = FileName;
 }
Ejemplo n.º 6
0
 public DocumentViewModel(RoslynEditorViewModel roslynEditorViewModel, string FilePath)
 {
     RoslynEditorViewModel = roslynEditorViewModel;
     this.FilePath         = FilePath;
     Title = FileName;
 }
Ejemplo n.º 7
0
 public RoslynEditor(RoslynEditorViewModel document)
 {
     InitializeComponent();
     DataContext = document;
 }