コード例 #1
0
 private void HandleEvent(UcwaResource resource)
 {
     if (OnEventNotificationsReceived != null)
     {
         OnEventNotificationsReceived(new UcwaEventsData(resource.OuterXml));
     }
 }
コード例 #2
0
        public async Task <UcwaAppOperationResult> GetResourceAsync(string uri)
        {
            HttpResponseMessage response;
            string responseContent;

            try
            {
                response = await Client.GetAsync(uri);

                responseContent = await response.Content.ReadAsStringAsync();

                try
                {
                    var resource = new UcwaResource(responseContent);
                    return(new UcwaAppOperationResult(response.StatusCode, response.Headers, resource));
                }
                catch (Exception ex)
                {
                    return(new UcwaAppOperationResult(response.StatusCode, response.Headers, responseContent, ex));
                }
            }
            catch (TaskCanceledException tcex)
            {
                return(new UcwaAppOperationResult(HttpStatusCode.RequestTimeout, tcex));
            }
            catch (Exception ex)
            {
                return(new UcwaAppOperationResult(HttpStatusCode.BadRequest, ex));
            }
        }
コード例 #3
0
 private async Task <HttpStatusCode> SetResource(string data, string name, UcwaResource parent)
 {
     if (string.IsNullOrEmpty(name) || parent == null)
     {
         return(HttpStatusCode.BadRequest);
     }
     return(await SetResource(data, parent.GetEmbeddedResourceUri(name)));
 }
コード例 #4
0
        /// <summary>
        /// Get an application resource bound to the user's local endpoint
        /// </summary>
        /// <param name="resUser">The authenticated user resource</param>
        /// <param name="userAgent">The name of this application</param>
        /// <param name="culture">The locale of this application</param>
        /// <returns>The application resoure as part of UcwaAppOperationResult</returns>
        async Task <UcwaAppOperationResult> GetApplicationResource(UcwaResource resUser,
                                                                   string userAgent = "ContosoApp/1.0 (WinStore)", string culture = "en-us")
        {
            applicationsUrl = resUser.GetLinkUri("applications");
            var    endpointId  = Guid.NewGuid().ToString();
            string appSettings = string.Format(appSettingsFormatter, culture, endpointId, userAgent);
            var    result      = await Transport.PostResourceAsync(applicationsUrl, appSettings);

            if (result.StatusCode != HttpStatusCode.Created)
            {
                return(new UcwaAppOperationResult(result.StatusCode, result.ResponseHeaders, result.ResponseBody,
                                                  new Exception("Failed to PostRequest on " + applicationsUrl)));
            }
            return(result);
        }
コード例 #5
0
        private async Task <UcwaResource> GetResource(string resourceName, UcwaResource parent)
        {
            if (string.IsNullOrEmpty(resourceName))
            {
                return(null);
            }
            if (parent == null)
            {
                return(null);
            }

            var uri = parent.GetEmbeddedResourceUri(resourceName);

            return(await GetResource(uri));
        }
コード例 #6
0
        //public async Task<Stream> GetPhotoStream(string photoUri = null)
        //{
        //    if (!makeMeAvailablePosted) return null;
        //    if (photoUri == null)
        //        photoUri = this.Resource.GetEmbeddedResourceUri("photo");
        //    if (string.IsNullOrEmpty(photoUri))
        //        return null;
        //    //var result = await Transport.GetResourceAsync(photoUri);
        //    this.Photo = await GetPhotoStream(photoUri);//GetResource(photoUri);
        //    return this.Photo ;
        //}
        public async Task <IEnumerable <UcwaAppPhoneLine> > GetPhoneLines(string uri = null)
        {
            this.Phones = await GetPhones(uri);

            List <UcwaAppPhoneLine> phoneList = new List <UcwaAppPhoneLine>();

            foreach (var xElem in this.Phones.EmbeddedResourceElements)
            {
                var resPhone     = new UcwaResource(xElem);
                var phoneType    = resPhone.GetPropertyValue("type");
                var phoneNumber  = resPhone.GetPropertyValue("number");
                var inConactCard = resPhone.GetPropertyValue("includeInContactCard");
                phoneList.Add(new UcwaAppPhoneLine(phoneNumber, phoneType, inConactCard));
            }
            return(phoneList.AsEnumerable());
        }
コード例 #7
0
 private string GetNextEventUri(UcwaResource resource)
 {
     try
     {
         if (resource.LinkNames.Contains("resync"))
         {
             return(resource.GetLinkUri("resync"));
         }
         if (resource.LinkNames.Contains("resume"))
         {
             return(resource.GetLinkUri("resume"));
         }
         if (resource.LinkNames.Contains("next"))
         {
             return(resource.GetLinkUri("next"));
         }
         return(null);
     }
     catch { return(null); }
 }
コード例 #8
0
        public async Task <UcwaAppOperationResult> PostResourceAsync(string uri, HttpContent content)
        {
            var response = await Client.PostAsync(uri, content);

            var responseContent = await response.Content.ReadAsStringAsync();

            if (string.IsNullOrEmpty(responseContent))
            {
                return(new UcwaAppOperationResult(response.StatusCode, response.Headers));
            }
            try
            {
                var resource = new UcwaResource(responseContent);
                return(new UcwaAppOperationResult(response.StatusCode, response.Headers, resource));
            }
            catch (Exception ex)
            {
                return(new UcwaAppOperationResult(response.StatusCode, response.Headers, responseContent, ex));
            }
        }
コード例 #9
0
        public async Task <UcwaResource> Refresh(string uri = null)
        {
            if (string.IsNullOrEmpty(uri))
            {
                this.Resource = await GetResource(this.Resource.Uri);
            }
            else
            {
                this.Resource = await GetResource(uri);
            }
            this.Note = await this.GetNote();

            this.Presence = await this.GetPresence();

            this.Location = await this.GetLocation();

            this.Phones = await this.GetPhones();

            return(this.Resource);
        }
 public UcwaAppOperationResult(HttpStatusCode status, HttpResponseHeaders httpHeaders, UcwaResource res)
 {
     this.Resource        = res;
     this.ResponseHeaders = httpHeaders;
     this.StatusCode      = status;
 }
コード例 #11
0
        public async Task <string> GetLocationCoordinates(string uri = null)
        {
            this.Location = await GetLocation(uri);

            return(Location.GetPropertyValue("location"));
        }