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(); } }
//private string GetValidFileExtensions(string validationExpression) //{ // string validFileExtensions = validationExpression.Replace(".", "").Replace("|", ", ").ToUpper(); // int index = validFileExtensions.LastIndexOf(","); // if (index != -1) // { // string substr = validFileExtensions.Substring(index); // string str = substr.Replace(",", " or"); // validFileExtensions = validFileExtensions.Replace(substr, str); // } // return validFileExtensions; //} private void PageSettings() { var mySiteMaster = (SiteMaster)this.Master; mySiteMaster.Page.Title = this.Resources["ApplicationTitle"] + " | " + this.Resources["ReverseSearchStartPageTitle"]; this.SetFileTypeAllowedExtensions(); this.hAsposeProductTitle.InnerText = this.Resources["Aspose" + this.TitleCase("imaging")]; this.hAsposeProductTitle.InnerText = this.hAsposeProductTitle.InnerText + " " + this.Resources["ReverseSearch4"]; if (this.hdnSearchId.Value == null) { this.Response.Redirect("~/errorpage"); } else if (this.hdnSearchId.Value != "new") { this.dvInputIdOrSite.Visible = false; var status = AsposeReverseSearchApiHelper.GetReverseSearchStatus(this.hdnSearchId.Value); if (status == null) { this.Response.Redirect("~/errorpage"); } else if (status.State != AsposeReverseSearchApiHelper.SearchState.Ready) { Response.RedirectToRoute("AsposeAppReverseSearchResultsRoute", new { SearchId = status.Id }); } if (status != null) { this.txtInputIdOrSite.InnerText = status.Id; } } }
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"); } } }