private void AddOrUpdateSongs(DateTimeOffset importDate)
        {
            foreach (var albumDirectory in Directory.EnumerateDirectories(_environmentOptions.Value.DataDirectoryPath, "*", SearchOption.TopDirectoryOnly))
            {
                using (var unit = _unitOfWorkFactory.Begin())
                {
                    var songCounter    = 0;
                    var coverImageFile = GetCoverImageFileOrDefault(albumDirectory);

                    foreach (var songFileName in Directory.EnumerateFiles(albumDirectory, "*.mp3", SearchOption.TopDirectoryOnly))
                    {
                        var song = ImportSong(songFileName, coverImageFile, importDate, unit.Dependent, unit.Dependent2);
                        if (song == null)
                        {
                            continue;
                        }

                        songCounter++;
                    }

                    unit.Commit();

                    _logger.LogInformation("Imported {0} song(s) in album directory {1}.", songCounter, albumDirectory);
                }
            }
        }
Exemplo n.º 2
0
        public void Teardown()
        {
            using (var unit = _factory.Begin())
            {
                var song = unit.Dependent2.GetById(_songId);

                unit.Dependent2.Remove(song);
                unit.Commit();
            }
        }
Exemplo n.º 3
0
        private async Task DispatchNextSongMessage(IClientProxy clients)
        {
            using (var unit = _unitOfWorkFactory.Begin())
            {
                var currentSong = await GetCurrentSongAsync(unit);

                var votingCandidates = await GetVotingCandidatesAsync(unit);

                await clients.SendAsync("NextSong", currentSong, votingCandidates);
            }
        }
Exemplo n.º 4
0
            private void UpdateHasDemandIndicator(Guid registrationParticipantId, bool hasDemandWhenLastCreatedOrModified)
            {
                using (var unitOfWork = _hasDemandUpdateUnitOfWork.Begin())
                {
                    var participant = unitOfWork.Dependent.GetById(registrationParticipantId);
                    participant.HasDemandWhenLastCreatedOrModified = hasDemandWhenLastCreatedOrModified;

                    unitOfWork.Commit();
                }
            }
        public async Task <Card> Add()
        {
            using (var uow = _uowFactory.Begin())
            {
                var card = await uow.AddAsync(new Card(ScheduleEnum.LEITNER));

                await uow.CommitAsync();

                return(card);
            }
        }
Exemplo n.º 6
0
        public async Task <IdentityResult> CreateAsync(ApplicationUser user, CancellationToken cancellationToken)
        {
            using (var work = _factory.Begin())
            {
                var data = Mapper.Map <ApplicationUser, UserData>(user);

                await work.Users.SaveAsync(data);

                work.Commit();
            }
            return(IdentityResult.Success);
        }
Exemplo n.º 7
0
        public async Task Execute(DeletePodcastCommand command)
        {
            var id = command.Id;

            using (var work = _factory.Begin())
            {
                work.Podcasts.Delete(command.Id);
                work.Commit();
            }

            await _eventDispatcher.Publish(new PodcastDeletedEvent { Id = id });
        }
Exemplo n.º 8
0
        public async Task Execute(DeleteCategoryCommand command)
        {
            var id = command.Id;

            using (var work = _factory.Begin())
            {
                work.Categories.Delete(id);
                work.Commit();
            }

            await _eventDispatcher.Publish(new CategoryDeletedEvent { Id = id });
        }
Exemplo n.º 9
0
        public static IApplicationBuilder UseScopeMiddleware(this IApplicationBuilder app, IUnitOfWorkFactory <ILifetimeScope> unitOfWorkFactory)
        {
            app.Use(async(context, next) =>
            {
                using (var unitOfWork = unitOfWorkFactory.Begin())
                {
                    context.SetRequestUnitOfWork(unitOfWork);

                    await next();
                }
            });

            return(app);
        }
        public void Teardown()
        {
            using (var unit = _factory.Begin())
            {
                var songs = unit.Dependent.Get();
                foreach (var song in songs)
                {
                    unit.Dependent.Remove(song);
                }

                unit.Commit();
            }
        }
        public void Teardown()
        {
            using (var unit = _factory.Begin())
            {
                var votingCandidates = unit.Dependent.Get();
                foreach (var votingCandidate in votingCandidates)
                {
                    unit.Dependent.Remove(votingCandidate);
                }

                var songs = unit.Dependent3.Get();
                foreach (var song in songs)
                {
                    unit.Dependent3.Remove(song);
                }

                unit.Commit();
            }
        }
