Browse Source

Made tracking a synchronous process

pull/111/head
Teknikode 5 years ago
parent
commit
c695051a9b
  1. 9
      Teknik/Filters/TrackDownload.cs
  2. 9
      Teknik/Filters/TrackLink.cs
  3. 9
      Teknik/Filters/TrackPageView.cs
  4. 22
      Utilities/Utilities/ResponseHelper.cs

9
Teknik/Filters/TrackDownload.cs

@ -28,7 +28,7 @@ namespace Teknik.Filters @@ -28,7 +28,7 @@ namespace Teknik.Filters
{
string userAgent = request.UserAgent;
string ipAddress = request.ClientIPFromRequest(true);
string clientIp = request.ClientIPFromRequest(true);
string urlReferrer = request.UrlReferrer?.ToString();
@ -37,15 +37,10 @@ namespace Teknik.Filters @@ -37,15 +37,10 @@ namespace Teknik.Filters
url = request.Url.ToString();
// Fire and forget. Don't need to wait for it.
Task.Run(() => AsyncTrackDownload(userAgent, ipAddress, url, urlReferrer));
Tracking.TrackDownload(userAgent, clientIp, url, urlReferrer);
}
base.OnActionExecuted(filterContext);
}
private static void AsyncTrackDownload(string userAgent, string clientIp, string url, string urlReferrer)
{
Tracking.TrackDownload(userAgent, clientIp, url, urlReferrer);
}
}
}

9
Teknik/Filters/TrackLink.cs

@ -27,7 +27,7 @@ namespace Teknik.Filters @@ -27,7 +27,7 @@ namespace Teknik.Filters
{
string userAgent = request.UserAgent;
string ipAddress = request.ClientIPFromRequest(true);
string clientIp = request.ClientIPFromRequest(true);
string urlReferrer = request.UrlReferrer?.ToString();
@ -36,15 +36,10 @@ namespace Teknik.Filters @@ -36,15 +36,10 @@ namespace Teknik.Filters
url = request.Url.ToString();
// Fire and forget. Don't need to wait for it.
Task.Run(() => AsyncTrackLink(userAgent, ipAddress, url, urlReferrer));
Tracking.TrackLink(userAgent, clientIp, url, urlReferrer);
}
base.OnActionExecuted(filterContext);
}
private static void AsyncTrackLink(string userAgent, string clientIp, string url, string urlReferrer)
{
Tracking.TrackLink(userAgent, clientIp, url, urlReferrer);
}
}
}

9
Teknik/Filters/TrackPageView.cs

@ -34,7 +34,7 @@ namespace Teknik.Filters @@ -34,7 +34,7 @@ namespace Teknik.Filters
sub = request.Url?.AbsoluteUri.GetSubdomain();
}
string ipAddress = request.ClientIPFromRequest(true);
string clientIp = request.ClientIPFromRequest(true);
string url = string.Empty;
if (request.Url != null)
@ -54,15 +54,10 @@ namespace Teknik.Filters @@ -54,15 +54,10 @@ namespace Teknik.Filters
bool hasJava = request.Browser.JavaApplets;
// Fire and forget. Don't need to wait for it.
Task.Run(() => AsyncTrackPageView(title, sub, ipAddress, url, urlReferrer, userAgent,pixelWidth, pixelHeight, hasCookies, acceptLang, hasJava));
Tracking.TrackPageView(title, sub, clientIp, url, urlReferrer, userAgent, pixelWidth, pixelHeight, hasCookies, acceptLang, hasJava);
}
base.OnActionExecuted(filterContext);
}
private static void AsyncTrackPageView(string title, string sub, string clientIp, string url, string urlReferrer, string userAgent, int pixelWidth, int pixelHeight, bool hasCookies, string acceptLang, bool hasJava)
{
Tracking.TrackPageView(title, sub, clientIp, url, urlReferrer, userAgent, pixelWidth, pixelHeight, hasCookies, acceptLang, hasJava);
}
}
}

22
Utilities/Utilities/ResponseHelper.cs

@ -20,13 +20,6 @@ namespace Teknik.Utilities @@ -20,13 +20,6 @@ namespace Teknik.Utilities
int bytesToRead = chunkSize;
do
{
// Flush the response
if (flush)
{
//response.OutputStream.Write(buffer, 0, 1);
response.Flush();
}
if (chunkSize > bytesRemaining)
{
bytesToRead = bytesRemaining;
@ -37,10 +30,18 @@ namespace Teknik.Utilities @@ -37,10 +30,18 @@ namespace Teknik.Utilities
{
response.OutputStream.Write(buffer, 0, processedBytes);
// Flush the response
if (flush)
{
response.Flush();
}
// Clear the buffer
Array.Clear(buffer, 0, chunkSize);
// decrement the total bytes remaining to process
bytesRemaining -= processedBytes;
}
bytesRemaining -= processedBytes;
}
while (processedBytes > 0 && bytesRemaining > 0);
}
@ -51,10 +52,7 @@ namespace Teknik.Utilities @@ -51,10 +52,7 @@ namespace Teknik.Utilities
finally
{
// dispose of file stream
if (stream != null)
{
stream.Dispose();
}
stream?.Dispose();
}
}
}

Loading…
Cancel
Save