public async Task NotifyPingbackAsync(PingbackRecord model) { if (!_isEnabled) { _logger.LogWarning($"Skipped {nameof(NotifyPingbackAsync)} because Email sending is disabled."); return; } try { var req = new PingPayload( model.TargetPostTitle, model.PingTimeUtc, model.Domain, model.SourceIp, model.SourceUrl, model.SourceTitle); await SendAsync(new NotificationRequest <PingPayload>(MailMesageTypes.BeingPinged, req)); } catch (Exception e) { _logger.LogError(e, e.Message); } }
public IContentResponse Get(string method, string rawUrl, NameValueCollection headers, Stream inputStream) { long length; using (new MutexLock(2000, _lockName)) { using (Stream output = new FileStream(_filename, FileMode.OpenOrCreate, FileAccess.Read, FileShare.Read)) length = output.Length; } using (Stream rawinput = new FileStream(_filename, FileMode.OpenOrCreate, FileAccess.Read, FileShare.ReadWrite)) { long position = 0; Match m = Regex.Match(headers["If-None-Match"] ?? String.Empty, "^\"position:(?<position>\\d+)\"$"); if (m.Success) { position = Math.Min(Math.Max(0, long.Parse(m.Groups["position"].Value)), length); } using (Stream input = new ClampedStream(rawinput, position, Math.Max(0, length - position))) { PingbackRecord rec = PingbackRecord.ParseFrom(input); return(new DynamicResponse("application/vnd.google.protobuf", rec.ToByteArray()) { ETag = String.Format("position:{0}", length), LastModified = rec.RecordsCount > 0 ? rec.RecordsList[rec.RecordsCount - 1].When : DateTime.Now, }); } } }
public async Task OnGet_StateUnderTest_ExpectedBehavior() { IEnumerable <PingbackRecord> pingback = new PingbackRecord[] { }; _mockPingbackService.Setup(p => p.GetPingbackHistoryAsync()) .Returns(Task.FromResult(pingback)); var pingbackModel = CreatePingbackModel(); await pingbackModel.OnGet(); Assert.IsNotNull(pingbackModel.PingbackRecords); }
public async Task Pingback_View() { IEnumerable <PingbackRecord> pingback = new PingbackRecord[] { }; _mockPingbackService.Setup(p => p.GetPingbackHistoryAsync()) .Returns(Task.FromResult(pingback)); var ctl = CreateAdminController(); var result = await ctl.Pingback(); Assert.IsInstanceOf <ViewResult>(result); }
public void Playback(Uri sourceSite, string stateFile) { Uri pingbackApi; if (!TryGetPingbackFromHeader(out pingbackApi)) { throw new ArgumentException("The site does not have an X-Pingback header."); } if (!Directory.Exists(Path.GetDirectoryName(stateFile))) { Directory.CreateDirectory(Path.GetDirectoryName(stateFile)); } using (Stream stream = new FileStream(stateFile, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Read)) { stream.Seek(0, SeekOrigin.End); HttpRequestUtil http = new HttpRequestUtil(sourceSite); http.RequestHeaders["If-None-Match"] = String.Format("\"position:{0}\"", stream.Position); if (http.Get(sourceSite.PathAndQuery) == HttpStatusCode.NotModified) { return; } if (http.StatusCode != HttpStatusCode.OK) { throw new ApplicationException(String.Format("Unexpected http result: {0}/{1}", (int)http.StatusCode, http.StatusCode)); } PingbackRecord response = PingbackRecord.ParseFrom(http.Content); foreach (PingbackInfo ping in response.RecordsList) { try { int errorCode; string serverMessage; Uri source = new Uri(ping.SourceUri, UriKind.Absolute); Uri target = new Uri(_targetLink, ping.TargetUri); if (!SendPingback(source, target, pingbackApi, LogError, out errorCode, out serverMessage)) { LogError(String.Format("Failed to register pingback from {0}, {1}", ping.SourceUri, serverMessage)); } } catch (Exception e) { LogError(String.Format("Failed to register pingback from {0}, {1}", ping.SourceUri, e.Message)); } } response.WriteTo(stream); } }