diff options
| author | mo khan <mo@mokhan.ca> | 2010-07-19 12:55:31 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2010-07-19 13:00:38 -0600 |
| commit | f5ed784fe69d5b6b321d5e08d0ab10840b2baba2 (patch) | |
| tree | 7dbf1f5619261d9d277d974aa66c373c729bc50f | |
| parent | f7756649a914fe55d3b6e7181c8c5dabdef37596 (diff) | |
figured out why the application was not getting shutdown. needed to stop the command processor and the queue.
| -rw-r--r-- | product/client/client.ui/Program.cs | 23 | ||||
| -rw-r--r-- | product/client/client.ui/WPFApplication.cs | 6 | ||||
| -rw-r--r-- | product/client/client.ui/bootstrappers/Bootstrapper.cs | 3 | ||||
| -rw-r--r-- | product/client/client.ui/client.csproj | 1 | ||||
| -rw-r--r-- | product/client/common/common.csproj | 1 | ||||
| -rw-r--r-- | product/client/common/messages/ApplicationShuttingDown.cs | 9 | ||||
| -rw-r--r-- | product/client/server/Bootstrapper.cs | 1 | ||||
| -rw-r--r-- | product/client/server/handlers/ShutdownApplicationCommand.cs | 16 | ||||
| -rw-r--r-- | product/client/server/server.csproj | 3 | ||||
| -rw-r--r-- | product/commons/infrastructure/threading/AsynchronousCommandProcessor.cs | 212 |
10 files changed, 161 insertions, 114 deletions
diff --git a/product/client/client.ui/Program.cs b/product/client/client.ui/Program.cs index 8c83db8..e2f20df 100644 --- a/product/client/client.ui/Program.cs +++ b/product/client/client.ui/Program.cs @@ -4,6 +4,7 @@ using System.IO; using System.Security.Principal;
using System.Windows;
using System.Windows.Threading;
+using Gorilla.Commons.Infrastructure.Logging;
using presentation.windows.bootstrappers;
using presentation.windows.views;
@@ -14,23 +15,33 @@ namespace presentation.windows [STAThread]
static public void Main(string[] args)
{
- Process.Start(get_startup_path_using(args));
+ Process.Start(new ProcessStartInfo
+ {
+ FileName = get_service_startup_path(args),
+ //WindowStyle = ProcessWindowStyle.Hidden,
+ });
+ AppDomain.CurrentDomain.UnhandledException += (o, e) =>
+ {
+ (e.ExceptionObject as Exception).add_to_log();
+ };
AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
Dispatcher.CurrentDispatcher.UnhandledException += (o, e) =>
{
+ e.Exception.add_to_log();
new ErrorWindow {DataContext = e.Exception}.ShowDialog();
+ e.Handled = true;
};
- new Application
+ new WPFApplication
{
- ShutdownMode = ShutdownMode.OnMainWindowClose
+ ShutdownMode = ShutdownMode.OnMainWindowClose,
}.Run(Bootstrapper.create_window());
}
- static string get_startup_path_using(string[] args)
+ static string get_service_startup_path(string[] args)
{
if (args.Length > 0)
- return Path.Combine(args[0], @"presentation.windows.server.exe");
- return Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, @"..\..\..\server\bin\Debug\presentation.windows.server.exe"));
+ return Path.Combine(args[0], @"momoney.server.exe");
+ return Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, @"..\..\..\server\bin\Debug\momoney.server.exe"));
}
}
}
\ No newline at end of file diff --git a/product/client/client.ui/WPFApplication.cs b/product/client/client.ui/WPFApplication.cs new file mode 100644 index 0000000..3005e44 --- /dev/null +++ b/product/client/client.ui/WPFApplication.cs @@ -0,0 +1,6 @@ +using System.Windows;
+
+namespace presentation.windows
+{
+ public class WPFApplication : Application {}
+}
\ No newline at end of file diff --git a/product/client/client.ui/bootstrappers/Bootstrapper.cs b/product/client/client.ui/bootstrappers/Bootstrapper.cs index 488914c..c33d308 100644 --- a/product/client/client.ui/bootstrappers/Bootstrapper.cs +++ b/product/client/client.ui/bootstrappers/Bootstrapper.cs @@ -71,13 +71,14 @@ namespace presentation.windows.bootstrappers builder.Register<WPFCommandBuilder>().As<UICommandBuilder>();
// queries
-
builder.Register<PublishEventHandler<AddedNewFamilyMember>>().As<Handler>();
Resolve.the<IEnumerable<NeedStartup>>().each(x => x.run());
Resolve.the<CommandProcessor>().run();
+ shell_window.Closed += (o, e) => Resolve.the<ServiceBus>().publish<ApplicationShuttingDown>();
shell_window.Closed += (o, e) => Resolve.the<CommandProcessor>().stop();
+ shell_window.Closed += (o, e) => manager.Dispose();
return shell_window;
}
}
diff --git a/product/client/client.ui/client.csproj b/product/client/client.ui/client.csproj index 7501df4..8f77774 100644 --- a/product/client/client.ui/client.csproj +++ b/product/client/client.ui/client.csproj @@ -212,6 +212,7 @@ <Compile Include="views\StatusBarRegion.xaml.cs">
<DependentUpon>StatusBarRegion.xaml</DependentUpon>
</Compile>
+ <Compile Include="WPFApplication.cs" />
<Compile Include="WpfApplicationController.cs" />
<Compile Include="WpfPresenterFactory.cs" />
<EmbeddedResource Include="Properties\Resources.resx">
diff --git a/product/client/common/common.csproj b/product/client/common/common.csproj index 3321e26..801ac68 100644 --- a/product/client/common/common.csproj +++ b/product/client/common/common.csproj @@ -87,6 +87,7 @@ <Compile Include="IEvent.cs" />
<Compile Include="MessageHandler.cs" />
<Compile Include="messages\AddedNewFamilyMember.cs" />
+ <Compile Include="messages\ApplicationShuttingDown.cs" />
<Compile Include="messages\CreateNewDetailAccount.cs" />
<Compile Include="messages\FamilyMemberToAdd.cs" />
<Compile Include="messages\FindAllFamily.cs" />
diff --git a/product/client/common/messages/ApplicationShuttingDown.cs b/product/client/common/messages/ApplicationShuttingDown.cs new file mode 100644 index 0000000..e920e33 --- /dev/null +++ b/product/client/common/messages/ApplicationShuttingDown.cs @@ -0,0 +1,9 @@ +using System;
+using ProtoBuf;
+
+namespace presentation.windows.common.messages
+{
+ [Serializable]
+ [ProtoContract]
+ public class ApplicationShuttingDown : IEvent {}
+}
\ No newline at end of file diff --git a/product/client/server/Bootstrapper.cs b/product/client/server/Bootstrapper.cs index 0896466..254837c 100644 --- a/product/client/server/Bootstrapper.cs +++ b/product/client/server/Bootstrapper.cs @@ -55,6 +55,7 @@ namespace presentation.windows.server builder.Register<AddNewFamilyMemberHandler>().As<Handler>();
builder.Register<FindAllFamilyHandler>().As<Handler>();
builder.Register<SaveNewAccountCommand>().As<Handler>();
+ builder.Register<ShutdownApplicationCommand>().As<Handler>();
// queries
diff --git a/product/client/server/handlers/ShutdownApplicationCommand.cs b/product/client/server/handlers/ShutdownApplicationCommand.cs new file mode 100644 index 0000000..dd78c48 --- /dev/null +++ b/product/client/server/handlers/ShutdownApplicationCommand.cs @@ -0,0 +1,16 @@ +using System;
+using Gorilla.Commons.Infrastructure.Logging;
+using presentation.windows.common;
+using presentation.windows.common.messages;
+
+namespace presentation.windows.server.handlers
+{
+ public class ShutdownApplicationCommand : AbstractHandler<ApplicationShuttingDown>
+ {
+ public override void handle(ApplicationShuttingDown item)
+ {
+ this.log().debug("shutting down");
+ Environment.Exit(Environment.ExitCode);
+ }
+ }
+}
\ No newline at end of file diff --git a/product/client/server/server.csproj b/product/client/server/server.csproj index c952b80..804074a 100644 --- a/product/client/server/server.csproj +++ b/product/client/server/server.csproj @@ -9,7 +9,7 @@ <OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>presentation.windows.server</RootNamespace>
- <AssemblyName>presentation.windows.server</AssemblyName>
+ <AssemblyName>momoney.server</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<FileUpgradeFlags>
@@ -128,6 +128,7 @@ <Compile Include="domain\Person.cs" />
<Compile Include="handlers\FindAllFamilyHandler.cs" />
<Compile Include="handlers\SaveNewAccountCommand.cs" />
+ <Compile Include="handlers\ShutdownApplicationCommand.cs" />
<Compile Include="NHibernateBootstrapper.cs" />
<Compile Include="orm\AccountRepository.cs" />
<Compile Include="orm\EmptyUnitOfWork.cs" />
diff --git a/product/commons/infrastructure/threading/AsynchronousCommandProcessor.cs b/product/commons/infrastructure/threading/AsynchronousCommandProcessor.cs index 7bfae67..4505abc 100644 --- a/product/commons/infrastructure/threading/AsynchronousCommandProcessor.cs +++ b/product/commons/infrastructure/threading/AsynchronousCommandProcessor.cs @@ -4,110 +4,110 @@ using System.Threading; using Gorilla.Commons.Infrastructure.Logging;
using gorilla.commons.utility;
-namespace gorilla.commons.infrastructure.threading -{ - public class AsynchronousCommandProcessor : CommandProcessor - { - readonly Queue<Command> queued_commands; - readonly EventWaitHandle manual_reset; - readonly IList<Thread> worker_threads; - bool keep_working; - - static public readonly Command Empty = new EmptyCommand(); - - public AsynchronousCommandProcessor() - { - queued_commands = new Queue<Command>(); - worker_threads = new List<Thread>(); - manual_reset = new ManualResetEvent(false); - } - - public void add(Action command) - { - add(new AnonymousCommand(command)); - } - - public void add(Command command_to_process) - { - lock (queued_commands) - { - if (queued_commands.Contains(command_to_process)) return; - queued_commands.Enqueue(command_to_process); - reset_thread(); - } - } - - public void run() - { - reset_thread(); - keep_working = true; - var worker_thread = new Thread(run_commands); - worker_thread.SetApartmentState(ApartmentState.STA); - worker_threads.Add(worker_thread); - worker_thread.Start(); - } - - public void stop() - { - keep_working = false; - manual_reset.Set(); - //manual_reset.Close(); - } - - [STAThread] - void run_commands() - { - while (keep_working) - { - manual_reset.WaitOne(); - run_next_command(); - } - } - - void run_next_command() - { - var command = Empty; - within_lock(() => - { - if (queued_commands.Count == 0) - manual_reset.Reset(); - else - command = queued_commands.Dequeue(); - }); - safely_invoke(() => - { - command.run(); - }); - reset_thread(); - } - - void safely_invoke(Action action) - { - try - { - action(); - } - catch (Exception e) - { - this.log().error(e); - } - } - - void reset_thread() - { - within_lock(() => - { - if (queued_commands.Count > 0) manual_reset.Set(); - else manual_reset.Reset(); - }); - } - - void within_lock(Action action) - { - lock (queued_commands) - { - action(); - } - } - } +namespace gorilla.commons.infrastructure.threading
+{
+ public class AsynchronousCommandProcessor : CommandProcessor
+ {
+ readonly Queue<Command> queued_commands;
+ readonly EventWaitHandle manual_reset;
+ readonly IList<Thread> worker_threads;
+ bool keep_working;
+
+ static public readonly Command Empty = new EmptyCommand();
+
+ public AsynchronousCommandProcessor()
+ {
+ queued_commands = new Queue<Command>();
+ worker_threads = new List<Thread>();
+ manual_reset = new ManualResetEvent(false);
+ }
+
+ public void add(Action command)
+ {
+ add(new AnonymousCommand(command));
+ }
+
+ public void add(Command command_to_process)
+ {
+ lock (queued_commands)
+ {
+ if (queued_commands.Contains(command_to_process)) return;
+ queued_commands.Enqueue(command_to_process);
+ reset_thread();
+ }
+ }
+
+ public void run()
+ {
+ reset_thread();
+ keep_working = true;
+ var worker_thread = new Thread(run_commands);
+ worker_thread.SetApartmentState(ApartmentState.STA);
+ worker_threads.Add(worker_thread);
+ worker_thread.Start();
+ }
+
+ public void stop()
+ {
+ keep_working = false;
+ manual_reset.Set();
+ //manual_reset.Close();
+ }
+
+ [STAThread]
+ void run_commands()
+ {
+ while (keep_working)
+ {
+ manual_reset.WaitOne();
+ run_next_command();
+ }
+ }
+
+ void run_next_command()
+ {
+ var command = Empty;
+ within_lock(() =>
+ {
+ if (queued_commands.Count == 0)
+ manual_reset.Reset();
+ else
+ command = queued_commands.Dequeue();
+ });
+ safely_invoke(() =>
+ {
+ command.run();
+ });
+ reset_thread();
+ }
+
+ void safely_invoke(Action action)
+ {
+ try
+ {
+ action();
+ }
+ catch (Exception e)
+ {
+ this.log().error(e);
+ }
+ }
+
+ void reset_thread()
+ {
+ within_lock(() =>
+ {
+ if (queued_commands.Count > 0) manual_reset.Set();
+ else manual_reset.Reset();
+ });
+ }
+
+ void within_lock(Action action)
+ {
+ lock (queued_commands)
+ {
+ action();
+ }
+ }
+ }
}
\ No newline at end of file |
