Statistics
| Branch: | Revision:

root / trunk / Pithos.Client.WPF / Services / StatusService.cs @ 4f6d51d4

History | View | Annotate | Download (3.2 kB)

1
// -----------------------------------------------------------------------
2
// <copyright file="StatusService.cs" company="Microsoft">
3
// TODO: Update copyright text.
4
// </copyright>
5
// -----------------------------------------------------------------------
6

    
7

    
8
using System;
9
using Caliburn.Micro;
10
using System.ServiceModel;
11
using System.ComponentModel.Composition;
12
using Pithos.Core;
13
using Pithos.Interfaces;
14

    
15
namespace Pithos.Client.WPF.Services
16
{
17
    /// <summary>
18
    /// TODO: Update summary.
19
    /// </summary>
20
    [ServiceBehavior(ConcurrencyMode=ConcurrencyMode.Reentrant, UseSynchronizationContext=false, IncludeExceptionDetailInFaults = true)]
21
    [Export]
22
    public class StatusService : IStatusService,ISettingsService, ICommandsService
23
    {
24
        [Import]
25
        public IPithosSettings Settings { get; set; }
26

    
27
        [Import]
28
        public IStatusChecker Checker { get; set; }
29

    
30
        [Import]
31
        public PithosMonitor Monitor { get; set; }
32

    
33
        [Import]
34
        public IEventAggregator Events { get; set; }
35

    
36
        public StatusService()
37
        {
38
            IoC.BuildUp(this);
39
        }        
40

    
41
        public FileOverlayStatus GetStatus(string filePath)
42
        {
43
            return Checker.GetFileOverlayStatus(filePath);
44
        }
45

    
46
        public void DisplayProperties(string filePath)
47
        {
48
            //Monitor.
49
        }
50

    
51
        public PithosSettingsData GetSettings()
52
        {
53
            var data = new PithosSettingsData(Settings);
54
            return data;
55
        }
56

    
57
        public void ShowProperties(string fileName)
58
        {
59
            Events.Publish(new ShowFilePropertiesEvent(fileName));
60
        }
61

    
62
        public static ServiceHost Start()
63
        {
64
            // Create a ServiceHost for the CalculatorService type and provide the base address.
65
            var baseAddress = new Uri("net.pipe://localhost/pithos");
66
            var service = new ServiceHost(typeof(StatusService), baseAddress);
67

    
68
            var binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None);
69

    
70
            service.AddServiceEndpoint(typeof(IStatusService), binding, "net.pipe://localhost/pithos/statuscache");
71
            service.AddServiceEndpoint(typeof(ISettingsService), binding, "net.pipe://localhost/pithos/settings");
72
            service.AddServiceEndpoint(typeof(ICommandsService), binding, "net.pipe://localhost/pithos/commands");
73

    
74

    
75
            //// Add a mex endpoint
76
/*
77
            var smb = new ServiceMetadataBehavior
78
                          { 
79
                              HttpGetEnabled = true,
80
                              HttpGetUrl = new Uri("http://localhost:30000/pithos/mex")
81
                          };
82
            service.Description.Behaviors.Add(smb);
83
*/
84

    
85
            service.Faulted+=OnError;
86
            service.Open();
87
            return service;
88
        }
89

    
90
        private static void OnError(object sender, EventArgs e)
91
        {
92
            
93
        }
94

    
95
        public static void Stop(ServiceHost statusService)
96
        {
97
            if (statusService == null)
98
                return;
99

    
100
            if (statusService.State == CommunicationState.Faulted)
101
                statusService.Abort();
102
            else if (statusService.State != CommunicationState.Closed)
103
                statusService.Close();            
104

    
105
        }
106
    }
107
}