Skip to content

Commit

Permalink
Some refactoring to tame the ShellView in future
Browse files Browse the repository at this point in the history
  • Loading branch information
flq committed Oct 24, 2010
1 parent 4898e6b commit d8ec4ef
Show file tree
Hide file tree
Showing 12 changed files with 178 additions and 126 deletions.
Original file line number Diff line number Diff line change
@@ -1,34 +1,17 @@
using MemBus.Publishing;
using MemBus.Setup;
using MemBus.Subscribing;
using MemBus.Support;
using Membus.WpfTwitterClient.Startup;

namespace Membus.WpfTwitterClient.Frame
namespace Membus.WpfTwitterClient.Frame.Config
{
public class ClientPublishingConventions : ISetup<IConfigurableBus>
{
public void Accept(IConfigurableBus setup)
{
setup.ConfigurePublishing(
p =>
{
p.MessageMatch(
m => m.IsType<TransportMessage>() || m.IsType<RequestToStartup>(),
l => l.PublishPipeline(new SequentialPublisher())
);
p.MessageMatch(
m => m.Name.EndsWith("Request"),
l => l.PublishPipeline(Publish.This(new TransportMessage { On = true }), new ParallelNonBlockingPublisher())
);
p.MessageMatch(
m => m.Name.EndsWith("Response"),
l => l.PublishPipeline(new ParallelBlockingPublisher(), Publish.This(new TransportMessage { On = false }))
);
});
setup.ConfigureSubscribing(s => s.MessageMatch(
m => m.Name.EndsWith("Response") || m.IsType<TransportMessage>(),
c => c.ShapeOutwards(new ShapeToUiDispatch(), new ShapeToDispose())));
p => p.MessageMatch(
m => m.IsType<RequestToStartup>(),
l => l.PublishPipeline(new SequentialPublisher())));
}
}
}
3 changes: 2 additions & 1 deletion Membus.WpfTwitterClient/Frame/Config/MainRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public MainRegistry()
For<IConfigReader>().Use<AppConfigReader>();
For<TwitterKeys>().Use(ctx => ctx.GetInstance<IConfigReader>().GetSection<TwitterKeys>());
ForSingletonOf<ITwitterSession>().Use<TwitterSession>();
For<IUserSettings>().Use(Settings.Default);
//For<IUserSettings>().Use(Settings.Default);
For<IUserSettings>().Use(new CheapUserSettings());
Forward<Settings,IUserSettings>();
}

Expand Down
7 changes: 0 additions & 7 deletions Membus.WpfTwitterClient/Frame/TransportMessage.cs

This file was deleted.

