Files

78 lines
1.7 KiB
C#
Raw Permalink Normal View History

2014-10-31 09:05:52 +02:00
using System;
using System.Collections.Generic;
using System.ServiceModel;
using System.ServiceModel.Channels;
namespace MTApiService
{
internal class MtApiProxy : DuplexClientBase<IMtApi>, IMtApi, IDisposable
2014-10-31 09:05:52 +02:00
{
public MtApiProxy(InstanceContext callbackContext, Binding binding, EndpointAddress remoteAddress)
2014-10-31 09:05:52 +02:00
: base(callbackContext, binding, remoteAddress)
{
InnerDuplexChannel.Faulted += InnerDuplexChannel_Faulted;
2014-10-31 09:05:52 +02:00
}
#region IMtApi Members
public bool Connect()
{
InnerDuplexChannel.Open();
2014-10-31 09:05:52 +02:00
return Channel.Connect();
}
public void Disconnect()
{
Channel.Disconnect();
}
public MtResponse SendCommand(MtCommand command)
{
return Channel.SendCommand(command);
}
public List<MtQuote> GetQuotes()
2014-10-31 09:05:52 +02:00
{
return Channel.GetQuotes();
}
#endregion
#region IDisposable Members
public void Dispose()
{
try
{
Close();
2014-10-31 09:05:52 +02:00
}
catch (CommunicationException)
{
Abort();
2014-10-31 09:05:52 +02:00
}
catch (TimeoutException)
{
Abort();
2014-10-31 09:05:52 +02:00
}
catch (Exception)
{
Abort();
2014-10-31 09:05:52 +02:00
}
}
#endregion
#region Private Methods
private void InnerDuplexChannel_Faulted(object sender, EventArgs e)
{
Faulted?.Invoke(this, e);
2014-10-31 09:05:52 +02:00
}
2014-10-31 09:05:52 +02:00
#endregion
#region Events
public event EventHandler Faulted;
#endregion
}
}