// ----------------------------------------------------------------------- // // TODO: Update copyright text. // // ----------------------------------------------------------------------- using System; using System.ServiceModel.Description; using Caliburn.Micro; using System.ServiceModel; using System.ComponentModel.Composition; using Pithos.Core; using Pithos.Interfaces; namespace Pithos.Client.WPF.Services { /// /// TODO: Update summary. /// [ServiceBehavior(ConcurrencyMode=ConcurrencyMode.Reentrant, UseSynchronizationContext=false, IncludeExceptionDetailInFaults = true)] [Export] public class StatusService : IStatusService,ISettingsService, ICommandsService { [Import] public IPithosSettings Settings { get; set; } [Import] public IStatusChecker Checker { get; set; } [Import] public PithosMonitor Monitor { get; set; } [Import] public IEventAggregator Events { get; set; } public StatusService() { IoC.BuildUp(this); } public FileOverlayStatus GetStatus(string filePath) { return Checker.GetFileOverlayStatus(filePath); } public void DisplayProperties(string filePath) { //Monitor. } public PithosSettingsData GetSettings() { var data = new PithosSettingsData(Settings); return data; } public void ShowProperties(string fileName) { Events.Publish(new ShowFilePropertiesEvent(fileName)); } public static ServiceHost Start() { // Create a ServiceHost for the CalculatorService type and provide the base address. var baseAddress = new Uri("net.pipe://localhost/pithos"); var service = new ServiceHost(typeof(StatusService), baseAddress); var binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None); service.AddServiceEndpoint(typeof(IStatusService), binding, "net.pipe://localhost/pithos/statuscache"); service.AddServiceEndpoint(typeof(ISettingsService), binding, "net.pipe://localhost/pithos/settings"); service.AddServiceEndpoint(typeof(ICommandsService), binding, "net.pipe://localhost/pithos/commands"); //// Add a mex endpoint var smb = new ServiceMetadataBehavior { HttpGetEnabled = true, HttpGetUrl = new Uri("http://localhost:30000/pithos/mex") }; service.Description.Behaviors.Add(smb); service.Faulted+=OnError; service.Open(); return service; } private static void OnError(object sender, EventArgs e) { } public static void Stop(ServiceHost statusService) { if (statusService == null) return; if (statusService.State == CommunicationState.Faulted) statusService.Abort(); else if (statusService.State != CommunicationState.Closed) statusService.Close(); } } }