Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Runtime.Remoting;
- using System.ServiceModel;
- using System.Windows;
- using Gui.MultiplayerService;
- using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling;
- namespace Gui.Classes
- {
- /// <summary>
- /// Clase Client. Se encarga de manejar la transferecia entre aplicaciones por LAN
- /// </summary>
- public class Client
- {
- private static Client _cliente;
- private static readonly Object Semaforo = new object();
- private readonly TransferServiceClient _clientServiceClient;
- private int _id = 1;
- /// <summary>
- /// Constructor de la clase Client
- /// </summary>
- protected Client()
- {
- _clientServiceClient = new TransferServiceClient("NetTcpBinding_ITransferService");
- }
- /// <summary>
- /// Gets the Client
- /// </summary>
- public TransferServiceClient ClientServiceClient
- {
- get { return _clientServiceClient; }
- }
- /// <summary>
- /// Gets the id of the client
- /// </summary>
- public int Id
- {
- get { return _id; }
- set { _id = value; }
- }
- /// <summary>
- /// Metodo que permite transferir datos al servidor
- /// </summary>
- /// <param name="tdata">Informacion a transferir</param>
- public void Transfer(TransferData tdata)
- {
- try
- {
- _clientServiceClient.SendDataClient(tdata);
- }
- catch (Exception ex)
- {
- //throw new ServerException("The Client had troubles connecting to the server", ex);
- if (ex is EndpointNotFoundException || ex is ServerException || ex is CommunicationObjectFaultedException || ex is CommunicationException)
- ExceptionPolicy.HandleException(ex, "ServerException");
- else
- ExceptionPolicy.HandleException(ex, "General");
- }
- finally
- {
- if (StringManager.Instance().CurrentLanguage == "english")
- MessageBox.Show("The Client had problems connecting to the server, please contact your System Administrator", "Connetion Error", MessageBoxButton.OK,
- MessageBoxImage.Error);
- else
- {
- MessageBox.Show("El cliente tuvo problemas al conectarse al servidor, por favor contacte al Administrador de su Sistema", "Error de Conexion", MessageBoxButton.OK,
- MessageBoxImage.Error);
- }
- }
- /*
- if (_clientServiceClient.State == CommunicationState.Opened)
- _clientServiceClient.SendDataClient(tdata);
- * */
- }
- /// <summary>
- /// Metodo que permite recibir datos del servidor
- /// </summary>
- public TransferData Receive()
- {
- try
- {
- return _clientServiceClient.DownloadDataServer(_id);
- }
- catch (Exception ex)
- {
- //throw new ServerException("The Client had troubles connecting to the server", ex);
- if (ex is EndpointNotFoundException || ex is ServerException || ex is CommunicationObjectFaultedException || ex is CommunicationException)
- ExceptionPolicy.HandleException(ex, "ServerException");
- else
- ExceptionPolicy.HandleException(ex, "General");
- }
- finally
- {
- if (StringManager.Instance().CurrentLanguage == "english")
- MessageBox.Show("The Client had problems connecting to the server, please contact your System Administrator", "Connetion Error", MessageBoxButton.OK,
- MessageBoxImage.Error);
- else
- MessageBox.Show("El cliente tuvo problemas al conectarse al servidor, por favor contacte al Administrador de su Sistema", "Error de Conexion", MessageBoxButton.OK,
- MessageBoxImage.Error);
- }
- return null;
- /*
- if (_clientServiceClient.State != CommunicationState.Closed || _clientServiceClient.State != CommunicationState.Closing)
- return _clientServiceClient.DownloadDataServer(_id);
- return null;
- * */
- }
- #region Singleton
- /// <summary>
- /// Metodo que sirve para llamar la clase Client desde un patron Singleton
- /// </summary>
- /// <returns></returns>
- public static Client Instance()
- {
- if (_cliente == null)
- {
- lock (Semaforo)
- {
- if (_cliente == null)
- {
- _cliente = new Client();
- }
- }
- }
- return _cliente;
- }
- #endregion
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment