Ejemplo n.º 1
0
        private static void PublishonAS2(object url)
        {
            FormatServerResponse.DisplayMessage("Publish EDI message");
            PropogationContext context = new PropogationContext();

            context.URL    = url as string;
            context.Folder = Settings.AvgFolder;
            SendEDIMessage request = new SendEDIMessage();

            request.SendEDI(context);
            FormatServerResponse.DisplayMessage("Number of messages published - " + MessageCounter.IncrementAvgMessageSent());
        }
Ejemplo n.º 2
0
        private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            clientStartTime = DateTime.Now;
            Stopwatch monitor   = new Stopwatch();
            int       loopCount = 0;

            monitor.Start();
            var worker = sender as BackgroundWorker;

            string[] urlLis = Settings.URL.Split('|');

            while (watch.ElapsedMilliseconds < Settings.Duration && !e.Cancel)
            {
                e.Cancel = worker.CancellationPending;

                if (monitor.ElapsedMilliseconds > 60000 * loopCount)
                {
                    FormatServerResponse.DisplaySuccessMessage("Entered loop - " + (loopCount + 1));

                    if (!String.IsNullOrEmpty(Settings.AvgFolder))
                    {
                        if (!e.Cancel)
                        {
                            Task.Factory.StartNew(() =>
                            {
                                FormatServerResponse.DisplayMessage("Starting Avg message publish");

                                for (int i = 0; i < Settings.AvgMessagePerMin; i++)
                                {
                                    if (e.Cancel)
                                    {
                                        break;
                                    }

                                    for (int j = 0; j < urlLis.Count(); j++)
                                    {
                                        if (!String.IsNullOrEmpty(urlLis[j]))
                                        {
                                            FormatServerResponse.DisplayMessage("Publish EDI message to " + urlLis[j]);
                                            PropogationContext context = new PropogationContext();
                                            context.URL    = urlLis[j];
                                            context.Folder = Settings.AvgFolder;
                                            Task.Factory.StartNew(() =>
                                            {
                                                if (!e.Cancel)
                                                {
                                                    SendEDIMessage request = new SendEDIMessage();
                                                    request.SendEDI(context);
                                                    FormatServerResponse.DisplayMessage("Number of Avg messages published - " + MessageCounter.IncrementAvgMessageSent());
                                                    UpdateTime(DateTime.Now);
                                                }
                                            });
                                        }
                                    }
                                }
                            });
                        }
                    }

                    if (!String.IsNullOrEmpty(Settings.MinFolder))
                    {
                        if (!e.Cancel)
                        {
                            Task.Factory.StartNew(() =>
                            {
                                FormatServerResponse.DisplayMessage("Starting Min message publish");
                                for (int i = 0; i < Settings.MinMessagePerMin; i++)
                                {
                                    if (e.Cancel)
                                    {
                                        break;
                                    }
                                    for (int j = 0; j < urlLis.Count(); j++)
                                    {
                                        if (!String.IsNullOrEmpty(urlLis[j]))
                                        {
                                            FormatServerResponse.DisplayMessage("Publish EDI message to " + urlLis[j]);
                                            PropogationContext context = new PropogationContext();
                                            context.URL    = urlLis[j];
                                            context.Folder = Settings.MinFolder;
                                            Task.Factory.StartNew(() =>
                                            {
                                                if (!e.Cancel)
                                                {
                                                    SendEDIMessage request = new SendEDIMessage();
                                                    request.SendEDI(context);
                                                    FormatServerResponse.DisplayMessage("Number of Min  messages published - " + MessageCounter.IncrementMinMessageSent());
                                                    UpdateTime(DateTime.Now);
                                                }
                                            });
                                        }
                                    }
                                }
                            });
                        }
                    }

                    if (!String.IsNullOrEmpty(Settings.MaxFolder))
                    {
                        if (!e.Cancel)
                        {
                            Task.Factory.StartNew(() =>
                            {
                                FormatServerResponse.DisplayMessage("Starting Max message publish");
                                for (int i = 0; i < Settings.MaxMessagePerMin; i++)
                                {
                                    if (e.Cancel)
                                    {
                                        break;
                                    }
                                    for (int j = 0; j < urlLis.Count(); j++)
                                    {
                                        if (!String.IsNullOrEmpty(urlLis[j]))
                                        {
                                            FormatServerResponse.DisplayMessage("Publish EDI message to " + urlLis[j]);
                                            PropogationContext context = new PropogationContext();
                                            context.URL    = urlLis[j];
                                            context.Folder = Settings.MaxFolder;

                                            Task.Factory.StartNew(() =>
                                            {
                                                if (!e.Cancel)
                                                {
                                                    SendEDIMessage request = new SendEDIMessage();
                                                    request.SendEDI(context);
                                                    FormatServerResponse.DisplayMessage("Number of Max messages published - " + MessageCounter.IncrementMaxMessageSent());
                                                    UpdateTime(DateTime.Now);
                                                }
                                            });
                                        }
                                    }
                                }
                            });
                        }
                    }

                    loopCount++;
                }

                if (!e.Cancel)
                {
                    Thread.Sleep(1000);
                }
                else
                {
                    break;
                }
            }
        }
