Statistics
| Branch: | Revision:

root / trunk / Pithos.Client.WPF / Services / StatusService.cs @ 363bad87

History | View | Annotate | Download (3.3 kB)

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

    
7

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

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

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

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

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

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

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

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

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

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

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

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

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

    
75

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

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

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

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

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

    
106
        }
107
    }
108
}