protected void btnTestNotify_Click(object sender, EventArgs e) { SNSNotification sns = new SNSNotification(); sns.Message = txtTestJSONData.Text; SendTestPost(JsonConvert.SerializeObject(sns), "Notification"); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { pnlTest.Visible = true; } if (String.Compare(Request.RequestType, "POST", StringComparison.OrdinalIgnoreCase) == 0) { string szMessageType = (Request.Headers["x-amz-sns-message-type"] ?? string.Empty).ToUpperInvariant(); switch (szMessageType) { case "NOTIFICATION": SNSNotification snsNotification = ReadJSONObject <SNSNotification>(); if (String.IsNullOrEmpty(snsNotification.Signature) || snsNotification.VerifySignature()) { // simply creating the object will do all that is necessary. if (new MFBImageInfo(snsNotification) == null) { } } Response.Clear(); Response.Write("OK"); Response.End(); break; case "SUBSCRIPTIONCONFIRMATION": { SNSSubscriptionConfirmation snsSubscription = ReadJSONObject <SNSSubscriptionConfirmation>(); // Visit the URL to confirm it. if (snsSubscription.VerifySignature()) { using (WebClient wc = new System.Net.WebClient()) { byte[] rgdata = wc.DownloadData(snsSubscription.SubscribeLink); _ = System.Text.UTF8Encoding.UTF8.GetString(rgdata); } } } Response.Clear(); Response.Write("OK"); Response.End(); break; case "UNSUBSCRIBECONFIRMATION": // Nothing to do for now. break; default: // Test messages/etc. can go here. break; } } }
private HttpResponseMessage HandleNotification(string message) { // parse the message SNSNotification obj = JsonConvert.DeserializeObject <SNSNotification>(message); // read the subject and message string subject = obj.Subject; string topicMessage = obj.Message; return(Request.CreateResponse(HttpStatusCode.OK)); }
protected void btnCleanPendingVideos_Click(object sender, EventArgs e) { List <SNSNotification> lstPending = new List <SNSNotification>(); List <int> lstFlights = new List <int>(); // Get all pending videos that are more than an hour old and create synthetic SNS notifications for them. DBHelper dbh = new DBHelper("SELECT * FROM pendingvideos pv WHERE submitted < DATE_ADD(Now(), INTERVAL -1 HOUR)"); dbh.ReadRows((comm) => { }, (dr) => { AWSETSStateMessage etsNotification = new AWSETSStateMessage() { JobId = (string)dr["jobID"], State = "COMPLETED" }; SNSNotification sns = new SNSNotification() { Message = JsonConvert.SerializeObject(etsNotification) }; lstPending.Add(sns); lstFlights.Add(Convert.ToInt32(dr["imagekey"], CultureInfo.InvariantCulture)); }); int cPending = lstPending.Count; gvVideos.DataSource = lstFlights; gvVideos.DataBind(); // Now, go through them and create each one. Should clean up as part of the process. // simply creating the object will do all that is necessary. foreach (SNSNotification sns in lstPending) { _ = new MFBImageInfo(sns); } int cRemaining = 0; dbh.CommandText = "SELECT count(*) AS numRemaining FROM pendingvideos pv WHERE submitted < DATE_ADD(Now(), INTERVAL -1 HOUR)"; dbh.ReadRow((comm) => { }, (dr) => { cRemaining = Convert.ToInt32(dr["numRemaining"], CultureInfo.InvariantCulture); }); lblPVResults.Text = String.Format(CultureInfo.CurrentCulture, "Found {0} videos orphaned, {1} now remain", cPending, cRemaining); }