Exemplo n.º 1
0
            public PerfStatisticData ExtractOldData(DateTime _NewestData)
            {
                PerfStatisticData oldData = new PerfStatisticData();

                foreach (var currPerfPageItem in m_PerfPageItems)
                {
                    int lastIndex = currPerfPageItem.Value.m_PageAccessItems.FindLastIndex((_Value) => { return(_Value.m_StartRequestDateTime < _NewestData); });
                    if (lastIndex != -1)
                    {
                        PerfPageItem newPerfPageItem = new PerfPageItem();
                        newPerfPageItem.m_PageName        = currPerfPageItem.Value.m_PageName;
                        newPerfPageItem.m_PageAccessItems = currPerfPageItem.Value.m_PageAccessItems.GetRange(0, lastIndex + 1);
                        currPerfPageItem.Value.m_PageAccessItems.RemoveRange(0, lastIndex + 1);
                        oldData.m_PerfPageItems.Add(currPerfPageItem.Key, newPerfPageItem);
                    }
                }
                foreach (var currUserAccess in m_UserAccesses)
                {
                    int lastIndex = currUserAccess.Value.FindLastIndex((_Value) => { return(_Value.m_StartRequestDateTime < _NewestData); });
                    if (lastIndex != -1)
                    {
                        List <PageAccessItem> newPerfAccessItems = currUserAccess.Value.GetRange(0, lastIndex + 1);
                        currUserAccess.Value.RemoveRange(0, lastIndex + 1);
                        oldData.m_UserAccesses.Add(currUserAccess.Key, newPerfAccessItems);
                    }
                }


                return(oldData);
            }
Exemplo n.º 2
0
 public void AddOldData(PerfStatisticData _OldData)
 {
     foreach (var currOldPerfPageItem in _OldData.m_PerfPageItems)
     {
         if (m_PerfPageItems.ContainsKey(currOldPerfPageItem.Key) == true)
         {
             m_PerfPageItems[currOldPerfPageItem.Key].m_PageAccessItems.InsertRange(0, currOldPerfPageItem.Value.m_PageAccessItems);
         }
         else
         {
             m_PerfPageItems.Add(currOldPerfPageItem.Key, currOldPerfPageItem.Value);
         }
     }
     foreach (var currOldUserAccess in _OldData.m_UserAccesses)
     {
         if (m_UserAccesses.ContainsKey(currOldUserAccess.Key) == true)
         {
             m_UserAccesses[currOldUserAccess.Key].InsertRange(0, currOldUserAccess.Value);
         }
         else
         {
             m_UserAccesses.Add(currOldUserAccess.Key, currOldUserAccess.Value);
         }
     }
 }
Exemplo n.º 3
0
        public static PerfStatisticData LoadStatistics(DateTime _EarliestDateTime)
        {
            PerfStatisticData retData          = null;
            string            statsNowFilename = Constants.RPPDbDir + "PerformanceStatistics/PerfStats_Now.dat";

            if (System.IO.File.Exists(statsNowFilename) == true)
            {
                VF_RealmPlayersDatabase.Utility.LoadSerialize(statsNowFilename, out retData);
                if (_EarliestDateTime < DateTime.UtcNow) //Add History
                {
                    string[] pathDirs = System.IO.Directory.GetDirectories(Constants.RPPDbDir + "PerformanceStatistics");
                    DateTime earliestStatisticsDate = DateTime.MaxValue;
                    foreach (var pathDir in pathDirs)
                    {
                        try
                        {
                            string[] yearMonth = pathDir.Split('\\', '/').Last().Split('_');
                            if (yearMonth.Count() == 2)
                            {
                                if (yearMonth[0].Length == 4 && yearMonth[1].Length == 2)
                                {
                                    int year  = int.Parse(yearMonth[0]);
                                    int month = int.Parse(yearMonth[1]);
                                    if (earliestStatisticsDate.Year < year || earliestStatisticsDate.Month < month)
                                    {
                                        earliestStatisticsDate = new DateTime(year, month, 1);
                                    }
                                }
                            }
                        }
                        catch (Exception)
                        { }
                    }
                    if (earliestStatisticsDate < DateTime.UtcNow)
                    {
                        for (DateTime currDate = DateTime.UtcNow.Date.AddDays(1); currDate >= earliestStatisticsDate; currDate = currDate.AddDays(-1))
                        {
                            string statsLoadDateFilename = Constants.RPPDbDir + "PerformanceStatistics/" + currDate.ToString("yyyy_MM") + "/PerfStats_" + currDate.ToString("dd") + ".dat";
                            if (System.IO.File.Exists(statsLoadDateFilename) == true)
                            {
                                PerfStatisticData oldData = null;
                                VF_RealmPlayersDatabase.Utility.LoadSerialize(statsNowFilename, out oldData);
                                retData.AddOldData(oldData);
                            }
                        }
                    }
                }
            }
            else
            {
                retData = new PerfStatisticData();
            }
            return(retData);
        }
Exemplo n.º 4
0
 public static void AssertInitialize()
 {
     if (sm_PerfStatsData == null)
     {
         lock (sm_PerfStatsDataLock)
         {
             if (sm_PerfStatsData == null)
             {
                 sm_PerfStatsData = LoadStatistics(DateTime.UtcNow.AddDays(1));
             }
         }
     }
 }
Exemplo n.º 5
0
        public static void SaveStatistics()
        {
            return;//DISABLED FOR NOW

            AssertInitialize();
            string statsNowFilename = Constants.RPPDbWriteDir + "PerformanceStatistics/PerfStats_Now.dat";

            VF_RealmPlayersDatabase.Utility.AssertFilePath(statsNowFilename);
            lock (sm_PerfStatsDataLock)
            {
                DateTime saveDateTime = sm_PerfStatsData.GetEarliestDataDateTime();
                try
                {
                    while (saveDateTime.AddDays(1) < DateTime.UtcNow)
                    {
                        if (sm_PerfStatsData.ExistsEarlierThan(saveDateTime.AddDays(1)) == true)
                        {
                            if (sm_PerfStatsData.ExistsEarlierThan(saveDateTime) == false)
                            {
                                bool removeOldData = (DateTime.UtcNow - saveDateTime.AddDays(1)).TotalDays > 7;
                                if (removeOldData == true)
                                {
                                    string statsSaveDateFilename = Constants.RPPDbDir + "PerformanceStatistics/" + saveDateTime.ToString("yyyy_MM") + "/PerfStats_" + saveDateTime.ToString("dd") + ".dat";
                                    VF_RealmPlayersDatabase.Utility.AssertFilePath(statsSaveDateFilename);
                                    PerfStatisticData oldPerfStatsData = sm_PerfStatsData.ExtractOldData(saveDateTime.AddDays(1));
                                    VF_RealmPlayersDatabase.Utility.SaveSerialize(statsSaveDateFilename, oldPerfStatsData);
                                }
                            }
                            else
                            {
                                Logger.ConsoleWriteLine("Error occurred in history data saving", ConsoleColor.Red);
                            }
                        }
                        saveDateTime = saveDateTime.AddMonths(1);
                    }
                    VF_RealmPlayersDatabase.Utility.SaveSerialize(statsNowFilename, sm_PerfStatsData);
                }
                catch (Exception ex)
                {
                    Logger.LogException(ex);
                }
            }
        }