Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Runbook"/> class.
        /// </summary>
        /// <param name="accountName">
        /// The account name.
        /// </param>
        /// <param name="runbook">
        /// The runbook.
        /// </param>
        /// <exception cref="System.ArgumentException">
        /// </exception>
        public Runbook(string accountName, AutomationManagement.Models.Runbook runbook)
        {
            Requires.Argument("runbook", runbook).NotNull();
            Requires.Argument("accountName", accountName).NotNull();

            this.AutomationAccountName = accountName;
            this.Name     = runbook.Name;
            this.Location = runbook.Location;
            this.Type     = runbook.Type;
            this.Tags     = runbook.Tags ?? new Dictionary <string, string>();

            if (runbook.Properties == null)
            {
                return;
            }

            this.CreationTime     = runbook.Properties.CreationTime.ToLocalTime();
            this.LastModifiedTime = runbook.Properties.LastModifiedTime.ToLocalTime();
            this.Description      = runbook.Properties.Description;

            this.LogVerbose  = runbook.Properties.LogVerbose;
            this.LogProgress = runbook.Properties.LogProgress;
            this.State       = runbook.Properties.State;
            this.JobCount    = runbook.Properties.JobCount;
            this.RunbookType = runbook.Properties.RunbookType;

            this.Parameters = runbook.Properties.Parameters ?? new Dictionary <string, RunbookParameter>();
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Runbook"/> class.
        /// </summary>
        /// <param name="accountName">
        /// The account name.
        /// </param>
        /// <param name="runbook">
        /// The runbook.
        /// </param>
        /// <exception cref="System.ArgumentException">
        /// </exception>
        public Runbook(string accountName, AutomationManagement.Models.Runbook runbook)
        {
            Requires.Argument("runbook", runbook).NotNull();
            Requires.Argument("accountName", accountName).NotNull();

            this.AutomationAccountName = accountName;
            this.Name     = runbook.Name;
            this.Location = runbook.Location;
            this.Tags     = null;

            if (runbook.Properties == null)
            {
                return;
            }

            this.CreationTime     = runbook.Properties.CreationTime.ToLocalTime();
            this.LastModifiedTime = runbook.Properties.LastModifiedTime.ToLocalTime();
            this.Description      = runbook.Properties.Description;

            this.LogVerbose  = runbook.Properties.LogVerbose;
            this.LogProgress = runbook.Properties.LogProgress;
            this.State       = runbook.Properties.State;
            this.JobCount    = runbook.Properties.JobCount;
            this.RunbookType = runbook.Properties.RunbookType;

            this.Parameters = new Hashtable(StringComparer.InvariantCultureIgnoreCase);
            foreach (var kvp in runbook.Properties.Parameters)
            {
                this.Parameters.Add(kvp.Key, (object)kvp.Value);
            }
        }
Esempio n. 3
0
        private AutomationManagement.Models.Runbook GetRunbookModel(string automationAccountName, Guid runbookId, bool withSchedules)
        {
            AutomationManagement.Models.Runbook runbookModel = withSchedules
                              ? this.automationManagementClient.Runbooks.GetWithSchedules(
                automationAccountName,
                runbookId.ToString()).Runbook
                              : this.automationManagementClient.Runbooks.Get(
                automationAccountName,
                runbookId.ToString()).Runbook;

            if (runbookModel == null)
            {
                throw new ResourceNotFoundException(typeof(Runbook), string.Format(CultureInfo.CurrentCulture, Resources.RunbookNotFoundById, runbookId));
            }

            return(runbookModel);
        }
Esempio n. 4
0
        private Runbook UpdateRunbookHelper(
            string automationAccountName,
            AutomationManagement.Models.Runbook runbook,
            string description,
            string[] tags,
            bool?logDebug,
            bool?logProgress,
            bool?logVerbose)
        {
            if (description != null)
            {
                runbook.Description = description;
            }

            if (tags != null)
            {
                runbook.Tags = string.Join(Constants.RunbookTagsSeparatorString, tags);
            }

            if (logDebug.HasValue)
            {
                runbook.LogDebug = logDebug.Value;
            }

            if (logProgress.HasValue)
            {
                runbook.LogProgress = logProgress.Value;
            }

            if (logVerbose.HasValue)
            {
                runbook.LogVerbose = logVerbose.Value;
            }

            var runbookUpdateParameters = new AutomationManagement.Models.RunbookUpdateParameters
            {
                Runbook = runbook
            };

            this.automationManagementClient.Runbooks.Update(automationAccountName, runbookUpdateParameters);

            var runbookId = new Guid(runbook.Id);

            return(this.GetRunbook(automationAccountName, runbookId));
        }
Esempio n. 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RunbookDefinition"/> class.
        /// </summary>
        /// <param name="accountName">
        /// The runbook version.
        /// </param>
        /// <param name="runbook">
        /// The runbook version.
        /// </param>
        /// <param name="content">
        /// The content.
        /// </param>
        /// <param name="slot">
        /// Slot published or draft.
        /// </param>
        public RunbookDefinition(string accountName, AutomationManagement.Models.Runbook runbook, string content, string slot)
        {
            Requires.Argument("runbook", runbook).NotNull();
            Requires.Argument("accountName", accountName).NotNull();
            Requires.Argument("slot", slot).NotNull();

            this.AutomationAccountName = accountName;
            this.Name    = runbook.Name;
            this.Content = content;

            if (runbook.Properties == null)
            {
                return;
            }

            this.CreationTime     = runbook.Properties.CreationTime.ToLocalTime();
            this.LastModifiedTime = runbook.Properties.LastModifiedTime.ToLocalTime();
            this.Slot             = slot;
            this.RunbookType      = runbook.Properties.RunbookType;
        }
Esempio n. 6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Runbook"/> class.
        /// </summary>
        /// <param name="runbook">
        /// The runbook.
        /// </param>
        /// <exception cref="System.ArgumentException">
        /// </exception>
        public Runbook(AutomationManagement.Models.Runbook runbook)
        {
            Requires.Argument("runbook", runbook).NotNull();
            if (runbook.Schedules == null)
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.InvalidRunbookModel));
            }

            this.AccountId        = new Guid(runbook.AccountId);
            this.Id               = new Guid(runbook.Id);
            this.Name             = runbook.Name;
            this.CreationTime     = DateTime.SpecifyKind(runbook.CreationTime, DateTimeKind.Utc).ToLocalTime();
            this.LastModifiedTime = DateTime.SpecifyKind(runbook.LastModifiedTime, DateTimeKind.Utc).ToLocalTime();
            this.LastModifiedBy   = runbook.LastModifiedBy;
            this.Description      = runbook.Description;
            this.IsApiOnly        = runbook.IsApiOnly;
            this.IsGlobal         = runbook.IsGlobal;

            if (runbook.PublishedRunbookVersionId != null)
            {
                this.PublishedRunbookVersionId = new Guid(runbook.PublishedRunbookVersionId);
            }

            if (runbook.DraftRunbookVersionId != null)
            {
                this.DraftRunbookVersionId = new Guid(runbook.DraftRunbookVersionId);
            }

            this.Tags = runbook.Tags != null?runbook.Tags.Split(Constants.RunbookTagsSeparatorChar) : new string[]
            {
            };
            this.LogDebug      = runbook.LogDebug;
            this.LogVerbose    = runbook.LogVerbose;
            this.LogProgress   = runbook.LogProgress;
            this.ScheduleNames = from schedule in runbook.Schedules where (schedule.NextRun != null) select schedule.Name;
        }
