示例#1
0
        /// <summary>
        /// Constructs a new <see cref="CmdExecutor"/> object, initializes its command queue and sets the <see cref="TargetEnvironment"/> property.
        /// </summary>
        /// <param name="targetEnvironmentViewModel">The target environment which will participate in the <see cref="EnvironmentChanged"/> event.</param>
        /// <seealso cref="CmdExecutorBase"/>
        public CmdExecutor(EnvironmentViewModel targetEnvironmentViewModel)
        {
            var converter            = new EnvironmentConverter();
            var convertedEnvironment = converter.From(targetEnvironmentViewModel);

            TargetEnvironment = convertedEnvironment;
        }
示例#2
0
        /// <summary>
        /// Converts an <see cref="EnvironmentViewModel"/> to an <see cref="Environment"/> entity and inserts it if it's not been persisted yet. If it has, updates it.
        /// </summary>
        /// <param name="environment">The <see cref="EnvironmentViewModel"/> to save or update.</param>
        /// <returns>The newly-inserted or updated <see cref="Environment"/>, converted to an <see cref="EnvironmentViewModel"/></returns>
        public EnvironmentViewModel SaveEnvironment(EnvironmentViewModel environment)
        {
            var converter = new EnvironmentConverter();
            var entity    = converter.From(environment);
            var inserted  = _repository.UpsertEnvironment(entity);

            return(converter.To(inserted));
        }
示例#3
0
        /// <summary>
        /// Performs all the commands in the <see cref="CmdExecutorBase.CommandQueue"/> queue asynchronously.
        /// It optionally notifies of progress and execution can be canceled.
        /// </summary>
        /// <param name="progress">Notifies of progress.</param>
        /// <param name="cancellationToken">Allows canceling the execution midway and revert to a previous state.</param>
        public override async Task ExecuteAsync(IProgress <CmdExecutorProgress> progress, CancellationToken cancellationToken)
        {
            await base.ExecuteAsync(progress, cancellationToken);

            if (TargetEnvironment != null)
            {
                var converter          = new EnvironmentConverter();
                var convertedViewModel = converter.To(TargetEnvironment);
                OnEnvironmentChanged(this, new EnvironmentChangedEventArgs(convertedViewModel));
            }
        }
示例#4
0
        /// <summary>
        /// Gets all the <see cref="EnvironmentViewModel"/>s marked as normal environments in the datastore.
        /// </summary>
        /// <returns>A <see cref="ICollection{T}"/> of <see cref="EnvironmentViewModel"/>s.</returns>
        public ICollection <EnvironmentViewModel> GetEnvironments()
        {
            var models = _repository.GetEnvironments();
            var output = new List <EnvironmentViewModel>();
            var environmentConverter = new EnvironmentConverter();

            foreach (var model in models)
            {
                output.Add(environmentConverter.To(model));
            }

            return(output);
        }
示例#5
0
        /// <summary>
        /// Get the <see cref="EnvironmentViewModel"/> with the specified id.
        /// </summary>
        /// <param name="id">The id of the <see cref="EnvironmentViewModel"/> to retrieve.</param>
        /// <returns>If an <see cref="Environment"/> with the specified id is found, converts it to an <see cref="EnvironmentViewModel"/>. If not, returns null.</returns>
        public EnvironmentViewModel GetEnvironmentById(int id)
        {
            var result = _repository.GetEnvironmentById(id);

            if (result == null)
            {
                return(null);
            }

            var converter = new EnvironmentConverter();

            return(converter.To(result));
        }
示例#6
0
        /// <summary>
        /// Validates the supplied <see cref="EnvironmentViewModel"/>. If the validation is successful, converts to an <see cref="Environment"/> entity and inserts it in the datastore.
        /// </summary>
        /// <param name="environmentViewModel">The <see cref="EnvironmentViewModel"/> to insert.</param>
        /// <returns>If the validation is successful, return a new instance of the <see cref="EnvironmentViewModel"/> with its id updated. Otherwise, returns null.</returns>
        public EnvironmentViewModel InsertEnvironment(EnvironmentViewModel environmentViewModel)
        {
            var validator        = new EnvironmentViewModelValidator();
            var validationResult = validator.Validate(environmentViewModel);

            if (validationResult.IsValid)
            {
                var converter = new EnvironmentConverter();
                var converted = converter.From(environmentViewModel);
                var inserted  = _repository.InsertEnvironment(converted);
                return(converter.To(inserted));
            }

            return(null);
        }