Ejemplo n.º 1
0
        public StockQuoteManager(IServiceProvider provider, List <StockServiceSettings> settings, string logPath)
        {
            this._logPath = logPath;
            EnsurePathExists(logPath);
            this.Settings         = settings;
            this.provider         = provider;
            this.myMoney          = (MyMoney)provider.GetService(typeof(MyMoney));
            this.status           = (IStatusService)provider.GetService(typeof(IStatusService));
            this.myMoney.Changed += new EventHandler <ChangeEventArgs>(OnMoneyChanged);

            // assume we have fetched all securities.
            // call UpdateQuotes to refetch them all again, otherwise this
            // class will track changes and automatically fetch any new securities that it finds.
            foreach (Security s in myMoney.Securities.AllSecurities)
            {
                if (!string.IsNullOrEmpty(s.Symbol))
                {
                    lock (fetched)
                    {
                        fetched.Add(s.Symbol);
                    }
                }
            }
            _downloadLog = DownloadLog.Load(logPath);
        }
Ejemplo n.º 2
0
        public static DownloadLog Load(string logFolder)
        {
            DownloadLog log      = new DownloadLog();
            var         filename = System.IO.Path.Combine(logFolder, "DownloadLog.xml");

            if (System.IO.File.Exists(filename))
            {
#if PerformanceBlocks
                using (PerformanceBlock.Create(ComponentId.Money, CategoryId.View, MeasurementId.LoadStockDownloadLog))
                {
#endif
                try
                {
                    XmlSerializer s = new XmlSerializer(typeof(DownloadLog));
                    using (XmlReader r = XmlReader.Create(filename))
                    {
                        log = (DownloadLog)s.Deserialize(r);
                    }
                }
                catch (Exception)
                {
                    // got corrupted? no problem, just start over.
                    log = new DownloadLog();
                }
                log._logFolder = logFolder;

                // ensure unique list.
                foreach (var info in log.Downloaded.ToArray())
                {
                    log._downloaded[info.Symbol] = info;
                }

                if (log._downloaded.Count != log.Downloaded.Count)
                {
                    log.Downloaded.Clear();
                    foreach (var info in log._downloaded.Values)
                    {
                        log.Downloaded.Add(info);
                    }
                }
#if PerformanceBlocks
            }
#endif
            }
            return(log);
        }
Ejemplo n.º 3
0
 public HistoryDownloader(IStockQuoteService service, DownloadLog log)
 {
     _service     = service;
     _downloadLog = log;
 }