I need help with a Lync issue we’re having while running LyncClient in UISuppession mode. We are trying to retrieve images for the contacts so we can use them in our application in a similar manor to the Lync client. What we are seeing is that some or most
the images aren’t loading. The problem is sporadic affecting different users each time we run tests. We are using the ContactInformationChanged event to trigger our code to load the image thru the GetContactInformation(ContactInformationType.Photo). What I’m
seeing is that for some of our installations images aren’t loading for some of the contacts that do have photos visible when the client runs with its UI. Over time it does find most of them but we are still failing to load them all and only some photos load
in a timely manner. Below is my code used to load photos.
In the event handler:
if (e.ChangedContactInformation.Contains(ContactInformationType.Photo))
OnPhotoChanged(sender, Utils.GetPhoto(sender, Settings.DefaultContactImagePath));
Here’s my method to retrieve the photo:
public static BitmapImage GetPhoto(object sender, Uri fallbackImagePath)
{
Stream photoStream;
Contact contact = sender as Contact;
ClientState state = Lync.LyncState;
photoStream = GetImageStream(contact);
if (photoStream == null)
{
Logger.Warning("No Image " + contact.Uri);
}
else
{
Logger.Warning("Found Image " + contact.Uri);
}
BitmapImage userImageBitMap = new BitmapImage();
if (photoStream != null)
{
try
{
userImageBitMap.BeginInit();
userImageBitMap.StreamSource = photoStream;
userImageBitMap.EndInit();
userImageBitMap.Freeze()
}
catch (Exception)
{ userImageBitMap = new BitmapImage(fallbackImagePath); }
}
else
userImageBitMap = new BitmapImage(fallbackImagePath);
userImageBitMap.Freeze();
return userImageBitMap;
}
public static Stream GetImageStream(Contact contact)
{
Stream imgStream = null;
try
{ imgStream = contact.GetContactInformation(ContactInformationType.Photo) as Stream; }
catch (NotReadyException)
{ return null; }
catch (ItemNotFoundException)
{ return null; }
catch (LyncClientException)
{ return null; }
return imgStream;
}