Esempio n. 1
0
        /// <summary>
        /// Invoked when another application wants to share content through this application.
        /// </summary>
        /// <param name="args">Activation data used to coordinate the process with Windows.</param>
        public async void Activate(ShareTargetActivatedEventArgs args)
        {
            this._shareOperation = args.ShareOperation;
            

            // Communicate metadata about the shared content through the view model
            var shareProperties = this._shareOperation.Data.Properties;
            var thumbnailImage = new BitmapImage();
            this.DefaultViewModel["Title"] = shareProperties.Title;
            this.DefaultViewModel["Description"] = shareProperties.Description;
            this.DefaultViewModel["Image"] = thumbnailImage;
            this.DefaultViewModel["Sharing"] = false;
            this.DefaultViewModel["ShowImage"] = false;
            this.DefaultViewModel["Comment"] = String.Empty;
            this.DefaultViewModel["SupportsComment"] = true;
            Window.Current.Content = this;
            Window.Current.Activate();

            Detector dt = new Detector(_shareOperation.Data);
            dt.Detect();
            this.DataContext = dt.Detected;

            // Update the shared content's thumbnail image in the background
            if (shareProperties.Thumbnail != null)
            {
                var stream = await shareProperties.Thumbnail.OpenReadAsync();
                thumbnailImage.SetSource(stream);
                this.DefaultViewModel["ShowImage"] = true;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 在其他应用程序想要共享此应用程序中的内容时进行调用。
        /// </summary>
        /// <param name="e">用于与 Windows 协调进程的激活数据。</param>
        public async void Activate(ShareTargetActivatedEventArgs e)
        {
            this._shareOperation = e.ShareOperation;

            // 通过视图模型沟通关于共享内容的元数据
            var shareProperties = this._shareOperation.Data.Properties;
            var thumbnailImage = new BitmapImage();
            this.DefaultViewModel["Title"] = shareProperties.Title;
            this.DefaultViewModel["Description"] = shareProperties.Description;
            this.DefaultViewModel["Image"] = thumbnailImage;
            this.DefaultViewModel["Sharing"] = false;
            this.DefaultViewModel["ShowImage"] = false;
            this.DefaultViewModel["Comment"] = String.Empty;
            this.DefaultViewModel["Placeholder"] = "Add a comment";
            this.DefaultViewModel["SupportsComment"] = true;
            Window.Current.Content = this;
            Window.Current.Activate();

            // 在后台更新共享内容的缩略图
            if (shareProperties.Thumbnail != null)
            {
                var stream = await shareProperties.Thumbnail.OpenReadAsync();
                thumbnailImage.SetSource(stream);
                this.DefaultViewModel["ShowImage"] = true;
            }
        }
        /// <summary>
        /// Invoked when another application wants to share content through this application.
        /// </summary>
        /// <param name="e">Activation data used to coordinate the process with Windows.</param>
        public async void Activate(ShareTargetActivatedEventArgs e)
        {
            this._shareOperation = e.ShareOperation;

            // Communicate metadata about the shared content through the view model
            var shareProperties = this._shareOperation.Data.Properties;
            var thumbnailImage  = new BitmapImage();

            this.DefaultViewModel["Title"]           = shareProperties.Title;
            this.DefaultViewModel["Description"]     = shareProperties.Description;
            this.DefaultViewModel["Image"]           = thumbnailImage;
            this.DefaultViewModel["Sharing"]         = false;
            this.DefaultViewModel["ShowImage"]       = false;
            this.DefaultViewModel["Comment"]         = String.Empty;
            this.DefaultViewModel["Placeholder"]     = "Add a comment";
            this.DefaultViewModel["SupportsComment"] = true;
            Window.Current.Content = this;
            Window.Current.Activate();

            // Update the shared content's thumbnail image in the background
            if (shareProperties.Thumbnail != null)
            {
                var stream = await shareProperties.Thumbnail.OpenReadAsync();

                thumbnailImage.SetSource(stream);
                this.DefaultViewModel["ShowImage"] = true;
            }
        }
Esempio n. 4
0
        /// <summary>
        /// 在其他应用程序想要共享此应用程序中的内容时进行调用。
        /// </summary>
        /// <param name="e">用于与 Windows 协调进程的激活数据。</param>
        public async void Activate(ShareTargetActivatedEventArgs e)
        {
            this._shareOperation = e.ShareOperation;

            // 通过视图模型沟通关于共享内容的元数据
            var shareProperties = this._shareOperation.Data.Properties;
            var thumbnailImage  = new BitmapImage();

            this.DefaultViewModel["Title"]           = shareProperties.Title;
            this.DefaultViewModel["Description"]     = shareProperties.Description;
            this.DefaultViewModel["Image"]           = thumbnailImage;
            this.DefaultViewModel["Sharing"]         = false;
            this.DefaultViewModel["ShowImage"]       = false;
            this.DefaultViewModel["Comment"]         = String.Empty;
            this.DefaultViewModel["Placeholder"]     = "Add a comment";
            this.DefaultViewModel["SupportsComment"] = true;
            Window.Current.Content = this;
            Window.Current.Activate();

            // 在后台更新共享内容的缩略图
            if (shareProperties.Thumbnail != null)
            {
                var stream = await shareProperties.Thumbnail.OpenReadAsync();

                thumbnailImage.SetSource(stream);
                this.DefaultViewModel["ShowImage"] = true;
            }
        }
Esempio n. 5
0
        protected override async void OnShareTargetActivated(ShareTargetActivatedEventArgs args)
        {
            ShareTargetActivatedEventArgs shareArgs = args as ShareTargetActivatedEventArgs;

            Windows.ApplicationModel.DataTransfer.ShareTarget.ShareOperation op = shareArgs.ShareOperation;
            Windows.Storage.StorageFile storageArg = null;
            string stringArg = null;

            if (op.Data.Contains(Windows.ApplicationModel.DataTransfer.StandardDataFormats.StorageItems))
            {
                System.Collections.Generic.IReadOnlyList <Windows.Storage.IStorageItem> items = await op.Data.GetStorageItemsAsync();

                Windows.Storage.IStorageItem item = items.First();
                if (item.IsOfType(Windows.Storage.StorageItemTypes.File))
                {
                    storageArg = item as Windows.Storage.StorageFile;
                }
            }
            else if (op.Data.Contains(Windows.ApplicationModel.DataTransfer.StandardDataFormats.Uri))
            {
                Uri uri = await op.Data.GetUriAsync();

                stringArg = uri.AbsoluteUri;
            }


            if (args.PreviousExecutionState != ApplicationExecutionState.Running)
            {
                startCN1("");
                if (storageArg != null)
                {
                    Main.appArg = storageArg;
                }
                else if (stringArg != null)
                {
                    Main.appArgStr = stringArg;
                }
            }
            else
            {
                Main.stopStatic();
                if (storageArg != null)
                {
                    Main.appArg = storageArg;
                }
                else if (stringArg != null)
                {
                    Main.appArgStr = stringArg;
                }
                Main.startStatic();
            }
        }
        /// <summary>
        /// Invoked when another application wants to share content through this application.
        /// </summary>
        /// <param name="args">Activation data used to coordinate the process with Windows.</param>
        public async void Activate(ShareTargetActivatedEventArgs args)
        {
            this._shareOperation = args.ShareOperation;

            if (this._shareOperation.Data.Contains(StandardDataFormats.Uri))
            {
                Uri uri = await this._shareOperation.Data.GetUriAsync();

                if (uri != null)
                {
                    // To output text from this example, you need a TextBlock control
                    // with a name of "contentValue".
                    this.url = uri.AbsoluteUri;
                }
            }


            // Communicate metadata about the shared content through the view model
            var shareProperties = this._shareOperation.Data.Properties;
            var thumbnailImage  = new BitmapImage();

            this.DefaultViewModel["Title"]           = this.title = shareProperties.Title;
            this.DefaultViewModel["Description"]     = this.url;// = shareProperties.Description;
            this.DefaultViewModel["Image"]           = thumbnailImage;
            this.DefaultViewModel["Sharing"]         = true;
            this.DefaultViewModel["ShowImage"]       = false;
            this.DefaultViewModel["Comment"]         = String.Empty;
            this.DefaultViewModel["SupportsComment"] = true;
            Window.Current.Content = this;
            Window.Current.Activate();
            SkyDriveDataSource source = await SkyDriveDataSource.GetInstance();

            // itemSelected = await source.GetFolder(source.Root);
            var sampleDataGroups = await source.GetGroups(source.Root, true);

            FolderStack.Add(sampleDataGroups);
            itemSelected = sampleDataGroups;
            this.DefaultViewModel["FolderName"] = itemSelected.Title;
            SemListView.ItemsSource             = sampleDataGroups.AllItems;
            this.DefaultViewModel["Sharing"]    = false;

            // Update the shared content's thumbnail image in the background
            if (shareProperties.Thumbnail != null)
            {
                var stream = await shareProperties.Thumbnail.OpenReadAsync();

                thumbnailImage.SetSource(stream);
                this.DefaultViewModel["ShowImage"] = true;
            }
        }
Esempio n. 7
0
        public async void Activate(ShareTargetActivatedEventArgs args)
        {
            this.shareOperation = args.ShareOperation;

            // Plain Text.
            if (shareOperation.Data.Contains(StandardDataFormats.Text))
            {
                string text = await shareOperation.Data.GetTextAsync();
            }
            // Some URI.
            if (shareOperation.Data.Contains(StandardDataFormats.Uri))
            {
                Uri uri = await shareOperation.Data.GetUriAsync();
            }
            // Formatted HTML Content.
            if (shareOperation.Data.Contains(StandardDataFormats.Html))
            {
                string html = await shareOperation.Data.GetHtmlFormatAsync();
            }



            // Communicate metadata about the shared content through the view model
            var shareProperties = this.shareOperation.Data.Properties;
            var thumbnailImage  = new BitmapImage();

            this.DefaultViewModel["Title"]           = shareProperties.Title;
            this.DefaultViewModel["Description"]     = shareProperties.Description;
            this.DefaultViewModel["Image"]           = thumbnailImage;
            this.DefaultViewModel["Sharing"]         = false;
            this.DefaultViewModel["ShowImage"]       = false;
            this.DefaultViewModel["Comment"]         = String.Empty;
            this.DefaultViewModel["SupportsComment"] = true;
            Window.Current.Content = this;
            Window.Current.Activate();

            // Update the shared content's thumbnail image in the background
            if (shareProperties.Thumbnail != null)
            {
                var stream = await shareProperties.Thumbnail.OpenReadAsync();

                thumbnailImage.SetSource(stream);
                this.DefaultViewModel["ShowImage"] = true;
            }
        }
        /// <summary>
        /// Invoked when another application wants to share content through this application.
        /// </summary>
        /// <param name="args">Activation data used to coordinate the process with Windows.</param>
        public async void Activate(ShareTargetActivatedEventArgs args)
        {
            this._shareOperation = args.ShareOperation;

            // Communicate metadata about the shared content through the view model
            var shareProperties = this._shareOperation.Data.Properties;
            var thumbnailImage = new BitmapImage();
            this.DefaultViewModel["Title"] = shareProperties.Title;
            this.DefaultViewModel["Description"] = shareProperties.Description;
            this.DefaultViewModel["Image"] = thumbnailImage;
            this.DefaultViewModel["Sharing"] = false;
            this.DefaultViewModel["ShowImage"] = false;
            this.DefaultViewModel["Comment"] = String.Empty;
            this.DefaultViewModel["SupportsComment"] = true;


            // Parse Transhipment package
            var geo = await _shareOperation.Data.GetStructuredDataAsync(Schema.GeoCoordinates) as IGeoCoordinates;
            if (geo != null)
            {
                DefaultViewModel["ThingName"] = geo.Name;
                DefaultViewModel["Latitude"] = geo.Latitude;
                DefaultViewModel["Longitude"] = geo.Longitude;
            }
            
            Window.Current.Content = this;
            Window.Current.Activate();

            // Update the shared content's thumbnail image in the background
            if (shareProperties.Thumbnail != null)
            {
                var stream = await shareProperties.Thumbnail.OpenReadAsync();
                thumbnailImage.SetSource(stream);
                this.DefaultViewModel["ShowImage"] = true;
            }
        }
Esempio n. 9
0
        private async Task FillCreateInfo(Windows.ApplicationModel.DataTransfer.ShareTarget.ShareOperation shareOperation)
        {
            string rawHtml = shareOperation.Data.Contains(StandardDataFormats.Html) ? HtmlFormatHelper.GetStaticFragment((await shareOperation.Data.GetHtmlFormatAsync()).ToString()) : "";
            string rawText = (shareOperation.Data.Contains(StandardDataFormats.Text)) ? (await shareOperation.Data.GetTextAsync()).ToString() : "";
            string rawLink = (shareOperation.Data.Contains(StandardDataFormats.WebLink)) ? (await shareOperation.Data.GetWebLinkAsync()).ToString() : "";

            bool   htmlFormed = false;
            string Content    = string.Empty;
            string Caption    = string.Empty;

            if (!String.IsNullOrEmpty(rawHtml))
            {
                #region parsing html
                System.Text.StringBuilder contentBuilder = new System.Text.StringBuilder();

                HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
                doc.LoadHtml(rawHtml);

                var allDivs    = doc.DocumentNode.Descendants("div");
                var titleNodes = allDivs.Where(div => div.GetAttributeValue("class", "").Equals("snippet-info-title-div"));
                if (titleNodes.Count() > 0)
                {
                    Caption = titleNodes.First().Descendants("a").First().InnerHtml?.Trim();
                    contentBuilder.AppendLine("[" + Caption + "](" + rawLink + ")");
                }
                var imagesNodes = allDivs.Where(div => div.GetAttributeValue("class", "").Equals("snippet-images-div"));
                if (imagesNodes.Count() > 0)
                {
                    foreach (var imageNode in imagesNodes)
                    {
                        string imgUrl = imageNode.GetAttributeValue("src", "")?.Trim();
                        if (!String.IsNullOrEmpty(imgUrl))
                        {
                            contentBuilder.AppendLine("![](" + imgUrl + ")");
                        }
                    }
                }
                var descriptionNodes = allDivs.Where(div => div.GetAttributeValue("class", "").Equals("snippet-info-description-div"));
                if (descriptionNodes.Count() > 0)
                {
                    contentBuilder.AppendLine(descriptionNodes.First().InnerHtml?.Trim());
                }
                if (contentBuilder.Length > 0)
                {
                    htmlFormed = true;
                    Content    = contentBuilder.ToString();
                }
                #endregion
            }

            if (!htmlFormed)
            {
                Content = rawText;
                if (!String.IsNullOrEmpty(rawLink))
                {
                    Content = "[" + (String.IsNullOrEmpty(Content) ? "link" : Content) + "](" + rawLink + ")";
                }
            }

            mdOrganizer.Pages.ViewerPage.AutoCreateInfo = new Pages.AutoCreateInfo()
            {
                Caption = Caption,
                Content = Content
            };
        }
Esempio n. 10
0
 private void Activate(ShareTargetActivatedEventArgs e)
 {
     this._shareOperation = e.ShareOperation;
     Window.Current.Content = this;
     Window.Current.Activate();
 }