Пример #1
0
        BotInputOutput GetHTMLReport(string xmlReport)
        {
            BotInputOutput input = GenerateNewCommand("tohtml");

            AddData(input, "Report", xmlReport);
            return(SendAndReceiveCommand(input));
        }
Пример #2
0
        BotInputOutput RunHealthCheck(StartScanInputAsset Asset)
        {
            BotInputOutput input    = GenerateNewCommand("healthcheck");
            var            Login    = ScanSetting.options?.Login;
            var            Password = ScanSetting.options?.Password;
            var            Port     = ScanSetting.options?.Port;
            var            Protocol = ScanSetting.options?.Protocol;

            if (!string.IsNullOrEmpty(Login))
            {
                AddData(input, "Login", Login);
            }
            if (!string.IsNullOrEmpty(Password))
            {
                AddData(input, "Password", Password);
            }
            if (!string.IsNullOrEmpty(Port))
            {
                AddData(input, "Port", Port);
            }
            if (!string.IsNullOrEmpty(Protocol))
            {
                AddData(input, "Protocol", Protocol);
            }
            AddData(input, "Server", Asset.value);
            return(SendAndReceiveCommand(input));
        }
Пример #3
0
        private static BotInputOutput GenerateNewCommand(string command)
        {
            var input = new BotInputOutput();

            input.Data = new List <BotData>();
            AddData(input, "Command", command);
            return(input);
        }
Пример #4
0
 static string GetItem(BotInputOutput input, string key)
 {
     foreach (var k in input.Data)
     {
         if (k.Key == key)
         {
             return(k.Value);
         }
     }
     return(null);
 }
Пример #5
0
 private static void AddData(BotInputOutput o, string key, string value)
 {
     o.Data.Add(new BotData(key, value));
 }
Пример #6
0
        BotInputOutput SendAndReceiveCommand(BotInputOutput input)
        {
            XmlSerializer xs = new XmlSerializer(typeof(BotInputOutput));

            lock (this)
            {
                try
                {
                    if (Bot == null || !Bot.Responding)
                    {
                        throw new ApplicationException("Job stopped");
                    }

                    using (var ms = new MemoryStream())
                        using (XmlWriter writer = XmlWriter.Create(ms))
                        {
                            xs.Serialize(writer, input);
                            ms.Position = 0;
                            var buffer = ms.GetBuffer();
                            var t      = BitConverter.GetBytes((int)ms.Length);
                            pipe.Write(t, 0, 4);
                            pipe.Write(buffer, 0, (int)ms.Length);
                        }
                    Console.WriteLine("Master: message sent");
                }
                catch (Exception ex)
                {
                    throw new ApplicationException("Exception when sending " + ex.Message);
                }
            }
            try
            {
                var buffer = new byte[4];
                int read   = pipe.Read(buffer, 0, 4);
                if (read < 4)
                {
                    throw new ApplicationException("Pipe shutdown");
                }
                int count = BitConverter.ToInt32(buffer, 0);
                var data  = new byte[count];
                read = 0;
                while (read < count)
                {
                    int r = pipe.Read(data, read, count - read);
                    if (r == 0)
                    {
                        throw new ApplicationException("Pipe shutdown");
                    }
                    read += r;
                }
                Console.WriteLine("Master: message received");
                //
                using (var ms = new MemoryStream(data))
                {
                    var output = (BotInputOutput)xs.Deserialize(ms);
                    return(output);
                }
            }
            catch (Exception ex)
            {
                throw new ApplicationException("Exception when receiving " + ex.Message);
            }
        }