summaryrefslogtreecommitdiff
path: root/product/Presentation/Presenters/ProcessQueryCommand.cs
blob: bf270338624bbc4647adceb21865e98baf0d8c8b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
using System;
using Gorilla.Commons.Infrastructure.Threading;
using Gorilla.Commons.Utility.Core;

namespace MoMoney.Presentation.Presenters
{
    public interface IProcessQueryCommand<T> : IParameterizedCommand<ICallback<T>>
    {
    }

    public class ProcessQueryCommand<T> : IProcessQueryCommand<T>
    {
        readonly IQuery<T> query;
        readonly ISynchronizationContextFactory factory;

        public ProcessQueryCommand(IQuery<T> query, ISynchronizationContextFactory factory)
        {
            this.query = query;
            this.factory = factory;
        }

        public void run(ICallback<T> callback)
        {
            var dto = query.fetch();
            factory.create().run(new ActionCommand((Action) (() => callback.run(dto))));
        }
    }
}