Example #1
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>());
            }
        }
Example #3
0
        /// <summary>
        /// method that returns the config data from the service
        /// </summary>
        /// <returns>config data</returns>
        public ConfigData GetConfig()
        {
            try
            {
                ConfigData            cData       = new ConfigData();
                string[]              args        = new string[1];
                SynchTcpClientHandler commChannel = new SynchTcpClientHandler();
                this.commConfigCommand = new ServerClientCommunicationCommand(CommandEnum.GetConfigCommand, args);

                string message = commChannel.Send(this.commConfigCommand.ToJson());
                ServerClientCommunicationCommand commCommand = ServerClientCommunicationCommand.FromJson(message);
                if (commCommand.CommId == CommandEnum.GetConfigCommand)
                {
                    string  jsonData      = commCommand.Args[0];
                    JObject appConfigData = JObject.Parse(jsonData);
                    cData.OutputDirectory = (string)appConfigData["OutputDir"];
                    cData.SourceName      = (string)appConfigData["SourceName"];
                    cData.LogName         = (string)appConfigData["LogName"];
                    cData.ThumbnailSize   = (string)appConfigData["ThumbnailSize"];
                    string dirPathsListString = (string)appConfigData["dirPathsToManageListString"];
                    cData.DirectoryHandlerPaths = new List <string>(JsonConvert.DeserializeObject <List <string> >(dirPathsListString));
                    commChannel.Close();
                    return(cData);
                }
                else
                {
                    commChannel.Close();
                    return(new ConfigData()
                    {
                        LogName = "", SourceName = "", ThumbnailSize = "", OutputDirectory = "", DirectoryHandlerPaths = new List <string>()
                    });
                }
            }
            catch
            {
                return(new ConfigData()
                {
                    LogName = "", SourceName = "", ThumbnailSize = "", OutputDirectory = "", DirectoryHandlerPaths = new List <string>()
                });
            }
        }