Skip to content

Commit

Permalink
temp
Browse files Browse the repository at this point in the history
  • Loading branch information
NinhPham704 committed Feb 6, 2024
1 parent c9d5fd1 commit 36a7183
Show file tree
Hide file tree
Showing 19 changed files with 181 additions and 569 deletions.
9 changes: 7 additions & 2 deletions Application.cs → App.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
using BimIshou.Commands;
using BimIshou.Commands.ChieucaoTB;
using BimIshou.TestAtt;
using BimIshou.DuplicateSheet;
using BimIshou.Commands.A14;
using Nice3point.Revit.Toolkit.External;
using Autodesk.Revit.UI;
using ricaun.Revit.DI;
using Autodesk.Revit.ApplicationServices;

namespace BimIshou
{
[UsedImplicitly]
public class Application : ApplicationBase
public class App : ExternalApplication, IHost
{
public override void OnStartup()
{
CreateRibbon();
//var container = this.GetContainer();
//container.AddRevitSingleton(Application);
}
private void CreateRibbon()
{
Expand Down
5 changes: 1 addition & 4 deletions BimIshou.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.39" />
<PackageReference Include="ModernWpfUI" Version="0.9.6" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.*" />
<PackageReference Include="ricaun.Revit.DI" Version="1.0.0" />
</ItemGroup>

<ItemGroup>
Expand All @@ -72,10 +73,6 @@
<Using Include="JetBrains.Annotations" />
</ItemGroup>

<ItemGroup>
<Folder Include="ViewModels\Objects" />
</ItemGroup>

<ItemGroup>
<Reference Include="AdWindows">
<HintPath>C:\Program Files\Autodesk\Revit 2021\AdWindows.dll</HintPath>
Expand Down
62 changes: 62 additions & 0 deletions Commands/TestDI.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB.ExtensibleStorage;
using BimIshou.Services;
using Nice3point.Revit.Toolkit.External;
using ricaun.Revit.DI;
using System.Diagnostics;

namespace BimIshou.Commands
{
[Transaction(TransactionMode.Manual)]
public class TestDI : ExternalCommand, IHost
{
public override void Execute()
{
Host.Container.AddRevitSingleton(UiApplication);
Host.Container.AddSingleton<IProjectInfoService, ProjectInfoService>();

var xxx = Host.Container.Resolve<IProjectInfoService>();
var format = xxx.GetProjectInfo(ConstantGUID.SchemaGUID_LoggerParking, nameof(LoggerParkingEnum.Format));
var RowNumber = xxx.GetProjectInfo(ConstantGUID.SchemaGUID_LoggerParking, nameof(LoggerParkingEnum.RowNumber));


Debug.WriteLine(RowNumber);
}
}
public enum LoggerParkingEnum
{
Format,
Type,
ProductType,
RowNumber,
SpanX,
SpanY,
SpotType,
SpotCount,
IndexEntry,
SlopeType,
SlopePos,
FloorCount,
SpecClimateArea,
TotalAcreageContruction,
AcreageAFloor,
ElevatorCount,
StairCount,
GroupProductName
}
public static class ConstantGUID
{
public static Schema GetGuid(this string stringGuid)
{
return Schema.Lookup(new Guid(stringGuid));
}
public const string SchemaGUID_GDSettings = "C3DB751D-5032-44A2-BBAE-AFCDB8ABA7CF";
public const string SchemaGUID_Input6Storage = "50DFBF8C-E182-4909-B9EC-A8FC9643DC13";
public const string SchemaGUID_Input5Settings = "A67646E2-5EC2-4745-9B6C-47706EDF6585";
public const string SchemaGUID_Input4BoxStorage = "C70DD2ED-78D4-44BC-8941-A299798AE1EF";
public const string SchemaGUID_LoggerParking = "96190439-48E7-4C1C-A537-6F95EB281C78";
public const string SchemaGUID_OutputParking = "4B9E3E1B-8D1B-4A64-8B55-A068F01ADB4E";
public const string SchemaGUID_OutputGD = "533E9DB4-F1F8-443F-BD5B-19AA03D423D2";
public const string SchemaGUID_CustomEntry = "0dc622fc-cdd7-4bec-8243-250d1d41ea44";
}
}
26 changes: 26 additions & 0 deletions Host.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using ricaun.DI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BimIshou
{
public static class Host
{
public static IContainer Container { get; } = ContainerUtils.CreateContainer();
public static IContainerResolver ContainerResolver => Container;
public static T Resolve<T>() where T : class => ContainerResolver.Resolve<T>();
public static T ResolveOrNull<T>() where T : class => ContainerResolver.ResolveOrNull<T>();
}

public interface IHost { }
public static class HostExtension
{
public static IContainer GetContainer(this IHost _) => Host.Container;
public static IContainerResolver GetContainerResolver(this IHost _) => Host.ContainerResolver;
public static T Resolve<T>(this IHost _) where T : class => Host.Resolve<T>();
public static T ResolveOrNull<T>(this IHost _) where T : class => Host.ResolveOrNull<T>();
}
}
2 changes: 1 addition & 1 deletion Hosting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace BimIshou
{
internal static class Hosting
public static class Hosting
{
private static ServiceProvider? _serviceProvider;
public static void StartHosting(UIApplication uiapp)
Expand Down
36 changes: 36 additions & 0 deletions Services/DocumentService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using System.Collections.Generic;
using System.Linq;

namespace RevitAddin.DI.Example.Services
{
public class DocumentService : IDocumentService
{
private readonly UIApplication uiapp;

public DocumentService(UIApplication uiapp)
{
this.uiapp = uiapp;
}

public Document GetDocument()
{
return uiapp.ActiveUIDocument.Document;
}

public IList<Document> GetDocuments()
{
return uiapp.Application.Documents
.OfType<Document>()
.ToList();
}

}

public interface IDocumentService
{
public Document GetDocument();
public IList<Document> GetDocuments();
}
}
25 changes: 25 additions & 0 deletions Services/ProjectInfoService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using BimIshou.Commands;

namespace BimIshou.Services
{
class ProjectInfoService : IProjectInfoService
{
Document Document;
public ProjectInfoService(UIApplication uiapp)
{
Document = uiapp.ActiveUIDocument.Document;
}

public string GetProjectInfo(string Guid, string name)
{
return Document.ProjectInformation.LoadEntity<string>(Guid.GetGuid(), name);
}
}

public interface IProjectInfoService
{
public string GetProjectInfo(string Guid, string name);
}
}
66 changes: 0 additions & 66 deletions TestAtt/ApplicationBase.cs

This file was deleted.

45 changes: 0 additions & 45 deletions TestAtt/DocumentExtension.cs

This file was deleted.

76 changes: 0 additions & 76 deletions TestAtt/ElementExtension.cs

This file was deleted.

Loading

0 comments on commit 36a7183

Please sign in to comment.