예제 #1
0
        private void btnGet_Click(object sender, EventArgs e)
        {
            WebApiCall      web = new WebApiCall(null);
            ApiCallArgument ar  = new ApiCallArgument(txtServerUrl.Text, "Employee", false);

            ar.UseName   = txtUser.Text;
            ar.Password  = txtPass.Text;
            ar.Parameter = "Saiful";
            //
            web.execute(ar, delegate(object p)
            {
                parseSingleEmployee(p);
            });
        }
예제 #2
0
        private void btnWebApi_Click(object sender, EventArgs e)
        {
            WebApiCall      web = new WebApiCall(null);
            ApiCallArgument ar  = new ApiCallArgument(txtServerUrl.Text, "Employee");

            ar.UseName  = txtUser.Text;
            ar.Password = txtPass.Text;
            //
            web.execute(ar, delegate(object p)
            {
                ResponseObject res = (ResponseObject)p;
                this.parseEmployee(res);

                return;
            });
        }
예제 #3
0
        // Match with Webservice
        // public IHttpActionResult post(Login obj)
        private async void executePOST(ApiCallArgument apiArgument)
        {
            try
            {
                HttpClient          client   = setup();
                HttpResponseMessage response = await client.PostAsJsonAsync(apiArgument.ApiName, apiArgument.Parameter);

                HttpResponseMessage message = response.EnsureSuccessStatusCode();
                // Get the URI of the created resource.
                var responseAsString = await response.Content.ReadAsStringAsync();

                //var json = JsonConvert.DeserializeObject(responseAsString);
                //var responseAsType = JsonConvert.DeserializeObject<Employee>(responseAsString);
                //notifyObserver(new ResponseObject(responseAsType));
                notifyObserver(new ResponseObject(responseAsString));
            }
            catch (Exception e)
            {
                notifyObserver(new ResponseObject(e));
            }
        }
예제 #4
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            WebApiCall      web = new WebApiCall(null);
            ApiCallArgument ar  = new ApiCallArgument(txtServerUrl.Text, "Employee");

            ar.UseName   = txtUser.Text;
            ar.Password  = txtPass.Text;
            ar.Parameter = new Login()
            {
                ID = txtUser.Text, Password = txtPass.Text
            };
            //
            web.execute(ar, delegate(object p)
            {
                Employee emp = parseSingleEmployee(p);
                if (emp != null)
                {
                    this.lblLoginID.Text = "Login as: " + emp.Name;
                }
            });
        }
예제 #5
0
        // http://localhost/Webservice/api/
        // Match with GetAllEmployees
        // Pass User and Password in Authorization with Ecoding
        public override void execute(ApiCallArgument apiArgument, IDelegeateObserver observer)
        {
            this.url = apiArgument.Url;
            // Set the Notiifcation Observer..
            this.mDelegeateObserver = observer;

            if (apiArgument.Parameter != null)
            {
                if (!apiArgument.POST)
                {
                    executeGET(apiArgument);
                }
                else
                {
                    executePOST(apiArgument);
                }
            }
            else
            {
                execute(apiArgument);
            }
        }
예제 #6
0
        async void execute(ApiCallArgument apiArgument)
        {
            try
            {
                HttpClient client = setup();
                //
                var authToken = Encoding.ASCII.GetBytes($"{apiArgument.UseName}:{apiArgument.Password}");
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(authToken));
                //
                HttpResponseMessage response = await client.GetAsync(apiArgument.ApiName);

                HttpResponseMessage message = response.EnsureSuccessStatusCode();
                var responseAsString        = await response.Content.ReadAsStringAsync();

                //var responseAsType = JsonConvert.DeserializeObject<Employee[]>(responseAsString);
                //
                // notifyObserver(new ResponseObject(responseAsType));
                notifyObserver(new ResponseObject(responseAsString));
            }
            catch (Exception e)
            {
                notifyObserver(new ResponseObject(e));
            }
        }
예제 #7
0
 abstract public void execute(ApiCallArgument apiArgument, IDelegeateObserver observer);