Esempio n. 7
0
 public IEnumerable <Job> ListJobsByRunbookId(string automationAccountName, Guid runbookId, DateTime?startTime, DateTime?endTime)
 {
     AutomationManagement.Models.Runbook runbookModel = this.GetRunbookModel(automationAccountName, runbookId, false);
     return(this.ListJobsByValidRunbookId(automationAccountName, new Guid(runbookModel.Id), startTime, endTime));
 }
Esempio n. 8
0
 public IEnumerable <RunbookDefinition> ListRunbookDefinitionsByRunbookId(string automationAccountName, Guid runbookId, bool?isDraft)
 {
     AutomationManagement.Models.Runbook runbookModel = this.GetRunbookModel(automationAccountName, runbookId, false);
     return(this.ListRunbookDefinitionsByValidRunbookId(automationAccountName, new Guid(runbookModel.Id), isDraft));
 }
Esempio n. 9
0
 public Runbook UpdateRunbook(string automationAccountName, string runbookName, string description, string[] tags, bool?logDebug, bool?logProgress, bool?logVerbose)
 {
     AutomationManagement.Models.Runbook runbookModel = this.GetRunbookModel(automationAccountName, runbookName, false);
     return(this.UpdateRunbookHelper(automationAccountName, runbookModel, description, tags, logDebug, logProgress, logVerbose));
 }