Example #1
0
        /// <summary>
        /// Execute command.
        /// </summary>
        /// <param name="args"></param>
        /// <param name="result"></param>
        /// <returns></returns>
        public string Execute(string[] args, out bool result)
        {
            //Get handler to remove from args.
            string removeHandler = args[0];

            //Remove wanted handler.
            result = m_imageServer.RemoveHandler(removeHandler);
            string resultString;

            //Check result and create result string accordingly.
            if (result)
            {
                resultString = "Handler " + removeHandler + " removed";
            }
            else
            {
                resultString = "Handler " + removeHandler + " can't be removed. Check log.";
            }
            //Create result command.
            ConfigurationRecieveEventArgs command =
                new ConfigurationRecieveEventArgs((int)ConfigurationEnum.RemoveHandler, args);
            //Serialize it.
            string output = JsonConvert.SerializeObject(command);

            //Invoke with result command.
            //m_handleGui.InvokeEvent(command);
            return(output);
        }
        /// <summary>
        /// handeling the command of removing a handler
        /// </summary>
        /// <param name="server">the server of the service</param>
        /// <param name="commandAndArg">the command and the path of the handler that need to be remove </param>
        private void RemoveHandler(ImageServer server, string[] commandAndArg)
        {
            List <TcpClient> clients = server.GetClients();
            string           result  = server.RemoveHandler(commandAndArg[1]);

            if (result == "sucsses")
            {
                foreach (TcpClient c in clients)
                {
                    NetworkStream tempStream = c.GetStream();
                    BinaryWriter  tempWriter = new BinaryWriter(tempStream);
                    try
                    {
                        JObject configObj = new JObject
                        {
                            ["CommandEnum"]        = (int)CommandEnum.CloseCommand,
                            ["RemovedHandlerPath"] = commandAndArg[1]
                        };
                        tempWriter.Write(configObj.ToString());
                        //tempWriter.Write("RemovedHandler" + '#' + commandAndArg[1]);
                    }
                    catch (Exception)
                    {
                        this.RemoveClient(clients, c);
                    }
                }
            }
        }