Ejemplo n.º 3
0
        private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            clientStartTime = DateTime.Now;

            int loopCount = 0;
            var worker    = sender as BackgroundWorker;

            if (Settings.LogToFile)
            {
                Logger.Log("Start Time - " + clientStartTime.ToString("o"));
            }

            string[] urlLis = Settings.URL.Split('|');

            while (Helper.ElapsedMilliseconds < Settings.Duration && !e.Cancel)
            {
                e.Cancel = worker.CancellationPending;

                if (DateTime.Now.Subtract(clientStartTime).TotalMilliseconds > Settings.Mins * 60000 * loopCount)
                {
                    FormatServerResponse.DisplaySuccessMessage("Entered loop - " + (loopCount + 1));

                    if (!String.IsNullOrEmpty(Settings.AvgFolder))
                    {
                        if (!e.Cancel)
                        {
                            Task.Factory.StartNew(() =>
                            {
                                FormatServerResponse.DisplayMessage("Starting Avg message publish");

                                for (int i = 0; i < Settings.AvgMessagePerMin; i++)
                                {
                                    if (e.Cancel)
                                    {
                                        break;
                                    }

                                    foreach (string url in urlLis)
                                    {
                                        if (!String.IsNullOrEmpty(url))
                                        {
                                            FormatServerResponse.DisplayMessage("Publish EDI message to " + url);
                                            PropogationContext context = new PropogationContext();
                                            context.URL    = url;
                                            context.Folder = Settings.AvgFolder;

                                            ThreadPool.QueueUserWorkItem(delegate(object a)
                                            {
                                                // MessageCounter.IncrementThread();

                                                if (!e.Cancel)
                                                {
                                                    SendEDIMessage request = new SendEDIMessage();
                                                    request.SendEDI(context);
                                                    FormatServerResponse.DisplayMessage("Number of Avg messages published - " + MessageCounter.IncrementAvgMessageSent());
                                                    UpdateTime(DateTime.Now);
                                                }

                                                // MessageCounter.DecrementThread();
                                            });
                                        }
                                    }
                                }
                            });
                        }
                    }

                    if (!String.IsNullOrEmpty(Settings.MinFolder))
                    {
                        if (!e.Cancel)
                        {
                            Task.Factory.StartNew(() =>
                            {
                                FormatServerResponse.DisplayMessage("Starting Min message publish");
                                for (int i = 0; i < Settings.MinMessagePerMin; i++)
                                {
                                    if (e.Cancel)
                                    {
                                        break;
                                    }
                                    foreach (string url in urlLis)
                                    {
                                        if (!String.IsNullOrEmpty(url))
                                        {
                                            FormatServerResponse.DisplayMessage("Publish EDI message to " + url);
                                            PropogationContext context = new PropogationContext();
                                            context.URL    = url;
                                            context.Folder = Settings.MinFolder;

                                            ThreadPool.QueueUserWorkItem(delegate(object a)
                                            {
                                                // MessageCounter.IncrementThread();

                                                if (!e.Cancel)
                                                {
                                                    SendEDIMessage request = new SendEDIMessage();
                                                    request.SendEDI(context);
                                                    FormatServerResponse.DisplayMessage("Number of Min  messages published - " + MessageCounter.IncrementMinMessageSent());
                                                    UpdateTime(DateTime.Now);
                                                }

                                                // MessageCounter.DecrementThread();
                                            });
                                        }
                                    }
                                }
                            });
                        }
                    }

                    if (!String.IsNullOrEmpty(Settings.MaxFolder))
                    {
                        if (!e.Cancel)
                        {
                            Task.Factory.StartNew(() =>
                            {
                                FormatServerResponse.DisplayMessage("Starting Max message publish");
                                for (int i = 0; i < Settings.MaxMessagePerMin; i++)
                                {
                                    if (e.Cancel)
                                    {
                                        break;
                                    }
                                    foreach (string url in urlLis)
                                    {
                                        if (!String.IsNullOrEmpty(url))
                                        {
                                            FormatServerResponse.DisplayMessage("Publish EDI message to " + url);
                                            PropogationContext context = new PropogationContext();
                                            context.URL    = url;
                                            context.Folder = Settings.MaxFolder;

                                            ThreadPool.QueueUserWorkItem(delegate(object a)
                                            {
                                                //  MessageCounter.IncrementThread();

                                                if (!e.Cancel)
                                                {
                                                    SendEDIMessage request = new SendEDIMessage();
                                                    request.SendEDI(context);
                                                    FormatServerResponse.DisplayMessage("Number of Max messages published - " + MessageCounter.IncrementMaxMessageSent());
                                                    UpdateTime(DateTime.Now);
                                                }

                                                // MessageCounter.DecrementThread();
                                            });
                                        }
                                    }
                                }
                            });
                        }
                    }

                    loopCount++;
                }

                if (!e.Cancel)
                {
                    Thread.Sleep(1000);
                }
                else
                {
                    break;
                }
            }
        }