public async Task <IActionResult> GetEvents([FromQuery] EventResourceParameters eventResourceParameters)
        {
            Func <Event, bool> filter = GetFilter(eventResourceParameters);

            IEnumerable <Event> events = await _batchReader.Read(filter);

            return(Ok(events));
        }
        public async Task <IActionResult> GetEventTypeMarketTypeFetchRoots(int dataProviderId)
        {
            DataProvider dataProvider = await _dataProviderReader.Read(dataProviderId);

            if (dataProvider == null)
            {
                return(NotFound($"Unable to find dataProvider with id {dataProviderId}"));
            }

            IEnumerable <EventTypeMarketType> eventTypeMarketTypes = await _eventTypeMarketTypeBatchReader.Read(etmt => etmt.DataProviderId == dataProviderId);

            return(Ok(eventTypeMarketTypes));
        }
        public async Task <IActionResult> GetCompetitionMarketTypeFetchRoots(int dataProviderId)
        {
            DataProvider dataProvider = await _dataProviderReader.Read(dataProviderId);

            if (dataProvider == null)
            {
                return(NotFound($"Unable to find dataProvider with id {dataProviderId}"));
            }

            IEnumerable <CompetitionMarketType> competitionMarketTypes = await _competitionMarketTypeBatchReader.Read(cmt => cmt.DataProviderId == dataProviderId);

            return(Ok(competitionMarketTypes));
        }
        public async Task DoWork()
        {
            IEnumerable <CompetitionMarketType> fetchRoots = await _competitionMarketTypesReader.Read(cmt => true);

            foreach (var competitionMarketType in fetchRoots ?? new CompetitionMarketType[0])
            {
                await _competitionMarketTypeWorker.DoWork(competitionMarketType);
            }
        }
예제 #5
0
        public void Write(IEnumerable <IRow> rows)
        {
            using (var cn = new SqlConnection(_cf.GetConnectionString())) {
                cn.Open();

                SqlDataAdapter adapter;
                var            dt = new DataTable();
                using (adapter = new SqlDataAdapter(_output.SqlSelectOutputSchema(_cf), cn)) {
                    adapter.Fill(dt);
                }

                var bulkCopy = new SqlBulkCopy(cn, _bulkCopyOptions, null)
                {
                    BatchSize            = _output.Entity.InsertSize,
                    BulkCopyTimeout      = 0,
                    DestinationTableName = "[" + _output.Entity.OutputTableName(_output.Process.Name) + "]"
                };

                for (var i = 0; i < _output.OutputFields.Length; i++)
                {
                    bulkCopy.ColumnMappings.Add(i, i);
                }

                foreach (var part in rows.Partition(_output.Entity.InsertSize))
                {
                    var batch = part.ToArray();

                    if (_output.Process.Mode == "init" || (_output.Entity.Insert && !_output.Entity.Update))
                    {
                        var inserts = new List <IRow>();
                        inserts.AddRange(batch);
                        Insert(bulkCopy, dt, inserts);
                    }
                    else
                    {
                        var inserts     = new List <IRow>();
                        var updates     = new List <IRow>();
                        var tflHashCode = _output.Entity.TflHashCode();
                        var tflDeleted  = _output.Entity.TflDeleted();
                        var matching    = _outputKeysReader.Read(batch);

                        for (int i = 0, batchLength = batch.Length; i < batchLength; i++)
                        {
                            var row = batch[i];
                            if (matching.Contains(i))
                            {
                                if (matching[i][tflDeleted].Equals(true) || !matching[i][tflHashCode].Equals(row[tflHashCode]))
                                {
                                    updates.Add(row);
                                }
                            }
                            else
                            {
                                inserts.Add(row);
                            }
                        }

                        Insert(bulkCopy, dt, inserts);

                        if (updates.Any())
                        {
                            _sqlUpdater.Write(updates);
                        }
                    }

                    _output.Increment(Convert.ToUInt32(batch.Length));
                }

                if (_output.Entity.Inserts > 0)
                {
                    _output.Info("{0} inserts into {1} {2}", _output.Entity.Inserts, _output.Connection.Name, _output.Entity.Alias);
                }

                if (_output.Entity.Updates > 0)
                {
                    _output.Info("{0} updates to {1}", _output.Entity.Updates, _output.Connection.Name);
                }
            }
        }
