/// <summary> /// Loads friends avatars from the web and updates it in UI. /// </summary> public void LoadAvatars() { try { var itemsToLoad = _GetInitialAvatarsToLoad(); if (!itemsToLoad.Any()) _isInited = true; // Only if no one item loaded we may think that nothing was initialized - this is first time. else { var service = new AsyncAvatarsLoader(); service.LoadAvatars(itemsToLoad, _UpdateAvatar, () => { var dialogsToReloadPicture = Dialogs.Where(d => d.IsConference); Deployment.Current.Dispatcher.BeginInvoke(() => { try { foreach (var dialog in dialogsToReloadPicture) { var key = _GenereateGroupChatAvatar(dialog); if (key == string.Empty) { dialog.Photo = DefaultAvatar; } else { var image = _imageCache.GetItem(key); if (image != null) dialog.Photo = image; } } } catch (Exception ex) { Debug.WriteLine("LoadAvatars failed in EntityService: " + ex.Message); } _isInited = true; }); }); } } catch (Exception ex) { Debug.WriteLine("LoadAvatars failed " + ex.Message); } }
private void _LoadPhotos() { try { var service = new AsyncAvatarsLoader(); // From map of attachment view model and load items get collection of avatar load items... var photosToLoad = _photosToLoad.Select(x => x.Value); if (photosToLoad.Any()) service.LoadAvatars(photosToLoad.ToList(), _UpdatePhoto, null); } catch (Exception ex) { Debug.WriteLine("LoadPhotos failed " + ex.Message); } }
private bool _AddLocationAttachment() { if (!string.IsNullOrEmpty(App.Current.EntityService.AttachedLatitude) && !string.IsNullOrEmpty(App.Current.EntityService.AttachedLongitude)) { try { string uri = String.Format(AppResources.GeolocationMapUriFormatMessage, App.Current.EntityService.AttachedLatitude.Replace(",", "."), App.Current.EntityService.AttachedLongitude.Replace(",", ".")); var avm = new AttachmentViewModel(-1, -1, -1, AttachmentType.Location, uri, null, null, null, null); _model.Add(avm); string filename = CommonHelper.DoDigest(uri); var photosToLoad = new List<AvatarLoadItem>(); photosToLoad.Add(new AvatarLoadItem(1, uri, filename)); var service = new AsyncAvatarsLoader(); if (photosToLoad.Any()) service.LoadAvatars(photosToLoad.ToList(), id => { Deployment.Current.Dispatcher.BeginInvoke(() => { try { ImageCache cache = new ImageCache(); BitmapImage image = cache.GetItem(filename); if (image != null && image.PixelHeight > 0 && image.PixelWidth > 0) { avm.AttachPhoto = image; } } catch (Exception ex) { Debug.WriteLine("_AddLocationAttachment failed in AttachmentsPage: " + ex.Message); } }); }, null); } catch (Exception ex) { Debug.WriteLine("Load attached location photo failed " + ex.Message); } return true; } return false; }