-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SetImage works with
Resources
without assembly name.
- Loading branch information
Showing
10 changed files
with
179 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using Autodesk.Revit.UI; | ||
|
||
namespace ricaun.Revit.UI.Example.Revit | ||
{ | ||
[AppLoader] | ||
public class AppResource : IExternalApplication | ||
{ | ||
private static RibbonPanel ribbonPanel; | ||
public Result OnStartup(UIControlledApplication application) | ||
{ | ||
ribbonPanel = application.CreatePanel("Resource"); | ||
|
||
ribbonPanel.RowLargeStackedItems( | ||
ribbonPanel.CreatePushButton<Commands.CommandAvailable>("Revit") | ||
.SetLargeImage("/Resources/Revit.ico"), | ||
ribbonPanel.CreatePushButton<Commands.CommandAvailable>("Revit") | ||
.SetLargeImage($"/{typeof(AppResource).Assembly.GetName().Name};component/Resources/revit.ico"), | ||
ribbonPanel.CreatePushButton<Commands.CommandAvailable>("Revit") | ||
.SetLargeImage("UIFrameworkRes;component/ribbon/images/revit.ico"), | ||
ribbonPanel.CreatePushButton<Commands.CommandAvailable>("Revit") | ||
.SetLargeImage("/UIFrameworkRes;component/ribbon/images/revit.ico") | ||
); | ||
|
||
return Result.Succeeded; | ||
} | ||
|
||
public Result OnShutdown(UIControlledApplication application) | ||
{ | ||
ribbonPanel?.Remove(); | ||
return Result.Succeeded; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using NUnit.Framework; | ||
using System; | ||
|
||
namespace ricaun.Revit.UI.Tests.Resources | ||
{ | ||
public class ResourceTests | ||
{ | ||
const string ResourceName = "Resources/Images/Revit.ico"; | ||
|
||
[Test] | ||
public void GetBitmapSource_NotNull() | ||
{ | ||
Console.WriteLine(ResourceName.GetBitmapSource()); | ||
Assert.IsNotNull(ResourceName.GetBitmapSource()); | ||
Assert.IsNotNull(("/" + ResourceName).GetBitmapSource()); | ||
} | ||
|
||
[Test] | ||
public void GetBitmapSource_NotNull_Component() | ||
{ | ||
var component = "ricaun.Revit.UI.Tests;component/"; | ||
Assert.IsNotNull((component + ResourceName).GetBitmapSource()); | ||
Assert.IsNotNull(("/" + component + ResourceName).GetBitmapSource()); | ||
} | ||
|
||
[Test] | ||
public void GetBitmapSource_Null_NotExist() | ||
{ | ||
var component = "NotExist/" + ResourceName; | ||
var source = component.GetBitmapSource(); | ||
Assert.IsNull(source); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using NUnit.Framework; | ||
using ricaun.Revit.UI.Utils; | ||
using System.Reflection; | ||
|
||
namespace ricaun.Revit.UI.Tests.Resources | ||
{ | ||
public class StackTaskTests | ||
{ | ||
[Test] | ||
public void GetCallingAssembly_Equal() | ||
{ | ||
var assembly = StackTraceUtils.GetCallingAssembly(); | ||
Assert.AreEqual(Assembly.GetExecutingAssembly(), assembly); | ||
} | ||
|
||
[Test] | ||
public void GetCallingAssembly_Nested() | ||
{ | ||
var assembly = StackTraceUtils.GetCallingAssemblyNested(); | ||
Assert.AreEqual(Assembly.GetExecutingAssembly(), assembly); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System.Diagnostics; | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace ricaun.Revit.UI.Utils | ||
{ | ||
internal static class StackTraceUtils | ||
{ | ||
/// <summary> | ||
/// GetCallingAssembly using StackTrace | ||
/// </summary> | ||
/// <returns></returns> | ||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
public static Assembly GetCallingAssembly() | ||
{ | ||
var callingAssembly = Assembly.GetCallingAssembly(); | ||
var executingAssembly = Assembly.GetExecutingAssembly(); | ||
if (callingAssembly != executingAssembly) { return callingAssembly; } | ||
|
||
const int skipFrames = 1; // Skip 'StackTraceUtils' method. | ||
var stackFrames = new StackTrace(skipFrames).GetFrames(); | ||
if (stackFrames == null) return null; | ||
|
||
foreach (var frame in stackFrames) | ||
{ | ||
var assembly = frame.GetMethod().DeclaringType.Assembly; | ||
//System.Console.WriteLine($"[{frame.GetMethod().Name}] \t{assembly}"); | ||
if (assembly != executingAssembly) | ||
{ | ||
callingAssembly = assembly; | ||
break; | ||
} | ||
} | ||
|
||
return callingAssembly; | ||
} | ||
|
||
/// <summary> | ||
/// This method is for test if <see cref="GetCallingAssembly"/> is working with StackTrace. | ||
/// </summary> | ||
/// <returns></returns> | ||
internal static Assembly GetCallingAssemblyNested() | ||
{ | ||
return GetCallingAssembly(); | ||
} | ||
} | ||
} |