Exemplo n.º 1
0
 public ScampUser(UserSummary user) : base()
 {
     Id = user.Id;
     Name = user.Name;
 }
Exemplo n.º 2
0
        /// <summary>
        /// Tries to find a user based on a search string
        /// </summary>
        /// <param name="search">search value to use</param>
        /// <returns>returns a match if one if found, otherwise returns null</returns>
        public async Task<List<UserSummary>> FindUser(string search)
        {
            DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(SearchResults));
            List<UserSummary> rtnList = new List<UserSummary>();

            // create search URI
            string searchURI = string.Format("https://graph.windows.net/{0}/users?api-version=2013-04-05&$top=5&$filter=startswith(userPrincipalName,'{1}')",
                GraphAPIProvider.Configuration[_cfgPropertyTenantId], 
                search);
            // create event handler for response
            WebClient client = new WebClient();
            
            //TODO: need to cache token until it expires and simply reuse
            client.Headers.Add("Authorization", await GetAADToken());

            string searchResults = await client.DownloadStringTaskAsync(new Uri(searchURI));
            //SearchResults tmpResults = JsonConvert.DeserializeObject<SearchResults>(searchResults);

            byte[] byteArray = Encoding.ASCII.GetBytes(searchResults);
            MemoryStream stream = new MemoryStream(byteArray);

            SearchResults srcResults = (SearchResults)ser.ReadObject(new MemoryStream(byteArray));

            if (srcResults.value.Count > 0)
            {
                UserSummary tmpUser = null;
                foreach (AADUser fndUser in srcResults.value)
                {
                    tmpUser = new UserSummary()
                    {
                        Id = fndUser.objectId,
                        Name = fndUser.displayName
                    };
                    rtnList.Add(tmpUser);
                }
                return rtnList;
            }
            else
                return null;
        }