public void SyncSSEDayQuotationFromWangYI() { DatabaseContextFactory factory = new DatabaseContextFactory(); DatabaseContext dbContext = factory.CreateDatabaseContext(); SecurityDayQuotationRepository securityDayQuotationRepository = SecurityDayQuotationRepositoryFactory.GetInstance().Create(dbContext); SecurityTaskRepository securityTaskRepository = SecurityTaskRepositoryFactory.GetInstance().Create(dbContext); SecurityDayQuotationFromWangYIRepository securityDayQuotationFromWangYIRepository = new SecurityDayQuotationFromWangYIRepository(); SecurityTaskEngine securityTaskEngine = new SecurityTaskEngine(); SecurityTaskDomain securityTask = securityTaskEngine.Pop(); List <SecurityDayQuotationDomain> lst = new List <SecurityDayQuotationDomain>(); SecurityTaskDomain nextSecurityTask; while (!securityTask.IsEmpty()) { CancelTokenSingleton.GetInstance().ThrowIfCancellationRequested(); lst = securityDayQuotationFromWangYIRepository.GetSSEDayQuotationFromWangYi(securityTask.SecurityCode, securityTask.BeginDate, securityTask.EndDate); dbContext.BeginTransaction(); foreach (SecurityDayQuotationDomain securityDayQuotation in lst) { securityDayQuotationRepository.InsertIntoDB(securityDayQuotation); } securityTask.IsFinished = true; securityTaskRepository.UpdateTaskStatus(securityTask); nextSecurityTask = securityTask.BuildNextTask(); securityTaskRepository.InsertIntoDB(nextSecurityTask); dbContext.CommitTransaction(); securityTask = securityTaskEngine.Pop(); } }
public void SyncSecuritiesFromSSE() { DatabaseContextFactory factory = new DatabaseContextFactory(); DatabaseContext dbContext = factory.CreateDatabaseContext(); SecurityRepository securityRepo = SecurityRepositoryFactory.GetInstance().Create(dbContext); SecurityTaskRepository securityTaskRepository = SecurityTaskRepositoryFactory.GetInstance().Create(dbContext); SecurityFromSSERepository securityFromSSERepository = new SecurityFromSSERepository(); #region 新增证券 List <SecurityDomain> securitiesFromSSE = securityFromSSERepository.GetSecuritiesFromSSE(); List <SecurityDomain> securitiesFromDB = securityRepo.GetList(); List <SecurityDomain> securities = new List <SecurityDomain>(); Dictionary <string, string> dicStockDB = new Dictionary <string, string>(); foreach (SecurityDomain security in securitiesFromDB) { dicStockDB.Add(security.SecurityCode, ""); } for (int i = 0; i < securitiesFromSSE.Count; i++) { if (!dicStockDB.ContainsKey(securitiesFromSSE[i].SecurityCode)) { securities.Add(securitiesFromSSE[i]); } } #endregion #region 保持证券,证券任务到数据库 dbContext.BeginTransaction(); SecurityTaskDomain securityTask; foreach (SecurityDomain security in securities) { securityRepo.InsertIntoDB(security); securityTask = security.BuildStartTask(); securityTaskRepository.InsertIntoDB(securityTask); } dbContext.CommitTransaction(); #endregion }