/// <summary>
        /// Initializes a new instance of the <see cref="JobStreamRecord"/> class.
        /// </summary>
        /// <param name="jobStream">
        /// The job stream.
        /// </param>
        /// <param name="resourceGroupName">
        /// The resource group name.
        /// </param>
        /// <param name="automationAccountName">
        /// The automation account name
        /// </param>
        /// <param name="jobId">
        /// The job Id
        /// </param>
        /// <exception cref="System.ArgumentException">
        /// </exception>
        public JobStreamRecord(AutomationManagement.Models.JobStream jobStream, string resourceGroupName, string automationAccountName, Guid jobId) : base(jobStream, resourceGroupName, automationAccountName, jobId)
        {
            this.Value = new Hashtable();

            if (jobStream.Value == null)
            {
                return;
            }

            foreach (var kvp in jobStream.Value)
            {
                if (kvp.Value != null)
                {
                    object paramValue;
                    try
                    {
                        paramValue = ((object)PowerShellJsonConverter.Deserialize(kvp.Value.ToString()));
                    }
                    catch (CmdletInvocationException exception)
                    {
                        if (!exception.Message.Contains("Invalid JSON primitive"))
                        {
                            throw;
                        }

                        paramValue = kvp.Value;
                    }
                    this.Value.Add(kvp.Key, paramValue);
                }
            }
        }
Beispiel #2
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));
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SourceControlSyncJobStreamRecord"/> class.
        /// </summary>
        /// <param name="SourceControlSyncJobStreamRecord">
        /// The source control job stream.
        /// </param>
        /// <param name="resourceGroupName">
        /// The resource group name.
        /// </param>
        /// <param name="automationAccountName">
        /// The automation account name.
        /// </param>
        /// <param name="sourceControlName">
        /// The source control name.
        /// </param>
        /// <param name="sourceControlSyncJobId">
        /// The job Id.
        /// </param>
        /// <exception cref="System.ArgumentException">
        /// </exception>
        public SourceControlSyncJobStreamRecord(
            AutomationManagement.Models.SourceControlSyncJobStreamById syncJobStream,
            string resourceGroupName,
            string automationAccountName,
            string sourceControlName,
            Guid sourceControlSyncJobId) : base()
        {
            Requires.Argument("syncJobStream", syncJobStream).NotNull();
            Requires.Argument("resourceGroupName", resourceGroupName).NotNullOrEmpty();
            Requires.Argument("accountName", automationAccountName).NotNullOrEmpty();
            Requires.Argument("sourceControlName", sourceControlName).NotNull();
            Requires.Argument("sourceControlSyncJobId", sourceControlSyncJobId).NotNull();

            this.AutomationAccountName        = automationAccountName;
            this.ResourceGroupName            = resourceGroupName;
            this.SourceControlName            = sourceControlName;
            this.SourceControlSyncJobId       = sourceControlSyncJobId;
            this.SourceControlSyncJobStreamId = syncJobStream.SourceControlSyncJobStreamId;
            this.Type = syncJobStream.StreamType;
            this.Time = syncJobStream.Time.HasValue ? syncJobStream.Time.Value.ToLocalTime() : (DateTimeOffset?)null;

            if (!String.IsNullOrWhiteSpace(syncJobStream.Summary))
            {
                this.Summary = syncJobStream.Summary;
            }

            if (!String.IsNullOrWhiteSpace(syncJobStream.StreamText))
            {
                this.StreamText = syncJobStream.StreamText;
            }

            if (syncJobStream.Value != null)
            {
                this.Value = new Hashtable();
                foreach (var kvp in syncJobStream.Value)
                {
                    object paramValue;
                    try
                    {
                        paramValue = ((object)PowerShellJsonConverter.Deserialize(kvp.Value.ToString()));
                    }
                    catch (CmdletInvocationException exception)
                    {
                        if (!exception.Message.Contains("Invalid JSON primitive"))
                        {
                            throw;
                        }

                        paramValue = kvp.Value;
                    }
                    this.Value.Add(kvp.Key, paramValue);
                }
            }
        }
