Ejemplo n.º 1
0
        /// <summary>
        /// Upserts a job
        /// </summary>
        /// <param name="resourceGroupName">The resource group name</param>
        /// <param name="agentServerName">The server name</param>
        /// <param name="agentName">The agent name</param>
        /// <param name="jobName">The job name</param>
        /// <param name="model">The job parameters</param>
        /// <returns></returns>
        public AzureSqlElasticJobModel UpsertJob(AzureSqlElasticJobModel model)
        {
            var param = new Job
            {
                Description = model.Description,
                Schedule    = new JobSchedule
                {
                    Enabled   = model.Enabled,
                    EndTime   = model.EndTime,
                    Interval  = model.Interval,
                    StartTime = model.StartTime,
                    Type      = model.ScheduleType
                }
            };

            var resp = Communicator.CreateOrUpdateJob(model.ResourceGroupName, model.ServerName, model.AgentName, model.JobName, param);

            return(CreateJobModelFromResponse(model.ResourceGroupName, model.ServerName, model.AgentName, resp));
        }
        /// <summary>
        /// Generates the model from user input.
        /// </summary>
        /// <param name="model">This is null since the job doesn't exist yet</param>
        /// <returns>The generated model from user input</returns>
        protected override IEnumerable <AzureSqlElasticJobModel> ApplyUserInputToModel(IEnumerable <AzureSqlElasticJobModel> model)
        {
            AzureSqlElasticJobModel newEntity = new AzureSqlElasticJobModel
            {
                ResourceGroupName = this.ResourceGroupName,
                ServerName        = this.ServerName,
                AgentName         = this.AgentName,
                JobName           = this.Name,
                Description       = this.Description,
                StartTime         = this.StartTime != null ? this.StartTime : DateTime.Now, // defaults to current date time
                EndTime           = this.EndTime != null ? this.EndTime : null,
                ScheduleType      = this.RunOnce.IsPresent ? JobScheduleType.Once :
                                    this.IntervalType != null ? JobScheduleType.Recurring : (JobScheduleType?)null,
                Interval = this.IntervalCount.HasValue ? CreateIso8601Duration(this.IntervalType, this.IntervalCount.Value) : null,
                Enabled  = this.Enable.IsPresent
            };

            return(new List <AzureSqlElasticJobModel> {
                newEntity
            });
        }