/// <summary>
        /// method to send request of removing a directory handler based on a directory path
        /// </summary>
        /// <param name="path">the path of the directory that the handler listens to</param>
        public void SendRequestRemoveDirectoryPath(string path)
        {
            string[] args = new string[1];
            args[0] = path;
            ServerClientCommunicationCommand commCommand = new ServerClientCommunicationCommand(CommandEnum.CloseCommand, args);

            this.commChannel.Write(commCommand.ToJson());
        }
Exemple #2
0
        /// <summary>
        /// method to delete a handler (through the service)
        /// </summary>
        /// <param name="path">path to the handler</param>
        public void DeleteHandler(string path)
        {
            SynchTcpClientHandler commChannel = new SynchTcpClientHandler();

            string[] args = new string[1];
            args[0] = path;
            ServerClientCommunicationCommand commCommand = new ServerClientCommunicationCommand(CommandEnum.CloseCommand, args);

            commChannel.Send(commCommand.ToJson());
        }
        /// <summary>
        /// method returns the logs from the service
        /// </summary>
        /// <param name="filterBy">string representing status to filter by</param>
        /// <returns>list of filtered logs</returns>
        public IEnumerable <LogMessage> GetLogs(string filterBy)
        {
            try
            {
                SynchTcpClientHandler commChannel = new SynchTcpClientHandler();

                bool filter = true;
                if (filterBy == null || filterBy == "")
                {
                    filter = false;
                }
                List <LogMessage> logs = new List <LogMessage>();
                filterBy = filterBy?.ToLower();

                ServerClientCommunicationCommand commCommand = new ServerClientCommunicationCommand(CommandEnum.LogCommand, null);
                string receivedMessage = commChannel.Send(commCommand.ToJson());
                ServerClientCommunicationCommand logsCommCommand = ServerClientCommunicationCommand.FromJson(receivedMessage);
                if (logsCommCommand.CommId == CommandEnum.LogCommand)
                {
                    string jsonLogs = logsCommCommand.Args[0];
                    List <MessageRecievedEventArgs> tmpList = JsonConvert.DeserializeObject <List <MessageRecievedEventArgs> >(jsonLogs);
                    foreach (MessageRecievedEventArgs entry in tmpList)
                    {
                        if (!filter)
                        {
                            logs.Add(new LogMessage()
                            {
                                Message = entry.Message, Status = entry.Status
                            });
                        }
                        else
                        if (entry.Status.ToString().ToLower() == filterBy)
                        {
                            logs.Add(new LogMessage()
                            {
                                Message = entry.Message, Status = entry.Status
                            });
                        }
                    }
                    return(logs);
                }
                else
                {
                    return(new List <LogMessage>());
                }
            }
            catch
            {
                return(new List <LogMessage>());
            }
        }
        /// <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>
        /// method to request to get the logs
        /// </summary>
        public void GetLogs()
        {
            ServerClientCommunicationCommand commCommand = new ServerClientCommunicationCommand(CommandEnum.LogCommand, null);

            this.commChannel.Write(commCommand.ToJson());
        }