Beispiel #1
0
        /*
        request.AddParameter("name", "value"); // adds to POST or URL querystring based on Method
        //request.AddUrlSegment("id", 123); // replaces matching token in request.Resource

        // add parameters for all properties on an object
        request.AddObject(object);

        // or just whitelisted properties
        //request.AddObject(object, "PersonId", "Name", ...);

        // easily add HTTP Headers
        request.AddHeader("header", "value");

        // add files to upload (works with compatible verbs)
        //request.AddFile(path);

        // execute the request
        RestResponse response = client.Execute(request);
        var content = response.Content; // raw content as string

        // or automatically deserialize result
        // return content type is sniffed but can be explicitly set via RestClient.AddHandler();
        RestResponse<Person> response2 = client.Execute<Person>(request);
        var name = response2.Data.Name;

        // or download and save file to disk
        client.DownloadData(request).SaveAs(path);

        // easy async support
        client.ExecuteAsync(request, response => {
            Console.WriteLine(response.Content);
        });

        // async with deserialization
        var asyncHandle = client.ExecuteAsync<Person>(request, response => {
            Console.WriteLine(response.Data.Name);
        });
        */
        private Service GetService(string serviceName, Action retryAction)
        {
            Service retVal = null;

            System.Diagnostics.Debug.WriteLine("Get Service: {0} refresh: {1}", serviceName, this.RefreshServices);

            if (this.RefreshServices)
            {
                this.CallGetServices((res) =>
                {
                    this.Services = res;
                    this.RefreshServices = false;

                    if (this.ServicesReceived != null)
                    {
                        this.ServicesReceived(res);
                    }

                    retryAction();
                },
                (err) =>
                { });

                return retVal;
            }

            if (this.Services == null || this.Services.Services == null)
            {
                //MessageBox.Show("Please wait", "Viafo", MessageBoxButton.OK);
                return retVal;
            }

            foreach (var service in this.Services.Services)
            {
                if (service.Name == serviceName)
                {
                    retVal = service;
                    break;
                }
            }

            return retVal;
        }
Beispiel #2
0
        public void Refresh()
        {
            if (string.IsNullOrEmpty(this.AccessToken))
            {
                this.CallRegister(this.clientId, this.clientSecret,
                    (resp) =>
                    {
                        System.Diagnostics.Debug.WriteLine("Success: " + resp.AccessToken);
                        this.AccessToken = resp.AccessToken;

                        if (this.AccessTokenReceived != null)
                        {
                            this.AccessTokenReceived(this.AccessToken);
                        }

                        this.CallGetServices(
                            (res) =>
                            {
                                this.Services = res;
                                this.RefreshServices = false;

                                if (this.ServicesReceived != null)
                                {
                                    this.ServicesReceived(res);
                                }
                            },
                            (err) =>
                            {
                                System.Diagnostics.Debug.WriteLine("Failure: " + err);
                            });
                    },
                    (err) =>
                    {
                        System.Diagnostics.Debug.WriteLine("Failure: " + err);
                    });
            }
            else if (this.RefreshServices || this.Services == null)
            {
                this.CallGetServices(
                    (res) =>
                    {
                        this.Services = res;
                        this.RefreshServices = false;

                        if (this.ServicesReceived != null)
                        {
                            this.ServicesReceived(res);
                        }
                    },
                    (err) =>
                    {
                        System.Diagnostics.Debug.WriteLine("Failure: " + err);
                    });
            }
        }