public List <KnowledgeEntryRecord> UpdateKnowledgeEntries(
            IList <KnowledgeEntryRecord> importKnowledgeEntries,
            IKnowledgeEntryService service,
            ref int modifiedRecords
            )
        {
            var knowledgeEntryRecords = service.FindAllAsync().Result;

            var patch = new PatchDefinition <KnowledgeEntryRecord, KnowledgeEntryRecord>(
                (source, list) => list.SingleOrDefault(a => a.Id == source.Id)
                );

            patch
            .Map(s => s.Id, t => t.Id)
            .Map(s => s.KnowledgeGroupId, t => t.KnowledgeGroupId)
            .Map(s => s.Title, t => t.Title)
            .Map(s => s.Text, t => t.Text)
            .Map(s => s.Order, t => t.Order)
            .Map(s => s.Links, t => t.Links)
            .Map(s => s.ImageIds, t => t.ImageIds);

            var diff = patch.Patch(importKnowledgeEntries, knowledgeEntryRecords);

            service.ApplyPatchOperationAsync(diff).Wait();

            modifiedRecords += diff.Count(a => a.Action != ActionEnum.NotModified);
            return(diff.Where(a => a.Entity.IsDeleted == 0).Select(a => a.Entity).ToList());
        }
        public List <KnowledgeGroupRecord> UpdateKnowledgeGroups(
            IList <KnowledgeGroupRecord> importKnowledgeGroups,
            IKnowledgeGroupService service,
            ref int modifiedRecords
            )
        {
            var knowledgeGroupRecords = service.FindAllAsync().Result;

            var patch = new PatchDefinition <KnowledgeGroupRecord, KnowledgeGroupRecord>(
                (source, list) => list.SingleOrDefault(a => a.Id == source.Id)
                );

            patch
            .Map(s => s.Id, t => t.Id)
            .Map(s => s.Name, t => t.Name)
            .Map(s => s.Description, t => t.Description)
            .Map(s => s.FontAwesomeIconCharacterUnicodeAddress, t => t.FontAwesomeIconCharacterUnicodeAddress)
            .Map(s => s.Order, t => t.Order);

            var diff = patch.Patch(importKnowledgeGroups, knowledgeGroupRecords);

            service.ApplyPatchOperationAsync(diff).Wait();

            modifiedRecords += diff.Count(a => a.Action != ActionEnum.NotModified);
            return(diff.Where(a => a.Entity.IsDeleted == 0).Select(a => a.Entity).ToList());
        }
        private List <EventRecord> UpdateEventEntries(
            IList <EventImportRow> ImportEventEntries,
            IList <EventConferenceTrackRecord> CurrentConferenceTracks,
            IList <EventConferenceRoomRecord> CurrentConferenceRooms,
            IList <EventConferenceDayRecord> CurrentConferenceDays,
            ref int modifiedRecords
            )
        {
            var eventRecords = _eventService.FindAllAsync().Result;

            var patch = new PatchDefinition <EventImportRow, EventRecord>(
                (source, list) => list.SingleOrDefault(a => a.SourceEventId == source.EventId)
                );

            patch.Map(s => s.EventId, t => t.SourceEventId)
            .Map(s => s.Slug, t => t.Slug)
            .Map(s => s.Title.Split('–')[0]?.Trim(), t => t.Title)
            .Map(s => (s.Title + '–').Split('–')[1]?.Trim(), t => t.SubTitle)
            .Map(s => s.Abstract, t => t.Abstract)
            .Map(
                s => CurrentConferenceTracks.Single(a => a.Name == s.ConferenceTrack).Id,
                t => t.ConferenceTrackId)
            .Map(
                s => CurrentConferenceRooms.Single(a => a.Name == s.ConferenceRoom).Id,
                t => t.ConferenceRoomId)
            .Map(
                s => CurrentConferenceDays.Single(a => a.Name == s.ConferenceDayName).Id,
                t => t.ConferenceDayId)
            .Map(s => s.Description, t => t.Description)
            .Map(s => s.Duration, t => t.Duration)
            .Map(s => s.StartTime, t => t.StartTime)
            .Map(s => s.EndTime, t => t.EndTime)
            .Map(s => DateTime.SpecifyKind(CurrentConferenceDays.Single(a => a.Name == s.ConferenceDayName)
                                           .Date.Add(s.StartTime), DateTimeKind.Utc).AddHours(-2), t => t.StartDateTimeUtc)
            .Map(s => DateTime.SpecifyKind(CurrentConferenceDays.Single(a => a.Name == s.ConferenceDayName)
                                           .Date.Add(s.EndTime).AddDays(s.StartTime < s.EndTime ? 0 : 1).AddHours(-2), DateTimeKind.Utc),
                 t => t.EndDateTimeUtc)
            .Map(s => s.PanelHosts, t => t.PanelHosts);

            var diff = patch.Patch(ImportEventEntries, eventRecords);

            _eventService.ApplyPatchOperationAsync(diff).Wait();

            modifiedRecords += diff.Count(a => a.Action != ActionEnum.NotModified);
            return(diff.Where(a => a.Entity.IsDeleted == 0).Select(a => a.Entity).ToList());
        }
