Exemple #1
0
        public void default_values()
        {
            var command = new ApplicationUpdateCommand();

            command.Id.Should().NotBe(0);
            command.Name.Should().Be("ApplicationUpdate");
        }
        public void Execute(ApplicationUpdateCommand message)
        {
            var latestAvailable = GetUpdatePackage(message.Trigger);

            if (latestAvailable != null)
            {
                try
                {
                    InstallUpdate(latestAvailable);
                    _logger.ProgressDebug("Restarting Radarr to apply updates");
                }
                catch (UpdateFolderNotWritableException ex)
                {
                    _logger.Error(ex, "Update process failed");
                    throw new CommandFailedException("Startup folder not writable by user '{0}'", ex, Environment.UserName);
                }
                catch (UpdateVerificationFailedException ex)
                {
                    _logger.Error(ex, "Update process failed");
                    throw new CommandFailedException("Downloaded update package is corrupt", ex);
                }
                catch (UpdateFailedException ex)
                {
                    _logger.Error(ex, "Update process failed");
                    throw new CommandFailedException(ex);
                }
            }
        }
        public async Task <ApplicationModel> UpdateAsync(ApplicationUpdateCommand cmd)
        {
            var result = await ExecuteAsync <ApplicationUpdateCommand, ApplicationUpdateCommandValidator, ApplicationModel>(cmd, async() =>
            {
                // get the application by unique id
                var application = Get <Domain.Application>(a => a.Id.Equals(cmd.Id));

                // if the application does not exist we need to throw an exception b/c the client believes it does
                if (null == application)
                {
                    throw new ApplicationNotFoundException($"Application with id {cmd.Id} does not exist.");
                }

                // store the original application as it's model
                var originalApplication = ApplicationFactory.ConvertToModel(application);

                // update the application
                application.Update(name: cmd.Name, updatedByUserId: MessageContext.UserId, resetApiKey: cmd.ResetApiKey);

                // save the updated application
                await Database.SaveAsync(application).ConfigureAwait(false);

                // convert the application to it's model
                var model = ApplicationFactory.ConvertToModel(application);

                // publish the domain event
                Publish(new ApplicationUpdatedEvent(MessageContext)
                {
                    OriginalApplication = originalApplication,
                    UpdatedApplication  = model
                });

                // return the application model
                return(model);
            }).ConfigureAwait(false);

            return(result);
        }
Exemple #4
0
        public void should_map_tracked_command()
        {
            var profileResource = new ApplicationUpdateCommand();

            profileResource.InjectTo <CommandResource>();
        }