示例#1
0
        public void MergeRepositories()
        {
            Utils.DatabaseUtils  dbu            = new Utils.DatabaseUtils(LogonTracerConfig.Instance.ConnectionString);
            SessionDbProvider    dbProvider     = new SessionDbProvider();
            List <ActiveSession> activeSessions = SessionLocalRepositoryProvider.Instance.GetSessionsFromRepository();
            List <Dictionary <string, object> > sessionsHistory  = SessionLocalRepositoryProvider.Instance.GetSessionsHistoryFromRepository();
            List <Dictionary <string, object> > sessionsActivity = SessionLocalRepositoryProvider.Instance.GetSessionsActivityFromRepository();

            foreach (ActiveSession session in activeSessions)
            {
                double dbSessionActivityHours = 0;
                if (session.DbId != 0)
                {
                    dbSessionActivityHours += Convert.ToDouble(dbu.GetFieldValue("Logins", "ActiveHours", "Id", session.DbId));
                }
                else
                {
                    dbProvider.SaveSession(session);
                    continue;
                }
                if (session.ActivityHours > dbSessionActivityHours)
                {
                    dbProvider.SaveSession(session);
                }
            }

            foreach (Dictionary <string, object> history in sessionsHistory)
            {
                dbProvider.UpdateDetailsMessage = (string)history.Where(h => h.Key == "UpdateDetails").Select(h => h.Value).FirstOrDefault();
                dbProvider.AgentMachineName     = (string)history.Where(h => h.Key == "AgentMachineName").Select(h => h.Value).FirstOrDefault();
                dbProvider.AgentVersion         = (string)history.Where(h => h.Key == "AgentVersion").Select(h => h.Value).FirstOrDefault();
                dbProvider.UpdateMoment         = Convert.ToDateTime(history.Where(h => h.Key == "UpdateMoment").Select(h => h.Value).FirstOrDefault());
                dbProvider.OnUpdateSessionHistory(Convert.ToDecimal(history.Where(h => h.Key == "SessionId").Select(h => h.Value).FirstOrDefault()));
            }

            foreach (Dictionary <string, object> activity in sessionsActivity)
            {
                dbProvider.ChunkBegin = Convert.ToDateTime(activity.Where(a => a.Key == "ChunkBegin").Select(a => a.Value).FirstOrDefault());
                dbProvider.ChunkEnd   = Convert.ToDateTime(activity.Where(a => a.Key == "ChunkEnd").Select(a => a.Value).FirstOrDefault());
                dbProvider.SaveSessionActivityProfile(
                    Convert.ToDecimal(activity.Where(a => a.Key == "SessionId").Select(a => a.Value).FirstOrDefault()),
                    Convert.ToBoolean(activity.Where(a => a.Key == "ActivityRegistered").Select(a => a.Value).FirstOrDefault())
                    );
            }
        }
示例#2
0
        public static SessionRepositoryProviderBase GetProvider()
        {
            SessionRepositoryProviderBase baseProvider = null;

            Utils.DatabaseUtils dbu = new Utils.DatabaseUtils(LogonTracerConfig.Instance.ConnectionString);

            if (dbu.CheckDbAvailability())
            {
                baseProvider = new SessionDbProvider();
                baseProvider.MergeRepositories();
            }
            else
            {
                baseProvider = SessionLocalRepositoryProvider.Instance;
            }

            return(baseProvider);
        }