Exemplo n.º 12
0
        public void Setup()
        {
            var rootContainer = IntegrationTestHelper.SetUp().Build();

            _factory = rootContainer.Resolve <IUnitOfWorkFactory <ICurrentSongRepository, ISongRepository> >();

            using (var unit = _factory.Begin())
            {
                var song = unit.Dependent2.Create();
                song.Title             = "LazyLoadingTests";
                song.DurationInSeconds = 120;
                song.FileName          = "LazyLoadingTests.mp3";

                unit.Dependent2.Add(song);
                unit.Commit();

                _songId = song.Id;
            }
        }
Exemplo n.º 13
0
        public void Teardown()
        {
            using (var unit = _songFactory.Begin())
            {
                var songs = unit.Dependent.Get();
                foreach (var song in songs)
                {
                    song.RemoveCoverImage(unit.Dependent2);
                    unit.Dependent.Remove(song);
                }

                unit.Commit();
            }
        }
Exemplo n.º 14
0
        public async Task Execute(CreatePodcastCommand command)
        {
            using (var work = _factory.Begin())
            {
                if (work.Podcasts.Exists(command.Id))
                {
                    return;
                }

                var Podcast = new Podcast {
                    Id         = command.Id,
                    Link       = command.Link,
                    CategoryId = command.CategoryId
                };

                work.Podcasts.Save(Podcast);
                work.Commit();
            }

            await _command.Send(new RetrievePodcastCommand { Id = command.Id, Link = command.Link });
        }
Exemplo n.º 15
0
            private async Task NotifyAsync(RegistrationWithParticipant registrationParticipant)
            {
                using (var unitOfWork = _notificationUnitOfWork.Begin())
                {
                    string[] messageLines =
                    {
                        $"Hallo {registrationParticipant.Registration.Applicant.Givenname}",
                        $"Für {registrationParticipant.RegistrationParticipant.Name} wurde eine passende Kursdurchführung gefunden. Schauen Sie bei Gelegenheit vorbei:",
                        string.Format(_environmentOptions.Current().RegistrationFrontendUrl, registrationParticipant.Registration.Id)
                    };

                    await unitOfWork.Dependent.SendNotification(
                        registrationParticipant.Registration.Applicant.PhoneNumber,
                        Constants.NotificationIds.ACCOMPLISH_DEMAND_FOR_REGISTRATION,
                        new [] { NotificationSubject(registrationParticipant) },
                        string.Join(Environment.NewLine, messageLines)
                        );

                    unitOfWork.Commit();
                }
            }
Exemplo n.º 16
0
        public async Task Execute(CreateCategoryCommand command)
        {
            var id   = command.Id;
            var name = command.Name;

            using (var work = _factory.Begin())
            {
                if (work.Categories.Exists(id))
                {
                    return;
                }

                var category = new Category {
                    Id = id, Name = name
                };
                work.Categories.Save(category);
                work.Commit();
            }

            await _eventDispatcher.Publish(new CategoryCreatedEvent { Id = id });
        }
Exemplo n.º 17
0
        public static IApplicationBuilder UseScopeMiddleware(this IApplicationBuilder app, IUnitOfWorkFactory <ILifetimeScope> unitOfWorkFactory)
        {
            app.Use(async(context, next) =>
            {
                // Don't create a unit of work for SignalR requests
                // The database connection would be held open for the entire time the user is connected,
                // which would lead to SqlConnection pool exhaustion over time
                if (context.Request.Path.StartsWithSegments(Constants.SIGNALR_PATH))
                {
                    await next();
                    return;
                }

                using (var unitOfWork = unitOfWorkFactory.Begin())
                {
                    context.SetRequestUnitOfWork(unitOfWork);

                    await next();
                }
            });

            return(app);
        }