-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from ricaun-io/develop
Version 1.4.0
- Loading branch information
Showing
8 changed files
with
188 additions
and
14 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 modified
BIN
+69.4 KB
(210%)
DesignAutomationConsole/Bundle/RevitAddin.DA.Tester.bundle.zip
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
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,77 @@ | ||
using DesignAutomationFramework; | ||
using System; | ||
using System.Linq; | ||
|
||
namespace RevitAddin.DA.Tester.Revit | ||
{ | ||
public class DesignAutomation<T> : DesignAutomation where T : IDesignAutomation | ||
{ | ||
public DesignAutomation() : base(Activator.CreateInstance(typeof(T))) | ||
{ | ||
|
||
} | ||
public DesignAutomation(T instance) : base(instance) | ||
{ | ||
|
||
} | ||
} | ||
|
||
public class DesignAutomation : IDisposable | ||
{ | ||
private readonly object instance; | ||
|
||
public DesignAutomation(Type type) | ||
{ | ||
this.instance = Activator.CreateInstance(type); | ||
Initialize(); | ||
} | ||
|
||
public DesignAutomation(object instance) | ||
{ | ||
this.instance = instance; | ||
Initialize(); | ||
} | ||
|
||
public virtual void Initialize() | ||
{ | ||
Console.WriteLine($"{nameof(DesignAutomation)} Initialize: \t{instance}"); | ||
DesignAutomationBridge.DesignAutomationReadyEvent += DesignAutomationReadyEvent; | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
Console.WriteLine($"{nameof(DesignAutomation)} Dispose: \t{instance}"); | ||
DesignAutomationBridge.DesignAutomationReadyEvent -= DesignAutomationReadyEvent; | ||
} | ||
|
||
private void DesignAutomationReadyEvent(object sender, DesignAutomationReadyEventArgs e) | ||
{ | ||
DesignAutomationBridge.DesignAutomationReadyEvent -= DesignAutomationReadyEvent; | ||
|
||
var data = e.DesignAutomationData; | ||
|
||
Console.WriteLine("--------------------------------------------------"); | ||
Console.WriteLine($"RevitApp: {data.RevitApp} FilePath: {data.FilePath} RevitDoc: {data.RevitDoc}"); | ||
Console.WriteLine("--------------------------------------------------"); | ||
|
||
try | ||
{ | ||
var method = instance.GetType().GetMethods() | ||
.Where(e => e.Name.Equals(nameof(IDesignAutomation.Execute))) | ||
.FirstOrDefault(e => e.GetParameters().Count() == 3); | ||
|
||
Console.WriteLine($"Invoke: {method}"); | ||
|
||
var result = method.Invoke(instance, new object[] { data.RevitApp, data.FilePath, data.RevitDoc }); | ||
|
||
if (result is bool resultBool) | ||
e.Succeeded = resultBool; | ||
} | ||
catch (Exception ex) | ||
{ | ||
Console.WriteLine($"{nameof(DesignAutomation)} Invoke Exception: \t{ex.Message}"); | ||
throw; | ||
} | ||
} | ||
} | ||
} |
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,79 @@ | ||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Runtime.Versioning; | ||
|
||
namespace RevitAddin.DA.Tester.Revit | ||
{ | ||
public class DesignAutomationLoadVersion<T> : DesignAutomationLoadVersion where T : IDesignAutomation | ||
{ | ||
public DesignAutomationLoadVersion() : base(typeof(T)) | ||
{ | ||
|
||
} | ||
} | ||
|
||
public class DesignAutomationLoadVersion : IDisposable | ||
{ | ||
readonly IDisposable designAutomation; | ||
readonly Assembly loadAssembly; | ||
|
||
public DesignAutomationLoadVersion(Type type) | ||
{ | ||
var location = type.Assembly.Location; | ||
var revitAssemblyReference = type.Assembly.GetReferencedAssemblies().FirstOrDefault(e => e.Name.Equals("RevitAPI")); | ||
var revitAssembly = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(e => e.GetName().Name.Equals("RevitAPI")); | ||
|
||
var revitReferenceVersion = revitAssemblyReference.Version.Major + 2000; | ||
var revitVersion = revitAssembly.GetName().Version.Major + 2000; | ||
|
||
Console.WriteLine($"DesignAutomationLoadVersion: \t{revitVersion} -> {revitReferenceVersion}"); | ||
|
||
for (int version = revitVersion; version > revitReferenceVersion; version--) | ||
{ | ||
var directory = System.IO.Path.GetDirectoryName(location); | ||
var directoryVersionRevit = System.IO.Path.Combine(directory, "..", version.ToString()); | ||
var fileName = System.IO.Path.Combine(directoryVersionRevit, System.IO.Path.GetFileName(location)); | ||
|
||
Console.WriteLine($"DesignAutomationLoadVersion Try: \t{version}"); | ||
|
||
if (File.Exists(fileName)) | ||
{ | ||
fileName = new FileInfo(fileName).FullName; | ||
Console.WriteLine($"DesignAutomationLoadVersion File Exists: \t{fileName}"); | ||
Console.WriteLine($"DesignAutomationLoadVersion Version: \t{version}"); | ||
Console.WriteLine($"DesignAutomationLoadVersion LoadFile: \t{Path.GetFileName(fileName)}"); | ||
AppDomain.CurrentDomain.AssemblyResolve += LoadAssemblyResolve; | ||
loadAssembly = Assembly.LoadFile(fileName); | ||
type = loadAssembly.GetType(type.FullName); | ||
break; | ||
} | ||
} | ||
|
||
Console.WriteLine("----------------------------------------"); | ||
Console.WriteLine($"DesignAutomationLoadVersion Type: {type}"); | ||
Console.WriteLine($"DesignAutomationLoadVersion FrameworkName: \t{type.Assembly.GetCustomAttribute<TargetFrameworkAttribute>()?.FrameworkName}"); | ||
designAutomation = new DesignAutomation(type); | ||
} | ||
|
||
private Assembly LoadAssemblyResolve(object sender, ResolveEventArgs args) | ||
{ | ||
var assemblyName = new AssemblyName(args.Name); | ||
var assemblyPath = Path.Combine(Path.GetDirectoryName(loadAssembly.Location), assemblyName.Name + ".dll"); | ||
if (File.Exists(assemblyPath)) | ||
{ | ||
var folderName = Path.GetFileName(Path.GetDirectoryName(assemblyPath)); | ||
Console.WriteLine($"AssemblyResolve LoadFile: {folderName}\\{assemblyName.Name + ".dll"}"); | ||
return Assembly.LoadFile(assemblyPath); | ||
} | ||
return null; | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
designAutomation?.Dispose(); | ||
AppDomain.CurrentDomain.AssemblyResolve -= LoadAssemblyResolve; | ||
} | ||
} | ||
} |
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,10 @@ | ||
using Autodesk.Revit.ApplicationServices; | ||
using Autodesk.Revit.DB; | ||
|
||
namespace RevitAddin.DA.Tester.Revit | ||
{ | ||
public interface IDesignAutomation | ||
{ | ||
bool Execute(Application application, string filePath, Document document); | ||
} | ||
} |
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