Exemplo n.º 4
0
        public static List <EventConferenceRoomRecord> UpdateEventConferenceRooms(
            IList <string> importConferenceRooms,
            IEventConferenceRoomService service
            )
        {
            var eventConferenceRoomRecords = service.FindAllAsync().Result;

            var patch = new PatchDefinition <string, EventConferenceRoomRecord>(
                (source, list) => list.SingleOrDefault(a => a.Name == source)
                );

            patch.Map(s => s, t => t.Name);
            var diff = patch.Patch(importConferenceRooms, eventConferenceRoomRecords);

            service.ApplyPatchOperationAsync(diff).Wait();

            return(diff.Where(a => a.Entity.IsDeleted == 0).Select(a => a.Entity).ToList());
        }
        private List <EventConferenceRoomRecord> UpdateEventConferenceRooms(
            IList <string> importConferenceRooms,
            ref int modifiedRecords
            )
        {
            var eventConferenceRoomRecords = _eventConferenceRoomService.FindAllAsync().Result;

            var patch = new PatchDefinition <string, EventConferenceRoomRecord>(
                (source, list) => list.SingleOrDefault(a => a.Name == source)
                );

            patch.Map(s => s, t => t.Name);
            var diff = patch.Patch(importConferenceRooms, eventConferenceRoomRecords);

            _eventConferenceRoomService.ApplyPatchOperationAsync(diff).Wait();

            modifiedRecords += diff.Count(a => a.Action != ActionEnum.NotModified);
            return(diff.Where(a => a.Entity.IsDeleted == 0).Select(a => a.Entity).ToList());
        }
Exemplo n.º 6
0
        public static List <EventConferenceDayRecord> UpdateEventConferenceDays(
            IList <Tuple <DateTime, string> > importConferenceDays,
            IEventConferenceDayService service
            )
        {
            var eventConferenceDayRecords = service.FindAllAsync().Result;

            var patch = new PatchDefinition <Tuple <DateTime, string>, EventConferenceDayRecord>(
                (source, list) => list.SingleOrDefault(a => a.Date == source.Item1)
                );

            patch.Map(s => s.Item1, t => t.Date)
            .Map(s => s.Item2, t => t.Name);

            var diff = patch.Patch(importConferenceDays, eventConferenceDayRecords);

            service.ApplyPatchOperationAsync(diff).Wait();

            return(diff.Where(a => a.Entity.IsDeleted == 0).Select(a => a.Entity).ToList());
        }
