Exemplo n.º 1
0
        /// <summary>
        /// method to handle a received message
        /// </summary>
        /// <param name="sender">sender of the message</param>
        /// <param name="messageArgs">the message arguments</param>
        private void ReadRecivedMessage(object sender, MessageCommunicationEventArgs messageArgs)
        {
            string message = messageArgs.Message;
            ServerClientCommunicationCommand commCommand = ServerClientCommunicationCommand.FromJson(message);

            switch (commCommand.CommId)
            {
            case CommandEnum.LogCommand:
                string jsonLogs = commCommand.Args[0];
                List <MessageRecievedEventArgs> tmpList = JsonConvert.DeserializeObject <List <MessageRecievedEventArgs> >(jsonLogs);
                foreach (MessageRecievedEventArgs entry in tmpList)
                {
                    try
                    {
                        //moving the action to be handled in the UI thread
                        App.Current.Dispatcher.Invoke((Action) delegate
                        {
                            this.Logs.Insert(0, entry);
                        });
                    }
                    catch (Exception exc)
                    {
                        string msg = exc.Message;
                    }
                }
                break;

            default:
                break;
            }
        }
        /// <summary>
        /// method to handle received message
        /// </summary>
        /// <param name="sender">the sender of the message</param>
        /// <param name="messageArgs">the arguments of the message</param>
        private void ReadRecivedMessage(object sender, MessageCommunicationEventArgs messageArgs)
        {
            string message = messageArgs.Message;
            ServerClientCommunicationCommand commCommand = ServerClientCommunicationCommand.FromJson(message);

            switch (commCommand.CommId)
            {
            case CommandEnum.GetConfigCommand:
                this.InitializeConfigData(commCommand.Args[0]);
                break;

            case CommandEnum.CloseCommand:
                this.ExecuteRemoveDirectoryPath(commCommand.Args[0]);
                break;

            default:
                break;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// method for handeling message from communication channel
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="message"> received message</param>
        private void HandleMessageFromServer(object sender, MessageCommunicationEventArgs message)
        {
            IClientHandler clientHandler = sender as IClientHandler;
            ServerClientCommunicationCommand commCommand = ServerClientCommunicationCommand.FromJson(message.Message);

            switch (commCommand.CommId)
            {
            case CommandEnum.GetConfigCommand:
            //asking for logs list
            case CommandEnum.LogCommand:
                bool     flag1;
                string   result       = this.m_controller.ExecuteCommand(commCommand.CommId, commCommand.Args, out flag1);
                string[] responseArr1 = new string[1];
                responseArr1[0] = result;
                ServerClientCommunicationCommand responseCommand = new ServerClientCommunicationCommand(commCommand.CommId, responseArr1);
                string responseJson = responseCommand.ToJson();
                //writing back the answer to the client request
                clientHandler?.WriteMessage(responseJson);
                break;

            //closing a directory handler request
            case CommandEnum.CloseCommand:
                bool   flag2;
                string pathRemoved = this.m_controller.ExecuteCommand(commCommand.CommId, commCommand.Args, out flag2);
                //writing to all of the connected clients the path of directory which's handler closed
                string[] responseArr2 = new string[1];
                responseArr2[0] = pathRemoved;
                this.m_serverChannel.BroadcastToClients(new ServerClientCommunicationCommand(CommandEnum.CloseCommand, responseArr2));
                break;

            case CommandEnum.PhotoTransferCommand:
                bool   flag3;
                string temp = this.m_controller.ExecuteCommand(commCommand.CommId, commCommand.Args, out flag3);
                break;

            default:
                clientHandler?.WriteMessage("Invalid command Id");
                break;
            }
        }
 /// <summary>
 /// invoke the message that was received, pass higher
 /// </summary>
 /// <param name="sender">the sender of the message</param>
 /// <param name="messageArgs">the message that was received</param>
 private void HandleRecivedMessage(object sender, MessageCommunicationEventArgs messageArgs)
 {
     this.MessageReceived?.Invoke(this, messageArgs);
 }