コード例 #1
0
        public async Task Post(MainWindowVM vm, int id, TakenNumberDTO dto)
        {
            var httpWebRequest = (HttpWebRequest)WebRequest.Create(requestUriString: vm.Url);

            httpWebRequest.ContentType = "application/json";
            httpWebRequest.Method      = "POST";

            using (var streamWriter = new StreamWriter(stream: httpWebRequest.GetRequestStream()))
            {
                streamWriter.Write(value: dto.toJSON());
            }
            try
            {
                var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                using (var streamReader = new StreamReader(stream: httpResponse.GetResponseStream()))
                {
                    var result = streamReader.ReadToEnd();
#if DEBUG
                    Trace.WriteLine(message: result);
                    //Trace.WriteLine(newDto.ToString());
#endif
                    JObject myJsonNetObject = JObject.Parse(json: result);

#if DEBUG
                    Trace.WriteLine(message: (string)myJsonNetObject[key: "id"]);
#endif
                    int newId = 0;
                    Int32.TryParse(s: (string)myJsonNetObject[key: "id"], result: out newId);
                    if (newId != 0)
                    {
                        dto.Id = newId;
                    }

                    vm.SetNumberResult(id: id, text: "Returned: \n" + result + "\n", dto: dto);
                }
            }
            catch (WebException e)
            {
                vm.SetNumberResult(id: id, text: "Returned: \n" + e + "\n", dto: null);
            }
        }
コード例 #2
0
        public void PostNumber()
        {
            int i = _numMin - 1;

            while (true)
            {
                if (i == _numMax)
                {
                    i = _numMin;
                }
                else
                {
                    i++;
                }

                int waitTime = _random.Next(minValue: _rndMin, maxValue: _rndMax);

                _vm.SetSleepingTime(id: _threadNum, text: waitTime.ToString());

                Thread.Sleep(millisecondsTimeout: waitTime * 1000);

                _vm.SetNumberValue(id: _threadNum, text: i.ToString());

                TakenNumberDTO dto = new TakenNumberDTO()
                {
                    PostId            = GetTimestamp(value: DateTime.Now),
                    Number            = i,
                    DateTaken         = DateTime.Now,
                    OfficeId          = _officeId,
                    TakenNumberTypeId = _numType
                };

                _vm.SetNumberResult(id: _threadNum, text: "Posted: \n" + dto.toJSON() + "\n", dto: null);

                _takenNumber.Post(_vm, id: _threadNum, dto: dto);
            }
        }
コード例 #3
0
        public void PostNumber()
        {
            while (true)
            {
                //TODO

                int waitTime = 1;

                if (
                    (_threadNum == 1 && _vm.Thread1Dtos.Count > 0) ||
                    (_threadNum == 2 && _vm.Thread2Dtos.Count > 0) ||
                    (_threadNum == 3 && _vm.Thread3Dtos.Count > 0)
                    )
                {
                    waitTime = _random.Next(minValue: _rndMin, maxValue: _rndMax);
                    _vm.SetSleepingTimeT(id: _threadNum, text: waitTime.ToString());
                    Thread.Sleep(millisecondsTimeout: waitTime * 1000);

                    TakenNumberDTO dto = null;
                    switch (_threadNum)
                    {
                    case 1:
                        dto = _vm.Thread1Dtos[index : 0];
                        break;

                    case 2:
                        dto = _vm.Thread2Dtos[index : 0];
                        break;

                    case 3:
                        dto = _vm.Thread3Dtos[index : 0];
                        break;
                    }

                    dto.DateService = DateTime.Now;
                    string dtoJSON = dto.toJSON();

                    switch (_threadNum)
                    {
                    case 1:
                        _vm.Thread1Dtos.Remove(item: dto);
                        break;

                    case 2:
                        _vm.Thread2Dtos.Remove(item: dto);
                        break;

                    case 3:
                        _vm.Thread3Dtos.Remove(item: dto);
                        break;
                    }

                    _vm.SetNumberValueT(id: _threadNum, text: dto.Number.ToString());
                    _vm.SetNumberResult(id: _threadNum, text: "Posted update: \n" + dto.toJSON() + "\n", dto: null);

                    _takenNumber.Put(_vm, id: _threadNum, json: dtoJSON);
                }
                else
                {
                    _vm.SetSleepingTimeT(id: _threadNum, text: waitTime.ToString());

                    Thread.Sleep(millisecondsTimeout: waitTime * 1000);
                }
            }
        }