17 changes: 17 additions & 0 deletions Membus.WpfTwitterClient/Frame/UI/RequestForAttention.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace Membus.WpfTwitterClient.Frame.UI
{
public class RequestForAttention
{
private readonly object viewModel;

public RequestForAttention(object viewModel)
{
this.viewModel = viewModel;
}

public object ViewModel
{
get { return viewModel; }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,28 @@
using System.Diagnostics;
using System.Text.RegularExpressions;
using MemBus;
using Membus.WpfTwitterClient.Frame.UI;

namespace Membus.WpfTwitterClient.GatherAccessToken
{
public class ScanContentForVerifierHandler : Handles<RequestToScanContentForVerifier>
{
private readonly IBus bus;
private static readonly Regex verifier = new Regex(@"\d\d\d\d\d\d\d", RegexOptions.Multiline | RegexOptions.Compiled);

public ScanContentForVerifierHandler(IBus bus)
{
this.bus = bus;
}

protected override void push(RequestToScanContentForVerifier message)
{
var match = verifier.Match(message.Content);
if (match.Captures.Count == 0)
return;
var possibleVerifier = match.Captures[0].Value;
Debug.WriteLine("Found a verifier: " + possibleVerifier);

bus.Publish(new RequestForAttention(new VerifyPinViewModel(possibleVerifier)));
}
}
}
30 changes: 30 additions & 0 deletions Membus.WpfTwitterClient/GatherAccessToken/VerifyPinViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Caliburn.Micro;

namespace Membus.WpfTwitterClient.GatherAccessToken
{
public class VerifyPinViewModel : PropertyChangedBase
{
private readonly string possibleVerifier;

public VerifyPinViewModel(string possibleVerifier)
{
this.possibleVerifier = possibleVerifier;
}

public string PossibleVerifier
{
get { return possibleVerifier; }
}

private string verifierOverride;
public string VerifierOverride
{
get { return verifierOverride; }
set
{
verifierOverride = value;
NotifyOfPropertyChange(()=>VerifierOverride);
}
}
}
}
8 changes: 5 additions & 3 deletions Membus.WpfTwitterClient/Membus.WpfTwitterClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
<Compile Include="Frame\UI\InteractionButton.xaml.cs">
<DependentUpon>InteractionButton.xaml</DependentUpon>
</Compile>
<Compile Include="Frame\UI\RequestForAttention.cs" />
<Compile Include="Frame\UI\RequestToActivateMainScreen.cs" />
<Compile Include="Frame\UI\ScreenConstructor.cs" />
<Compile Include="Frame\UI\SingleAttribute.cs" />
Expand All @@ -120,13 +121,14 @@
<Compile Include="GatherAccessToken\GetAccessTokenViewModel.cs" />
<Compile Include="GatherAccessToken\RequestToScanContentForVerifier.cs" />
<Compile Include="GatherAccessToken\ScanContentForVerifierHandler.cs" />
<Compile Include="GatherAccessToken\VerifyPinViewModel.cs" />
<Compile Include="Properties\Settings.cs" />
<Compile Include="Frame\Twitter\TwitterKeys.cs" />
<Compile Include="ShellViewModel.cs" />
<Compile Include="ShellOfApp\ActivityViewModel.cs" />
<Compile Include="ShellOfApp\ShellViewModel.cs" />
<Compile Include="Startup\AppBootstrap.cs" />
<Compile Include="Startup\TwitterBootstrap.cs" />
<Compile Include="Startup\RequestToStartup.cs" />
<Compile Include="Frame\TransportMessage.cs" />
<Compile Include="Frame\ServiceLocator.cs" />
<Compile Include="Frame\Twitter\TwitterFacade.cs" />
<Page Include="Frame\UI\InteractionButton.xaml">
Expand All @@ -149,7 +151,7 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="ShellView.xaml">
<Page Include="ShellOfApp\ShellView.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
Expand Down
68 changes: 68 additions & 0 deletions Membus.WpfTwitterClient/ShellOfApp/ActivityViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using System;
using System.Linq;
using Caliburn.Micro;
using MemBus.Support;
using Membus.WpfTwitterClient.Frame.UI;

namespace Membus.WpfTwitterClient.ShellOfApp
{
public class ActivityViewModel : PropertyChangedBase, IDisposable
{
private readonly DisposeContainer disposer = new DisposeContainer();

public ActivityViewModel(IObservable<ApplicationActivityMessage> activityMessages)
{
var busyStream1 = activityMessages
.Where(msg => msg.GettingBusy)
.SubscribeOnDispatcher().Subscribe(onGettingBusy);
var busyStream2 = activityMessages
.Where(msg => msg.GettingCalm)
.SubscribeOnDispatcher().Subscribe(onGettingCalm);
disposer.Add(busyStream1, busyStream2);
}

private bool isBusy;
public bool IsBusy
{
get { return isBusy; }
set
{
if (value.Equals(isBusy))
return;
isBusy = value;
NotifyOfPropertyChange(() => IsBusy);
}
}

private string busyMessage;
public string BusyMessage
{
get { return busyMessage; }
set
{
if (value == null || value.Equals(busyMessage))
return;
busyMessage = value;
NotifyOfPropertyChange(() => BusyMessage);
}
}

private void onGettingBusy(ApplicationActivityMessage msg)
{
BusyMessage = string.Empty;
IsBusy = true;
BusyMessage = msg.BusyText;
}

private void onGettingCalm(ApplicationActivityMessage msg)
{
IsBusy = false;
}


void IDisposable.Dispose()
{
disposer.Dispose();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Window x:Class="Membus.WpfTwitterClient.ShellView"
<Window x:Class="Membus.WpfTwitterClient.ShellOfApp.ShellView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:UI="clr-namespace:Membus.WpfTwitterClient.Frame.UI"
Expand All @@ -15,11 +15,11 @@

<StatusBar Grid.Row="2" Style="{StaticResource ResourceKey=StatusbarStyle}" HorizontalAlignment="Stretch">
<StatusBarItem HorizontalContentAlignment="Right">
<StackPanel Orientation="Horizontal" Visibility="Collapsed">
<StackPanel Orientation="Horizontal" Visibility="Collapsed" DataContext="{Binding Path=ActivityViewModel, Mode=OneWay}">
<i:Interaction.Behaviors>
<UI:FadeOnVisibilityBehaviour Visible="{Binding IsBusy, Mode=OneWay}" />
</i:Interaction.Behaviors>
<Label Margin="5 0" x:Name="BusyMessage"></Label>
<Label Margin="5 0" x:Name="BusyMessage" Content="{Binding Path=BusyMessage}"></Label>
<UI:GifImage Margin="0 3" Grid.Column="1" GifUri="pack://application:,,,/Resources/wait.gif" FramesPerSecond="5" DockPanel.Dock="Right" />
</StackPanel>
</StatusBarItem>
Expand Down
39 changes: 39 additions & 0 deletions Membus.WpfTwitterClient/ShellOfApp/ShellViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using System.Linq;
using Caliburn.Micro;
using MemBus.Support;
using Membus.WpfTwitterClient.Frame.UI;

namespace Membus.WpfTwitterClient.ShellOfApp
{
[Single]
public class ShellViewModel : Conductor<Screen>
{
public ActivityViewModel ActivityViewModel { get; private set; }
private readonly DisposeContainer disposeContainer = new DisposeContainer();

public ShellViewModel(IObservable<RequestToActivateMainScreen> activationStream, ActivityViewModel activityVm)
{
ActivityViewModel = activityVm;
var screenStreamDispose = activationStream
.Where(msg => msg.ScreenAvailable)
.SubscribeOnDispatcher().Subscribe(onNextScreenRequest);

disposeContainer.Add(screenStreamDispose, activityVm);

DisplayName = "MemBus OnTweet!";
}

private void onNextScreenRequest(RequestToActivateMainScreen request)
{
DisplayName = request.Screen.DisplayName;
ActivateItem(request.Screen);
}

protected override void OnDeactivate(bool close)
{
disposeContainer.Dispose();
base.OnDeactivate(close);
}
}
}
89 changes: 0 additions & 89 deletions Membus.WpfTwitterClient/ShellViewModel.cs

This file was deleted.

Loading

0 comments on commit d8ec4ef

Please sign in to comment.