Exemplo n.º 1
0
        /// <summary>
        /// Does the request.
        /// </summary>
        /// <param name="reqTyp">The req typ.</param>
        /// <param name="postObj">The post object.</param>
        /// <param name="query">The query.</param>
        /// <returns></returns>
        private object DoRequest(RequestTyp reqTyp, object postObj, string query)
        {
            object result = null;

            req = WebRequest.CreateHttp(confList[reqTyp].Uri + query);
            req.Headers.Add("Authorization", "Bearer " + token);
            req.ContentType       = "application/json";
            req.AllowAutoRedirect = false;

            if (postObj == null)
            {
                req.Method = "GET";
            }
            else
            {
                req.Method = "POST";
            }

            try
            {
                AddPostDataToRequest(postObj);
                res = req.GetResponse();

                using (StreamReader reader = new StreamReader(this.res.GetResponseStream()))
                {
                    result = JsonConvert.DeserializeObject(reader.ReadToEnd(), confList[reqTyp].Type);
                }

                return(result);
            }
            catch (WebException ex)
            {
                HandleError(ex);
                return(null);
            }
        }
Exemplo n.º 2
0
        public string CreateJsonObject(RequestTyp typ, object obj1, object obj2 = null)
        {
            string ObjectToSend = "";

            if (typ == RequestTyp.Loggin)
            {
                User user = (User)obj1;
                ObjectToSend = "{" + $"\"Email\":\"{user.Email}\",\"Passwort\" : \"{user.Passwort}\"" + "}";
            }

            else if (typ == RequestTyp.Registrierung)
            {
                User user = (User)obj1;
                ObjectToSend = "{" + $"\"Id\": {user.Id},\"Username\": \"{user.Benutzername}\",\"Email\": \"{user.Email}\",\"Passwort\" : \"{user.Passwort}\", \"Action\" : 5" + "}";
            }

            else if (typ == RequestTyp.SendDemand)
            {
                User   user = (User)obj1;
                string To   = (string)obj2;
                ObjectToSend = "{" + $"\"Id\": {user.Id},\"Friends\": [ {To}],\"Action\": 1" + "}";
            }
            else if (typ == RequestTyp.InfoUser)
            {
                User   user = (User)obj1;
                string To   = (string)obj2;
                ObjectToSend = "{" + $"\"Id\": {user.Id},\"Action\": 7" + "}";
            }
            else if (typ == RequestTyp.ConfirmDemand)
            {
                User   user1 = (User)obj1;
                string To    = (string)obj2;
                ObjectToSend = "{" + $"\"Id\": {user1.Id},\"Friends\": [ {To}],\"Action\": 2" + "}";
            }
            else if (typ == RequestTyp.DeniedDemand)
            {
                User   user1 = (User)obj1;
                string To    = (string)obj2;
                ObjectToSend = "{" + $"\"Id\": {user1.Id},\"Friends\": [ {To}],\"Action\": 3" + "}";
            }
            else if (typ == RequestTyp.DeleteFriend)
            {
                User   user1 = (User)obj1;
                string To    = (string)obj2;
                ObjectToSend = "{" + $"\"Id\": {user1.Id},\"Friends\": [ {To}],\"Action\": 4" + "}";
            }
            else if (typ == RequestTyp.ChangeSetting)
            {
                User user = (User)obj1;
                ObjectToSend = "{" + $"\"All\": {user.All.ToString()}" + "}";
            }
            else if (typ == RequestTyp.Live)
            {
                User user = (User)obj1;
                ObjectToSend = "{" + $"\"Id\": {user.Id}" + "}";
            }
            else
            {
                ObjectToSend = "";
            }

            return(ObjectToSend);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Performs the specified req typ.
 /// </summary>
 /// <param name="reqTyp">The req typ.</param>
 /// <param name="postObj">The post object.</param>
 /// <returns></returns>
 public object Perform(RequestTyp reqTyp, InAction postObj)
 {
     return(DoRequest(reqTyp, postObj, null));
 }
Exemplo n.º 4
0
 /// <summary>
 /// Performs the specified req typ.
 /// </summary>
 /// <param name="reqTyp">The req typ.</param>
 /// <returns></returns>
 public object Perform(RequestTyp reqTyp)
 {
     return(DoRequest(reqTyp, null, null));
 }
Exemplo n.º 5
0
 /// <summary>
 /// Performs the specified req typ.
 /// </summary>
 /// <param name="reqTyp">The req typ.</param>
 /// <param name="query">The query.</param>
 /// <returns></returns>
 public object Perform(RequestTyp reqTyp, string query)
 {
     return(DoRequest(reqTyp, null, query));
 }