예제 #1
0
        private async Task <ImportedEvent> GetAudioRecordingId(ImportedEvent importedEvent)
        {
            if (!importedEvent.AudioRecordingId.HasValue)
            {
                long audioEventId = importedEvent.AudioEventId.Value;
                Log.Debug($"Requesting metadata for audio event {audioEventId}");
                AudioEvent audioEvent;
                try
                {
                    audioEvent = await this.acousticEventService.GetAudioEvent(audioEventId);
                }
                catch (Service.HttpResponseException exception)
                {
                    if (Debugger.IsAttached)
                    {
                        Debugger.Break();
                    }

                    Log.Error(exception);
                    throw;
                }

                Log.Trace($"Metadata for audio event {audioEventId} retrieved");

                importedEvent.AudioRecordingId = audioEvent.AudioRecordingId;
            }

            return(importedEvent);
        }
예제 #2
0
        static CsvTests()
        {
            // pump static class initializers - it seems when running multiple tests that sometimes
            // these classes are not discovered.

            _ = new AcousticEvent();
            _ = new ImportedEvent();
        }
예제 #3
0
        static CsvTests()
        {
            // pump static class initializers - it seems when running multiple tests that sometimes
            // these classes are not discovered.

            AcousticEvent aev = new AcousticEvent();
            ImportedEvent iev = new ImportedEvent();

            var         configuration = Csv.DefaultConfiguration;
            IDictionary csvMaps       = (IDictionary)configuration.Maps.GetFieldValue("data");

            Debug.WriteLine("initializing static types" + aev + iev + csvMaps.Count);
        }
예제 #4
0
        private async Task ImportEventData(DataSet dataSet)
        {
            //  Verify that there is only one tab in the spreadsheet
            if (dataSet.Tables.Count != 1)
            {
                throw new Exception($"Expected one sheet in Excel file, found {dataSet.Tables.Count}");
            }
            //  Get the first tab of the spreadsheet
            DataTable table = dataSet.Tables[0];

            //Verify that the columns are what we expect
            if (table.Columns.Count != 4 ||
                table.Columns[0].ColumnName != "Title" ||
                table.Columns[1].ColumnName != "Location" ||
                table.Columns[2].ColumnName != "EventDate" ||
                table.Columns[3].ColumnName != "Text")
            {
                throw new Exception("Expected columns Title, Location, EventDate, Text");
            }
            //  Load data from the table into memory
            var importedEvents = new List <ImportedEvent>();
            int rowNumber      = 1;

            foreach (DataRow row in table.Rows)
            {
                ++rowNumber;
                var evt = new ImportedEvent
                {
                    RowNumber = rowNumber,
                    Title     = row[0].ToString().Trim(),
                    Location  = row[1].ToString().Trim(),
                    Text      = row[3].ToString().Trim(),
                };
                DateTime evtDate;
                if (DateTime.TryParse(row[2].ToString().Trim(), out evtDate))
                {
                    evt.EventDate = evtDate;
                }
                else
                {
                    throw new Exception("Date in improper format, expected DateTime Format");
                }
                importedEvents.Add(evt);
            }

            // check for dupli

            //  Load existing event data from the database
            var dates          = importedEvents.Select(x => x.EventDate);
            var dbEvents       = _db.Events.Where(x => dates.Contains(x.EventDate)).ToList();
            var existingEvents = (
                from e in dbEvents
                join i in importedEvents
                on new { e.Title, e.Location, e.EventDate }
                equals new { i.Title, i.Location, i.EventDate }
                select e
                ).ToList();

            //  Filter out existing events
            var newEvents =
                from i in importedEvents
                join e in existingEvents
                on new { i.Title, i.Location, i.EventDate }
            equals new { e.Title, e.Location, e.EventDate }
            into g
            where !g.Any()
            select new Event
            {
                Title     = i.Title,
                Location  = i.Location,
                EventDate = i.EventDate,
                Text      = i.Text,
                Going     = 0,
            };

            //  Save only the new customers
            _db.Events.AddRange(newEvents);
            _db.SaveChanges();
        }