Exemplo n.º 7
0
        public static List <EventRecord> UpdateEventEntries(
            IList <EventImportRow> ImportEventEntries,
            IList <EventConferenceTrackRecord> CurrentConferenceTracks,
            IList <EventConferenceRoomRecord> CurrentConferenceRooms,
            IList <EventConferenceDayRecord> CurrentConferenceDays,
            IEventService service
            )
        {
            var eventRecords = service.FindAllAsync().Result;

            var patch = new PatchDefinition <EventImportRow, EventRecord>(
                (source, list) => list.SingleOrDefault(a => a.SourceEventId == source.EventId)
                );

            patch.Map(s => s.EventId, t => t.SourceEventId)
            .Map(s => s.Slug, t => t.Slug)
            .Map(s => s.Title.Split('|')[0], t => t.Title)
            .Map(s => (s.Title + '|').Split('|')[1], t => t.SubTitle)
            .Map(s => s.Abstract, t => t.Abstract)
            .Map(
                s => CurrentConferenceTracks.Single(a => a.Name == s.ConferenceTrack).Id,
                t => t.ConferenceTrackId)
            .Map(
                s => CurrentConferenceRooms.Single(a => a.Name == s.ConferenceRoom).Id,
                t => t.ConferenceRoomId)
            .Map(
                s => CurrentConferenceDays.Single(a => a.Name == s.ConferenceDayName).Id,
                t => t.ConferenceDayId)
            .Map(s => s.Description, t => t.Description)
            .Map(s => s.Duration, t => t.Duration)
            .Map(s => s.StartTime, t => t.StartTime)
            .Map(s => s.EndTime, t => t.EndTime)
            .Map(s => s.PanelHosts, t => t.PanelHosts);

            var diff = patch.Patch(ImportEventEntries, eventRecords);

            service.ApplyPatchOperationAsync(diff).Wait();

            return(diff.Where(a => a.Entity.IsDeleted == 0).Select(a => a.Entity).ToList());
        }
        public static List <KnowledgeGroupRecord> UpdateKnowledgeGroups(
            IList <KnowledgeGroupRecord> importKnowledgeGroups,
            IKnowledgeGroupService service
            )
        {
            var knowledgeGroupRecords = service.FindAllAsync().Result;

            var patch = new PatchDefinition <KnowledgeGroupRecord, KnowledgeGroupRecord>(
                (source, list) => list.SingleOrDefault(a => a.Id == source.Id)
                );

            patch
            .Map(s => s.Id, t => t.Id)
            .Map(s => s.Name, t => t.Name)
            .Map(s => s.Description, t => t.Description)
            .Map(s => s.Order, t => t.Order);

            var diff = patch.Patch(importKnowledgeGroups, knowledgeGroupRecords);

            service.ApplyPatchOperationAsync(diff).Wait();

            return(diff.Where(a => a.Entity.IsDeleted == 0).Select(a => a.Entity).ToList());
        }
Exemplo n.º 9
0
        public async Task ImportZipPackageAsync(string fileName)
        {
            var importRecords = new List <DealerRecord>();

            using (var fileStream = File.OpenRead(fileName))
                using (var archive = new ZipArchive(fileStream))
                {
                    var csvEntry =
                        archive.Entries.Single(a => a.Name.EndsWith(".csv", StringComparison.CurrentCultureIgnoreCase));

                    TextReader reader = new StreamReader(csvEntry.Open(), Encoding.GetEncoding(1252));

                    var csvReader = new CsvReader(reader);
                    csvReader.Configuration.RegisterClassMap <DealerImportRowClassMap>();
                    var csvRecords = csvReader.GetRecords <DealerImportRow>().ToList();

                    foreach (var record in csvRecords)
                    {
                        var dealerRecord = new DealerRecord
                        {
                            RegistrationNumber = record.RegNo,
                            AttendeeNickname   = record.Nickname,
                            AboutTheArtistText = record.AboutTheArtist,
                            AboutTheArtText    = record.AboutTheArt,
                            ArtPreviewCaption  = record.ArtPreviewCaption,
                            DisplayName        = record.DisplayName,
                            ShortDescription   = record.ShortDescription
                        };

                        dealerRecord.ArtistImageId = await GetImageIdAsync(archive, $"artist_{record.RegNo}.",
                                                                           $"dealer:artist:{record.RegNo}");

                        dealerRecord.ArtistThumbnailImageId = await GetImageIdAsync(archive, $"thumbnail_{record.RegNo}.",
                                                                                    $"dealer:thumbnail:{record.RegNo}");

                        dealerRecord.ArtPreviewImageId =
                            await GetImageIdAsync(archive, $"art_{record.RegNo}.", $"dealer:art:{record.RegNo}");

                        ImportLinks(dealerRecord, record.WebsiteUrl);
                        SanitizeFields(dealerRecord);

                        importRecords.Add(dealerRecord);
                    }
                }

            var existingRecords = await _dealerService.FindAllAsync();

            var patch = new PatchDefinition <DealerRecord, DealerRecord>((source, list) =>
                                                                         list.SingleOrDefault(a => a.RegistrationNumber == source.RegistrationNumber));

            patch
            .Map(s => s.RegistrationNumber, t => t.RegistrationNumber)
            .Map(s => s.AttendeeNickname, t => t.AttendeeNickname)
            .Map(s => s.AboutTheArtistText, t => t.AboutTheArtistText)
            .Map(s => s.AboutTheArtText, t => t.AboutTheArtText)
            .Map(s => s.ArtPreviewCaption, t => t.ArtPreviewCaption)
            .Map(s => s.DisplayName, t => t.DisplayName)
            .Map(s => s.ShortDescription, t => t.ShortDescription)
            .Map(s => s.ArtistImageId, t => t.ArtistImageId)
            .Map(s => s.ArtistThumbnailImageId, t => t.ArtistThumbnailImageId)
            .Map(s => s.ArtPreviewImageId, t => t.ArtPreviewImageId)
            .Map(s => s.Links, t => t.Links);

            var diff = patch.Patch(importRecords, existingRecords);
            await _dealerService.ApplyPatchOperationAsync(diff);
        }
