// Asynchronous task to try and get cached response when image is dragged from an ImageStore to the query pane.
        // Logic slightly varies based on whether image is from azure or local
        public async virtual Task DownloadQueryImageAndResponseFromQueryImageStore(object o)
        {
            if (!CanSearch(o))
            {
                return;
            }
            ImageInfoViewModel iivm = o as ImageInfoViewModel;


            string url = iivm.Url;
            bool   shouldResizeImage = true;
            bool   issueQueryIfCachedResponseEmpty = true;


            if (iivm.ImageInfo is FileImageInfo)
            {
                // For file blobs we have to resize the image, we want to issue a new query
                shouldResizeImage = true;
                issueQueryIfCachedResponseEmpty = true;
            }
            else
            {
                // For azure blob store blobs we don't resize so that we can reproduce the original query as sent from device
                shouldResizeImage = false;
                issueQueryIfCachedResponseEmpty = false;
            }
            await iivm.FetchTagsAsync();  // the ImageInfoViewModel may not have been rendered

            await DownloadAndRender(iivm, issueQueryIfCachedResponseEmpty, shouldResizeImage, url);
        }
示例#2
0
        private async void ScrollViewer_Drop(object sender, DragEventArgs e) //This method gets data on any images dropped in the ImageModSection
        {
            if (e.Data.GetDataPresent(DataFormats.Text))
            {
                string str = (string)e.Data.GetData(DataFormats.Text);
                await VM.DownloadAndSearchQueryImage(str);

                e.Handled = true;
            }
            else if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                string[] fileNames = e.Data.GetData(DataFormats.FileDrop, true) as string[];
                await VM.DownloadAndSearchQueryImage(fileNames[0]);

                e.Handled = true;
            }
            else if (e.Data.GetFormats().Length == 1)          //for internal components participating in drag/drop the list contains exactly 1 item, which is the type name
            {
                var f = e.Data.GetFormats()[0];                //get the one and only formatname which must be a type name
                var o = e.Data.GetData(f);                     //fetch the object using that type name.
                if (o is VSPing.ViewModels.ImageInfoViewModel) //if the fetched object is an ImageInfoViewModel, we recognize as internal type
                {
                    VSPing.ViewModels.ImageInfoViewModel iivm = o as VSPing.ViewModels.ImageInfoViewModel;
                    await VM.DownloadQueryImageAndResponseFromQueryImageStore(iivm);

                    e.Handled = true;
                }
            }
        }
        // Renders from url and tries to retrieve a cached response
        protected virtual async Task DownloadAndRender(ImageInfoViewModel iivm, bool issueQuery, bool shouldResize, string url)
        {
            this.UpdateQueryImageUrl(url);

            await this.DownloadQueryImageAsync(url, shouldResize);

            await this.ShowExistingSearchResponseForUrl(iivm.Url);

            // For cases where we don't have a cached response, we want to directly issue the query.
            if (issueQuery || (this.SearchResponse?.Source ?? SearchResponseSource.None) == SearchResponseSource.None)
            {
                await Search();
            }
        }
示例#4
0
        public virtual async Task <ImageInfoViewModel> GetImage(string url)
        {
            var iivm = this.QueryImages.FirstOrDefault(i => i.Url == url);

            if (iivm != null)
            {
                return(iivm);
            }

            //url is not in our ViewModel. Get it from the store
            var ii = await this.ImageStore.GetImage(url);

            if (ii == null)
            {
                return(null); //the store doesn't have it
            }
            iivm = new ImageInfoViewModel(ii, this.QueryImages.Count + 1, this.ParentViewModel);

            this.QueryImages.Insert(0, iivm);

            return(iivm);
        }