Пример #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Job"/> class.
        /// </summary>
        /// <param name="resourceGroupName">
        /// The resource group name.
        /// </param>
        /// <param name="accountName">
        /// The account name.
        /// </param>
        /// <param name="job">
        /// The Job.
        /// </param>
        /// <exception cref="System.ArgumentException">
        /// </exception>
        public Job(string resourceGroupName, string accountName, Azure.Management.Automation.Models.Job job)
        {
            Requires.Argument("job", job).NotNull();
            Requires.Argument("accountName", accountName).NotNull();

            this.ResourceGroupName     = resourceGroupName;
            this.AutomationAccountName = accountName;

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

            this.Id                     = job.Properties.JobId;
            this.CreationTime           = job.Properties.CreationTime.ToLocalTime();
            this.LastModifiedTime       = job.Properties.LastModifiedTime.ToLocalTime();
            this.StartTime              = job.Properties.StartTime.HasValue ? job.Properties.StartTime.Value.ToLocalTime() : (DateTimeOffset?)null;
            this.Status                 = job.Properties.Status;
            this.StatusDetails          = job.Properties.StatusDetails;
            this.RunbookName            = job.Properties.Runbook.Name;
            this.Exception              = job.Properties.Exception;
            this.EndTime                = job.Properties.EndTime.HasValue ? job.Properties.EndTime.Value.ToLocalTime() : (DateTimeOffset?)null;
            this.LastStatusModifiedTime = job.Properties.LastStatusModifiedTime;
            this.HybridWorker           = job.Properties.RunOn;
            this.JobParameters          = new Hashtable(StringComparer.InvariantCultureIgnoreCase);
            foreach (var kvp in job.Properties.Parameters)
            {
                if (0 != String.Compare(kvp.Key, Constants.JobStartedByParameterName, CultureInfo.InvariantCulture, CompareOptions.IgnoreCase) &&
                    0 != String.Compare(kvp.Key, Constants.JobRunOnParameterName, CultureInfo.InvariantCulture, CompareOptions.IgnoreCase))
                {
                    this.JobParameters.Add(kvp.Key, (object)PowerShellJsonConverter.Deserialize(kvp.Value));
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Job"/> class.
        /// </summary>
        /// <param name="accountName">
        /// The account name.
        /// </param>
        /// <param name="Job">
        /// The Job.
        /// </param>
        /// <exception cref="System.ArgumentException">
        /// </exception>
        public Job(string accountName, Azure.Management.Automation.Models.Job job)
        {
            Requires.Argument("job", job).NotNull();
            Requires.Argument("accountName", accountName).NotNull();

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

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

            this.CreationTime           = job.Properties.CreationTime.ToLocalTime();
            this.LastModifiedTime       = job.Properties.LastModifiedTime.ToLocalTime();
            this.StartTime              = job.Properties.StartTime;
            this.Status                 = job.Properties.Status;
            this.StatusDetails          = job.Properties.StatusDetails;
            this.RunbookName            = job.Properties.Runbook.Name;
            this.Exception              = job.Properties.Exception;
            this.EndTime                = job.Properties.EndTime;
            this.LastStatusModifiedTime = job.Properties.LastStatusModifiedTime;
            this.Parameters             = job.Properties.Parameters ?? new Dictionary <string, string>();
        }
Пример #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Job"/> class.
        /// </summary>
        /// <param name="resourceGroupName">
        /// The resource group name.
        /// </param>
        /// <param name="accountName">
        /// The account name.
        /// </param>
        /// <param name="job">
        /// The Job.
        /// </param>
        /// <exception cref="System.ArgumentException">
        /// </exception>
        public Job(string resourceGroupName, string accountName, Azure.Management.Automation.Models.Job job)
        {
            Requires.Argument("job", job).NotNull();
            Requires.Argument("accountName", accountName).NotNull();

            this.ResourceGroupName     = resourceGroupName;
            this.AutomationAccountName = accountName;

            if (job == null)
            {
                return;
            }

            this.JobId                  = job.JobId;
            this.CreationTime           = job.CreationTime.ToLocalTime();
            this.LastModifiedTime       = job.LastModifiedTime.HasValue ? job.LastModifiedTime.Value.ToLocalTime() : new DateTimeOffset();
            this.StartTime              = job.StartTime.HasValue ? job.StartTime.Value.ToLocalTime() : (DateTimeOffset?)null;
            this.Status                 = job.Status;
            this.StatusDetails          = job.StatusDetails;
            this.RunbookName            = job.Runbook.Name;
            this.Exception              = job.Exception;
            this.EndTime                = job.EndTime.HasValue ? job.EndTime.Value.ToLocalTime() : (DateTimeOffset?)null;
            this.LastStatusModifiedTime = job.LastStatusModifiedTime.HasValue ? job.LastStatusModifiedTime.Value.ToLocalTime() : DateTimeOffset.MinValue;
            this.HybridWorker           = job.RunOn;
            this.StartedBy              = job.StartedBy;
            this.JobParameters          = new Hashtable(StringComparer.InvariantCultureIgnoreCase);

            if (job.Parameters != null)
            {
                foreach (var kvp in job.Parameters)
                {
                    if (0 != String.Compare(kvp.Key, Constants.JobStartedByParameterName, CultureInfo.InvariantCulture, CompareOptions.IgnoreCase) &&
                        0 != String.Compare(kvp.Key, Constants.JobRunOnParameterName, CultureInfo.InvariantCulture, CompareOptions.IgnoreCase))
                    {
                        object paramValue;
                        try
                        {
                            paramValue = ((object)PowerShellJsonConverter.Deserialize(kvp.Value));
                        }
                        catch (CmdletInvocationException exception)
                        {
                            if (!exception.Message.Contains("Invalid JSON primitive"))
                            {
                                throw;
                            }

                            paramValue = kvp.Value;
                        }
                        this.JobParameters.Add(kvp.Key, paramValue);
                    }
                }
            }
        }