Пример #1
0
        private void addData(long timestamp, string u, bool isClick)
        {
            DatabaseHandler da = new DatabaseHandler();

            da.Add(new DateTime(1970, 1, 1).AddMilliseconds(timestamp), u, isClick);
        }
        private void parsingWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            Dictionary <HandHistoryParserFactory, IEnumerable <FileInfo> > factories =
                new Dictionary <HandHistoryParserFactory, IEnumerable <FileInfo> >();
            int totalFiles = 0;

            foreach (string siteDetailsString in Settings.Default.Sites)
            {
                SiteDetails details = new SiteDetails(siteDetailsString);
                HandHistoryParserFactory parserFactory = HandHistoryParserFactory.GetHandHistoryParserFactory(details);
                DirectoryInfo            info          = new DirectoryInfo(details.HandsLocation);
                IEnumerable <FileInfo>   files         = info.GetFiles().Where(fi => parserFactory.IsHandHistoryFile(fi) &&
                                                                               fi.LastWriteTime > lastUpdate);
                totalFiles += files.Count();
                factories.Add(parserFactory, files);
            }

            handsFound       = 0;
            tournamentsFound = 0;

            float fileProgressInc = 100.0f / totalFiles;
            int   filesProcessed  = 0;

            foreach (HandHistoryParserFactory factory in factories.Keys)
            {
                factory.HandHistoryParser.AmountsAsBigBlindMultiples = true;
                foreach (FileInfo file in factories[factory])
                {
                    int         byteCount  = 0;
                    HandHistory parsedHand = null;

                    TournamentSummary tournamentSummary = null;

                    if (factory.HasTournamentSummaryParser() && File.Exists(factory.GetTournamentFile(file.FullName)))
                    {
                        tournamentSummary = factory.ParseTournamentSummary(file.FullName);
                        DatabaseHandler.Add(tournamentSummary);
                        ++tournamentsFound;
                    }
                    IEnumerable <HandHistory> hands = factory.ParseHandHistories(file.FullName);
                    float totalHands = (float)hands.Count();
                    int   fileHands  = 0;

                    foreach (HandHistory hand in hands)
                    {
                        if (parsingWorker.CancellationPending)
                        {
                            break;
                        }

                        try
                        {
                            parsedHand = hand;
                            string tournamentId = parsedHand.GameDescription.TournamentId;

                            if (tournamentSummary != null)
                            {
                                parsedHand.GameDescription.TournamentSummary = tournamentSummary;
                            }
                            DatabaseHandler.Add(parsedHand);
                            byteCount += parsedHand.FullHandHistoryText.Length;
                            ++handsFound;
                            ++fileHands;
                            float progress = (int)((filesProcessed + fileHands / totalHands) * fileProgressInc);
                            parsingWorker.ReportProgress((int)progress);
                        }
                        catch (MongoWriteException ex)
                        {
                            Console.Write("Failed");
                        }
                        catch (HandParseException ex)
                        {
                            Console.Write("Parsing failed for: " + string.Concat(ex.HandText) + "\n");
                        }
                    }
                    if (parsingWorker.CancellationPending)
                    {
                        break;
                    }

                    ++filesProcessed;
                    parsingWorker.ReportProgress((int)(filesProcessed * fileProgressInc));
                }
            }

            parsingWorker.ReportProgress(100);
        }