// If you have install the code sniplets, use "propvm + [tab] +[tab]" create a property。 // 如果您已经安装了 MVVMSidekick 代码片段,请用 propvm +tab +tab 输入属性 public SharePanelPage_Model() { if (IsInDesignMode) { ReceivedShareItem = new ReceivedShareItem { ContentSourceApplicationLink = new Uri("http://ContentSourceApplicationLink/"), ContentSourceWebLink = new Uri("http://ContentSourceWebLink"), DefaultFailedDisplayText = "Default failed", Description = "Description", LogoBackgroundColor = Colors.Red, QuickLinkId = "QuickLinkId", Square30x30Logo = null, Thumbnail = null, PackageFamilyName = "PackageFamilyName", Title = "Title", Text = "hhh", AvialableShareItems = new ObservableCollection <object> { new WebLinkShareItem { WebLink = new Uri("Http://notok") }, } }; } }
public async Task <ReceivedShareItem> GetReceivedSharedItemAsync(ShareOperation sourceOperation) { var packageView = sourceOperation.Data; ReceivedShareItem rval = await FetchDataFromPackageViewAsync(packageView); rval.QuickLinkId = sourceOperation.QuickLinkId; return(rval); }
public MainPage_Model() { if (IsInDesignMode) { ReceivedShareItem = new ReceivedShareItem { ContentSourceApplicationLink = new Uri("http://ContentSourceApplicationLink/"), ContentSourceWebLink = new Uri("http://ContentSourceWebLink"), DefaultFailedDisplayText = "Default failed", Description = "Description", LogoBackgroundColor = Colors.Red, QuickLinkId = "QuickLinkId", Square30x30Logo = null, Thumbnail = null, PackageFamilyName = "PackageFamilyName", Title = "Title", Text = "hhh", AvialableShareItems = new ObservableCollection <object> { new WebLinkShareItem { WebLink = new Uri("Http://notok") }, } }; } else { ReceivedShareItem = new ReceivedShareItem { IsEmptyPlaceHoder = true, Title = "", AvialableShareItems = new ObservableCollection <object> { } }; //ReceivedShareItem = new ReceivedShareItem(); App.CurrentFile .AsObservable() .ObserveOn(this.Dispatcher) .DoExecuteUIBusyTask( this, async f => { if (f != null) { var loadService = ServiceLocator.Instance.Resolve <Services.ISubStorageService>(); var file = f as StorageFile; ReceivedShareItem = await loadService.LoadFromFileAsync <ReceivedShareItem>(file); FocusingViewIndex = 0; } }) .Subscribe() .DisposeWith(this); } }
private static void PushClipboardToCurrent(MainPage_Model vm) { if ((vm.ClipboardImportingItem?.AvialableShareItems?.Count <= 0)) { return; } vm.FocusingViewIndex = 0; if (vm.ReceivedShareItem == null) { vm.ReceivedShareItem = vm.ClipboardImportingItem; } else { var newItem = vm.ClipboardImportingItem.AvialableShareItems[0]; var targetItemPair = vm.ReceivedShareItem.AvialableShareItems .Select((o, i) => new { o, i }) .Where(p => p.o?.GetType() == newItem.GetType()).FirstOrDefault(); if (targetItemPair != null) { switch (newItem.GetType().Name) { case nameof(TextShareItem): var newText = newItem as TextShareItem; var oldText = vm.ReceivedShareItem.AvialableShareItems[targetItemPair.i] as TextShareItem; var newTextString = newText.Text; ReceivedShareItem.MergeNewText(oldText, newTextString, true, false); break; case nameof(FilesShareItem): var newFile = newItem as FilesShareItem; var oldFile = vm.ReceivedShareItem.AvialableShareItems[targetItemPair.i] as FilesShareItem; oldFile.StorageFiles = new ObservableCollection <FileItem>(oldFile.StorageFiles.Concat(newFile.StorageFiles)); break; default: vm.ReceivedShareItem.AvialableShareItems[targetItemPair.i] = newItem; break; } } else { vm.ReceivedShareItem.AvialableShareItems.Add(newItem); } //var index = targetItemPair == null ? 0 : targetItemPair.i; vm.CurrentViewingItem = newItem; } vm.ClipboardImportingItem = null; }
private static ReceivedShareItem CreateACopyOfShareItem(ReceivedShareItem sharedsource) { return(new ReceivedShareItem() { ContentSourceApplicationLink = sharedsource.ContentSourceApplicationLink, DefaultFailedDisplayText = sharedsource.DefaultFailedDisplayText, ContentSourceWebLink = sharedsource.ContentSourceWebLink, Description = sharedsource.Description, LogoBackgroundColor = sharedsource.LogoBackgroundColor, PackageFamilyName = sharedsource.PackageFamilyName, QuickLinkId = sharedsource.QuickLinkId, Square30x30Logo = sharedsource.Square30x30Logo, Text = sharedsource.Text, Thumbnail = sharedsource.Thumbnail, Title = sharedsource.Title, }); }
protected override Task OnBindedViewLoad(IView view) { //New file activation; //View switching: suggests Different command var obv = this.ListenChanged( x => x.FocusingViewIndex, x => x.ReceivedShareItem, x => x.ClipboardImportingItem); obv.Where(_ => this.FocusingViewIndex == 0) .Where(_ => this.ReceivedShareItem == null) .Subscribe(_ => SugguestingCommand = nameof(CommandLoadFromUserFile)) .DisposeWhenUnload(this); obv.Where(_ => this.FocusingViewIndex == 0) .Where(_ => this.ReceivedShareItem != null) .Subscribe(_ => SugguestingCommand = nameof(CommandReshare)) .DisposeWhenUnload(this); obv.Where(_ => this.FocusingViewIndex == 1) .Where(_ => this.ClipboardImportingItem != null) .Where(_ => this.ClipboardImportingItem.AvialableShareItems != null) .Where(_ => this.ClipboardImportingItem.AvialableShareItems.Count > 0) .Subscribe(_ => SugguestingCommand = nameof(CommandPushClipToCurrentItem)) .DisposeWhenUnload(this); obv.Where(_ => this.FocusingViewIndex == 1) .Where( _ => this.ClipboardImportingItem == null || this.ClipboardImportingItem.AvialableShareItems == null || this.ClipboardImportingItem.AvialableShareItems.Count == 0) .Subscribe(_ => SugguestingCommand = nameof(CommandGetFromClipboard)) .DisposeWhenUnload(this); //Receive Global messages EventRouter.Instance.GetEventChannel <Tuple <EventMessage, Object> >() .Where(x => x.EventData.Item1 == EventMessage.AddTextComment) .Where(x => ReceivedShareItem != null) .Where(x => ReceivedShareItem.AvialableShareItems != null) .ObserveOnDispatcher() .Subscribe( tp => { var str = ResourceLoader.GetForViewIndependentUse().GetString("AddYourCommentsHere"); var target = ReceivedShareItem.AvialableShareItems.OfType <TextShareItem>().FirstOrDefault(); if (target == null) { target = new TextShareItem() { Text = str }; ReceivedShareItem.AvialableShareItems.Add(target); } else { ReceivedShareItem.MergeNewText(target, str, true, false); } CurrentViewingItem = target; } ).DisposeWhenUnload(this); EventRouter.Instance.GetEventChannel <Tuple <EventMessage, Object> >() .Where(x => x.EventData.Item1 == EventMessage.ConvertToWebUri && x.EventData.Item2 != null) .Where(x => ReceivedShareItem != null) .Where(x => ReceivedShareItem.AvialableShareItems != null) .ObserveOnDispatcher() .Subscribe( tp => { if (!Uri.IsWellFormedUriString(tp.EventData.Item2 as string, UriKind.Absolute)) { return; } var uri = new Uri(tp.EventData.Item2.ToString()); var target = ReceivedShareItem.AvialableShareItems.OfType <WebLinkShareItem>().FirstOrDefault(); if (target == null) { target = new WebLinkShareItem() { WebLink = uri }; ReceivedShareItem.AvialableShareItems.Add(target); } else { target.WebLink = uri; //ReceivedShareItem.MergeNewText(target, tp.EventData.Item2.ToString(), true, false); } CurrentViewingItem = target; } ) .DisposeWhenUnload(this); EventRouter.Instance.GetEventChannel <Tuple <EventMessage, Object> >() .Where(x => x.EventData.Item1 == EventMessage.ConvertToText && x.EventData.Item2 != null) .Where(x => ReceivedShareItem != null) .Where(x => ReceivedShareItem.AvialableShareItems != null) .ObserveOnDispatcher() .DoExecuteUIBusyTask( this, async tp => { var str = tp.EventData.Item2.ToString(); var target = ReceivedShareItem.AvialableShareItems.OfType <TextShareItem>().FirstOrDefault(); if (target == null) { target = new TextShareItem() { Text = str }; ReceivedShareItem.AvialableShareItems.Add(target); } else { target.Text = str; //ReceivedShareItem.MergeNewText(target, tp.EventData.Item2.ToString(), true, false); } CurrentViewingItem = target; await Task.Yield(); } ) .Subscribe() .DisposeWhenUnload(this); EventRouter.Instance.GetEventChannel <Tuple <EventMessage, Object> >() .Where(x => x.EventData.Item1 == EventMessage.ImageInkComment && x.EventData.Item2 != null) .Where(x => ReceivedShareItem != null) .Where(x => ReceivedShareItem.AvialableShareItems != null) .ObserveOnDispatcher() .DoExecuteUIBusyTask( this, async e => { var vm = new ImageEditor_Model { CurrentImage = e.EventData.Item2 as Models.MemoryStreamBase64Item }; await StageManager.DefaultStage.Show(vm); }) .Subscribe() .DisposeWhenUnload(this); EventRouter.Instance.GetEventChannel <Tuple <EventMessage, Object> >() .Where(x => x.EventData.Item1 == EventMessage.FileInkComment && x.EventData.Item2 != null) .Where(x => ReceivedShareItem != null) .Where(x => ReceivedShareItem.AvialableShareItems != null) .ObserveOnDispatcher() .DoExecuteUIBusyTask( this, async tp => { var fileitem = tp.EventData.Item2 as FileItem; var file = await StorageApplicationPermissions.FutureAccessList.GetFileAsync(fileitem.AccessToken); if (file == null) { return; } var target = ReceivedShareItem.AvialableShareItems.OfType <DelayRenderedImageShareItem>().FirstOrDefault(); byte[] buf = null; using (var stm = await file.OpenReadAsync()) { var ms = new MemoryStream(); await stm.AsStreamForRead().CopyToAsync(ms); buf = ms.ToArray(); } if (target == null) { target = new DelayRenderedImageShareItem() { SelectedImage = new Models.MemoryStreamBase64Item(buf) }; ReceivedShareItem.AvialableShareItems.Add(target); } else { target.SelectedImage = new Models.MemoryStreamBase64Item(buf); //ReceivedShareItem.MergeNewText(target, tp.EventData.Item2.ToString(), true, false); } CurrentViewingItem = target; var vm = new ImageEditor_Model { CurrentImage = target.SelectedImage }; await StageManager.DefaultStage.Show(vm); }) .Subscribe() .DisposeWhenUnload(this); return(base.OnBindedViewLoad(view)); }
private static async Task<ReceivedShareItem> FetchDataFromPackageViewAsync(DataPackageView packageView) { var rval = new ReceivedShareItem() { Title = packageView.Properties.Title, Description = packageView.Properties.Description, PackageFamilyName = packageView.Properties.PackageFamilyName, ContentSourceWebLink = packageView.Properties.ContentSourceWebLink, ContentSourceApplicationLink = packageView.Properties.ContentSourceApplicationLink, LogoBackgroundColor = packageView.Properties.LogoBackgroundColor, }; if (packageView.Properties.Square30x30Logo != null) { using (var logoStream = await packageView.Properties.Square30x30Logo.OpenReadAsync()) { var logo = new MemoryStream(); await logoStream.AsStreamForRead().CopyToAsync(logo); logo.Position = 0; var str = Convert.ToBase64String(logo.ToArray()); //rval.Square30x30LogoBase64 = Convert.ToBase64String(logo.ToArray()); rval.Square30x30Logo = new Models.MemoryStreamBase64Item { Base64String = str }; } } if (packageView.Properties.Thumbnail != null) { using (var thumbnailStream = await packageView.Properties.Thumbnail.OpenReadAsync()) { var thumbnail = new MemoryStream(); await thumbnailStream.AsStreamForRead().CopyToAsync(thumbnail); thumbnail.Position = 0; var str = Convert.ToBase64String(thumbnail.ToArray()); rval.Thumbnail = new Models.MemoryStreamBase64Item { Base64String = str }; } } if (packageView.Contains(StandardDataFormats.WebLink)) { try { var link = new WebLinkShareItem { WebLink = await packageView.GetWebLinkAsync() }; rval.AvialableShareItems.Add(link); } catch (Exception ex) { //NotifyUserBackgroundThread("Failed GetWebLinkAsync - " + ex.Message, NotifyType.ErrorMessage); } } if (packageView.Contains(StandardDataFormats.ApplicationLink)) { try { var sharedApplicationLink = new ApplicationLinkShareItem { ApplicationLink = await packageView.GetApplicationLinkAsync() }; rval.AvialableShareItems.Add(sharedApplicationLink); } catch (Exception ex) { //NotifyUserBackgroundThread("Failed GetApplicationLinkAsync - " + ex.Message, NotifyType.ErrorMessage); } } if (packageView.Contains(StandardDataFormats.Text)) { try { var sharedText = new TextShareItem { Text = await packageView.GetTextAsync() }; rval.AvialableShareItems.Add(sharedText); rval.Text = await packageView.GetTextAsync(); //rval.GetValueContainer(x => x.Text) // .GetNullObservable() // .Subscribe(e => sharedText.Text = rval.Text) // .DisposeWith(rval); sharedText.GetValueContainer(x => x.Text) .GetNullObservable() .Subscribe(e => rval.Text = sharedText.Text) .DisposeWith(rval); } catch (Exception ex) { //NotifyUserBackgroundThread("Failed GetTextAsync - " + ex.Message, NotifyType.ErrorMessage); } } if (packageView.Contains(StandardDataFormats.StorageItems)) { try { var files = await packageView.GetStorageItemsAsync(); var sharedStorageItem = new FilesShareItem { StorageFiles = new ObservableCollection<FileItem>() //StorageItems = }; foreach (StorageFile sf in files) { var guidString = Guid.NewGuid().ToString(); StorageApplicationPermissions.FutureAccessList.AddOrReplace(guidString, sf, sf.Name); var ts = await sf.GetScaledImageAsThumbnailAsync(Windows.Storage.FileProperties.ThumbnailMode.VideosView); var tmbs = new MemoryStream(); await ts.AsStreamForRead().CopyToAsync(tmbs); var file = new FileItem { AccessToken = guidString, ContentType = sf.ContentType, FileName = sf.DisplayName, PossiblePath = sf.Path, Thumbnail = new Models.MemoryStreamBase64Item(tmbs.ToArray()) }; sharedStorageItem.StorageFiles.Add(file); } //StorageApplicationPermissions.FutureAccessList.AddOrReplace() rval.AvialableShareItems.Add(sharedStorageItem); } catch (Exception ex) { //NotifyUserBackgroundThread("Failed GetStorageItemsAsync - " + ex.Message, NotifyType.ErrorMessage); } } //if (packageView.Contains(dataFormatName)) //{ // try // { // this.sharedCustomData = await packageView.GetTextAsync(dataFormatName); // } // catch (Exception ex) // { // //NotifyUserBackgroundThread("Failed GetTextAsync(" + dataFormatName + ") - " + ex.Message, NotifyType.ErrorMessage); // } //} if (packageView.Contains(StandardDataFormats.Html)) { var sharedHtmlFormatItem = new HtmlShareItem(); var sharedHtmlFormat = string.Empty; try { sharedHtmlFormat = await packageView.GetHtmlFormatAsync(); //sharedHtmlFormatItem.HtmlFormat = sharedHtmlFormat; sharedHtmlFormatItem.HtmlFragment = HtmlFormatHelper.GetStaticFragment(sharedHtmlFormat); } catch (Exception ex) { //NotifyUserBackgroundThread("Failed GetHtmlFormatAsync - " + ex.Message, NotifyType.ErrorMessage); } //try //{ // var sharedResourceMap = await packageView.GetResourceMapAsync(); //} //catch (Exception ex) //{ // //NotifyUserBackgroundThread("Failed GetResourceMapAsync - " + ex.Message, NotifyType.ErrorMessage); //} //if (packageView.Contains(StandardDataFormats.WebLink)) //{ // try // { // sharedHtmlFormatItem.WebLink = await packageView.GetWebLinkAsync(); // } // catch (Exception ex) // { // //NotifyUserBackgroundThread("Failed GetWebLinkAsync - " + ex.Message, NotifyType.ErrorMessage); // } //} rval.AvialableShareItems.Add(sharedHtmlFormatItem); } if (packageView.Contains(StandardDataFormats.Bitmap)) { try { var fi = await packageView.GetBitmapAsync(); using (var imgFileStream = await fi.OpenReadAsync()) { var saveTargetStream = new InMemoryRandomAccessStream(); var bitmapSourceStream = imgFileStream; await ServiceLocator .Instance .Resolve<IImageConvertService>() .ConverterBitmapToTargetStreamAsync(bitmapSourceStream, saveTargetStream); saveTargetStream.Seek(0); var sr = saveTargetStream.GetInputStreamAt(0); var source = sr.AsStreamForRead(); var ms = new MemoryStream(); await source.CopyToAsync(ms); var sharedBitmapStreamRef = new DelayRenderedImageShareItem { SelectedImage = new Models.MemoryStreamBase64Item(ms.ToArray()) }; rval.AvialableShareItems.Add(sharedBitmapStreamRef); } } catch (Exception ex) { //NotifyUserBackgroundThread("Failed GetBitmapAsync - " + ex.Message, NotifyType.ErrorMessage); } } //foreach (var item in rval.AvialableShareItems) //{ // //item.ContentSourceApplicationLink = rval.ContentSourceApplicationLink; // //item.ContentSourceWebLink = rval.ContentSourceWebLink; // //item.DefaultFailedDisplayText = rval.DefaultFailedDisplayText; // //item.Description = rval.Description; // //item.Title = rval.Title; //} return rval; }
public async Task ShareItemAsync(ReceivedShareItem item) { //PrepareData if (item == null) { return; } var defaultUri = await App.CurrentAppUri; var sqt = item?.Square30x30Logo?.GetRandowmAccessStreamAsync(); var Square30x30Logo = sqt == null ? null : await sqt; var rbt = item?.Thumbnail?.GetRandowmAccessStreamAsync(); var Thumbnail = rbt == null ? null : await rbt; ; var fsitm = item.AvialableShareItems.OfType<FilesShareItem>().FirstOrDefault(); var files = await GetStorageItemsAsync(fsitm); var dm = DataTransferManager.GetForCurrentView(); TaskCompletionSource<object> dataTrasferedCompletion = new TaskCompletionSource<object>(); using (Observable.FromEventPattern<TypedEventHandler<DataTransferManager, DataRequestedEventArgs>, DataRequestedEventArgs> (eh => dm.DataRequested += eh, eh => dm.DataRequested -= eh) //.ObserveOnDispatcher() .Subscribe( e => { var def = e.EventArgs.Request.GetDeferral(); try { //dataTrasferedCompletion.TrySetResult(null); var r = e.EventArgs.Request; var package = r.Data; package.Properties.ContentSourceApplicationLink = item.ContentSourceApplicationLink ?? defaultUri; package.Properties.ContentSourceWebLink = item.ContentSourceWebLink ?? defaultUri; package.Properties.Description = item.Description; package.Properties.PackageFamilyName = item.PackageFamilyName; if (Square30x30Logo != null) { package.Properties.Square30x30Logo = RandomAccessStreamReference.CreateFromStream(Square30x30Logo); package.Properties.LogoBackgroundColor = item.LogoBackgroundColor; } if (Thumbnail != null) { package.Properties.Thumbnail = RandomAccessStreamReference.CreateFromStream(Thumbnail); } //package.SetText(item.Text?? "Reshared by " + Windows.ApplicationModel.Package.Current.DisplayName); package.Properties.Title = item.Title; var order = item.AvialableShareItems.OrderBy(x => x is TextShareItem); //make sure text share item execute last foreach (var subShareItem in order) { FillPackage(files, package, subShareItem); } } catch (Exception ex) { e.EventArgs.Request.FailWithDisplayText(ex.Message); } finally { def.Complete(); } } )) { DataTransferManager.ShowShareUI(); await Task.WhenAny(Task.Delay(500), dataTrasferedCompletion.Task); } }
private static async Task <ReceivedShareItem> FetchDataFromPackageViewAsync(DataPackageView packageView) { var rval = new ReceivedShareItem() { Title = packageView.Properties.Title, Description = packageView.Properties.Description, PackageFamilyName = packageView.Properties.PackageFamilyName, ContentSourceWebLink = packageView.Properties.ContentSourceWebLink, ContentSourceApplicationLink = packageView.Properties.ContentSourceApplicationLink, LogoBackgroundColor = packageView.Properties.LogoBackgroundColor, }; if (packageView.Properties.Square30x30Logo != null) { using (var logoStream = await packageView.Properties.Square30x30Logo.OpenReadAsync()) { var logo = new MemoryStream(); await logoStream.AsStreamForRead().CopyToAsync(logo); logo.Position = 0; var str = Convert.ToBase64String(logo.ToArray()); //rval.Square30x30LogoBase64 = Convert.ToBase64String(logo.ToArray()); rval.Square30x30Logo = new Models.MemoryStreamBase64Item { Base64String = str }; } } if (packageView.Properties.Thumbnail != null) { using (var thumbnailStream = await packageView.Properties.Thumbnail.OpenReadAsync()) { var thumbnail = new MemoryStream(); await thumbnailStream.AsStreamForRead().CopyToAsync(thumbnail); thumbnail.Position = 0; var str = Convert.ToBase64String(thumbnail.ToArray()); rval.Thumbnail = new Models.MemoryStreamBase64Item { Base64String = str }; } } if (packageView.Contains(StandardDataFormats.WebLink)) { try { var link = new WebLinkShareItem { WebLink = await packageView.GetWebLinkAsync() }; rval.AvialableShareItems.Add(link); } catch (Exception ex) { //NotifyUserBackgroundThread("Failed GetWebLinkAsync - " + ex.Message, NotifyType.ErrorMessage); } } if (packageView.Contains(StandardDataFormats.ApplicationLink)) { try { var sharedApplicationLink = new ApplicationLinkShareItem { ApplicationLink = await packageView.GetApplicationLinkAsync() }; rval.AvialableShareItems.Add(sharedApplicationLink); } catch (Exception ex) { //NotifyUserBackgroundThread("Failed GetApplicationLinkAsync - " + ex.Message, NotifyType.ErrorMessage); } } if (packageView.Contains(StandardDataFormats.Text)) { try { var sharedText = new TextShareItem { Text = await packageView.GetTextAsync() }; rval.AvialableShareItems.Add(sharedText); rval.Text = await packageView.GetTextAsync(); //rval.GetValueContainer(x => x.Text) // .GetNullObservable() // .Subscribe(e => sharedText.Text = rval.Text) // .DisposeWith(rval); sharedText.GetValueContainer(x => x.Text) .GetNullObservable() .Subscribe(e => rval.Text = sharedText.Text) .DisposeWith(rval); } catch (Exception ex) { //NotifyUserBackgroundThread("Failed GetTextAsync - " + ex.Message, NotifyType.ErrorMessage); } } if (packageView.Contains(StandardDataFormats.StorageItems)) { try { var files = await packageView.GetStorageItemsAsync(); var sharedStorageItem = new FilesShareItem { StorageFiles = new ObservableCollection <FileItem>() //StorageItems = }; foreach (StorageFile sf in files) { var guidString = Guid.NewGuid().ToString(); StorageApplicationPermissions.FutureAccessList.AddOrReplace(guidString, sf, sf.Name); var ts = await sf.GetScaledImageAsThumbnailAsync(Windows.Storage.FileProperties.ThumbnailMode.VideosView); var tmbs = new MemoryStream(); await ts.AsStreamForRead().CopyToAsync(tmbs); var file = new FileItem { AccessToken = guidString, ContentType = sf.ContentType, FileName = sf.DisplayName, PossiblePath = sf.Path, Thumbnail = new Models.MemoryStreamBase64Item(tmbs.ToArray()) }; sharedStorageItem.StorageFiles.Add(file); } //StorageApplicationPermissions.FutureAccessList.AddOrReplace() rval.AvialableShareItems.Add(sharedStorageItem); } catch (Exception ex) { //NotifyUserBackgroundThread("Failed GetStorageItemsAsync - " + ex.Message, NotifyType.ErrorMessage); } } //if (packageView.Contains(dataFormatName)) //{ // try // { // this.sharedCustomData = await packageView.GetTextAsync(dataFormatName); // } // catch (Exception ex) // { // //NotifyUserBackgroundThread("Failed GetTextAsync(" + dataFormatName + ") - " + ex.Message, NotifyType.ErrorMessage); // } //} if (packageView.Contains(StandardDataFormats.Html)) { var sharedHtmlFormatItem = new HtmlShareItem(); var sharedHtmlFormat = string.Empty; try { sharedHtmlFormat = await packageView.GetHtmlFormatAsync(); //sharedHtmlFormatItem.HtmlFormat = sharedHtmlFormat; sharedHtmlFormatItem.HtmlFragment = HtmlFormatHelper.GetStaticFragment(sharedHtmlFormat); } catch (Exception ex) { //NotifyUserBackgroundThread("Failed GetHtmlFormatAsync - " + ex.Message, NotifyType.ErrorMessage); } //try //{ // var sharedResourceMap = await packageView.GetResourceMapAsync(); //} //catch (Exception ex) //{ // //NotifyUserBackgroundThread("Failed GetResourceMapAsync - " + ex.Message, NotifyType.ErrorMessage); //} //if (packageView.Contains(StandardDataFormats.WebLink)) //{ // try // { // sharedHtmlFormatItem.WebLink = await packageView.GetWebLinkAsync(); // } // catch (Exception ex) // { // //NotifyUserBackgroundThread("Failed GetWebLinkAsync - " + ex.Message, NotifyType.ErrorMessage); // } //} rval.AvialableShareItems.Add(sharedHtmlFormatItem); } if (packageView.Contains(StandardDataFormats.Bitmap)) { try { var fi = await packageView.GetBitmapAsync(); using (var imgFileStream = await fi.OpenReadAsync()) { var saveTargetStream = new InMemoryRandomAccessStream(); var bitmapSourceStream = imgFileStream; await ServiceLocator .Instance .Resolve <IImageConvertService>() .ConverterBitmapToTargetStreamAsync(bitmapSourceStream, saveTargetStream); saveTargetStream.Seek(0); var sr = saveTargetStream.GetInputStreamAt(0); var source = sr.AsStreamForRead(); var ms = new MemoryStream(); await source.CopyToAsync(ms); var sharedBitmapStreamRef = new DelayRenderedImageShareItem { SelectedImage = new Models.MemoryStreamBase64Item(ms.ToArray()) }; rval.AvialableShareItems.Add(sharedBitmapStreamRef); } } catch (Exception ex) { //NotifyUserBackgroundThread("Failed GetBitmapAsync - " + ex.Message, NotifyType.ErrorMessage); } } //foreach (var item in rval.AvialableShareItems) //{ // //item.ContentSourceApplicationLink = rval.ContentSourceApplicationLink; // //item.ContentSourceWebLink = rval.ContentSourceWebLink; // //item.DefaultFailedDisplayText = rval.DefaultFailedDisplayText; // //item.Description = rval.Description; // //item.Title = rval.Title; //} return(rval); }
public async Task ShareItemAsync(ReceivedShareItem item) { //PrepareData if (item == null) { return; } var defaultUri = await App.CurrentAppUri; var sqt = item?.Square30x30Logo?.GetRandowmAccessStreamAsync(); var Square30x30Logo = sqt == null ? null : await sqt; var rbt = item?.Thumbnail?.GetRandowmAccessStreamAsync(); var Thumbnail = rbt == null ? null : await rbt;; var fsitm = item.AvialableShareItems.OfType <FilesShareItem>().FirstOrDefault(); var files = await GetStorageItemsAsync(fsitm); var dm = DataTransferManager.GetForCurrentView(); TaskCompletionSource <object> dataTrasferedCompletion = new TaskCompletionSource <object>(); using (Observable.FromEventPattern <TypedEventHandler <DataTransferManager, DataRequestedEventArgs>, DataRequestedEventArgs> (eh => dm.DataRequested += eh, eh => dm.DataRequested -= eh) //.ObserveOnDispatcher() .Subscribe( e => { var def = e.EventArgs.Request.GetDeferral(); try { //dataTrasferedCompletion.TrySetResult(null); var r = e.EventArgs.Request; var package = r.Data; package.Properties.ContentSourceApplicationLink = item.ContentSourceApplicationLink ?? defaultUri; package.Properties.ContentSourceWebLink = item.ContentSourceWebLink ?? defaultUri; package.Properties.Description = item.Description; package.Properties.PackageFamilyName = item.PackageFamilyName; if (Square30x30Logo != null) { package.Properties.Square30x30Logo = RandomAccessStreamReference.CreateFromStream(Square30x30Logo); package.Properties.LogoBackgroundColor = item.LogoBackgroundColor; } if (Thumbnail != null) { package.Properties.Thumbnail = RandomAccessStreamReference.CreateFromStream(Thumbnail); } //package.SetText(item.Text?? "Reshared by " + Windows.ApplicationModel.Package.Current.DisplayName); package.Properties.Title = item.Title; var order = item.AvialableShareItems.OrderBy(x => x is TextShareItem); //make sure text share item execute last foreach (var subShareItem in order) { FillPackage(files, package, subShareItem); } } catch (Exception ex) { e.EventArgs.Request.FailWithDisplayText(ex.Message); } finally { def.Complete(); } } )) { DataTransferManager.ShowShareUI(); await Task.WhenAny(Task.Delay(500), dataTrasferedCompletion.Task); } }