Пример #1
0
        public static TaskResult RunTask(ITask task)
        {
            task.IsStarted = true;
            task.RealStartTime = DateTime.Now;
            try
            {
                //set the request.
                HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(task.GetRequestUrl());
                request.CachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.Reload);
                task.PrepareTaskRequest(request);

                //do the request
                WebResponse response = request.GetResponse();
                var taskResult = task.GetResult(response);
                SaveLog(taskResult.Message);
                return taskResult;
            }
            catch (Exception exception)
            {
               SaveLog(exception);
               throw exception;
            }
            finally
            {
                task.RealEndTime = DateTime.Now;
                task.IsFinished = true;
            }
        }