public async Task ShareAsync(ShareOperation shareOperation) { _shareOperation = shareOperation; shareOperation.ReportStarted(); var dataPackageView = shareOperation.Data; RequestTitle = shareOperation.Data.Properties.Title; RequestDescription = shareOperation.Data.Properties.Description; try { if ( dataPackageView.IsTextMessage() ) { IsTextRequest = true; TextShareValue = await dataPackageView.GetTextAsync(); } else if (dataPackageView.IsUrlMessage()) { IsUrlRequest = true; var foundUri = await dataPackageView.GetUriAsync(); UrlShareValue = foundUri.AbsoluteUri; } else if (dataPackageView.IsStorageItemsMessage()) { IsStorageRequest = true; var storageItems = await dataPackageView.GetStorageItemsAsync(); if ( storageItems.Any()) { var storageItem = storageItems.First(); if ( storageItem.IsOfType(StorageItemTypes.File)) { StorageFileName = storageItem.Name; var thumbNail = dataPackageView.Properties.Thumbnail; var thumbnailStream = await thumbNail.OpenReadAsync(); ImageShareValue = new BitmapImage(); ImageShareValue.SetSource(thumbnailStream); } } } else if (dataPackageView.IsImageMessage()) { IsImageRequest = true; var imageRecieved = await dataPackageView.GetBitmapAsync(); var imageStream = await imageRecieved.OpenReadAsync(); ImageShareValue = new BitmapImage(); ImageShareValue.SetSource(imageStream); } } catch (Exception e) { shareOperation.ReportError(e.Message); RequestDescription = e.Message; } shareOperation.ReportDataRetrieved(); }
public async void Initialize(ShareOperation share) { _share = share; _share.ReportStarted(); await _share.Data.CopyTo(_values); _share.ReportDataRetrieved(); }
public async Task SetupShareDataAsync(ShareOperation share) { // store the share operation - we need to do this to hold a // reference otherwise the sharing subsystem will assume // that we've finished... this.ShareOperation = share; // get the properties out... var data = share.Data; var props = data.Properties; this.Title = props.Title; this.Description = props.Description; // now the text... if (data.Contains(StandardDataFormats.Text)) this.SharedText = await data.GetTextAsync(); // do we have an image? if so, load it... if (data.Contains(StandardDataFormats.StorageItems) || data.Contains(StandardDataFormats.Bitmap)) { IRandomAccessStreamReference reference = null; // load the first one... if (data.Contains(StandardDataFormats.StorageItems)) { var file = (IStorageFile)(await data.GetStorageItemsAsync()).FirstOrDefault(); reference = RandomAccessStreamReference.CreateFromFile(file); } else reference = await data.GetBitmapAsync(); // load it into an image... var image = new BitmapImage(); using (var stream = await reference.OpenReadAsync()) image.SetSource(stream); // set... this.SharedImage = image; this.ShowImage = true; } // tell the OS that we have the data... share.ReportDataRetrieved(); }