Beispiel #4
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);
                    }
                }
            }
        }
Beispiel #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="JobSchedule"/> class.
 /// </summary>
 /// <param name="jobSchedule">
 /// The job schedule.
 /// </param>
 public JobSchedule(string automationAccountName, WindowsAzure.Management.Automation.Models.JobSchedule jobSchedule)
 {
     Requires.Argument("jobSchedule", jobSchedule).NotNull();
     this.AutomationAccountName = automationAccountName;
     this.JobScheduleId         = jobSchedule.Properties.Id;
     this.RunbookName           = jobSchedule.Properties.Runbook.Name;
     this.ScheduleName          = jobSchedule.Properties.Schedule.Name;
     this.Parameters            = new Hashtable(StringComparer.InvariantCultureIgnoreCase);
     foreach (var kvp in jobSchedule.Properties.Parameters.Where(kvp => 0 != String.Compare(kvp.Key, Constants.JobStartedByParameterName, CultureInfo.InvariantCulture,
                                                                                            CompareOptions.IgnoreCase)))
     {
         this.Parameters.Add(kvp.Key, (object)PowerShellJsonConverter.Deserialize(kvp.Value));
     }
 }
Beispiel #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="JobSchedule"/> class.
 /// </summary>
 /// <param name="resourceGroupName">
 /// The resource group name.
 /// </param>
 /// <param name="automationAccountName">
 /// The account name.
 /// </param>
 /// <param name="jobSchedule">
 /// The job schedule.
 /// </param>
 public JobSchedule(string resourceGroupName, string automationAccountName, Azure.Management.Automation.Models.JobSchedule jobSchedule)
 {
     Requires.Argument("jobSchedule", jobSchedule).NotNull();
     this.ResourceGroupName     = resourceGroupName;
     this.AutomationAccountName = automationAccountName;
     this.JobScheduleId         = jobSchedule.JobScheduleId.ToString();
     this.RunbookName           = jobSchedule.Runbook.Name;
     this.ScheduleName          = jobSchedule.Schedule.Name;
     this.Parameters            = new Hashtable(StringComparer.InvariantCultureIgnoreCase);
     this.HybridWorker          = jobSchedule.RunOn;
     if (jobSchedule.Parameters != null)
     {
         foreach (var kvp in jobSchedule.Parameters.Where(kvp => 0 != String.Compare(kvp.Key, Constants.JobStartedByParameterName, CultureInfo.InvariantCulture,
                                                                                     CompareOptions.IgnoreCase)))
         {
             this.Parameters.Add(kvp.Key, (object)PowerShellJsonConverter.Deserialize(kvp.Value));
         }
     }
 }
