Ejemplo n.º 1
0
 /// <summary>
 /// ImageServiceSrv constructor.
 /// </summary>
 /// <param name="port">port num</param>
 /// <param name="logging">ILoggingService obj</param>
 /// <param name="ch">IClientHandler obj</param>
 public ImageServiceSrv(int port, ILoggingService logging, IClientHandler ch)
 {
     this.Port           = port;
     this.Logging        = logging;
     this.Ch             = ch;
     ClientHandler.Mutex = m_mutex;
 }
Ejemplo n.º 2
0
        private void OnLoginPress(object sender, RoutedEventArgs e)
        {
            //purposely using variable capturing here
            string loginName = this.localName.Text;

            this.Name = loginName;

            //get sending task off the GUI thread
            Task.Run(() =>
            {
                try
                {
                    IResponseManager responseManager = this.services.ResponseManager;
                    responseManager.Start();

                    IMessageHandler messageHandler = this.services.MessageHandler;
                    IMessage request = messageHandler.GetMessage(loginName, "server", loginName,
                                                                 MessageCommand.LoginRequest);

                    IClientHandler clientHandler = this.services.ClientHandler;
                    clientHandler.SendMessage(request);
                }
                catch (Exception exception)
                {
                    this.services.ChatLog.LogMessage(string.Format("Unable to send log in : {0}", exception.Message));
                }
            });
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Represents a TCP server channel.
 /// </summary>
 /// <param name="port">The server's port.</param>
 /// <param name="loggingService">The logging service.</param>
 /// <param name="clientHandler">The client handler.</param>
 public TcpServerChannel(int port, ILoggingService loggingService, IClientHandler clientHandler)
 {
     this.port           = port;
     this.clientHandler  = clientHandler;
     this.loggingService = loggingService;
     writeLock           = clientHandler.getLock();
 }
Ejemplo n.º 4
0
        private void OnUpdateNamePress(object sender, RoutedEventArgs e)
        {
            //purposely using variable capturing here
            string newName = this.localName.Text;
            string oldName = this.Name;

            this.Name = newName;

            //get sending task off the GUI thread
            Task.Run(() =>
            {
                try
                {
                    IMessageHandler messageHandler = this.services.MessageHandler;
                    IMessage request = messageHandler.GetMessage(oldName, "server", newName, MessageCommand.UpdateName);

                    IClientHandler clientHandler = this.services.ClientHandler;
                    clientHandler.SendMessage(request);
                }
                catch (Exception exception)
                {
                    this.services.ChatLog.LogMessage(string.Format("Unable to send name update : {0}", exception.Message));
                }
            });
        }
Ejemplo n.º 5
0
 public TcpServerChannel(int port, IClientHandler ch, ILoggingService logger)
 {
     this.port   = port;
     this.ch     = ch;
     this.logger = logger;
     clients     = new List <TcpClient>();
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Constructor for ImageServer class
        /// </summary>
        /// <param name="logging">the logging service that will be connected to the image service</param>
        /// <param name="port">the port of the tcp server the constructor creates</param>
        public ImageServer(ILoggingService logging, int port)
        {
            m_logging = logging;
            IImageServiceModal modal = new ImageServiceModal();

            m_controller                      = new ImageController(modal);
            m_clientHandler                   = new ClientHandler(m_controller);
            m_TCPServer                       = new TcpServerChannel(port, m_clientHandler);
            m_handlerManager                  = HandlerManager.Instance;
            m_handlerManager.Logging          = m_logging;
            m_handlerManager.Controller       = m_controller;
            m_handlerManager.CommandRecieved += delegate(object sender, CommandRecievedEventArgs e)
            {
                switch (e.CommandID)
                {
                case (int)CommandEnum.RemoveHandler:
                    CommandMessage message = new CommandMessage
                    {
                        Status   = true,
                        Type     = CommandEnum.RemoveHandler,
                        Message  = @"Removed handler " + e.RequestDirPath,
                        Handlers = new string[] { e.RequestDirPath }
                    };
                    m_logging.Log(message.Message, LogMessageTypeEnum.INFO);
                    m_TCPServer.SendMessage(message.ToJSONString(), ServerMessageTypeEnum.CloseHandlerMessage);
                    break;

                default:
                    break;
                }
            };
            m_logStorage = LogStorage.Instance;
            m_logging.MessageRecieved += m_logStorage.AddLog;
        }
Ejemplo n.º 7
0
        private void OnSendMessagePress(object sender, RoutedEventArgs e)
        {
            //Capture message text
            string message       = this.messageText.Text;
            string messageSender = this.Name;

            //send message
            Task.Run(() =>
            {
                try
                {
                    IMessageHandler messageHandler = this.services.MessageHandler;
                    IMessage request = messageHandler.GetMessage(messageSender, "server", message,
                                                                 MessageCommand.ChatMessage);

                    IClientHandler clientHandler = this.services.ClientHandler;
                    clientHandler.SendMessage(request);
                }
                catch (Exception exception)
                {
                    this.services.ChatLog.LogMessage(string.Format("Unable to send message : {0}", exception.Message));
                }
            });

            //Clear message text from box
            this.messageText.Clear();
        }
Ejemplo n.º 8
0
 public ISServer(int port, ILoggingService logging, IClientHandler ch)
 {
     this.port           = port;
     this.Logging        = logging;
     this.ch             = ch;
     ClientHandler.Mutex = m_mutex;
 }
Ejemplo n.º 9
0
        private void HandleReceived_Client(NecClient client, NecPacket packet)
        {
            if (!_clientHandlers.ContainsKey(packet.id))
            {
                _Logger.LogUnknownIncomingPacket(client, packet, _serverType);
                return;
            }

            IClientHandler clientHandler = _clientHandlers[packet.id];

            if (clientHandler.expectedSize != NO_EXPECTED_SIZE && packet.data.Size < clientHandler.expectedSize)
            {
                _Logger.Error(client,
                              $"[{_serverType}] Ignoring Packed (Id:{packet.id}) is smaller ({packet.data.Size}) than expected ({clientHandler.expectedSize})");
                return;
            }

            _Logger.LogIncomingPacket(client, packet, _serverType);
            packet.data.SetPositionStart();
            try
            {
                clientHandler.Handle(client, packet);
            }
            catch (Exception ex)
            {
                _Logger.Exception(client, ex);
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// getting the settings from the app config and Initializing the service
        /// </summary>
        /// <param name="args">arguments</param>
        public ImageService(string[] args)
        {
            InitializeComponent();
            string handler       = ConfigurationManager.AppSettings.Get("Handler");
            string outputDir     = ConfigurationManager.AppSettings.Get("OutputDir");
            string thumbnailSize = ConfigurationManager.AppSettings.Get("ThumbnailSize");

            string eventSourceName = ConfigurationManager.AppSettings.Get("SourceName");
            string logName         = ConfigurationManager.AppSettings.Get("LogName");

            eventLog1 = new System.Diagnostics.EventLog();
            if (!System.Diagnostics.EventLog.SourceExists(eventSourceName))
            {
                System.Diagnostics.EventLog.CreateEventSource(eventSourceName, logName);
            }
            eventLog1.Source = eventSourceName;
            eventLog1.Log    = logName;

            logging = new LoggingService();
            logging.MessageRecieved += OnMsg;
            modal       = new ImageServiceModal(outputDir, int.Parse(thumbnailSize));
            controller  = new ImageController(modal, logging);
            imageServer = new ImageServer(controller, logging, handler);
            //clientHandler = new HandleGuiClient(controller, logging, imageServer);
            clientHandler = new HandleAndroidClient(controller, logging, imageServer);
            serverChannel = new TcpServerChannel(8000, logging, clientHandler);
            clientHandler.NotifyClients += serverChannel.NotifyClients;
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Removes client handler
        /// </summary>
        public void RemoveClientHandler(IClientHandler handler)
        {
            List <IClientHandler> list = _clientHandlers.ToList();

            list.Remove(handler);
            _clientHandlers = list.ToArray();
        }
Ejemplo n.º 12
0
 public NetworkServer(int i_Port, IImageController i_Controller, ILoggingService i_Logger)
 {
     m_Port          = i_Port;
     m_Logger        = i_Logger;
     m_Controller    = i_Controller;
     m_ClientHandler = new ClientHandler();
 }
Ejemplo n.º 13
0
        private void HandleReceived_Client(MhfClient client, MhfPacket packet)
        {
            if (!_clientHandlers.ContainsKey(packet.Id))
            {
                //_logger.LogUnknownIncomingPacket(client, packet);
                return;
            }

            IClientHandler clientHandler = _clientHandlers[packet.Id];

            if (clientHandler.ExpectedSize != NoExpectedSize && packet.Data.Size < clientHandler.ExpectedSize)
            {
                _logger.Error(client,
                              $"Ignoring Packed (Id:{packet.Id}) is smaller ({packet.Data.Size}) than expected ({clientHandler.ExpectedSize})");
                return;
            }

            //  _logger.LogIncomingPacket(client, packet);
            packet.Data.SetPositionStart();
            try
            {
                clientHandler.Handle(client, packet);
            }
            catch (Exception ex)
            {
                _logger.Exception(client, ex);
            }
        }
Ejemplo n.º 14
0
        public IServerMsg.EnterRoomResponse <byte[]> EnterRoom(IClientHandler client, string?password, byte[]?status)
        {
            if (Password is string p && p != password)
            {
                return(IServerMsg.EnterRoomResponse.InvalidPassword);
            }
            if (Info.MaxNumberOfPlayers == _clients.Count)
            {
                return(IServerMsg.EnterRoomResponse.NumberOfPlayersLimitation);
            }

            if (!_roomConfig.EnterWhenPlayingAllowed && RoomStatus == RoomStatus.Playing)
            {
                return(IServerMsg.EnterRoomResponse.InvalidRoomStatus);
            }

            if (_clients.Contains(client))
            {
                return(IServerMsg.EnterRoomResponse.AlreadyEntered);
            }

            var ownerId = EnterRoomWithoutCheck(client, status);

            WriteInfo($"Room({Id}): client({client.Id}) entered.");

            return(IServerMsg.EnterRoomResponse.Success(ownerId, _playersStatuses, Info.Message));
        }
Ejemplo n.º 15
0
 public Info()
 {
     ep        = new IPEndPoint(IPAddress.Parse(_settings.FlightServerIP), _settings.FlightInfoPort);
     _settings = ApplicationSettingsModel.Instance;
     _stop     = false;
     ch        = new ClientHandler();
 }
        public async Task <GenericCommandResult <ClientEntity> > Repprove([FromServices] IClientHandler handler,
                                                                          [FromBody] RepproveClientCommand command)
        {
            var result = (GenericCommandResult <ClientEntity>) await handler.HandleAsync(command);

            return(result);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Starts this instance.
        /// </summary>
        public void Start()
        {
            listener.Start();
            Console.WriteLine("Waiting for conections...");

            Task task = new Task(() =>
            {
                IClientHandler ch;
                while (true)
                {
                    try
                    {
                        TcpClient client = listener.AcceptTcpClient();
                        ch = new ClientHandler(client);
                        clients.Add(ch);
                        ch.DataReceived += MoveToServer;
                        ch.Start();
                    }
                    catch (SocketException)
                    {
                        break;
                    }
                }
            });

            task.Start();
        }
Ejemplo n.º 18
0
        private List <TcpClient> clientsList; //list of all connected clients.

        /*constructor for server communication.
         * param name=port1, the port we listen to.
         * param name=clientHandler, variable of the class that handles all gui service.
         */
        public TCPServer(int port1, IClientHandler clientHandler1)
        {
            this.port          = port1;
            this.clientHandler = clientHandler1;
            this.clientsList   = new List <TcpClient>();
            Start();
        }
Ejemplo n.º 19
0
        public void AddHandler(IClientHandler clientHandler, bool overwrite = false)
        {
            if (overwrite)
            {
                if (_clientHandlers.ContainsKey(clientHandler.Id))
                {
                    _clientHandlers[clientHandler.Id] = clientHandler;
                }
                else
                {
                    _clientHandlers.Add(clientHandler.Id, clientHandler);
                }

                return;
            }

            if (_clientHandlers.ContainsKey(clientHandler.Id))
            {
                _logger.Error($"ClientHandlerId: {clientHandler.Id} already exists");
            }
            else
            {
                _clientHandlers.Add(clientHandler.Id, clientHandler);
            }
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Adds client handler
        /// </summary>
        public void AddClientHandler(IClientHandler handler)
        {
            List <IClientHandler> list = _clientHandlers.ToList();

            list.Add(handler);
            _clientHandlers = list.ToArray();
        }
Ejemplo n.º 21
0
        public void Start(string ip, int port, IClientHandler clientHandler)
        {
            //Initialize connection settings.
            IPEndPoint ep = new
                            IPEndPoint(IPAddress.Parse(ip), port);

            listener = new TcpListener(ep);

            //Start listening for connections.
            listener.Start();
            Console.WriteLine("Waiting for connections...");

            //The server task.
            this.ServerTask = new Task(() =>
            {
                while (true)
                {
                    try
                    {
                        //Accept new connection.
                        TcpClient client = listener.AcceptTcpClient();
                        Console.WriteLine("Got new connection");
                        clientHandler.HandleClient(client);
                    }
                    catch (SocketException)
                    {
                        break;
                    }
                }
                Console.WriteLine("Server stopped");
            });
            this.ServerTask.Start();
        }
Ejemplo n.º 22
0
        public void Start()
        {
            //create socket to server
            IPEndPoint ep = new IPEndPoint(IPAddress.Parse("127.0.0.1"), port);

            listener = new TcpListener(ep);
            listener.Start();

            /*
             * wait to clients
             */
            Task task = new Task(() =>
            {
                while (true)
                {
                    try
                    {
                        TcpClient client = listener.AcceptTcpClient();
                        Console.WriteLine("Got new connection");
                        //perform the task
                        this.ch = new ClientHandler(client);
                        ch.HandleClient(client, this.controller);
                    }
                    catch (SocketException)
                    {
                        break;
                    }
                }
                Console.WriteLine("Server stopped");
                Console.ReadKey();
            }); task.Start();
        }
Ejemplo n.º 23
0
        /// <summary>
        /// OnClientClose is summoned by the ClientClose event.
        /// The method gets the ClientHandler out from the SendAll event handlers list,
        /// and gets the ExecuteCommand out from the ClientHandler's NewMessage event handlers list.
        /// </summary>
        /// <param name="sender">the ClientHandler that closed</param>
        public void OnClientClose(object sender, EventArgs args)
        {
            m_logging.Log("Client closed", MessageTypeEnum.INFO);
            IClientHandler ch = (IClientHandler)sender;

            CloseAll      -= ch.OnCloseAll;
            ch.NewMessage -= GetPhoto;
        }
Ejemplo n.º 24
0
 public TcpServer(int port, IClientHandler ch, ILoggingService m_logging)
 {
     this.port    = port;
     this.ch      = ch;
     this.clients = new List <TcpClient>();
     this.mux     = new Mutex();
     m_logging.MessageRecieved += SpreadLogEntry;
 }
        public TcpServerChannel()
        {
            string ip   = ConfigurationManager.AppSettings["Ip"];
            string port = ConfigurationManager.AppSettings["Port"];

            server        = new TcpListener(IPAddress.Any, Int32.Parse(port));
            clientHandler = new ClientHandler();
        }
Ejemplo n.º 26
0
 /// <summary>
 /// new
 /// </summary>
 /// <param name="protocol"></param>
 public BaseSocketClient(IPAddress remote, int port, IClientHandler handler)
     : this(new DefaultBinaryProtocol(), 8192, 8192, 3000, 3000)
 {
     if (handler == null) throw new ArgumentNullException("handler");
     this._handler = handler;
     this._remote = remote;
     this._port = port;
 }
Ejemplo n.º 27
0
    /// <summary>
    /// Removes the handler from list.
    /// </summary>
    /// <param name="sender">The sender.</param>
    /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
    private void RemoveHandlerFromList(object sender, EventArgs e)
    {
        IClientHandler handlerToRemove = (IClientHandler)sender;

        m_mutex.WaitOne();
        this.ch.Remove(handlerToRemove);
        m_mutex.ReleaseMutex();
    }
Ejemplo n.º 28
0
 /// <summary>
 /// Constuctor.
 /// </summary>
 /// <param name="logging"></param>
 /// <param name="handler"></param>
 /// <param name="port"></param>
 public ServiceServer(ILoggingService logging, IClientHandler handler, int port)
 {
     this.Logging            = logging;
     this.PortNumber         = port;
     this.Handler            = handler;
     clientList              = new List <TcpClient>();
     ClientHandler.MutexLock = serverMutex;
 }
Ejemplo n.º 29
0
 public ISServer(int port, ILoggingService logging, IClientHandler ch)
 {
     this.port           = port;
     this.Logging        = logging;
     this.ch             = ch;
     ClientHandler.Mutex = m_mutex;
     debug = new Debug_program();
 }
Ejemplo n.º 30
0
 public StateService(IFarmContext context, IDateTime dateTime, ISettingsService settingsService, IFarmBuilder farmBuilder, IClientHandler clientHandler)
 {
     _context         = context;
     _dateTime        = dateTime;
     _settingsService = settingsService;
     _farmBuilder     = farmBuilder;
     _clientHandler   = clientHandler;
 }
Ejemplo n.º 31
0
 /// <summary>
 /// constructor
 /// </summary>
 /// <param name="imageServer"></param>
 /// <param name="imageController"></param>
 /// <param name="logging"></param>
 /// <param name="port"></param>
 public MobileServer(ImageServer imageServer, IImageController imageController, ILoggingService logging, int port)
 {
     this.m_port        = port;
     this.m_logging     = logging;
     this.m_controller  = imageController;
     this.m_imageServer = imageServer;
     this.m_ch          = new ClientHandleForMobile(this.m_logging);
 }
        public Client(string hostname, int port, IClientHandler handler)
        {
            this.handler = handler;
            this.tcpClient = new TcpClient();
            this.tcpClient.Connect(hostname, port);
            this.networkStream = this.tcpClient.GetStream();

            this.handler.Log("Connected");

            ThreadPool.QueueUserWorkItem(ReadThread);
        }
Ejemplo n.º 33
0
 public DefaultSocketClient(IPAddress address, int port, IClientHandler handler,IEncoder encoder)
     : base(address, port, handler)
 {
     if (encoder == null) throw new ArgumentNullException("encoder");
     this._encoder = encoder;
 }
Ejemplo n.º 34
0
 public void Add(IPEndPoint endpoint, IClientHandler clientHandler)
 {
     this.m_Handlers.Add(endpoint, clientHandler);
 }
Ejemplo n.º 35
0
 private void RemoveHandler(IClientHandler handler)
 {
     lock(_openConnections) {
         _openConnections.Remove(handler);
     }
 }