コード例 #1
0
ファイル: Program.cs プロジェクト: darkogele/Rabota
        private static void FireRequests(object filePath)
        {
            var whenFired = DateTime.Now;

            _firedRequests++;
            //_logItems.Add("Request  - ID: " + _firedRequests + " " + whenFired.ToString("hh:mm:ss.fff tt"));
            Console.WriteLine("Request  - ID: " + _firedRequests + " " + whenFired.ToString("hh:mm:ss.fff tt"));
            var responseId = _requestsFinished + 1;
            var request    = new LogItemMessage
            {
                Id        = _firedRequests,
                TimeStamp = whenFired
            };

            if (_firedRequests == _totaNumberOfRequests)
            {
                _timer.Change(Timeout.Infinite, Timeout.Infinite);
            }

            var callIsSuccessful = false;

            try
            {
                CallService(ConfigurationManager.AppSettings["Institution"]);
                callIsSuccessful = true;
            }
            catch
            {
                callIsSuccessful = false;
            }
            finally
            {
                var whenFinished = DateTime.Now;
                _logItemModels.Add(new LogItemModel
                {
                    Request  = request,
                    Response = new LogItemMessage
                    {
                        Id        = responseId,
                        TimeStamp = whenFinished
                    },
                    WasCallSuccessful = callIsSuccessful
                });

                if (callIsSuccessful)
                {
                    Console.WriteLine("Response - ID: " + (_requestsFinished + 1) + " " +
                                      whenFinished.ToString("hh:mm:ss.fff tt") + " (" +
                                      Math.Round((whenFinished - whenFired).TotalMilliseconds) + " ms.) OK");
                }
                else
                {
                    Console.WriteLine("Response - ID: " + (_requestsFinished + 1) + " " +
                                      whenFinished.ToString("hh:mm:ss.fff tt") + " (" +
                                      Math.Round((whenFinished - whenFired).TotalMilliseconds) + " ms.) ERROR");
                }
            }

            _requestsFinished++;

            if (_requestsFinished == _totaNumberOfRequests)
            {
                foreach (var logItem in _logItems)
                {
                    _stream.WriteLine(logItem);
                }
                foreach (var logItemModel in _logItemModels)
                {
                    _stream.WriteLine(logItemModel.ToString());
                }
                _stream.WriteLine();
                _stream.WriteLine("--- End testing --- " + DateTime.Now);
                _stream.Close();
                Console.WriteLine();
                Console.WriteLine("--- End testing --- " + DateTime.Now);
            }
        }
コード例 #2
0
ファイル: LogItemModel.cs プロジェクト: darkogele/Rabota
 public LogItemModel()
 {
     Request  = new LogItemMessage();
     Response = new LogItemMessage();
 }