예제 #1
0
        protected virtual void InitializeDHImporterService()
        {
            if (dhImporterService != null)
            {
                return;
            }

            var endpointAddress = CommonResourceManager.Instance.GetResourceString("SystemSettings_ImporterPipeAddress");
            var pipeFactory     = new ChannelFactory <IDHImporterService>(new NetNamedPipeBinding(), new EndpointAddress(endpointAddress));

            dhImporterService = pipeFactory.CreateChannel();
        }
예제 #2
0
파일: Utils.cs 프로젝트: Michael-Z/DriveHud
        public static IDHImporterService GetImporterService(bool reCreate = false)
        {
            if (dhImporterService != null && !reCreate)
            {
                return(dhImporterService);
            }

            lock (lockObject)
            {
                if (dhImporterService != null)
                {
                    return(dhImporterService);
                }

                var endpointAddress = "net.pipe://localhost/DriveHUD/Importer/ImportHandHistory";
                var pipeFactory     = new ChannelFactory <IDHImporterService>(new NetNamedPipeBinding(), new EndpointAddress(endpointAddress));

                dhImporterService = pipeFactory.CreateChannel();

                return(dhImporterService);
            }
        }
예제 #3
0
        /// <summary>
        /// Exports captured hand history to the supported DB
        /// </summary>
        protected virtual void ExportHandHistory(List <HandHistoryData> handHistories)
        {
            InitializeDHImporterService();

            // merge hands
            var playerWithHoleCards = handHistories
                                      .SelectMany(x => x.HandHistory.Players)
                                      .Where(x => x.hasHoleCards)
                                      .DistinctBy(x => x.SeatNumber)
                                      .ToDictionary(x => x.SeatNumber, x => x.HoleCards);

            foreach (var handHistoryData in handHistories)
            {
                handHistoryData.HandHistory.Players.ForEach(player =>
                {
                    if (!player.hasHoleCards && playerWithHoleCards.ContainsKey(player.SeatNumber))
                    {
                        player.HoleCards = playerWithHoleCards[player.SeatNumber];
                    }
                });

                handHistoryData.HandHistory.Players = GetPlayerList(handHistoryData.HandHistory);

                var handHistoryText = SerializationHelper.SerializeObject(handHistoryData.HandHistory);

#if DEBUG
                if (!Directory.Exists("Hands"))
                {
                    Directory.CreateDirectory("Hands");
                }

                File.WriteAllText($"Hands\\{HandHistoryFilePrefix}_hand_exported_{handHistoryData.Uuid}_{handHistoryData.HandHistory.HandId}.xml", handHistoryText);
#endif

                try
                {
                    var handHistoryDto = new HandHistoryDto
                    {
                        PokerSite    = EnumPokerSites.PPPoker,
                        WindowHandle = handHistoryData.WindowHandle.ToInt32(),
                        HandText     = handHistoryText
                    };

                    dhImporterService.ImportHandHistory(handHistoryDto);
                    LogProvider.Log.Info($"Hand #{handHistoryData.HandHistory.HandId} has been sent. [{handHistoryData.HandHistory.TableName}]");
                }
                catch (EndpointNotFoundException)
                {
                    LogProvider.Log.Error(this, $"DriveHUD isn't running. Hand #{handHistoryData.HandHistory.HandId} hasn't been sent. [{handHistoryData.HandHistory.TableName}]");
                    dhImporterService = null;
                }
                catch (Exception e)
                {
                    if (IsAdvancedLogEnabled)
                    {
                        LogProvider.Log.Error(this, $"Hand #{handHistoryData.HandHistory.HandId} hasn't been sent. [{handHistoryData.HandHistory.TableName}]", e);
                    }
                    else
                    {
                        LogProvider.Log.Error(this, $"Hand #{handHistoryData.HandHistory.HandId} hasn't been sent. [{handHistoryData.HandHistory.TableName}]");
                    }

                    dhImporterService = null;
                }
            }
        }