Skip to content

Commit

Permalink
Fluent lookup service
Browse files Browse the repository at this point in the history
  • Loading branch information
Nice3point committed Nov 15, 2023
1 parent 0fc01e7 commit 8e87c9f
Show file tree
Hide file tree
Showing 35 changed files with 146 additions and 120 deletions.
2 changes: 1 addition & 1 deletion RevitLookup.UI.Demo/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private void OnStartup(object sender, StartupEventArgs e)
var host = HostProvider.CreateHost();

Host.StartHost(host);
Host.GetService<MoqLookupService>().Show<DashboardView>();
Host.GetService<ILookupService>().Show<DashboardView>();
}

private void OnExit(object sender, ExitEventArgs e)
Expand Down
4 changes: 2 additions & 2 deletions RevitLookup.UI.Demo/HostProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private static void AddServices(HostBuilderContext _, IServiceCollection service
services.AddScoped<IContentDialogService, ContentDialogService>();
services.AddScoped<NotificationService>();

services.AddScoped<ISnoopService, MoqSnoopService>();
services.AddScoped<ISnoopVisualService, MoqSnoopVisualService>();
services.AddScoped<AboutView>();
services.AddScoped<AboutViewModel>();
services.AddScoped<DashboardView>();
Expand All @@ -55,7 +55,7 @@ private static void AddServices(HostBuilderContext _, IServiceCollection service
services.AddScoped<ISnoopViewModel, MoqSnoopViewModel>();
services.AddScoped<IWindow, RevitLookupView>();

services.AddTransient<MoqLookupService>();
services.AddTransient<ILookupService, MoqLookupService>();
}

private static void SetConfiguration(IConfigurationBuilder builder)
Expand Down
16 changes: 8 additions & 8 deletions RevitLookup.UI.Demo/Services/MoqLookupService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

namespace RevitLookup.UI.Demo.Services;

public class MoqLookupService
public class MoqLookupService : ILookupService
{
private Window _owner;
private Task _activeTask;
Expand All @@ -39,25 +39,25 @@ public MoqLookupService(IServiceScopeFactory scopeFactory)
_serviceProvider = scopeFactory.CreateScope().ServiceProvider;
}

public MoqLookupService Snoop(SnoopableType snoopableType)
public ILookupServiceDependsStage Snoop(SnoopableType snoopableType)
{
_activeTask = _serviceProvider.GetService<ISnoopService>()!.SnoopAsync(snoopableType);
_activeTask = _serviceProvider.GetService<ISnoopVisualService>()!.SnoopAsync(snoopableType);
return this;
}

public MoqLookupService Snoop(SnoopableObject snoopableObject)
public ILookupServiceDependsStage Snoop(SnoopableObject snoopableObject)
{
_serviceProvider.GetService<ISnoopService>()!.Snoop(snoopableObject);
_serviceProvider.GetService<ISnoopVisualService>()!.Snoop(snoopableObject);
return this;
}

public MoqLookupService Attach(IWindow window)
public ILookupServiceShowStage DependsOn(IServiceProvider provider)
{
_owner = (Window) window;
_owner = (Window) provider.GetService<IWindow>();
return this;
}

public MoqLookupService Show<T>() where T : Page
public ILookupServiceExecuteStage Show<T>() where T : Page
{
if (_activeTask is null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@

namespace RevitLookup.UI.Demo.Services;

public class MoqSnoopService : ISnoopService
public class MoqSnoopVisualService : ISnoopVisualService
{
private readonly NotificationService _notificationService;
private readonly ISnoopViewModel _viewModel;
private readonly IWindow _window;

public MoqSnoopService(NotificationService notificationService, ISnoopViewModel viewModel, IWindow window)
public MoqSnoopVisualService(NotificationService notificationService, ISnoopViewModel viewModel, IWindow window)
{
_notificationService = notificationService;
_viewModel = viewModel;
Expand Down
12 changes: 6 additions & 6 deletions RevitLookup.UI.Demo/ViewModels/MoqSnoopViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,20 @@ namespace RevitLookup.UI.Demo.ViewModels;

public sealed partial class MoqSnoopViewModel : ObservableObject, ISnoopViewModel
{
private readonly IWindow _window;
private readonly IServiceProvider _provider;
private readonly NotificationService _notificationService;
private CancellationTokenSource _searchCancellationToken = new();

[ObservableProperty] private string _searchText = string.Empty;
[ObservableProperty] private IReadOnlyCollection<SnoopableObject> _snoopableObjects = Array.Empty<SnoopableObject>();
[ObservableProperty] private IReadOnlyCollection<SnoopableObject> _filteredSnoopableObjects = Array.Empty<SnoopableObject>();
[ObservableProperty] private IReadOnlyCollection<Descriptor> _snoopableData;
[ObservableProperty] private IReadOnlyCollection<Descriptor> _filteredSnoopableData;

public MoqSnoopViewModel(NotificationService notificationService, IWindow window)
public MoqSnoopViewModel(NotificationService notificationService, IServiceProvider provider)
{
_notificationService = notificationService;
_window = window;
_provider = provider;
}

public SnoopableObject SelectedObject { get; set; }
Expand All @@ -57,9 +57,9 @@ public void Navigate(Descriptor selectedItem)
if (selectedItem.Value.Descriptor is not IDescriptorCollector) return;
if (selectedItem.Value.Descriptor is IDescriptorEnumerator {IsEmpty: true}) return;

Host.GetService<MoqLookupService>()
Host.GetService<ILookupService>()
.Snoop(selectedItem.Value)
.Attach(_window)
.DependsOn(_provider)
.Show<SnoopView>();
}

Expand Down
4 changes: 1 addition & 3 deletions RevitLookup/Commands/DashboardCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@
// (Rights in Technical Data and Computer Software), as applicable.

using Autodesk.Revit.Attributes;
using Microsoft.Extensions.DependencyInjection;
using Nice3point.Revit.Toolkit.External;
using RevitLookup.Services;
using RevitLookup.Services.Contracts;
using RevitLookup.Views.Pages;
using Wpf.Ui.Contracts;

namespace RevitLookup.Commands;

Expand All @@ -34,6 +32,6 @@ public class DashboardCommand : ExternalCommand
{
public override void Execute()
{
Host.GetService<LookupService>().Show<DashboardView>();
Host.GetService<ILookupService>().Show<DashboardView>();
}
}
3 changes: 2 additions & 1 deletion RevitLookup/Commands/EventMonitorCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using Autodesk.Revit.Attributes;
using Nice3point.Revit.Toolkit.External;
using RevitLookup.Services;
using RevitLookup.Services.Contracts;
using RevitLookup.Views.Pages;

namespace RevitLookup.Commands;
Expand All @@ -31,6 +32,6 @@ public class EventMonitorCommand : ExternalCommand
{
public override void Execute()
{
Host.GetService<LookupService>().Show<EventsView>();
Host.GetService<ILookupService>().Show<EventsView>();
}
}
5 changes: 1 addition & 4 deletions RevitLookup/Commands/SearchElementsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,11 @@
// (Rights in Technical Data and Computer Software), as applicable.

using Autodesk.Revit.Attributes;
using Microsoft.Extensions.DependencyInjection;
using Nice3point.Revit.Toolkit.External;
using RevitLookup.Services;
using RevitLookup.Services.Contracts;
using RevitLookup.Services.Enums;
using RevitLookup.ViewModels.Pages;
using RevitLookup.Views.Pages;
using Wpf.Ui.Contracts;

namespace RevitLookup.Commands;

Expand All @@ -36,7 +33,7 @@ public class SearchElementsCommand : ExternalCommand
{
public override void Execute()
{
Host.GetService<LookupService>()
Host.GetService<ILookupService>()
.Show<DashboardView>()
.Execute<DashboardViewModel>(dashboard =>
{
Expand Down
4 changes: 1 addition & 3 deletions RevitLookup/Commands/SnoopDatabaseCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@
// (Rights in Technical Data and Computer Software), as applicable.

using Autodesk.Revit.Attributes;
using Microsoft.Extensions.DependencyInjection;
using Nice3point.Revit.Toolkit.External;
using RevitLookup.Services;
using RevitLookup.Services.Contracts;
using RevitLookup.Services.Enums;
using RevitLookup.ViewModels.Pages;
using RevitLookup.Views.Pages;

namespace RevitLookup.Commands;
Expand All @@ -35,7 +33,7 @@ public class SnoopDatabaseCommand : ExternalCommand
{
public override void Execute()
{
Host.GetService<LookupService>()
Host.GetService<ILookupService>()
.Snoop(SnoopableType.Database)
.Show<SnoopView>();
}
Expand Down
3 changes: 1 addition & 2 deletions RevitLookup/Commands/SnoopDocumentCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
// (Rights in Technical Data and Computer Software), as applicable.

using Autodesk.Revit.Attributes;
using Microsoft.Extensions.DependencyInjection;
using Nice3point.Revit.Toolkit.External;
using RevitLookup.Services;
using RevitLookup.Services.Contracts;
Expand All @@ -34,7 +33,7 @@ public class SnoopDocumentCommand : ExternalCommand
{
public override void Execute()
{
Host.GetService<LookupService>()
Host.GetService<ILookupService>()
.Snoop(SnoopableType.Document)
.Show<SnoopView>();
}
Expand Down
3 changes: 1 addition & 2 deletions RevitLookup/Commands/SnoopEdgeCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
// (Rights in Technical Data and Computer Software), as applicable.

using Autodesk.Revit.Attributes;
using Microsoft.Extensions.DependencyInjection;
using Nice3point.Revit.Toolkit.External;
using RevitLookup.Services;
using RevitLookup.Services.Contracts;
Expand All @@ -34,7 +33,7 @@ public class SnoopEdgeCommand : ExternalCommand
{
public override void Execute()
{
Host.GetService<LookupService>()
Host.GetService<ILookupService>()
.Snoop(SnoopableType.Edge)
.Show<SnoopView>();
}
Expand Down
3 changes: 1 addition & 2 deletions RevitLookup/Commands/SnoopFaceCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
// (Rights in Technical Data and Computer Software), as applicable.

using Autodesk.Revit.Attributes;
using Microsoft.Extensions.DependencyInjection;
using Nice3point.Revit.Toolkit.External;
using RevitLookup.Services;
using RevitLookup.Services.Contracts;
Expand All @@ -34,7 +33,7 @@ public class SnoopFaceCommand : ExternalCommand
{
public override void Execute()
{
Host.GetService<LookupService>()
Host.GetService<ILookupService>()
.Snoop(SnoopableType.Face)
.Show<SnoopView>();
}
Expand Down
3 changes: 1 addition & 2 deletions RevitLookup/Commands/SnoopLinkedElementCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
// (Rights in Technical Data and Computer Software), as applicable.

using Autodesk.Revit.Attributes;
using Microsoft.Extensions.DependencyInjection;
using Nice3point.Revit.Toolkit.External;
using RevitLookup.Services;
using RevitLookup.Services.Contracts;
Expand All @@ -34,7 +33,7 @@ public class SnoopLinkedElementCommand : ExternalCommand
{
public override void Execute()
{
Host.GetService<LookupService>()
Host.GetService<ILookupService>()
.Snoop(SnoopableType.LinkedElement)
.Show<SnoopView>();
}
Expand Down
3 changes: 1 addition & 2 deletions RevitLookup/Commands/SnoopPointCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
// (Rights in Technical Data and Computer Software), as applicable.

using Autodesk.Revit.Attributes;
using Microsoft.Extensions.DependencyInjection;
using Nice3point.Revit.Toolkit.External;
using RevitLookup.Services;
using RevitLookup.Services.Contracts;
Expand All @@ -34,7 +33,7 @@ public class SnoopPointCommand : ExternalCommand
{
public override void Execute()
{
Host.GetService<LookupService>()
Host.GetService<ILookupService>()
.Snoop(SnoopableType.Point)
.Show<SnoopView>();
}
Expand Down
3 changes: 1 addition & 2 deletions RevitLookup/Commands/SnoopSelectionCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
// (Rights in Technical Data and Computer Software), as applicable.

using Autodesk.Revit.Attributes;
using Microsoft.Extensions.DependencyInjection;
using Nice3point.Revit.Toolkit.External;
using RevitLookup.Services;
using RevitLookup.Services.Contracts;
Expand All @@ -34,7 +33,7 @@ public class SnoopSelectionCommand : ExternalCommand
{
public override void Execute()
{
Host.GetService<LookupService>()
Host.GetService<ILookupService>()
.Snoop(SnoopableType.Selection)
.Show<SnoopView>();
}
Expand Down
3 changes: 1 addition & 2 deletions RevitLookup/Commands/SnoopSubElementCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
// (Rights in Technical Data and Computer Software), as applicable.

using Autodesk.Revit.Attributes;
using Microsoft.Extensions.DependencyInjection;
using Nice3point.Revit.Toolkit.External;
using RevitLookup.Services;
using RevitLookup.Services.Contracts;
Expand All @@ -34,7 +33,7 @@ public class SnoopSubElementCommand : ExternalCommand
{
public override void Execute()
{
Host.GetService<LookupService>()
Host.GetService<ILookupService>()
.Snoop(SnoopableType.SubElement)
.Show<SnoopView>();
}
Expand Down
3 changes: 1 addition & 2 deletions RevitLookup/Commands/SnoopViewCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
// (Rights in Technical Data and Computer Software), as applicable.

using Autodesk.Revit.Attributes;
using Microsoft.Extensions.DependencyInjection;
using Nice3point.Revit.Toolkit.External;
using RevitLookup.Services;
using RevitLookup.Services.Contracts;
Expand All @@ -34,7 +33,7 @@ public class SnoopViewCommand : ExternalCommand
{
public override void Execute()
{
Host.GetService<LookupService>()
Host.GetService<ILookupService>()
.Snoop(SnoopableType.View)
.Show<SnoopView>();
}
Expand Down
4 changes: 2 additions & 2 deletions RevitLookup/Host.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private static void AddServices(HostBuilderContext context, IServiceCollection s
services.AddScoped<IContentDialogService, ContentDialogService>();
services.AddScoped<NotificationService>();

services.AddScoped<ISnoopService, SnoopService>();
services.AddScoped<ISnoopVisualService, SnoopVisualService>();
services.AddScoped<AboutView>();
services.AddScoped<AboutViewModel>();
services.AddScoped<DashboardView>();
Expand All @@ -55,7 +55,7 @@ private static void AddServices(HostBuilderContext context, IServiceCollection s
services.AddScoped<ISnoopViewModel, SnoopViewModel>();
services.AddScoped<IWindow, RevitLookupView>();

services.AddTransient<LookupService>();
services.AddTransient<ILookupService, LookupService>();
}

private static void SetConfiguration(IConfigurationBuilder builder)
Expand Down
Loading

0 comments on commit 8e87c9f

Please sign in to comment.