Exemplo n.º 1
0
        public FirebaseEventHandler Delete()
        {
            FirebaseEventHandler handler = new FirebaseEventHandler();

            handler.SetProcess(() =>
            {
                FirebaseOperation operation = new FirebaseOperation();
                try
                {
                    HttpWebRequest request    = WebRequest.CreateHttp(URIs.EndsWith(DotJSON) ? URIs : URIs + DotJSON);
                    request.Method            = "DELETE";
                    request.ContentType       = "application/json";
                    request.Timeout           = handler.Timeout;
                    WebResponse response      = request.GetResponse();
                    operation.OperationResult = (new StreamReader(response.GetResponseStream())).ReadToEnd();
                    operation.OperationState  = true;
                    operation.ThrownException = null;
                }
                catch (Exception exp)
                {
                    operation.ThrownException = exp;
                    operation.OperationState  = false;
                }

                return(operation);
            });

            return(handler);
        }
Exemplo n.º 2
0
        public FirebaseEventHandler Post(object obj)
        {
            FirebaseEventHandler handler = new FirebaseEventHandler();

            handler.SetProcess(() =>
            {
                FirebaseOperation operation = new FirebaseOperation();
                try
                {
                    string json            = Newtonsoft.Json.JsonConvert.SerializeObject(obj);
                    HttpWebRequest request = WebRequest.CreateHttp(URIs.EndsWith(DotJSON) ? URIs : URIs + DotJSON);
                    request.Method         = "POST";
                    request.ContentType    = "application/json";
                    request.Timeout        = handler.Timeout;
                    byte[] buffer          = Encoding.UTF8.GetBytes(json);
                    request.ContentLength  = buffer.Length;
                    request.GetRequestStream().Write(buffer, 0, buffer.Length);
                    WebResponse response      = request.GetResponse();
                    operation.OperationResult = (new StreamReader(response.GetResponseStream())).ReadToEnd();
                    operation.OperationState  = true;
                    operation.ThrownException = null;
                }
                catch (Exception exp)
                {
                    operation.ThrownException = exp;
                    operation.OperationState  = false;
                }

                return(operation);
            });

            return(handler);
        }
Exemplo n.º 3
0
        public FirebaseEventHandler Get(RetrievedDataType r)
        {
            FirebaseEventHandler handler = new FirebaseEventHandler();

            handler.SetProcess(() =>
            {
                FirebaseOperation operation = new FirebaseOperation();
                try
                {
                    string json               = Newtonsoft.Json.JsonConvert.SerializeObject("");
                    HttpWebRequest request    = WebRequest.CreateHttp((URIs.EndsWith(DotJSON) ? URIs : URIs + DotJSON) + (r == RetrievedDataType.HUMAN_READABLE ? "?print=pretty" : string.Empty));
                    request.Method            = "GET";
                    request.ContentType       = "application/json";
                    request.Timeout           = handler.Timeout;
                    byte[] buffer             = Encoding.UTF8.GetBytes(json);
                    WebResponse response      = request.GetResponse();
                    operation.OperationResult = (new StreamReader(response.GetResponseStream())).ReadToEnd();
                    operation.OperationState  = true;
                    operation.ThrownException = null;
                }
                catch (Exception exp)
                {
                    operation.ThrownException = exp;
                    operation.OperationState  = false;
                }

                return(operation);
            });

            return(handler);
        }