Example #1
0
            public IEnumerable <ParsingResult> Import(string text, IDHProgress progress, GameInfo gameInfo)
            {
                lock (locker)
                {
                    var handXml = XDocument.Parse(text);

                    ImportedHands.Add(new ImportedHand
                    {
                        HandXml  = handXml,
                        GameInfo = gameInfo
                    });

                    if (Xml == null)
                    {
                        Xml = handXml;
                        return(null);
                    }

                    var sessionNode = Xml.Descendants("session").FirstOrDefault();
                    var gameNode    = handXml.Descendants("game").FirstOrDefault();

                    sessionNode.Add(gameNode);

                    return(null);
                }
            }
Example #2
0
 public void Import(FileInfo file, IDHProgress progress)
 {
 }
Example #3
0
 public void Import(FileInfo[] files, IDHProgress progress)
 {
 }
Example #4
0
 public void Import(DirectoryInfo directory, IDHProgress progress)
 {
 }
Example #5
0
        public async Task ExportHands(string folder, IEnumerable <HandExportInfo> exportInfo, IDHProgress progress, bool useCommonExporter)
        {
            await Task.Run(() =>
            {
                try
                {
                    var handsGroupedBySite = exportInfo
                                             .GroupBy(x => x.Site)
                                             .ToDictionary(x => x.Key, x => x.Select(p => p.HandNumber).ToArray());

                    var exportedHands      = 0;
                    var totalExportedHands = exportInfo.Count();

                    LogProvider.Log.Info(this, $"Starting export of {totalExportedHands} hands.");

                    progress.Report(new LocalizableString("Progress_ExportingHands", exportedHands, totalExportedHands), 0);

                    using (var session = ModelEntities.OpenStatelessSession())
                    {
                        foreach (var siteHands in handsGroupedBySite)
                        {
                            LogProvider.Log.Info(this, $"Exporting {siteHands.Value.Length} hands of {siteHands.Key} site.");

                            var serviceName = useCommonExporter ?
                                              HandExportPreparingServiceProvider.Common :
                                              HandExportPreparingServiceProvider.GetServiceName(siteHands.Key);

                            var preparingService = ServiceLocator.Current.GetInstance <IHandExportPreparingService>(serviceName);

                            var queriesCount = (int)Math.Ceiling((double)siteHands.Value.Length / HandPerQuery);

                            for (var i = 0; i < queriesCount; i++)
                            {
                                if (progress.CancellationToken.IsCancellationRequested)
                                {
                                    LogProvider.Log.Info(this, "Exporting cancelled by user.");
                                    LogProvider.Log.Info(this, $"Successfully exported {exportedHands} hands.");
                                    return;
                                }

                                var handsToQuery = siteHands.Value.Skip(i *HandPerQuery).Take(HandPerQuery).ToArray();

                                var restriction = Restrictions.Disjunction();

                                restriction.Add(Restrictions.Conjunction()
                                                .Add(Restrictions.On <Handhistory>(x => x.Gamenumber).IsIn(handsToQuery))
                                                .Add(Restrictions.Where <Handhistory>(x => x.PokersiteId == (short)siteHands.Key)));

                                var hands = session.QueryOver <Handhistory>().Where(restriction)
                                            .Select(x => x.HandhistoryVal)
                                            .List <string>();

                                preparingService.WriteHandsToFile(folder, hands, siteHands.Key);

                                exportedHands += hands.Count;

                                progress.Report(new LocalizableString("Progress_ExportingHands", exportedHands, exportInfo.Count()), 0);
                            }
                        }
                    }

                    LogProvider.Log.Info(this, $"Successfully exported {exportedHands} hands.");
                }
                catch (Exception e)
                {
                    throw new DHInternalException(new NonLocalizableString("Export service failed to export hands."), e);
                }
            });
        }
 /// <summary>
 /// Initializes progress to report progress
 /// </summary>
 public void InitializeProgress(IDHProgress progress)
 {
     this.progress = progress;
 }