protected void Page_Load(object sender, EventArgs e) { Product = "Imaging"; this.hdnSearchId.Value = Page.RouteData.Values["SearchId"]?.ToString(); if (!this.IsPostBack) { try { var status = AsposeReverseSearchApiHelper.GetReverseSearchStatus(this.hdnSearchId.Value); if (status != null) { ViewState["site"] = status.Site; ViewState["searchId"] = status.Id; this.hdnSearchStatus.Value = ((int)status.State).ToString(); this.IndexingPlaceHolder.Visible = status.State == AsposeReverseSearchApiHelper.SearchState.Indexing; this.SearchingPlaceHolder.Visible = status.State == AsposeReverseSearchApiHelper.SearchState.Searching; this.ResultsPlaceHolder.Visible = status.State == AsposeReverseSearchApiHelper.SearchState.Ready; if (status.State == AsposeReverseSearchApiHelper.SearchState.Ready) { this.ShowSearchResults(AsposeReverseSearchApiHelper.GetLastResuts(status.Id)); } } } catch (Exception) { this.Response.Redirect("~/errorpage"); } this.btnNewSearch.Text = Resources["ReverseSearchNewImage"]; // Set page settings based on from and top selection this.PageSettings(); } }
protected void ListView1_PagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e) { ContactsDataPager.SetPageProperties(e.StartRowIndex, e.MaximumRows, false); ShowResult(AsposeReverseSearchApiHelper.GetLastResuts(this.hdnSearchId.Value)); }
protected void btnStart_Click(object sender, EventArgs e) { Guid inputId; var isIdInput = Guid.TryParse(txtInputIdOrSite.Value, out inputId); var isNew = this.hdnSearchId.Value == "new"; this.rfvFile.Enabled = !(isNew && isIdInput); Page.Validate("uploadFile"); if (Page.IsValid) { pMessage.Attributes.Remove("class"); pMessage.InnerHtml = ""; string error = null; try { AsposeReverseSearchApiHelper.ImageSearchStatus status = null; if (isIdInput) { status = AsposeReverseSearchApiHelper.GetReverseSearchStatus(this.txtInputIdOrSite.Value); if (status == null) { error = $"Reverse image search with Id {this.txtInputIdOrSite.Value} not found"; } else if (status.State == AsposeReverseSearchApiHelper.SearchState.Ready) { var searchResults = this.FileUpload1.PostedFile.InputStream.Length == 0 ? AsposeReverseSearchApiHelper.GetLastResuts(status.Id) : AsposeReverseSearchApiHelper.StartSearchSimilarImages(status.Id, this.FileUpload1.PostedFile.InputStream); this.Session["searchResults"] = searchResults; } } else { string url; if (AsposeReverseSearchApiHelper.TryGetUrl(this.txtInputIdOrSite.Value, out url, out error)) { status = AsposeReverseSearchApiHelper.CreateReverseSearch(url, this.FileUpload1.PostedFile.InputStream); if (status == null) { error = $"Cannot create reverse image search for the site {this.txtInputIdOrSite.Value}"; } } } if (status == null) { pMessage.Visible = true; pMessage.InnerHtml = error; pMessage.Attributes.Add("class", "alert alert-danger"); } else { Response.RedirectToRoute("AsposeAppReverseSearchResultsRoute", new { SearchId = status.Id }); } } catch (Exception ex) { pMessage.Visible = true; pMessage.InnerHtml = "Error: " + ex.Message; pMessage.Attributes.Add("class", "alert alert-danger"); } } }