Exemplo n.º 1
0
        private void UpdateParameter(String name, String value)
        {
            using (FinanceDBEntities context = new FinanceDBEntities())
            {
                using (TransactionScope transaction = new TransactionScope(TransactionScopeOption.Required))
                {
                    Parameters[] parameters = (from ps in context.Parameters
                                               where ps.Name == name
                                               select ps).Take <Parameters>(1).ToArray();

                    if (null != parameters && parameters.Length > 0)
                    {
                        parameters[0].Value = value;
                    }
                    else
                    {
                        Parameters newItem = Parameters.CreateParameters(name, value);

                        context.Parameters.AddObject(newItem);
                    }

                    context.SaveChanges();

                    transaction.Complete();
                }
            }
        }
Exemplo n.º 2
0
        public void AddFileToProcess(String source, Byte[] bytes, FileType fileType)
        {
            using (FinanceDBEntities context = new FinanceDBEntities())
            {
                using (TransactionScope transaction = new TransactionScope())
                {
                    FilesToProcess newItem = FilesToProcess.CreateFilesToProcess(0, source, bytes, DateTime.Now, (Byte)fileType);

                    context.FilesToProcess.AddObject(newItem);

                    context.SaveChanges();

                    transaction.Complete();
                }
            }
        }
Exemplo n.º 3
0
        public ElementCorrelation UpdateElementCorrelation(String tickerA, String tickerB, CorrelationPeriodType correlationPeriodType, Decimal value)
        {
            Byte correlationPeriodTypeValue = (Byte)correlationPeriodType;

            using (FinanceDBEntities context = new FinanceDBEntities())
            {
                using (TransactionScope transaction = new TransactionScope())
                {
                    ElementCorrelation item = FirstElementOrNull <ElementCorrelation>((from er in context.ElementCorrelation
                                                                                       where
                                                                                       er.PeriodType == correlationPeriodTypeValue &&
                                                                                       (er.TickerA == tickerA && er.TickerB == tickerB ||
                                                                                        er.TickerA == tickerB && er.TickerB == tickerA)
                                                                                       select er).ToArray <ElementCorrelation>());

                    if (null != item)
                    {
                        item.Upd         = DateTime.Now;
                        item.Correlation = value;

                        LoggerFactory.AppLogger.Debug("[ItemsDataProvider.UpdateElementCorrelation] Updating existing item " + item.TickerA + " " + item.TickerB + " " + correlationPeriodType.ToString());
                    }
                    else
                    {
                        item             = context.ElementCorrelation.CreateObject();
                        item.TickerB     = tickerB;
                        item.TickerA     = tickerA;
                        item.PeriodType  = correlationPeriodTypeValue;
                        item.Upd         = DateTime.Now;
                        item.Correlation = value;

                        LoggerFactory.AppLogger.Debug("[ItemsDataProvider.UpdateElementCorrelation] Adding new item " + item.TickerA + " " + item.TickerB + " " + correlationPeriodType.ToString());

                        context.ElementCorrelation.AddObject(item);
                    }

                    context.SaveChanges();

                    transaction.Complete();

                    return(item);
                }
            }
        }
Exemplo n.º 4
0
        public void RemoveProcessedFile(FilesToProcess file)
        {
            using (FinanceDBEntities context = new FinanceDBEntities())
            {
                using (TransactionScope transaction = new TransactionScope())
                {
                    FilesToProcess toRemove = FirstElementOrNull <FilesToProcess>((from fs in context.FilesToProcess where fs.RecId == file.RecId select fs).Take <FilesToProcess>(1).ToArray <FilesToProcess>());

                    if (null != toRemove)
                    {
                        context.FilesToProcess.DeleteObject(toRemove);

                        context.SaveChanges();

                        transaction.Complete();
                    }
                }
            }
        }
