protected override bool GetShareContent(DataRequest request) { bool succeeded = false; string dataPackageFormat = DataFormatInputBox.Text; if (!String.IsNullOrEmpty(dataPackageFormat)) { string dataPackageText = CustomDataTextBox.Text; if (!String.IsNullOrEmpty(dataPackageText)) { DataPackage requestData = request.Data; requestData.Properties.Title = TitleInputBox.Text; requestData.Properties.Description = DescriptionInputBox.Text; // The description is optional. requestData.Properties.ContentSourceApplicationLink = ApplicationLink; requestData.SetData(dataPackageFormat, dataPackageText); succeeded = true; } else { request.FailWithDisplayText("Enter the custom data you would like to share and try again."); } } else { request.FailWithDisplayText("Enter a custom data format and try again."); } return(succeeded); }
private void ShareHtmlHandler(DataTransferManager sender, DataRequestedEventArgs e) { DataRequest request = e.Request; DataRequestDeferral deferral = request.GetDeferral(); request.Data.Properties.Title = "Instructions to sync IE's favorites on your desktop to SkyDrive"; request.Data.Properties.Description = ""; if (counter == this.promoContentSource.GetPromoData.Count - 1) { try { string localImage = "ms-appx:///Assets/SkyDriveSetupInstruction.png"; string html = @"<html><body><h2>Instructions to sync IE's favorites on your desktop to SkyDrive</h2>" + @"<p><img src=""" + localImage + @""" alt=""Sync Favorites""></p>" + @"<p><ol>" + @"<li>Download SkyDrive http://windows.microsoft.com/en-us/skydrive/download</li>" + @"<li>Open directory c:\users\%username%. (Replace %username% with login ID you use to logon to your computer)</li>" + @"<li>Right click on Favorites folder and click Properties -> Click Location tab -> Click Move</li>" + @"<li>Choose the folder C:\Users\%username%\SkyDrive\RoamingFavoritesApp\Bookmark.</li>" + @"<li>Open folder C:\Users\%username%\SkyDrive and right click on RoamingFavoritesApp folder and click Make available offline.</li>" + @"<li>Done. Repeat above instructions for all of your laptop/desktop.</li>" + @"</ol></p></body></html>"; request.Data.SetHtmlFormat(HtmlFormatHelper.CreateHtmlFormat(html)); request.Data.Properties.ApplicationName = "Favorites Browser"; RandomAccessStreamReference streamRef = RandomAccessStreamReference.CreateFromUri(new Uri(localImage)); request.Data.ResourceMap[localImage] = streamRef; } catch { request.FailWithDisplayText("Folder can't be shared as bookmarks."); } //do nothing : might be empty string becuase only folder is selected } else { request.FailWithDisplayText("Nothing to share."); } deferral.Complete(); }
protected override bool GetShareContent(DataRequest request) { bool succeeded = false; if (this.imageFile != null) { DataPackage requestData = request.Data; requestData.Properties.Title = TitleInputBox.Text; requestData.Properties.Description = DescriptionInputBox.Text; // The description is optional. requestData.Properties.ContentSourceApplicationLink = ApplicationLink; // It's recommended to use both SetBitmap and SetStorageItems for sharing a single image // since the target app may only support one or the other. List <IStorageItem> imageItems = new List <IStorageItem>(); imageItems.Add(this.imageFile); requestData.SetStorageItems(imageItems); RandomAccessStreamReference imageStreamRef = RandomAccessStreamReference.CreateFromFile(this.imageFile); requestData.Properties.Thumbnail = imageStreamRef; requestData.SetBitmap(imageStreamRef); succeeded = true; } else { request.FailWithDisplayText("Select an image you would like to share and try again."); } return(succeeded); }
protected override bool GetShareContent(DataRequest request) { bool succeeded = false; Uri selectedApplicationLink = ApplicationLinkComboBox.SelectedItem as Uri; if (selectedApplicationLink != null) { DataPackage requestData = request.Data; requestData.Properties.Title = TitleInputBox.Text; requestData.Properties.Description = DescriptionInputBox.Text; // The description is optional. requestData.Properties.ContentSourceApplicationLink = ApplicationLink; requestData.SetApplicationLink(selectedApplicationLink); // Place the selected logo and the background color in the data package properties if (MicrosoftLogo.IsChecked.Value) { requestData.Properties.Square30x30Logo = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///assets/microsoftLogo.png")); requestData.Properties.LogoBackgroundColor = GetLogoBackgroundColor(); } else if (VisualStudioLogo.IsChecked.Value) { requestData.Properties.Square30x30Logo = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///assets/visualStudioLogo.png")); requestData.Properties.LogoBackgroundColor = GetLogoBackgroundColor(); } succeeded = true; } else { request.FailWithDisplayText("Select the application link you would like to share and try again."); } return(succeeded); }
private void GetShareContent(DataRequest request) { if (_currentComic != null) { DataRequestDeferral deferral = request.GetDeferral(); DataPackage requestData = request.Data; requestData.Properties.Title = _currentComic.Title; requestData.Properties.Description = _currentComic.Subtitle; string textToShare = string.Format("Title: {1}{0}Number: {2}{0}Published: {3}{0}Alternate Text: {4}", Environment.NewLine, _currentComic.Title, _currentComic.Number, _currentComic.Date.ToString("d"), _currentComic.AltText); requestData.SetText(textToShare); var bitmap = RandomAccessStreamReference.CreateFromUri(_currentComic.ImageUri); request.Data.Properties.Thumbnail = bitmap; requestData.SetBitmap(bitmap); requestData.SetUri(_currentComic.Uri); deferral.Complete(); } else { request.FailWithDisplayText("Select a comic you would like to share and try again."); } }
public void Share(DataRequest request) { // We work with a copy of the list of document references List <DocumentReference> list = null; if (DocumentReferences != null) { list = DocumentReferences.ToList(); } request.Data.Properties.Title = SearchResultInfo; // request.Data.Properties.Description = ...; if (list != null) { var stb = new StringBuilder(); stb.AppendLine(); stb.Append("Suchresultate:\r\n"); foreach (var docref in list) { stb.AppendFormat("{0}, {1}\r\nRIS Bundesrecht Österreich URL: risdok://{2}/\r\nWeb URL: {3}\r\n\r\n", docref.ArtikelParagraphAnlage, docref.Kurzinformation, docref.Dokumentnummer, docref.DokumentUrl); } request.Data.SetText(stb.ToString()); } else { request.FailWithDisplayText("Keine Resultate für Sharing vorhanden"); } }
protected override bool GetShareContent(DataRequest request) { string errorMessage = CustomErrorText.Text; if (String.IsNullOrEmpty(errorMessage)) { errorMessage = "Enter a failure display text and try again."; } request.FailWithDisplayText(errorMessage); return(false); }
private void MainPage_DataRequested(DataTransferManager sender, DataRequestedEventArgs args) { DataRequest request = args.Request; Todo shared = TodoViewModel.getInstance().GetTodoOfIndex(MainAdaptiveViewModel.getInstance().SelectedItemIndex); if (shared == null) { request.FailWithDisplayText("You have not selected any todo item"); } else { request.Data.Properties.Title = "Todo: " + shared.Title; request.Data.SetText(shared.Detail); } }
void dataTransferManager_DataRequested(DataTransferManager sender, DataRequestedEventArgs args) { DataRequest request = args.Request; DataPackage p = WebView7.DataTransferPackage; if (p.GetView().Contains(StandardDataFormats.Text)) { p.Properties.Title = "WebView Sharing Excerpt"; p.Properties.Description = "This is a snippet from the content hosted in the WebView control"; request.Data = p; } else { request.FailWithDisplayText("Nothing to share"); } dataTransferManager.DataRequested -= dataTransferManager_DataRequested; }
protected override bool GetShareContent(DataRequest request) { bool succeeded = false; if (storageItems != null) { DataPackage requestData = request.Data; requestData.Properties.Title = TitleInputBox.Text; requestData.Properties.Description = DescriptionInputBox.Text; // The description is optional. requestData.SetStorageItems(this.storageItems); succeeded = true; } else { request.FailWithDisplayText("Select the files you would like to share and try again."); } return(succeeded); }
private void ProvideSharingDataFromWebView(DataRequest request) { try { var html = new StringBuilder(webView.InvokeScript("eval", new string[] { "document.documentElement.outerHTML;" })); // Fix Urls to base Urls otherwise it won't look right (css, js et cetera missing) - really, really simple html.Replace("src=\"/", "src=\"http://www.ris.bka.gv.at/"); html.Replace("href=\"/", "href=\"http://www.ris.bka.gv.at/"); request.Data.Properties.Title = ViewModel.PageTitle; request.Data.SetHtmlFormat(HtmlFormatHelper.CreateHtmlFormat(html.ToString())); } catch { request.FailWithDisplayText("Es gibt keine Inhalte die geteilt werden können"); } }
protected bool GetShareContent(DataRequest request) { bool succeeded = false; string dataPackageText = Synopsis.Text; if (!String.IsNullOrEmpty(dataPackageText)) { DataPackage requestData = request.Data; requestData.Properties.Title = PageTitle.Text; requestData.SetText(dataPackageText); succeeded = true; } else { request.FailWithDisplayText("Enter the text you would like to share and try again."); } return succeeded; }
protected override bool GetShareContent(DataRequest request) { bool succeeded = false; if (this.selectedImage != null) { DataPackage requestData = request.Data; requestData.Properties.Title = "Delay rendered image"; requestData.Properties.Description = "Resized image from the Share Source sample"; requestData.Properties.Thumbnail = RandomAccessStreamReference.CreateFromFile(this.selectedImage); requestData.SetDataProvider(StandardDataFormats.Bitmap, providerRequest => this.OnDeferredImageRequestedHandler(providerRequest, this.selectedImage)); succeeded = true; } else { request.FailWithDisplayText("Select an image you would like to share and try again."); } return(succeeded); }
protected override bool GetShareContent(DataRequest request) { bool succeeded = false; string dataPackageText = TextToShare.Text; if (!String.IsNullOrEmpty(dataPackageText)) { DataPackage requestData = request.Data; requestData.Properties.Title = TitleInputBox.Text; requestData.Properties.Description = DescriptionInputBox.Text; // The description is optional. requestData.SetText(dataPackageText); succeeded = true; } else { request.FailWithDisplayText("Enter the text you would like to share and try again."); } return(succeeded); }
// This function is implemented by each scenario to share the content specific to that scenario (text, link, image, etc.). protected bool GetShareContent(DataRequest request) { bool succeeded = false; var app = Application.Current as App; if (!String.IsNullOrEmpty(app.SharingTitle)) { DataPackage requestData = request.Data; requestData.Properties.Title = app.SharingTitle; requestData.Properties.Description = app.SharingText; // The description is optional. requestData.SetUri(new Uri(app.SharingLink)); succeeded = true; } else { request.FailWithDisplayText("nothing to share"); } return(succeeded); }
public bool getShareContent(DataRequest request, String share_id) { // The URI used in this sample is provided by the user so we need to ensure it's a wellformatted absolute URI // before we try to share it. //rootPage.NotifyUser("", NotifyType.StatusMessage); Uri dataPackageUri = new Uri(getFromResourceFile("ShareUrl01_part01") + share_id + getFromResourceFile("ShareUrl01_part02"), UriKind.Absolute); if (dataPackageUri != null) { DataPackage requestData = request.Data; requestData.Properties.Title = "Ajapaik"; requestData.Properties.Description = "Kus ajalugu asub?"; // The description is optional. requestData.SetUri(dataPackageUri); return(true); } else { request.FailWithDisplayText("Sisesta link ja proovi uuesti."); return(false); } }
public void OnShareRequested(DataRequest dataRequest) { if (string.IsNullOrWhiteSpace(_exceptionString)) { dataRequest.FailWithDisplayText("There is nothing to share at this moment."); } else { dataRequest.Data.Properties.Title = "Error report"; dataRequest.Data.Properties.Description = "Share this with us by email"; dataRequest.Data.Properties.ApplicationName = "Subsonic8"; var dataBuilder = new StringBuilder(); var actionInformation = string.Format( _resourceService.GetStringResource("ErrorDialogViewModelStrings/ActionInformation"), _resourceService.GetStringResource("ErrorDialogViewModelStrings/ErrorReportDeliveryEmail")); dataBuilder.Append(string.Format("<h2>{0}</h2><br/>", actionInformation)); dataBuilder.Append(string.Format("<div><span>{0}</span></div>", ExceptionString)); dataRequest.Data.SetHtmlFormat(HtmlFormatHelper.CreateHtmlFormat(dataBuilder.ToString())); } }
// // http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.webview.datatransferpackage // didn't work, thus DataRequested uses code from // http://codesnack.com/blog/2012/01/05/metro-webview-source-workarounds/ // void DataTransferManager_DataRequested(DataTransferManager sender, DataRequestedEventArgs args) { DataRequest request = args.Request; if (NavigationAction.LoadFromUrl == ViewModel.NavigationParameter.Action) { ProvideSharingDataFromWebView(request); } else { if (ViewModel.SourceHtml != null) { request.Data.Properties.Title = ViewModel.PageTitle; request.Data.SetHtmlFormat(HtmlFormatHelper.CreateHtmlFormat(ViewModel.SourceHtml)); } else { request.FailWithDisplayText("Es gibt keine Inhalte die geteilt werden können"); } } }
public bool GetShareContent(DataRequest request) { bool succeeded = false; string dataPackageText = "I started using my fashion assistant ! it's very useful and free \n "; if (!String.IsNullOrEmpty(dataPackageText)) { DataPackage requestData = request.Data; requestData.Properties.Title = "My Fashion assistant"; requestData.Properties.Description = "My Fashion assistant it's a free application that helps you to get better dressed"; // The description is optional. //requestData.Properties.ContentSourceApplicationLink = ApplicationLink; requestData.SetText(dataPackageText); succeeded = true; } else { request.FailWithDisplayText("Enter the text you would like to share and try again."); } return(succeeded); }
private static bool GetShareContent(DataRequest request) { bool succeeded = false; string dataPackageText = Content; if (!String.IsNullOrEmpty(dataPackageText)) { DataPackage requestData = request.Data; requestData.Properties.Title = Title; requestData.SetText(dataPackageText); succeeded = true; } else { #pragma warning disable CS0618 // Type or member is obsolete request.FailWithDisplayText("错误,请稍后重试"); #pragma warning restore CS0618 // Type or member is obsolete } return(succeeded); }
protected override bool GetShareContent(DataRequest request) { bool succeeded = false; // Get the user's selection from the WebView. DataPackage requestData = ShareWebView.DataTransferPackage; DataPackageView dataPackageView = requestData.GetView(); if ((dataPackageView != null) && (dataPackageView.AvailableFormats.Count > 0)) { requestData.Properties.Title = "A web snippet for you"; requestData.Properties.Description = "HTML selection from a WebView control"; // The description is optional. request.Data = requestData; succeeded = true; } else { request.FailWithDisplayText("Make a selection in the WebView control and try again."); } return(succeeded); }
private async void DataTransferManager_DataRequested(DataTransferManager sender, DataRequestedEventArgs args) { DataRequestDeferral deferral = args.Request.GetDeferral(); // MyLogger has SendLogs method but calling this in Button_Click above will not work and the Share // dialog will just open and close. Moving it down to this event solves the issue. await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() => { DataRequest request = args.Request; if (shareList != null) { if (shareList.FlagFolde != true) { try { StorageFile myFile = await StorageFile.GetFileFromPathAsync(shareList.Path);// shareList.storageFile; request.Data.Properties.Title = "Share My File"; request.Data.Properties.Description = string.Format("Share log file {0}.", myFile.DisplayName); List <IStorageItem> myStorageItems = new List <IStorageItem>() { myFile }; request.Data.SetStorageItems(myStorageItems); deferral.Complete(); } catch (Exception ex) { //Debug.WriteLine(ex.ToString()); request.FailWithDisplayText(ex.ToString()); } } } }); }
protected override bool GetShareContent(DataRequest request) { bool succeeded = false; // The URI used in this sample is provided by the user so we need to ensure it's a wellformatted absolute URI // before we try to share it. rootPage.NotifyUser("", NotifyType.StatusMessage); Uri dataPackageUri = ValidateAndGetUri(UriToShare.Text); if (dataPackageUri != null) { DataPackage requestData = request.Data; requestData.Properties.Title = TitleInputBox.Text; requestData.Properties.Description = DescriptionInputBox.Text; // The description is optional. requestData.SetUri(dataPackageUri); succeeded = true; } else { request.FailWithDisplayText("Enter the link you would like to share and try again."); } return(succeeded); }
protected override bool GetShareContent(DataRequest request) { // Get the user's selection from the WebView. Since this is an asynchronous operation we need to acquire the deferral first. DataRequestDeferral deferral = request.GetDeferral(); // Make sure to always call Complete when done with the deferral. try { var requestDataOperation = ShareWebView.CaptureSelectedContentToDataPackageAsync(); requestDataOperation.Completed += (asyncInfo, status) => { DataPackage requestData = asyncInfo.GetResults(); if ((requestData != null) && (requestData.GetView().AvailableFormats.Count > 0)) { requestData.Properties.Title = "A web snippet for you"; requestData.Properties.Description = "HTML selection from a WebView control"; // The description is optional. requestData.Properties.ContentSourceApplicationLink = ApplicationLink; requestData.Properties.ContentSourceWebLink = new Uri("http://msdn.microsoft.com"); request.Data = requestData; deferral.Complete(); } else { // FailWithDisplayText calls Complete on the deferral. request.FailWithDisplayText("Make a selection in the WebView control and try again."); } }; } catch (Exception) { deferral.Complete(); } // At this point, we haven't populated the data package yet. It's done asynchronously above. return(false); }
public virtual void ShareItem(RoutedEventArgs e) { DataTransferManager manager = DataTransferManager.GetForCurrentView(); manager.DataRequested += new TypedEventHandler <DataTransferManager, DataRequestedEventArgs>(Manager_DataRequested); DataTransferManager.ShowShareUI(new ShareUIOptions { Theme = Enum.IsDefined(typeof(ShareUITheme), ThemeHelper.RootTheme.ToString()) ? (ShareUITheme)ThemeHelper.RootTheme : ShareUITheme.Default }); async void Manager_DataRequested(DataTransferManager sender, DataRequestedEventArgs args) { DataRequestDeferral dataRequestDeferral = args.Request.GetDeferral(); List <IStorageItem> items = new List <IStorageItem>(); DataRequest dataRequest = args.Request; /*dataRequest.Data.Properties.Title = "Data Shared From Files"; * dataRequest.Data.Properties.Description = "The items you selected will be shared";*/ foreach (ListedItem item in SlimContentPage.SelectedItems) { if (item.IsShortcutItem) { if (item.IsLinkItem) { dataRequest.Data.Properties.Title = string.Format("ShareDialogTitle".GetLocalized(), items.First().Name); dataRequest.Data.Properties.Description = "ShareDialogSingleItemDescription".GetLocalized(); dataRequest.Data.SetWebLink(new Uri(((ShortcutItem)item).TargetPath)); dataRequestDeferral.Complete(); return; } } else if (item.PrimaryItemAttribute == StorageItemTypes.Folder) { if (await StorageItemHelpers.ToStorageItem <StorageFolder>(item.ItemPath, associatedInstance) is StorageFolder folder) { items.Add(folder); } } else { if (await StorageItemHelpers.ToStorageItem <StorageFile>(item.ItemPath, associatedInstance) is StorageFile file) { items.Add(file); } } } if (items.Count == 1) { dataRequest.Data.Properties.Title = string.Format("ShareDialogTitle".GetLocalized(), items.First().Name); dataRequest.Data.Properties.Description = "ShareDialogSingleItemDescription".GetLocalized(); } else if (items.Count == 0) { dataRequest.FailWithDisplayText("ShareDialogFailMessage".GetLocalized()); dataRequestDeferral.Complete(); return; } else { dataRequest.Data.Properties.Title = string.Format("ShareDialogTitleMultipleItems".GetLocalized(), items.Count, "ItemsCount.Text".GetLocalized()); dataRequest.Data.Properties.Description = "ShareDialogMultipleItemsDescription".GetLocalized(); } dataRequest.Data.SetStorageItems(items); dataRequestDeferral.Complete(); // TODO: Unhook the event somewhere } }
public void FailWithDisplayText(string text) { _dataRequest.FailWithDisplayText(text); }
private async Task <bool> GetShareContent(DataRequest request) { bool succeeded = false; //Uri dataPackageUri = ValidateAndGetUri(ShareLink); //if (dataPackageUri != null) //{ // DataPackage requestData = request.Data; // requestData.Properties.Title = ShareTitle; // requestData.Properties.Description = ShareDescription; // requestData.SetUri(dataPackageUri); // if (!isImageFile && !string.IsNullOrEmpty(this.ImageUri) && !string.IsNullOrWhiteSpace(this.ImageUri)) // { // await GetlocalUri(this.ImageUri); // } // if (this.ImageFile != null) // { // List<IStorageItem> imageItems = new List<IStorageItem>(); // imageItems.Add(this.ImageFile); // requestData.SetStorageItems(imageItems); // RandomAccessStreamReference imageStreamRef = RandomAccessStreamReference.CreateFromFile(this.ImageFile); // if (imageStreamRef != null && (await imageStreamRef.OpenReadAsync()).Size > 0) // { // requestData.Properties.Thumbnail = imageStreamRef; // requestData.SetBitmap(imageStreamRef); // } // } // succeeded = true; //} //else //{ // request.FailWithDisplayText("Select an YouTube Link you would like to share and try again."); //} if (!String.IsNullOrEmpty(ShareTitle) && !string.IsNullOrWhiteSpace(ShareTitle)) { DataPackage requestData = request.Data; requestData.Properties.Title = ShareTitle; requestData.Properties.Description = ShareDescription; if (ShareType == SystemShareType.Link) { Uri dataPackageUri = ValidateAndGetUri(ShareLinkOrText); if (dataPackageUri != null) { requestData.SetUri(dataPackageUri); } else { request.FailWithDisplayText("Select an YouTube link you would like to share and try again."); return(succeeded); } } else { if (!string.IsNullOrEmpty(ShareLinkOrText) && !string.IsNullOrWhiteSpace(ShareLinkOrText)) { requestData.SetText(ShareLinkOrText); } else { request.FailWithDisplayText("Select an YouTube content you would like to share and try again."); return(succeeded); } } if (!isImageFile && !string.IsNullOrEmpty(this.ImageUri) && !string.IsNullOrWhiteSpace(this.ImageUri)) { await GetLocalUri(this.ImageUri); } if (this.ImageFile != null) { List <IStorageItem> imageItems = new List <IStorageItem>(); imageItems.Add(this.ImageFile); requestData.SetStorageItems(imageItems); RandomAccessStreamReference imageStreamRef = RandomAccessStreamReference.CreateFromFile(this.ImageFile); if (imageStreamRef != null && (await imageStreamRef.OpenReadAsync()).Size > 0) { requestData.Properties.Thumbnail = imageStreamRef; requestData.SetBitmap(imageStreamRef); } } succeeded = true; } else { request.FailWithDisplayText("Enter a title for what you are sharing and try again."); } return(succeeded); }