protected void Page_Init(object sender, EventArgs e) { if (Request.PathInfo.Length > 0) { int idAd = -1; try { idAd = Convert.ToInt32(Request.PathInfo.Substring(1), CultureInfo.InvariantCulture); } catch (Exception ex) when(ex is FormatException) { } if (idAd > 0) { SponsoredAd ad = SponsoredAd.GetAd(idAd); if (ad != null) { // Yeah, it's a click, but if "imp=1" is present, treat it as an impression, not a click. if (util.GetIntParam(Request, "imp", 0) != 0) { ad.AddImpression(); } else { ad.AddClick(); } } } } }
protected void lnkPostInsurance_Click(object sender, EventArgs e) { const string szSkywatchEndpoint = "https://user.skywatch.ai/aviation/analyze_logs"; WriteInsurenceZip((szFile, fs) => { List <IDisposable> objectsToDispose = new List <IDisposable>(); try { using (HttpClient client = new HttpClient()) { using (MultipartFormDataContent formData = new MultipartFormDataContent()) { fs.Seek(0, SeekOrigin.Begin); StreamContent strc = new StreamContent(fs); objectsToDispose.Add(strc); formData.Add(strc, "Files", szFile + ".zip"); StringContent sc = new StringContent(Profile.GetUser(Page.User.Identity.Name).Email); objectsToDispose.Add(sc); formData.Add(sc, "Email"); sc = new StringContent("(Multiple)"); objectsToDispose.Add(sc); formData.Add(sc, "AircraftModel"); sc = new StringContent("(Unspecified)"); objectsToDispose.Add(sc); formData.Add(sc, "NNumber"); HttpResponseMessage response = client.PostAsync(new Uri(szSkywatchEndpoint), formData).Result; response.EnsureSuccessStatusCode(); // If we're here, we were successful. lblInsErr.Text = Resources.LocalizedText.InsurancePostSuccessful; lblInsErr.CssClass = "success"; SponsoredAd.GetAd(4)?.AddClick(); // Skywatch is 4. We're treating POST as a click, and click-through as an impression. } } } catch (HttpRequestException ex) { lblInsErr.Text = String.Format(CultureInfo.CurrentCulture, "{0}: {1}", Resources.LocalizedText.InsurancePostFailed, ex.Message); } finally { foreach (IDisposable disposable in objectsToDispose) { disposable.Dispose(); } } }); }
protected void Page_Init(object sender, EventArgs e) { if (Request.PathInfo.Length > 0) { int idAd = -1; try { idAd = Convert.ToInt32(Request.PathInfo.Substring(1), CultureInfo.InvariantCulture); } catch (FormatException) { } if (idAd > 0) { SponsoredAd ad = SponsoredAd.GetAd(idAd); if (ad != null) { ad.AddClick(); GoogleAnalytics1.RedirURL = ad.TargetURL; } } } }