Exemple #1
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));
        }
Exemple #2
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));
            }
        }
Exemple #3
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);
        }
Exemple #4
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));
        }
Exemple #5
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);
        }