Beispiel #1
0
        static void Main(string[] args)
        {
            var files = (Directory.EnumerateFiles(LogDirectory) as IEnumerable <string>);//.Take(20);

            LoginCounter metric1 = new LoginCounter();

            //LoginTimeAccumulator metric2 = new LoginTimeAccumulator(offset: TimeSpan.Zero);
            //LoginTimePerDay metric3 = new LoginTimePerDay(offset: new TimeSpan(-4, 0, 0));

            //var metrics = new IMetric[] { metric1, metric2, metric3 };

            foreach (var file in files)
            {
                //using (FileReader reader = new FileReader(file, metrics))
                //{
                //    reader.ReadLines();
                //}
            }

            // var ordered = metric2.UserTimeSpans.OrderByDescending(kvp => kvp.Value.TotalMilliseconds).ToArray();

            //TimeSpan offset = new TimeSpan(0, 0, 0);
            //LoginTimePerDay metric = new LoginTimePerDay(offset);

            //string loginString = "01:30:00+0200 -!- Squirrel623 [[email protected]] has joined #berrytube";
            //string logoutString = "01:00:00+0100 -!- Squirrel623 [[email protected]] has left #berrytube";

            //DateTimeOffset baseDt = new DateTimeOffset(2017, 11, 5, 0, 0, 0, TimeSpan.Zero);

            //var firstMessage = TimestampMessage.Create(baseDt, loginString);
            //var lastMessage = TimestampMessage.Create(baseDt, logoutString);

            //metric.HandleLogMessage(firstMessage);
            //metric.HandleLogMessage(lastMessage);

            Console.ReadKey();
        }
Beispiel #2
0
        public StatsProvider()
        {
            if (string.IsNullOrEmpty(LogDirectory))
            {
                LogDirectory = @"C:\Users\Brady\Documents\BTLogs2";
            }

            logFiles = Directory.EnumerateFiles(LogDirectory) as IEnumerable <string>;

            usernameMetric       = new LoginUsernames();
            loginCountMetric     = new LoginCounter();
            loginTimeMetric      = new LoginTimeAccumulator();
            messageCountMetric   = new TotalMessages();
            emoteCountMetric     = new UserEmotes();
            firstLastLoginMetric = new FirstLastLogin();

            TzdbDateTimeZoneSource tzSource = TzdbDateTimeZoneSource.Default;

            dailyLoginTimeMetrics = new List <LoginTimePerDay>()
            {
                new LoginTimePerDay(timezone: tzSource.ForId("US/Pacific")),
                new LoginTimePerDay(timezone: tzSource.ForId("US/Mountain")),
                new LoginTimePerDay(timezone: tzSource.ForId("US/Central")),
                new LoginTimePerDay(timezone: tzSource.ForId("US/Eastern")),
                new LoginTimePerDay(timezone: tzSource.ForId("Europe/London")),
                new LoginTimePerDay(timezone: tzSource.ForId("Europe/Berlin")),
                new LoginTimePerDay(timezone: tzSource.ForId("Europe/Athens")),
                new LoginTimePerDay(timezone: tzSource.ForId("Asia/Hong_Kong")),
                new LoginTimePerDay(timezone: tzSource.ForId("Asia/Tokyo")),
            };

            metrics = new List <IMetric>()
            {
                usernameMetric,
                loginCountMetric,
                loginTimeMetric,
                messageCountMetric,
                emoteCountMetric,
                firstLastLoginMetric
            };
            metrics.AddRange(dailyLoginTimeMetrics);

            CancellationTokenSource cts = new CancellationTokenSource();

            InitializeTask = Task.Factory.StartNew(() =>
            {
                return(this.CheckForNewFiles(cts.Token));
            })
                             .Unwrap()
                             .ContinueWith(task =>
            {
                foreach (var file in Directory.EnumerateFiles(LogDirectory))
                {
                    using (FileReader reader = new FileReader(file, metrics))
                    {
                        reader.ReadLines();
                    }
                    Console.WriteLine($"Done processing {file}");
                }
            });
        }