コード例 #1
0
        public async Task<bool> getSessionCookieAsync()
        {
            Debug.WriteLine("I'm here");
            HttpClient request = null;
            HttpResponseMessage response = null;
            HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Post,
                                         ApplicationModel.Current.Domain + "/claroline/auth/login.php");

            Debug.WriteLine("Message : " + message.ToString());
            CallbackArgs args = new CallbackArgs() { login = ApplicationModel.Current.Login, password = ApplicationModel.Current.Password, operation = AllowedOperations.authenticate };
            StringContent content = new StringContent(args.ToString());
            content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/x-www-form-urlencoded");
            message.Content = content;

            request = getClient();
            response = await request.SendAsync(message);

            Debug.WriteLine("getSessionCookie : " + response.StatusCode);

            bool empty = String.IsNullOrEmpty(await response.Content.ReadAsStringAsync());
            if (empty)
            {
                CookieCreation = DateTime.Now;
            }
            Debug.WriteLine("empty : " + empty.ToString());
            return empty;
        }
コード例 #2
0
        public async Task<string> makeOperationAsync(AllowedOperations op, Cours reqCours = null, int resID = -1)
        {
            if (ApplicationModel.Current.IsConnected)
            {
                if (!isExpired || (await getSessionCookieAsync()))
                {
                    CallbackArgs args = null;
                    switch (op)
                    {
                        case AllowedOperations.getSingleAnnounce:
                            if (reqCours == null && resID < 0)
                            {
                                return "";
                            }
                            args = new CallbackArgs() { cidReq = reqCours, resId = resID, operation = op };
                            break;
                        case AllowedOperations.getCourseToolList:
                        case AllowedOperations.getDocList:
                        case AllowedOperations.getAnnounceList:
                            if (reqCours == null)
                            {
                                return "";
                            }
                            args = new CallbackArgs() { cidReq = reqCours, operation = op };
                            break;
                        case AllowedOperations.getUserData:
                        case AllowedOperations.getCourseList:
                        case AllowedOperations.getUpdates:
                            args = new CallbackArgs() { operation = op };
                            break;
                    }

                    HttpResponseMessage response = null;
                    HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Post,
                                                 ApplicationModel.Current.Domain + ApplicationModel.Current.WebServicePath);
                    
                    StringContent content = new StringContent(args.ToString());
                    content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/x-www-form-urlencoded");
                    message.Content = content;
                    HttpClient request = getClient();
                    response = await request.SendAsync(message);
                    String result = await response.Content.ReadAsStringAsync();

                    Debug.WriteLine("Fin de la méthode " + op.ToString() + " : " + result);
                    return result;
                }
            }
                //TODO tell the user the network is unavailable
                return "";

        }