Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Isssues/table renaming #6

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Components/FeatureController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using System;

namespace Dnn.WebAnalytics.Components
{
public class FeatureController
{
}
}
43 changes: 22 additions & 21 deletions Components/VisitorTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
using System.Web;
using DotNetNuke.Entities.Portals;
using DotNetNuke.Entities.Users;
using System.Linq;
using DotNetNuke.Instrumentation;
using DotNetNuke.Services.Exceptions;

namespace Dnn.WebAnalytics
{
public class VisitorTracker : IHttpModule
{
private static readonly ILog Logger = LoggerSource.Instance.GetLogger(typeof(VisitorTracker));
private System.Text.RegularExpressions.Regex UserAgentFilter = new System.Text.RegularExpressions.Regex(VisitController.UserAgentFilter, System.Text.RegularExpressions.RegexOptions.Compiled | System.Text.RegularExpressions.RegexOptions.IgnoreCase);
VisitController visitController = new VisitController();
VisitorController visitorController = new VisitorController();
DataContext dc = new DataContext();
private VisitorInfoRepo visitorRepo = new VisitorInfoRepo();

public string ModuleName
{
Expand Down Expand Up @@ -52,14 +52,14 @@ public void OnEndRequest(object s, EventArgs e)
}

// update/create visitor
var visitor = dc.Visitors.Where(i => i.id == visitor_id).SingleOrDefault();
var visitor = visitorRepo.GetItem(visitor_id, _portalSettings.PortalId);
if (visitor == null)
{ // create Visitor record
visitor = new Visitor()
visitor = new VisitorInfo()
{
created_on_date = DateTime.Now
};
dc.Visitors.InsertOnSubmit(visitor);
visitorRepo.CreateItem(visitor);
}

// get User if authenticated
Expand All @@ -77,7 +77,7 @@ public void OnEndRequest(object s, EventArgs e)
{
visitor.user_id = user_id;
}
dc.SubmitChanges();
visitorRepo.UpdateItem(visitor);

// only process requests for content pages
if (_portalSettings != null && Request.Url.LocalPath.ToLower().EndsWith("default.aspx"))
Expand Down Expand Up @@ -170,46 +170,47 @@ public void OnEndRequest(object s, EventArgs e)
string user_agent = Request.UserAgent;

// create visit object
VisitDTO visitDTO = new VisitDTO()
var visitDto = new VisitDTO()
{
date = DateTime.Now,
visitor_id = visitor.id,
tab_id = _portalSettings.ActiveTab.TabID,
ip = ip,
country = "",
region = "",
city = "",
latitude = "",
longitude = "",
country = string.Empty,
region = string.Empty,
city = string.Empty,
latitude = string.Empty,
longitude = string.Empty,
language = language,
domain = domain,
url = url,
user_agent = user_agent,
device_type = "Desktop",
device = "",
platform = "",
browser = "",
device = string.Empty,
platform = string.Empty,
browser = string.Empty,
referrer_domain = domain_referrer,
referrer_url = url_referrer,
server = "",
server = string.Empty,
activity = "click",
campaign = campaign,
session_id = session_id,
request_id = request_id,
last_request_id = last_request_id
};

visitDTO = visitController.ProcessVisit(visitDTO);
visitDto = visitController.ProcessVisit(visitDto);

Visit visit = visitController.ConvertDtoToItem(null, visitDTO);
VisitInfo visit = visitController.ConvertDtoToItem(null, visitDto);

dc.Visits.InsertOnSubmit(visit);
dc.SubmitChanges();
var repo = new VisitInfoRepo();
repo.CreateItem(visit);
}
}
}
catch (Exception ex)
{
Logger.Error(ex.Message, ex);
Exceptions.LogException(ex);
}
}
Expand Down
17 changes: 9 additions & 8 deletions Controllers/MapController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using DotNetNuke.Security;
using DotNetNuke.Instrumentation;
using DotNetNuke.Security;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.Web.Api;
using System;
Expand All @@ -12,11 +13,10 @@

namespace Dnn.WebAnalytics
{
//[SupportedModules("Dnn.WebAnalytics")]
//[ValidateAntiForgeryToken]
public class MapController : DnnApiController
{
DataContext dc = new DataContext();
private static readonly ILog Logger = LoggerSource.Instance.GetLogger(typeof(MapController));
private VisitInfoRepo visitRepo = new VisitInfoRepo();

[HttpGet]
[DnnModuleAuthorize(AccessLevel = SecurityAccessLevel.View)]
Expand All @@ -27,10 +27,10 @@ public HttpResponseMessage Get(int minutes)
{
List<MapDTO> dtos = new List<MapDTO>();

List<Visit> recent_visits = dc.Visits
List<VisitInfo> recent_visits = visitRepo.GetItemsAll()
.Where(i =>
i.date >= DateTime.Now.AddMinutes(-minutes) &&
i.latitude != "" && i.longitude != ""
i.latitude != string.Empty && i.longitude != string.Empty
)
.ToList();

Expand All @@ -46,7 +46,7 @@ public HttpResponseMessage Get(int minutes)

foreach (long id in ids)
{
var visit = dc.Visits.Where(i => i.id == id).SingleOrDefault();
var visit = visitRepo.GetItemById((int)id); // this may need to be debugged and/or handled better later
if (visit != null)
{
MapDTO mapDTO = new MapDTO()
Expand All @@ -56,14 +56,14 @@ public HttpResponseMessage Get(int minutes)
longitude = visit.longitude
};
dtos.Add(mapDTO);

}
}

return Request.CreateResponse(HttpStatusCode.OK, dtos);
}
catch (Exception ex)
{
Logger.Error(ex.Message, ex);
Exceptions.LogException(ex);
return Request.CreateResponse(HttpStatusCode.InternalServerError, ex);
}
Expand Down Expand Up @@ -107,6 +107,7 @@ public HttpResponseMessage Get()
}
catch (Exception ex)
{
Logger.Error(ex.Message, ex);
Exceptions.LogException(ex);
return Request.CreateResponse(HttpStatusCode.InternalServerError, ex);
}
Expand Down
Loading