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; }
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); }