Exemplo n.º 5
0
        public ElementMovementDistribution UpdateElementDistribution(String ticker, Int32 rangeId, Byte[] result)
        {
            using (FinanceDBEntities context = new FinanceDBEntities())
            {
                using (TransactionScope transaction = new TransactionScope())
                {
                    ElementMovementDistribution item = FirstElementOrNull <ElementMovementDistribution>((from er in context.ElementMovementDistributions
                                                                                                         where
                                                                                                         er.RangeId == rangeId &&
                                                                                                         er.Ticker == ticker
                                                                                                         select er).ToArray <ElementMovementDistribution>());

                    if (null != item)
                    {
                        item.Upd = DateTime.Now;
                        item.DistributionData = result;

                        LoggerFactory.AppLogger.Debug("[ItemsDataProvider.UpdateElementCorrelation] Updating existing item " + item.Ticker + " " + item.RangeId);
                    }
                    else
                    {
                        item                  = context.ElementMovementDistributions.CreateObject();
                        item.Ticker           = ticker;
                        item.RangeId          = rangeId;
                        item.Upd              = DateTime.Now;
                        item.DistributionData = result;

                        LoggerFactory.AppLogger.Debug("[ItemsDataProvider.UpdateElementCorrelation] Adding new item " + item.Ticker + " " + item.RangeId);

                        context.ElementMovementDistributions.AddObject(item);
                    }

                    context.SaveChanges();

                    transaction.Complete();

                    return(item);
                }
            }
        }
Exemplo n.º 6
0
        public void AddDailyData(String ticker, DailyData[] records, FileType sourceFileType)
        {
            LoggerFactory.AppLogger.Info("[ItemsDataProvider.AddDailyData] Adding data for item item " + ticker);

            using (FinanceDBEntities context = new FinanceDBEntities())
            {
                using (TransactionScope transaction = new TransactionScope())
                {
                    Element element = FirstElementOrNull <Element>((from es in context.Elements where es.Symbol == ticker select es).Take <Element>(1).ToArray <Element>());

                    if (null == element)
                    {
                        element = new Element();

                        element.Symbol = ticker;
                        element.Type   = 0;
                        element.Domain = 0;
                        element.Name   = ticker;

                        context.Elements.AddObject(element);

                        LoggerFactory.AppLogger.Info("[ItemsDataProvider.AddDailyData] Adding new item " + element.Symbol);
                    }

                    DailyData lastStoredRecord = FirstElementOrNull <DailyData>((from dd in context.DailyDatas where dd.Ticker == ticker orderby dd.Day descending select dd).Take <DailyData>(1).ToArray <DailyData>());

                    //////////////////////////////////////////////////////////////////////////////////////////////////
                    /// check if records overlap
                    ///

                    if (sourceFileType != FileType.AllData)
                    {
                        if (null == lastStoredRecord)
                        {
                            LoggerFactory.AppLogger.Warn("[ItemsDataProvider.AddDailyData] Can not import daily data as there is no ALL data for the item " + ticker);

                            return;
                        }

                        if (!records.Any <DailyData>(x => x.Day <= lastStoredRecord.Day))
                        {
                            LoggerFactory.AppLogger.Warn("[ItemsDataProvider.AddDailyData] Can not import daily data asrecords are not continuous with already stored ALL data for the item " + ticker);

                            return;
                        }
                    }

                    if (null != lastStoredRecord)
                    {
                        LoggerFactory.AppLogger.Trace("[ItemsDataProvider.AddDailyData] Skipping records older then " + ticker + " " + lastStoredRecord.Day);

                        List <DailyData> tempList = new List <DailyData>(records);

                        records = tempList.FindAll(x => x.Day > lastStoredRecord.Day).ToArray();
                    }

                    if (records.Length <= 0)
                    {
                        LoggerFactory.AppLogger.Info("[ItemsDataProvider.AddDailyData] No records to add " + ticker);

                        return;
                    }

                    for (Int32 q = 0; q < records.Length; q++)
                    {
                        DailyData record = records[q];

                        context.DailyDatas.AddObject(records[q]);
                    }

                    context.SaveChanges();

                    transaction.Complete();
                }
            }
        }