Ejemplo n.º 1
0
        public void TestInsertQuote()
        {
            //вставим несколько значений за разные даты
            var tempConnection = DataBaseLink.Fabricate.CreateConnection(_connection, ConnectionType.Npgsql);

            DataBaseLink.DbLink dbLink = new DbLink(tempConnection);
            //создать финансовый инструмент
            fin_instrument fin_instrument = new fin_instrument("roman", 13, "bushuev");

            if (FinInstrument.FindId(dbLink, fin_instrument.ident) == null)
            {
                FinInstrument.Insert(dbLink, fin_instrument);
            }

            var result = FinInstrument.FindId(dbLink, fin_instrument.ident);

            ffd ffd = new ffd()
            {
                ds_id  = 17,
                fi_id  = result.fi_id,
                fif_id = 3
            };

            if (FFD.Find(dbLink, result.fi_id, ffd.ds_id, ffd.fif_id) == null)
            {
                FFD.Insert(dbLink, ffd);
            }
            var ffdResult = FFD.Find(dbLink, result.fi_id, ffd.ds_id, ffd.fif_id);

            fisd_dq fisd_dq = new fisd_dq()
            {
                dat     = DateTime.Today.AddDays(-1),
                fisd_id = ffdResult.fisd_id,
                val     = 10.0m
            };

            if (FisdDq.FindId(dbLink, fisd_dq.fisd_id, fisd_dq.dat) == null)
            {
                FisdDq.Insert(dbLink, fisd_dq);
            }

            fisd_dq = new fisd_dq()
            {
                dat     = DateTime.Today,
                fisd_id = ffdResult.fisd_id,
                val     = 11.0m
            };

            if (FisdDq.FindId(dbLink, fisd_dq.fisd_id, fisd_dq.dat) == null)
            {
                FisdDq.Insert(dbLink, fisd_dq);
            }
        }
Ejemplo n.º 2
0
        public void TestUpdateQuote()
        {
            var tempConnection = DataBaseLink.Fabricate.CreateConnection(_connection, ConnectionType.Npgsql);

            DataBaseLink.DbLink dbLink = new DbLink(tempConnection);

            fisd_dq fisd_dq = new fisd_dq()
            {
                fisd_id = 20281,
                dat     = new DateTime(2018, 05, 16),
                val     = 77.0m
            };

            if (FisdDq.FindId(dbLink, fisd_dq.fisd_id, fisd_dq.dat) != null)
            {
                FisdDq.Update(dbLink, fisd_dq);
            }
        }
        private void Save(Dictionary <PortfolioPosition, TimeSeries> storage)
        {
            foreach (var x in storage)
            {
                var transaction = _dbLink.GetConnection().BeginTransaction(IsolationLevel.ReadCommitted);
                try
                {
                    // найдем тип финансового инструмента
                    var    finIdent     = x.Key.Ident;
                    var    finType      = x.Key.FinType;
                    string finTypeIdent = _mapping.GetAI(finType);

                    #region финансовый инструмент
                    fin_instrument finInstrument = new fin_instrument()
                    {
                        ident = finIdent,
                        title = finIdent,
                        ft_id = int.Parse(finTypeIdent)
                    };

                    if (FinInstrument.FindId(_dbLink, finInstrument.ident) == null)
                    {
                        FinInstrument.Insert(_dbLink, finInstrument);
                    }

                    finInstrument = FinInstrument.FindId(_dbLink, finInstrument.ident);
                    #endregion

                    #region Data_source
                    data_source dataSource = new data_source()
                    {
                        ident = _providerParams[SCALAR].ToString(),
                    };

                    dataSource = DataSource.FindId(_dbLink, dataSource.ident);
                    #endregion

                    #region fisd_id
                    ffd ffd = new ffd()
                    {
                        ds_id  = dataSource.ds_id,
                        fi_id  = finInstrument.fi_id,
                        fif_id = int.Parse(_mapping.GetAI(x.Value.Attribute))
                    };

                    if (FFD.Find(_dbLink, ffd.fi_id, ffd.ds_id, ffd.fif_id) == null)
                    {
                        FFD.Insert(_dbLink, ffd);
                    }
                    ffd = FFD.Find(_dbLink, ffd.fi_id, ffd.ds_id, ffd.fif_id);
                    #endregion

                    #region TimeSeries
                    foreach (var z in x.Value.Series)
                    {
                        fisd_dq fisd_dq = new fisd_dq()
                        {
                            dat     = z.Key,
                            val     = z.Value,
                            fisd_id = ffd.fisd_id
                        };

                        if (FisdDq.FindId(_dbLink, fisd_dq.fisd_id, fisd_dq.dat) == null)
                        {
                            FisdDq.Insert(_dbLink, fisd_dq);
                        }
                        else
                        {
                            FisdDq.Update(_dbLink, fisd_dq);
                        }
                    }
                    #endregion

                    transaction.Commit();
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                }
            }
        }