예제 #6
0
        public void Write(IEnumerable <IRow> rows)
        {
            var tflHashCode = _output.Entity.TflHashCode();
            var tflDeleted  = _output.Entity.TflDeleted();

            foreach (var part in rows.Partition(_output.Entity.InsertSize))
            {
                var inserts    = new List <IRow>(_output.Entity.InsertSize);
                var updates    = new List <IRow>(_output.Entity.InsertSize);
                var batchCount = (uint)0;

                if (_output.Process.Mode == "init" || (_output.Entity.Insert && !_output.Entity.Update))
                {
                    foreach (var row in part)
                    {
                        inserts.Add(row);
                        batchCount++;
                    }
                }
                else
                {
                    var newRows = part.ToArray();
                    var oldRows = _matcher.Read(newRows);
                    for (int i = 0, batchLength = newRows.Length; i < batchLength; i++)
                    {
                        var row = newRows[i];
                        if (oldRows.Contains(i))
                        {
                            if (oldRows[i][tflDeleted].Equals(true) || !oldRows[i][tflHashCode].Equals(row[tflHashCode]))
                            {
                                updates.Add(row);
                            }
                        }
                        else
                        {
                            inserts.Add(row);
                        }
                        batchCount++;
                    }
                }

                if (inserts.Any())
                {
                    _inserter.Write(inserts);
                }

                if (updates.Any())
                {
                    _updater.Write(updates);
                }

                _output.Increment(batchCount);
            }

            if (_output.Entity.Inserts > 0)
            {
                _output.Info("{0} inserts into {1}", _output.Entity.Inserts, _output.Connection.Name);
            }

            if (_output.Entity.Updates > 0)
            {
                _output.Info("{0} updates to {1}", _output.Entity.Updates, _output.Connection.Name);
            }
        }
        public async Task <IActionResult> GetDataProviders()
        {
            IEnumerable <DataProvider> dataProviders = await _batchDataProviderReader.Read(dp => true);

            return(Ok(dataProviders));
        }
        public async Task <IActionResult> GetCompetitions()
        {
            IEnumerable <Competition> competitions = await _batchReader.Read(et => true);

            return(Ok(competitions));
        }
예제 #9
0
        public async Task <IActionResult> GetSelections()
        {
            IEnumerable <Selection> selections = await _batchReader.Read(s => true);

            return(Ok(selections));
        }
