コード例 #1
0
        // Methods

        #region Get(IRobID activityRID)
        public ActivityModel Get(IRobID activityRID)
        {
            var request = BuildRequest("api/activities/{0}".AsFormat(activityRID));
            HttpResponseMessage response = Client.SendAsync(request).Result;

            if (response.IsSuccessStatusCode)
            {
                var jobject = response.Content.ReadAsAsync <JObject>().Result;
                // read past the "activity" wrapper
                var jProperty = (JProperty)jobject.Children().Single();
                return(jProperty.Value.ToObject <ActivityModel>());
            }

            Logger.Error("Request {0} returned {1} ({2})", request.RequestUri, (int)response.StatusCode, response.ReasonPhrase);
            // ReSharper disable EmptyGeneralCatchClause
            try
            {
                Logger.Error("Response Body: {0}", response.Content.ReadAsAsync <string>().Result);
            }
            catch (Exception)
            {
            }
            // ReSharper restore EmptyGeneralCatchClause

            Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase);
            return(null);
        }
コード例 #2
0
        // Methods

        public virtual List <IDeviceModel> Get(IRobID principalRID)
        {
            var request = BuildRequest("api/people/{0}/devices".AsFormat(principalRID));
            HttpResponseMessage response = Client.SendAsync(request).Result;
            var result = new List <IDeviceModel>();

            if (response.IsSuccessStatusCode)
            {
                var jobject = response.Content.ReadAsAsync <JObject>().Result;
                Logger.Debug("Request {0} returned {1}", request.RequestUri, jobject.ToString());
                var jdevices = jobject["devices"] as JArray;
                foreach (JObject jdevice in jdevices)
                {
                    result.Add(jdevice.ToObject <DeviceModel>());
                }
            }
            else
            {
                Logger.Error("Request {0} returned {1} ({2})", request.RequestUri, (int)response.StatusCode, response.ReasonPhrase);
                // ReSharper disable EmptyGeneralCatchClause
                try
                {
                    Logger.Error("Response Body: {0}", response.Content.ReadAsAsync <string>().Result);
                }
                catch (Exception)
                {
                }
                // ReSharper restore EmptyGeneralCatchClause
            }

            return(result);
        }
コード例 #3
0
 public AuthenticationHeaderValue GetAuthenticationHeaderValue(IRobID principalRID)
 {
     return(new AuthenticationHeaderValue(
                "Basic",
                Convert.ToBase64String(
                    System.Text.Encoding.ASCII.GetBytes(
                        string.Format("{0}:{1}", "*****@*****.**", "test"))))); //, "unforgiven+notting!7649458436+6955865"))));
 }
コード例 #4
0
ファイル: PeopleService.cs プロジェクト: burimameti/ClientApi
        public override IPersonModel Get(IRobID rid)
        {
            var key    = _ToKey(rid);
            var result = Context.Cache.Get <IPersonModel>(key);

            if (result != null)
            {
                return(result);
            }

            result = base.Get(rid);
            Context.Cache.Add(result, key);
            return(result);
        }
コード例 #5
0
        public override List <IDeviceModel> Get(IRobID principalRID)
        {
            var key    = _ToKey(principalRID);
            var result = Context.Cache.Get <List <IDeviceModel> >(key);

            if (result != null)
            {
                return(result);
            }

            result = base.Get(principalRID);
            Context.Cache.Add(result, key);
            return(result);
        }
コード例 #6
0
ファイル: PeopleService.cs プロジェクト: burimameti/ClientApi
        // Methods

        #region Get(IRobID rid)
        public virtual IPersonModel Get(IRobID rid)
        {
            var request = BuildRequest("api/people/{0}".AsFormat(rid));
            HttpResponseMessage response = Client.SendAsync(request).Result;

            if (response.IsSuccessStatusCode)
            {
                var jobject = response.Content.ReadAsAsync <JObject>().Result;
                // read past the "person" wrapper
                var jProperty = (JProperty)jobject.Children().Single();
                return(jProperty.Value.ToObject <PersonModel>());
            }

            Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase);
            return(null);
        }
コード例 #7
0
ファイル: PeopleService.cs プロジェクト: burimameti/ClientApi
 private string _ToKey(IRobID rid)
 {
     return("PeopleService_Get_{0}".AsFormat(rid));
 }
コード例 #8
0
 private string _ToKey(IRobID principalRID)
 {
     return("DevicesService_Get_{0}".AsFormat(principalRID));
 }