Skip to content

Commit

Permalink
Revit/misc (#1567)
Browse files Browse the repository at this point in the history
* fix: updates some old manager links and paths

* feat: check for updates against the new endpoint

* feat(revit): adds some safity guards & herror handling
  • Loading branch information
teocomi authored Aug 31, 2022
1 parent ed0f457 commit 721edab
Show file tree
Hide file tree
Showing 4 changed files with 179 additions and 122 deletions.
43 changes: 27 additions & 16 deletions ConnectorRevit/ConnectorRevit/Entry/OneClickSendCommand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading;
using Autodesk.Revit.Attributes;
Expand All @@ -9,6 +10,7 @@
using DesktopUI2.ViewModels;
using DesktopUI2.Views;
using Speckle.ConnectorRevit.UI;
using Speckle.Core.Logging;

namespace Speckle.ConnectorRevit.Entry
{
Expand Down Expand Up @@ -45,26 +47,24 @@ public Result Execute(ExternalCommandData commandData, ref string message, Eleme
public static void CreateOrFocusSpeckle(bool showWindow = true)
{


if (MainWindow == null)
try
{
var viewModel = new MainViewModel(Bindings);
MainWindow = new MainWindow
if (MainWindow == null)
{
DataContext = viewModel
};

//massive hack: we start the avalonia main loop and stop it immediately (since it's thread blocking)
//to avoid an annoying error when closing revit
var cts = new CancellationTokenSource();
cts.CancelAfter(100);
AvaloniaApp.Run(cts.Token);

var viewModel = new MainViewModel(Bindings);
MainWindow = new MainWindow
{
DataContext = viewModel
};

//massive hack: we start the avalonia main loop and stop it immediately (since it's thread blocking)
//to avoid an annoying error when closing revit
var cts = new CancellationTokenSource();
cts.CancelAfter(100);
AvaloniaApp.Run(cts.Token);
}

}

try
{
if (showWindow)
{
MainWindow.Show();
Expand All @@ -85,6 +85,17 @@ public static void CreateOrFocusSpeckle(bool showWindow = true)
}
catch (Exception ex)
{
Log.CaptureException(ex, Sentry.SentryLevel.Error);
var td = new TaskDialog("Error");
td.MainContent = $"Oh no! Something went wrong while loading Speckle, please report it on the forum:\n{ex.Message}";
td.AddCommandLink(TaskDialogCommandLinkId.CommandLink1, "Report issue on our Community Forum");

TaskDialogResult tResult = td.Show();

if (TaskDialogResult.CommandLink1 == tResult)
{
Process.Start("https://speckle.community/");
}
}
}

Expand Down
129 changes: 79 additions & 50 deletions ConnectorRevit/ConnectorRevit/Entry/SpeckleRevitCommand2.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading;
using Autodesk.Revit.Attributes;
Expand Down Expand Up @@ -76,75 +77,92 @@ public Result Execute(ExternalCommandData commandData, ref string message, Eleme

internal static void RegisterPane()
{
if (!UseDockablePanel)
return;
try
{
if (!UseDockablePanel)
return;

var registered = DockablePane.PaneIsRegistered(PanelId);
var created = DockablePane.PaneExists(PanelId);
var registered = DockablePane.PaneIsRegistered(PanelId);
var created = DockablePane.PaneExists(PanelId);

if (registered && created)
{
_panel.Init();
return;
}
if (registered && created)
{
_panel.Init();
return;
}

if (!registered)
{
//Register dockable panel
var viewModel = new MainViewModel(Bindings);
_panel = new Panel
if (!registered)
{
DataContext = viewModel
};
App.AppInstance.RegisterDockablePane(PanelId, "Speckle", _panel);
_panel.Init();
}
created = DockablePane.PaneExists(PanelId);
//Register dockable panel
var viewModel = new MainViewModel(Bindings);
_panel = new Panel
{
DataContext = viewModel
};
App.AppInstance.RegisterDockablePane(PanelId, "Speckle", _panel);
_panel.Init();
}
created = DockablePane.PaneExists(PanelId);

//if revit was launched double-clicking on a Revit file, we're screwed
//could maybe show the old window?
if (!created && App.AppInstance.Application.Documents.Size > 0)
{
TaskDialog mainDialog = new TaskDialog("Dockable Panel Issue");
mainDialog.MainInstruction = "Dockable Panel Issue";
mainDialog.MainContent =
"Revit cannot properly register Dockable Panels when launched by double-clicking a Revit file. "
+ "Please close and re-open Revit without launching a file OR open/create a new project to trigger the Speckle panel registration.";

//if revit was launched double-clicking on a Revit file, we're screwed
//could maybe show the old window?
if (!created && App.AppInstance.Application.Documents.Size > 0)
{
TaskDialog mainDialog = new TaskDialog("Dockable Panel Issue");
mainDialog.MainInstruction = "Dockable Panel Issue";
mainDialog.MainContent =
"Revit cannot properly register Dockable Panels when launched by double-clicking a Revit file. "
+ "Please close and re-open Revit without launching a file OR open/create a new project to trigger the Speckle panel registration.";

// Set footer text. Footer text is usually used to link to the help document.
mainDialog.FooterText =
"<a href=\"https://github.com/specklesystems/speckle-sharp/issues/1469 \">"
+ "Click here for more info</a>";

// Set footer text. Footer text is usually used to link to the help document.
mainDialog.FooterText =
"<a href=\"https://github.com/specklesystems/speckle-sharp/issues/1469 \">"
+ "Click here for more info</a>";
mainDialog.Show();

}
}
catch (Exception ex)
{
Log.CaptureException(ex, Sentry.SentryLevel.Error);
var td = new TaskDialog("Error");
td.MainContent = $"Oh no! Something went wrong while loading Speckle, please report it on the forum:\n{ex.Message}";
td.AddCommandLink(TaskDialogCommandLinkId.CommandLink1, "Report issue on our Community Forum");

mainDialog.Show();
TaskDialogResult tResult = td.Show();

if (TaskDialogResult.CommandLink1 == tResult)
{
Process.Start("https://speckle.community/");
}
}

}

public static void CreateOrFocusSpeckle(bool showWindow = true)
{


if (MainWindow == null)
try
{
var viewModel = new MainViewModel(Bindings);
MainWindow = new MainWindow

if (MainWindow == null)
{
DataContext = viewModel
};
var viewModel = new MainViewModel(Bindings);
MainWindow = new MainWindow
{
DataContext = viewModel
};

//massive hack: we start the avalonia main loop and stop it immediately (since it's thread blocking)
//to avoid an annoying error when closing revit
var cts = new CancellationTokenSource();
cts.CancelAfter(100);
AvaloniaApp.Run(cts.Token);
//massive hack: we start the avalonia main loop and stop it immediately (since it's thread blocking)
//to avoid an annoying error when closing revit
var cts = new CancellationTokenSource();
cts.CancelAfter(100);
AvaloniaApp.Run(cts.Token);

}

}

try
{
if (showWindow)
{
MainWindow.Show();
Expand All @@ -165,6 +183,17 @@ public static void CreateOrFocusSpeckle(bool showWindow = true)
}
catch (Exception ex)
{
Log.CaptureException(ex, Sentry.SentryLevel.Error);
var td = new TaskDialog("Error");
td.MainContent = $"Oh no! Something went wrong while loading Speckle, please report it on the forum:\n{ex.Message}";
td.AddCommandLink(TaskDialogCommandLinkId.CommandLink1, "Report issue on our Community Forum");

TaskDialogResult tResult = td.Show();

if (TaskDialogResult.CommandLink1 == tResult)
{
Process.Start("https://speckle.community/");
}
}
}

Expand Down
113 changes: 66 additions & 47 deletions Core/Core/Logging/Log.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,73 +17,92 @@ public static class Log

public static void Initialize()
{
if (_initialized)
return;
try
{
if (_initialized)
return;

var dsn = "https://[email protected]/5396846";
var dsn = "https://[email protected]/5396846";

var env = "production";
var debug = false;
var env = "production";
var debug = false;
#if DEBUG
env = "dev";
dsn = null;
debug = true;
env = "dev";
dsn = null;
debug = true;
#endif

SentrySdk.Init(o =>
{
o.Dsn = dsn;
o.Environment = env;
o.Debug = debug;
o.Release = "SpeckleCore@" + Assembly.GetExecutingAssembly().GetName().Version.ToString();
o.StackTraceMode = StackTraceMode.Enhanced;
o.AttachStacktrace = true;
});
SentrySdk.Init(o =>
{
o.Dsn = dsn;
o.Environment = env;
o.Debug = debug;
o.Release = "SpeckleCore@" + Assembly.GetExecutingAssembly().GetName().Version.ToString();
o.StackTraceMode = StackTraceMode.Enhanced;
o.AttachStacktrace = true;
});


var da = AccountManager.GetDefaultAccount();
var id = da != null ? da.GetHashedEmail() : "unknown";
var da = AccountManager.GetDefaultAccount();
var id = da != null ? da.GetHashedEmail() : "unknown";


SentrySdk.ConfigureScope(scope =>
{
scope.User = new User { Id = id, };
scope.SetTag("hostApplication", Setup.HostApplication);
});
SentrySdk.ConfigureScope(scope =>
{
scope.User = new User { Id = id, };
scope.SetTag("hostApplication", Setup.HostApplication);
});

_initialized = true;
_initialized = true;
}
catch (Exception ex)
{
//swallow
}
}


//capture and make sure Sentry is initialized
public static void CaptureException(
Exception e,
SentryLevel level = SentryLevel.Info,
List<KeyValuePair<string, object>> extra = null)
public static void CaptureException(Exception e, SentryLevel level = SentryLevel.Info, List<KeyValuePair<string, object>> extra = null)
{
Initialize();

//ignore infos as they're hogging us
if (level == SentryLevel.Info)
return;

SentrySdk.WithScope(s =>
try
{
Initialize();

//ignore infos as they're hogging us
if (level == SentryLevel.Info)
return;

SentrySdk.WithScope(s =>
{
s.Level = level;

if (extra != null)
s.SetExtras(extra);
if (e is AggregateException aggregate)
aggregate.InnerExceptions.ToList().ForEach(ex => SentrySdk.CaptureException(e));
else
SentrySdk.CaptureException(e);
});

}
catch (Exception ex)
{
s.Level = level;

if (extra != null)
s.SetExtras(extra);
if (e is AggregateException aggregate)
aggregate.InnerExceptions.ToList().ForEach(ex => SentrySdk.CaptureException(e));
else
SentrySdk.CaptureException(e);
});
//swallow
}
}

public static void AddBreadcrumb(string message)
{
Initialize();
SentrySdk.AddBreadcrumb(message);
try
{
Initialize();
SentrySdk.AddBreadcrumb(message);
}
catch (Exception ex)
{
//swallow
}
}
}
}
Loading

0 comments on commit 721edab

Please sign in to comment.