예제 #10
0
        public void Write(IEnumerable <IRow> rows)
        {
            var table = _output.Entity.OutputTableName(_output.Process.Name);

            using (var cn = new SqlCeConnection(_cf.GetConnectionString())) {
                cn.Open();

                foreach (var part in rows.Partition(_output.Entity.InsertSize))
                {
                    var batch = part.ToArray();

                    if (_output.Process.Mode == "init")
                    {
                        var inserts = new List <IRow>();
                        inserts.AddRange(batch);
                        Insert(inserts, cn, table);
                    }
                    else
                    {
                        var inserts     = new List <IRow>();
                        var updates     = new List <IRow>();
                        var tflHashCode = _output.Entity.TflHashCode();
                        var tflDeleted  = _output.Entity.TflDeleted();

                        var matching = _outputKeysReader.Read(batch);

                        for (int i = 0, batchLength = batch.Length; i < batchLength; i++)
                        {
                            var row = batch[i];
                            if (matching.Contains(i))
                            {
                                if (matching[i][tflDeleted].Equals(true) || !matching[i][tflHashCode].Equals(row[tflHashCode]))
                                {
                                    updates.Add(row);
                                }
                            }
                            else
                            {
                                inserts.Add(row);
                            }
                        }


                        Insert(inserts, cn, table);

                        if (updates.Any())
                        {
                            _output.Entity.OutputTableName(_output.Process.Name);
                            _sqlUpdater.Write(updates);
                        }
                    }

                    _output.Increment(Convert.ToUInt32(batch.Length));
                }

                if (_output.Entity.Inserts > 0)
                {
                    _output.Info("{0} inserts into {1} {2}", _output.Entity.Inserts, _output.Connection.Name, _output.Entity.Alias);
                }

                if (_output.Entity.Updates > 0)
                {
                    _output.Info("{0} updates to {1}", _output.Entity.Updates, _output.Connection.Name);
                }
            }
        }
        public async Task <IActionResult> GetMarkets()
        {
            IEnumerable <Market> markets = await _batchReader.Read(e => true);

            return(Ok(markets));
        }
        private void InternalWrite(IEnumerable <IRow> rows)
        {
            using (var cn = new SqlConnection(_cf.GetConnectionString())) {
                cn.Open();

                var dt = new DataTable();

                try {
                    SqlDataAdapter adapter;
                    using (adapter = new SqlDataAdapter(_output.SqlSelectOutputSchema(_cf), cn)) {
                        adapter.Fill(dt);
                    }
                } catch (System.Data.Common.DbException e) {
                    _output.Error($"Error reading schema from {_output.Connection.Name}, {_output.Entity.Alias}.");
                    _output.Error(e.Message);
                    _output.Debug(() => e.StackTrace);
                    return;
                }

                using (var bulkCopy = new SqlBulkCopy(cn, _bulkCopyOptions, null)
                {
                    BatchSize = _output.Entity.InsertSize,
                    BulkCopyTimeout = 0,
                    DestinationTableName = "[" + _output.Entity.OutputTableName(_output.Process.Name) + "]"
                }) {
                    for (var i = 0; i < _output.OutputFields.Length; i++)
                    {
                        bulkCopy.ColumnMappings.Add(i, i);
                    }

                    if (_orderHint != null)
                    {
                        _orderHint.Set(bulkCopy, _output.OutputFields);
                    }

                    foreach (var part in rows.Partition(_output.Entity.InsertSize))
                    {
                        var batch = part.ToArray();

                        if (_output.Process.Mode == "init" || (_output.Entity.Insert && !_output.Entity.Update))
                        {
                            var inserts = new List <IRow>();
                            inserts.AddRange(batch);
                            Insert(bulkCopy, dt, inserts);
                        }
                        else
                        {
                            var inserts     = new List <IRow>();
                            var updates     = new List <IRow>();
                            var tflHashCode = _output.Entity.TflHashCode();
                            var tflDeleted  = _output.Entity.TflDeleted();
                            var matching    = _outputKeysReader.Read(batch);

                            for (int i = 0, batchLength = batch.Length; i < batchLength; i++)
                            {
                                var row = batch[i];
                                if (matching.Contains(i))
                                {
                                    if (matching[i][tflDeleted].Equals(true) || !matching[i][tflHashCode].Equals(row[tflHashCode]))
                                    {
                                        updates.Add(row);
                                    }
                                }
                                else
                                {
                                    inserts.Add(row);
                                }
                            }

                            Insert(bulkCopy, dt, inserts);

                            if (updates.Any())
                            {
                                _sqlUpdater.Write(updates);
                            }
                        }
                    }
                }

                if (_output.Entity.Inserts > 0)
                {
                    _output.Info("{0} inserts into {1} {2}", _output.Entity.Inserts, _output.Connection.Name, _output.Entity.Alias);
                }

                if (_output.Entity.Updates > 0)
                {
                    _output.Info("{0} updates to {1}", _output.Entity.Updates, _output.Connection.Name);
                }
            }
        }
        public async Task <IActionResult> GetEventTypes()
        {
            IEnumerable <EventType> eventTypes = await _batchReader.Read(et => true);

            return(Ok(eventTypes));
        }