private void btnLoadServerInfo_Click(object sender, EventArgs e)
 {
     try
     {
         OpenFileDialog ofd = new OpenFileDialog();
         ofd.Filter = "JSON File|*.json";
         var result = ofd.ShowDialog();
         if (result == DialogResult.OK)
         {
             lblServerInfoFile.Text = ofd.FileName;
             var text = File.ReadAllText(ofd.FileName);
             serverInfo           = JsonConvert.DeserializeObject <ServerInfo>(text);
             client               = new AwsSqsClient(serverInfo);
             btnLoadSites.Enabled = true;
         }
         else
         {
             lblServerInfoFile.Text = "No File Selected";
         }
     }
     catch (Exception ex)
     {
         ShowMessage(ex);
     }
 }
示例#2
0
        private static void PushToServer(IEnumerable <ReonParsedPacket> packets)
        {
            try
            {
                ServerInfo listener = JsonConvert.DeserializeObject <ServerInfo>(File.ReadAllText(@"Config\aws.json"));
                int        total    = packets.Count();
                Console.WriteLine("Total: {0}", total);
                var client = new AwsSqsClient(listener);

                int count = 0;
                foreach (var packet in packets)
                {
                    count++;
                    try
                    {
                        var request = JsonConvert.SerializeObject(packet);

                        var res = client.PostData(request);
                        Console.WriteLine(string.Format("{0} - Count: {1} - Remaining: {2}", res.Result, count, (total - count)));
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
示例#3
0
        private void PushToServer(IEnumerable <PushApiEntity> packets)
        {
            string MethodName = nameof(PushToServer);

            try
            {
                var listeners = ServerChannelConfigurationManager.Instance.Configurations.Listeners;

                foreach (var listener in listeners)
                {
                    try
                    {
                        var client = new AwsSqsClient(listener);

                        int logLevel = (int)WebApiServerConfigurationManager.Instance.Configurations.LogLevel;

                        client.LogPacketOnFailure = true;

                        if (logLevel >= (int)Component.Logging.Models.LogLevel.Debug)
                        {
                            client.LogPacketOnSuccess = true;
                        }
                        else
                        {
                            client.LogPacketOnSuccess = false;
                        }

                        foreach (var packet in packets)
                        {
                            try
                            {
                                var res = client.PostData(packet.Request).Result;
                            }
                            catch (Exception)
                            {
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        WebServer.WebApiLogger?.Error(ClassName, MethodName, ex.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                WebServer.WebApiLogger?.Error(ClassName, MethodName, ex.ToString());
            }
        }
示例#4
0
        public Result <Production> Produce(int messages)
        {
            var production = new Production();
            var final      = new Result <Production>();

            AsyncUtil.Fork(() => {
                try {
                    _log.DebugFormat("{0}: Producing {1} messages", production.Id, messages);
                    var responses = new List <Result <string> >();
                    var client    = new AwsSqsClient(_clientConfig);
                    for (var i = 0; i < messages; i++)
                    {
                        var result = new Result <string>();
                        responses.Add(result);
                        var msg = production.Id + ":" + messages;
                        client.Send(_queue, AwsSqsMessage.FromBody(msg), new Result <AwsSqsSendResponse>()).WhenDone(r => {
                            if (r.HasException)
                            {
                                result.Throw(r.Exception);
                                return;
                            }
                            result.Return(msg);
                        });
                    }
                    responses.Join(new Result()).WhenDone(r => {
                        if (r.HasException)
                        {
                            final.Throw(r.Exception);
                            return;
                        }
                        production.Stopwatch.Stop();
                        production.Sent.AddRange(responses.Select(x => x.Value));
                        _log.DebugFormat("{0}: Sent {1} messages in {2:0.00}s @ {3:0.00}msg/sec",
                                         production.Id,
                                         production.Sent.Count,
                                         production.Stopwatch.Elapsed.TotalSeconds,
                                         production.Sent.Count / production.Stopwatch.Elapsed.TotalSeconds
                                         );
                        final.Return(production);
                    });
                } catch (Exception e) {
                    final.Throw(e);
                }
            });
            return(final);
        }
        private void PushToServer(object request)
        {
            string methodName = nameof(PushToServer);

            try
            {
                var listeners = ServerChannelConfigurationManager.Instance.Configurations.Listeners;

                foreach (var listener in listeners)
                {
                    try
                    {
                        var client = new AwsSqsClient(listener);

                        int logLevel = (int)WebApiServerConfigurationManager.Instance.Configurations.LogLevel;

                        client.LogPacketOnFailure = true;

                        if (logLevel >= (int)Component.Logging.Models.LogLevel.Debug)
                        {
                            client.LogPacketOnSuccess = true;
                        }
                        else
                        {
                            client.LogPacketOnSuccess = false;
                        }

                        Task.Run(() => client.PostData(JsonConvert.SerializeObject(request, Formatting.None)));
                    }
                    catch (Exception ex)
                    {
                        Log?.Error(className, methodName, ex.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                Log?.Error(className, methodName, ex.ToString());
            }
        }
示例#6
0
 public Result<Production> Produce(int messages)
 {
     var production = new Production();
     var final = new Result<Production>();
     Async.Fork(() => {
         try {
             _log.DebugFormat("{0}: Producing {1} messages", production.Id, messages);
             var responses = new List<Result<string>>();
             var client = new AwsSqsClient(_clientConfig);
             for(var i = 0; i < messages; i++) {
                 var result = new Result<string>();
                 responses.Add(result);
                 var msg = production.Id + ":" + messages;
                 client.Send(_queue, AwsSqsMessage.FromBody(msg), new Result<AwsSqsSendResponse>()).WhenDone(r => {
                     if(r.HasException) {
                         result.Throw(r.Exception);
                         return;
                     }
                     result.Return(msg);
                 });
             }
             responses.Join(new Result()).WhenDone(r => {
                 if(r.HasException) {
                     final.Throw(r.Exception);
                     return;
                 }
                 production.Stopwatch.Stop();
                 production.Sent.AddRange(responses.Select(x => x.Value));
                 _log.DebugFormat("{0}: Sent {1} messages in {2:0.00}s @ {3:0.00}msg/sec",
                     production.Id,
                     production.Sent.Count,
                     production.Stopwatch.Elapsed.TotalSeconds,
                     production.Sent.Count / production.Stopwatch.Elapsed.TotalSeconds
                 );
                 final.Return(production);
             });
         } catch(Exception e) {
             final.Throw(e);
         }
     });
     return final;
 }