Beispiel #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Module"/> class.
        /// </summary>
        /// <param name="resourceGroupName">
        /// The resource group name.
        /// </param>
        /// <param name="automationAccountName">
        /// The account name.
        /// </param>
        /// <param name="webhook">
        /// The Webhook.
        /// </param>
        /// <param name="webhookUri">
        /// The Webhook URI
        /// </param>
        public Webhook(
            string resourceGroupName,
            string automationAccountName,
            Azure.Management.Automation.Models.Webhook webhook,
            string webhookUri = "")
        {
            Requires.Argument("resourceGroupName", resourceGroupName).NotNull();
            Requires.Argument("automationAccountName", automationAccountName).NotNull();
            Requires.Argument("webhook", webhook).NotNull();

            this.ResourceGroupName     = resourceGroupName;
            this.AutomationAccountName = automationAccountName;
            this.Name = webhook.Name;

            if (webhook == null)
            {
                return;
            }

            this.CreationTime = webhook.CreationTime.ToLocalTime();
            this.Description  = webhook.Description;
            this.ExpiryTime   = webhook.ExpiryTime.ToLocalTime();
            this.IsEnabled    = webhook.IsEnabled;
            if (webhook.LastInvokedTime.HasValue)
            {
                this.LastInvokedTime = webhook.LastInvokedTime.Value.ToLocalTime();
            }

            this.LastModifiedTime = webhook.LastModifiedTime.ToLocalTime();
            this.Parameters       = new Hashtable(StringComparer.InvariantCultureIgnoreCase);
            if (webhook.Parameters != null)
            {
                foreach (var kvp in webhook.Parameters)
                {
                    this.Parameters.Add(kvp.Key, (object)PowerShellJsonConverter.Deserialize(kvp.Value));
                }
            }

            this.RunbookName  = webhook.Runbook.Name;
            this.WebhookURI   = webhookUri;
            this.HybridWorker = webhook.RunOn;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="Variable"/> class.
        /// </summary>
        /// <param name="variable">
        /// The varaiable.
        /// </param>
        /// <exception cref="System.ArgumentException">
        /// </exception>
        public Variable(AutomationManagement.Models.Variable variable, string automationAccoutName)
        {
            Requires.Argument("variable", variable).NotNull();

            this.Name             = variable.Name;
            this.CreationTime     = variable.Properties.CreationTime.ToLocalTime();
            this.LastModifiedTime = variable.Properties.LastModifiedTime.ToLocalTime();

            if (variable.Properties.Value == null || variable.Properties.IsEncrypted)
            {
                this.Value = null;
            }
            else
            {
                this.Value = PowerShellJsonConverter.Deserialize(variable.Properties.Value);
            }

            this.Description           = variable.Properties.Description;
            this.Encrypted             = variable.Properties.IsEncrypted;
            this.AutomationAccountName = automationAccoutName;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="Connection"/> class.
        /// </summary>
        /// <param name="accountAcccountName">
        /// The account name.
        /// </param>
        /// <param name="connection">
        /// The connection.
        /// </param>
        /// <exception cref="System.ArgumentException">
        /// </exception>
        public Connection(string accountAcccountName, WindowsAzure.Management.Automation.Models.Connection connection)
        {
            Requires.Argument("connection", connection).NotNull();
            this.AutomationAccountName = accountAcccountName;
            this.Name = connection.Name;

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

            this.Description           = connection.Properties.Description;
            this.CreationTime          = connection.Properties.CreationTime.ToLocalTime();
            this.LastModifiedTime      = connection.Properties.LastModifiedTime.ToLocalTime();
            this.ConnectionTypeName    = connection.Properties.ConnectionType.Name;
            this.FieldDefinitionValues = new Hashtable(StringComparer.InvariantCultureIgnoreCase);
            foreach (var kvp in connection.Properties.FieldDefinitionValues)
            {
                this.FieldDefinitionValues.Add(kvp.Key, (object)PowerShellJsonConverter.Deserialize(kvp.Value));
            }
        }
Beispiel #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Variable"/> class.
        /// </summary>
        /// <param name="variable">
        /// The varaiable.
        /// </param>
        /// <param name="automationAccoutName">
        /// The automation account name.
        /// </param>
        /// <param name="resourceGroupName">
        /// The resource group name.
        /// </param>
        /// <exception cref="System.ArgumentException">
        /// </exception>
        public Variable(AutomationManagement.Models.Variable variable, string automationAccoutName, string resourceGroupName)
        {
            Requires.Argument("variable", variable).NotNull();

            this.ResourceGroupName = resourceGroupName;
            this.Name             = variable.Name;
            this.CreationTime     = variable.CreationTime.ToLocalTime();
            this.LastModifiedTime = variable.LastModifiedTime.ToLocalTime();

            if (variable.Value == null || (variable.IsEncrypted.HasValue && variable.IsEncrypted.Value))
            {
                this.Value = null;
            }
            else
            {
                this.Value = PowerShellJsonConverter.Deserialize(variable.Value);
            }

            this.Description           = variable.Description;
            this.Encrypted             = variable.IsEncrypted ?? false;
            this.AutomationAccountName = automationAccoutName;
        }