Exemple #1
0
        /// <summary>
        /// Converts betonline hand history xml to iPoker xml
        /// </summary>
        /// <returns>The result of conversion</returns>
        public ConvertedResult Convert()
        {
            if (!IsInitialized)
            {
                return(null);
            }

            try
            {
                gameInfo = new GameInfo
                {
                    PokerSite = EnumPokerSites.BetOnline
                };

                sessionCode = BuildSessionCode();

                var handHistory = BuildHandHistory();

                var settings     = ServiceLocator.Current.GetInstance <ISettingsService>().GetSettings();
                var siteSettings = settings.SiteSettings.SitesModelList?.FirstOrDefault(x => x.PokerSite == gameInfo.PokerSite);

                if (siteSettings != null && !siteSettings.Enabled)
                {
                    return(null);
                }

                AdjustHandHistory(handHistory);

                var convertedXml = SerializationHelper.SerializeObject(handHistory);

                var result = new ConvertedResult
                {
                    ConvertedXml = convertedXml,
                    TableName    = isTournament ? string.Format("{0}, {1}", GetTableName(), GetTournamentName()) : handHistory.General.TableName,
                    TableId      = tableDetails.Attribute("id").Value,
                    HandNumber   = HandNumber,
                    Players      = playersOnTable.Values.ToList(),
                    GameInfo     = gameInfo
                };

                return(result);
            }
            catch (Exception e)
            {
                LogProvider.Log.Error(this, $"Data could not be parsed. [{Identifier}]", e);
                return(null);
            }
        }
Exemple #2
0
        /// <summary>
        /// Import results in DB
        /// </summary>
        /// <param name="convertedResult"></param>
        private void ImportResult(ConvertedResult convertedResult)
        {
            // send data to file importer
            var dbImporter = ServiceLocator.Current.GetInstance <IFileImporter>();
            var progress   = new DHProgress();

            IEnumerable <ParsingResult> parsingResult = null;

            LogProvider.Log.Info(this, $"Hand {convertedResult.HandNumber} processed. [{Identifier}]");

            try
            {
                parsingResult = dbImporter.Import(convertedResult.ConvertedXml, progress, convertedResult.GameInfo);
            }
            catch (DHLicenseNotSupportedException)
            {
                LogProvider.Log.Error(this, $"Hand {convertedResult.HandNumber} has not been imported. License issue. [{Identifier}]");

                var windowHwnd = new IntPtr(convertedResult.GameInfo.WindowHandle);

                if (windowHwnd != IntPtr.Zero && WinApi.IsWindow(windowHwnd))
                {
                    var preImportedArgs = new PreImportedDataEventArgs(convertedResult.GameInfo,
                                                                       CommonResourceManager.Instance.GetResourceString("Notifications_HudLayout_PreLoadingText_NoLicense"));

                    eventAggregator.GetEvent <PreImportedDataEvent>().Publish(preImportedArgs);
                }

                return;
            }
            catch (Exception e)
            {
                LogProvider.Log.Error(this, string.Format("Hand {0} has not been imported. [{1}]", convertedResult.HandNumber, Identifier), e);
            }

            if (parsingResult == null)
            {
                return;
            }

            foreach (var result in parsingResult)
            {
                if (result.HandHistory == null)
                {
                    continue;
                }

                if (result.IsDuplicate)
                {
                    LogProvider.Log.Info(this, string.Format("Hand {0} has not been imported. Duplicate. [{1}]", result.HandHistory.Gamenumber, Identifier));
                    continue;
                }

                if (!result.WasImported)
                {
                    LogProvider.Log.Info(this, string.Format("Hand {0} has not been imported. [{1}]", result.HandHistory.Gamenumber, Identifier));
                    continue;
                }

                LogProvider.Log.Info(this, string.Format("Hand {0} has been imported in {2}ms. [{1}]", result.HandHistory.Gamenumber, Identifier, result.Duration));

                if (result.Source.GameDescription.TableTypeDescriptors.Contains(TableTypeDescription.FastFold))
                {
                    var preImportedArgs = new PreImportedDataEventArgs(convertedResult.GameInfo,
                                                                       CommonResourceManager.Instance.GetResourceString("Notifications_HudLayout_PreLoadingText_NotSupportedFastFold"));

                    eventAggregator.GetEvent <PreImportedDataEvent>().Publish(preImportedArgs);

                    return;
                }

                var dataImportedArgs = new DataImportedEventArgs(result.Source.Players, convertedResult.GameInfo, result.Source.Hero, result.Source.HandId);
                eventAggregator.GetEvent <DataImportedEvent>().Publish(dataImportedArgs);
            }
        }