Esempio n. 1
0
        private void SpecialSpanExpansion(Row[] rows, TableColumnMappings colMappings)
        {
            var rowsToInsert = new List <Row>();
            var spanIds      = new List <long>();

            foreach (var r in rows)
            {
                long spanId = (long)r["federated_span_id"];
                spanIds.Add(spanId);

                string wks = ((string)r["weeks"]).ToUpper();

                int timetableId = (int)r["src_timetable_id"];
                var weekDates   = _caches.WeekDatesCache.Get(timetableId);

                int weekNum    = 0;
                int occurrence = 0;

                foreach (var ch in wks)
                {
                    if (ch == 'Y')
                    {
                        ++occurrence;

                        var dt = weekDates.StartingDates[weekNum];
                        for (int day = 0; day < 7; ++day)
                        {
                            Row vr = r.Clone();
                            vr["span_date"]            = dt.AddDays(day);
                            vr["span_week_number"]     = weekNum + 1;
                            vr["span_week_occurrence"] = occurrence;

                            rowsToInsert.Add(vr);
                        }
                    }

                    ++weekNum;
                }
            }

            if (spanIds.Any())
            {
                // first remove all instances of span...
                _targetTable.DeleteSpanInstances(_connectionString, _timeoutSecs, spanIds);

                // then insert afresh...
                _targetTable.Upsert(_connectionString, _timeoutSecs, rowsToInsert, colMappings, _caches, _configuration);
            }
        }