Beispiel #1
0
 void ITaskRepository.DeleteTask(Task task, Action<TaskResult> callback)
 {
     string uri = _BaseAddress + "tasks/" + task.Key;
     var request = WebRequest.CreateHttp(uri);
     request.Method = "DELETE";
     request.ContentType = "application/json";
     request.BeginGetResponse(result =>
     {
         var response = (HttpWebResponse)request.EndGetResponse(result);
         if (response.StatusCode != HttpStatusCode.OK)
         {
             var error = new WebException(response.StatusDescription);
             callback(new TaskResult(new Task[0], error: error));
         }
         else
         {
             callback(new TaskResult(new Task[] { task.Clone() }));
         }
     }, null);
 }
Beispiel #2
0
        void ITaskRepository.CreateTask(Task task, Action<TaskResult> callback)
        {
            string query = _BaseAddress + "tasks";
            string parameters = string.Format(
                "{0}={1}",
                TaskMeta.Name,
                HttpUtility.UrlEncode(task.Name));

            var client = new WebClient();
            client.UploadStringCompleted += (sender, e) =>
            {
                if (null != e.Error)
                {
                    callback(new TaskResult(new Task[0], e.Cancelled, e.Error));
                }
                else
                {
                    var result = new Task(JsonObject.Parse(e.Result));
                    callback(new TaskResult(new Task[] { result }));
                }
            };
            client.UploadStringAsync(new Uri(query), parameters);
        }
Beispiel #3
0
 public TaskViewModel(Task model)
 {
     this.model = model;
 }
 /// <summary>
 /// <see cref="TaskResult"/> クラスの新しいインスタンスを初期化します。
 /// </summary>
 /// <param name="tasks">タスク。</param>
 /// <param name="cancelled">キャンセルされたかどうか。</param>
 /// <param name="error">発生したエラー。</param>
 public TaskResult(Task[] tasks, bool cancelled = false, Exception error = null)
 {
     this.Tasks = tasks;
     this.Cancelled = cancelled;
     this.Error = error;
 }
Beispiel #5
0
        void ITaskRepository.UpdateTask(Task task, Action<TaskResult> callback)
        {
            string uri = _BaseAddress + "tasks/" + task.Key;
            byte[] bytes = Encoding.UTF8.GetBytes(task.ToJsonString());

            var request = WebRequest.CreateHttp(uri);
            request.Method = "PUT";
            request.ContentType = "application/json";
            request.ContentLength = bytes.Length;
            request.BeginGetRequestStream(result =>
            {
                using (var stream = request.EndGetRequestStream(result))
                {
                    stream.Write(bytes, 0, bytes.Length);
                }

                request.BeginGetResponse(result2 =>
                {
                    var response = (HttpWebResponse)request.EndGetResponse(result2);
                    if (response.StatusCode != HttpStatusCode.OK)
                    {
                        var error = new WebException(response.StatusDescription);
                        callback(new TaskResult(new Task[0], error: error));
                    }
                    else
                    {
                        callback(new TaskResult(new Task[] { task.Clone() }));
                    }
                }, null);
            }, null);
        }