Beispiel #1
0
        public ActionResult DailyActivity(int?SelectedStudentId, DateTime?SelectedDate)
        {
            DailyActivityViewModel vm = new DailyActivityViewModel();

            if (SelectedStudentId != null && SelectedDate != null)
            {
                vm.SelectedDate      = (DateTime)SelectedDate;
                vm.SelectedStudentId = (int)SelectedStudentId;
                DateTime tomorrow = vm.SelectedDate.AddDays(1);

                //pull event logs
                List <EventLog> logs = Db.EventLogs
                                       .Where(u => u.SenderId == vm.SelectedStudentId)
                                       .Where(e => e.DateReceived > vm.SelectedDate)
                                       .Where(e => e.DateReceived < tomorrow)
                                       .ToList();
                foreach (EventLog log in logs)
                {
                    vm.ActivityItems.Add(log.DateReceived, log);
                }

                //pull request logs from azure storage
                var requestLogs = DomainObjectHelpers.GetActionRequests(1, vm.SelectedStudentId)
                                  .Where(l => l.CreatorId == vm.SelectedStudentId)
                                  .Where(l => l.AccessDate > vm.SelectedDate)
                                  .Where(l => l.AccessDate < tomorrow)
                                  .ToList();
                foreach (OSBIDE.Data.DomainObjects.ActionRequestLog log in requestLogs)
                {
                    vm.ActivityItems.Add(log.AccessDate, log);
                }

                //pull comments
                List <LogCommentEvent> comments = Db.LogCommentEvents
                                                  .Where(c => c.EventLog.SenderId == vm.SelectedStudentId)
                                                  .Where(c => c.EventDate > vm.SelectedDate)
                                                  .Where(c => c.EventDate < tomorrow)
                                                  .ToList();
                foreach (LogCommentEvent comment in comments)
                {
                    vm.ActivityItems.Add(comment.EventDate, comment);
                }
            }
            vm.Students = Db.Users.Where(u => u.RoleValue == (int)SystemRole.Student).OrderBy(s => s.LastName).ToList();

            return(View(vm));
        }
        public static bool Run(int schoolId)
        {
            using (var context = new OsbideProcs())
            {
                // storage tables not completely processed
                foreach (var table in context.GetPassiveSocialEventProcessLog())
                {
                    var passiveSocialEvents = DomainObjectHelpers.GetPassiveSocialActivities(table.SourceTableName, schoolId).ToList();
                    var totalCounts         = passiveSocialEvents.Count;

                    var processedCounts = table.ProcessedRecordCounts.HasValue ? table.ProcessedRecordCounts.Value : 0;
                    var batches         = (totalCounts - processedCounts) / BATCH_SIZE;
                    for (var b = 0; b < batches + 1; b++)
                    {
                        var tsql = new StringBuilder();

                        var firstRow = processedCounts + b * BATCH_SIZE;
                        var lastRow  = processedCounts + (b + 1) * BATCH_SIZE > totalCounts ? totalCounts : processedCounts + (b + 1) * BATCH_SIZE;

                        for (var idx = firstRow; idx < lastRow; idx++)
                        {
                            var sql = GetSQLRowStatement(passiveSocialEvents[idx]);
                            if (sql.Length > 0)
                            {
                                // build batch insert statements
                                tsql.AppendFormat("{0}{1}", sql, Environment.NewLine);
                            }
                        }

                        // batch execution and log updates
                        DynamicSQLExecutor.Execute(tsql.ToString());
                        context.UpdatePassiveSocialEventProcessLog(table.Id, DESTINATIONTABLE, lastRow == totalCounts, lastRow);
                    }
                }

                return(true);
            }
        }
Beispiel #3
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var auth = new Authentication();
            var key  = auth.GetAuthenticationKey();

            //were we supplied an authentication key from the query string?
            if (filterContext.HttpContext != null)
            {
                var authQueryKey = filterContext.HttpContext.Request.QueryString.Get("auth");
                if (!authQueryKey.IsNullOrWhiteSpace())
                {
                    key = authQueryKey;

                    //if the key is valid, log the user into the system and then retry the request
                    if (auth.IsValidKey(key))
                    {
                        auth.LogIn(auth.GetActiveUser(key));
                        var routeValues = new RouteValueDictionary();
                        routeValues["controller"] = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName;
                        routeValues["action"]     = filterContext.ActionDescriptor.ActionName;
                        foreach (var parameterKey in filterContext.ActionParameters.Keys)
                        {
                            var parameterValue = filterContext.ActionParameters[parameterKey];
                            routeValues[parameterKey] = parameterValue;
                        }
                        filterContext.Result = new RedirectToRouteResult(routeValues);
                        return;
                    }
                }
            }
            if (auth.IsValidKey(key) == false)
            {
                if (filterContext.HttpContext != null)
                {
                    filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { controller = "Account", action = "Login", returnUrl = filterContext.HttpContext.Request.Url }));
                }
            }
            else
            {
                //log the request
                var log = new ActionRequestLog
                {
                    ActionName     = filterContext.ActionDescriptor.ActionName,
                    ControllerName = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName,
                    CreatorId      = auth.GetActiveUser(key).Id,
                    AccessDate     = DateTime.UtcNow,
                    SchoolId       = 1, // need to get school Id
                };
                try
                {
                    log.IpAddress = filterContext.RequestContext.HttpContext.Request.ServerVariables["REMOTE_ADDR"];
                }
                catch (Exception)
                {
                    log.IpAddress = "Unknown";
                }
                var parameters = new StringBuilder();
                foreach (var parameterKey in filterContext.ActionParameters.Keys)
                {
                    var parameterValue = filterContext.ActionParameters[parameterKey] ?? DomainConstants.ActionParameterNullValue;
                    parameters.Append(string.Format("{0}={1}{2}", parameterKey, parameterValue, DomainConstants.ActionParameterDelimiter));
                }
                log.ActionParameters = parameters.ToString();

                //save to azure table storage
                DomainObjectHelpers.LogActionRequest(log);
            }
        }