Exemplo n.º 10
0
        public async Task ImportZipPackageAsync(string fileName)
        {
            var importRecords = new List <DealerRecord>();

            using (var fileStream = File.OpenRead(fileName))
                using (var archive = new ZipArchive(fileStream))
                {
                    var csvEntry =
                        archive.Entries.Single(a => a.Name.EndsWith(".csv", StringComparison.CurrentCultureIgnoreCase));

                    TextReader reader = new StreamReader(csvEntry.Open(), true);

                    var csvReader = new CsvReader(reader);
                    csvReader.Configuration.RegisterClassMap <DealerImportRowClassMap>();
                    csvReader.Configuration.Delimiter = ";";
                    var csvRecords = csvReader.GetRecords <DealerImportRow>().ToList();

                    _output?.WriteLine($"Parsed {csvRecords.Count} records from CSV");

                    foreach (var record in csvRecords)
                    {
                        var dealerRecord = new DealerRecord
                        {
                            RegistrationNumber = record.RegNo,
                            AttendeeNickname   = record.Nickname,
                            AboutTheArtistText = record.AboutTheArtist,
                            AboutTheArtText    = record.AboutTheArt,
                            ArtPreviewCaption  = record.ArtPreviewCaption,
                            DisplayName        = record.DisplayName,
                            ShortDescription   = record.ShortDescription,
                            Merchandise        = record.Merchandise,
                            AttendsOnThursday  = !string.IsNullOrWhiteSpace(record.AttendsThu),
                            AttendsOnFriday    = !string.IsNullOrWhiteSpace(record.AttendsFri),
                            AttendsOnSaturday  = !string.IsNullOrWhiteSpace(record.AttendsSat),
                            TelegramHandle     = record.Telegram,
                            TwitterHandle      = record.Twitter
                        };

                        dealerRecord.ArtistImageId = await GetImageIdAsync(archive, $"artist_{record.RegNo}.",
                                                                           $"dealer:artist:{record.RegNo}");

                        dealerRecord.ArtistThumbnailImageId = await GetImageIdAsync(archive, $"thumbnail_{record.RegNo}.",
                                                                                    $"dealer:thumbnail:{record.RegNo}");

                        dealerRecord.ArtPreviewImageId =
                            await GetImageIdAsync(archive, $"art_{record.RegNo}.", $"dealer:art:{record.RegNo}");

                        ImportLinks(dealerRecord, record.Website);
                        SanitizeFields(dealerRecord);

                        importRecords.Add(dealerRecord);
                    }
                }

            var existingRecords = await _dealerService.FindAllAsync();

            var patch = new PatchDefinition <DealerRecord, DealerRecord>((source, list) =>
                                                                         list.SingleOrDefault(a => a.RegistrationNumber == source.RegistrationNumber));

            patch
            .Map(s => s.RegistrationNumber, t => t.RegistrationNumber)
            .Map(s => s.AttendeeNickname, t => t.AttendeeNickname)
            .Map(s => s.AboutTheArtistText, t => t.AboutTheArtistText)
            .Map(s => s.AboutTheArtText, t => t.AboutTheArtText)
            .Map(s => s.ArtPreviewCaption, t => t.ArtPreviewCaption)
            .Map(s => s.DisplayName, t => t.DisplayName)
            .Map(s => s.ShortDescription, t => t.ShortDescription)
            .Map(s => s.Merchandise, t => t.Merchandise)
            .Map(s => s.ArtistImageId, t => t.ArtistImageId)
            .Map(s => s.ArtistThumbnailImageId, t => t.ArtistThumbnailImageId)
            .Map(s => s.ArtPreviewImageId, t => t.ArtPreviewImageId)
            .Map(s => s.TelegramHandle, t => t.TelegramHandle)
            .Map(s => s.TwitterHandle, t => t.TwitterHandle)
            .Map(s => s.AttendsOnThursday, t => t.AttendsOnThursday)
            .Map(s => s.AttendsOnFriday, t => t.AttendsOnFriday)
            .Map(s => s.AttendsOnSaturday, t => t.AttendsOnSaturday)
            .Map(s => s.Links, t => t.Links);

            var diff = patch.Patch(importRecords, existingRecords);
            await _dealerService.ApplyPatchOperationAsync(diff);

            _output?.WriteLine($"Added: {diff.Count(a => a.Action == ActionEnum.Add)}");
            _output?.WriteLine($"Deleted: {diff.Count(a => a.Action == ActionEnum.Delete)}");
            _output?.WriteLine($"Updated: {diff.Count(a => a.Action == ActionEnum.Update)}");
            _output?.WriteLine($"Not Modified: {diff.Count(a => a.Action == ActionEnum.NotModified)}");
        }
        public async Task ExecuteAsync()
        {
            _logger.LogDebug("Job started");

            var response = string.Empty;

            using (var client = new HttpClient())
            {
                var url = _configuration["source:url"];
                _logger.LogDebug("Fetching data from {url}", url);
                response = await client.GetStringAsync(url);
            }

            if (response == "null")
            {
                _logger.LogDebug("Received null response");
                return;
            }


            var records       = JsonConvert.DeserializeObject <JObject[]>(response);
            var unixReference = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);

            var mapping = records.Select(j => new
            {
                Record = new AnnouncementRecord()
                {
                    ExternalReference = j["id"].Value <string>(),
                    Area    = j["news"]["type"].Value <string>().UppercaseFirst(),
                    Author  = j["news"]?["department"]?.Value <string>().UppercaseFirst() ?? "Eurofurence",
                    Title   = j["news"]["title"].Value <string>(),
                    Content = j["news"]["message"].Value <string>().RemoveMarkdown(),
                    ValidFromDateTimeUtc  = unixReference.AddSeconds(j["date"].Value <double>()).ToUniversalTime(),
                    ValidUntilDateTimeUtc = unixReference
                                            .AddSeconds(j["news"]["valid_until"].Value <double>()).ToUniversalTime(),
                },
                Type = j["news"]["type"].Value <string>()
            }).ToList();

            foreach (var item in mapping)
            {
                if (new[] { "new", "reschedule" }.Contains(item.Type))
                {
                    item.Record.ValidUntilDateTimeUtc = item.Record.ValidFromDateTimeUtc.AddHours(48);
                }
            }

            var existingRecords = await _announcementService.FindAllAsync();

            var patch = new PatchDefinition <AnnouncementRecord, AnnouncementRecord>((source, list) =>
                                                                                     list.SingleOrDefault(a => a.ExternalReference == source.ExternalReference));

            patch
            .Map(s => s.ExternalReference, t => t.ExternalReference)
            .Map(s => s.Area, t => t.Area)
            .Map(s => s.Author, t => t.Author)
            .Map(s => s.Title, t => t.Title)
            .Map(s => s.Content, t => t.Content)
            .Map(s => s.ValidUntilDateTimeUtc, t => t.ValidUntilDateTimeUtc)
            .Map(s => s.ValidFromDateTimeUtc, t => t.ValidFromDateTimeUtc);

            var diff = patch.Patch(mapping.Select(a => a.Record), existingRecords)
                       .Where(a => !string.IsNullOrEmpty(a.Entity.ExternalReference) && a.Action != ActionEnum.NotModified)
                       .ToList();

            _logger.LogDebug("Diff results in {count} new/modified records", diff.Count);

            if (diff.Count == 0)
            {
                return;
            }

            _logger.LogInformation("Processing {count} new/modified records", diff.Count);

            await _announcementService.ApplyPatchOperationAsync(diff);

            await _pushEventMediator.PushSyncRequestAsync();

            foreach (var record in diff.Where(a => a.Action == ActionEnum.Add))
            {
                _logger.LogInformation("Sending push notification for announcement {id} ({title})", record.Entity.Id, record.Entity.Title);
                await _pushEventMediator.PushAnnouncementNotificationAsync(record.Entity);
            }

            _logger.LogDebug("Job finished");
        }