public override void ExecuteCmdlet()
        {
            if (DegreeOfParallelism < 1)
            {
                WriteWarning(Resources.InvalidDegreeOfParallelism);
            }

            // error handling for not passing or passing both script and script path
            if ((string.IsNullOrEmpty(Script) && string.IsNullOrEmpty(ScriptPath)) ||
                (!string.IsNullOrEmpty(Script) && !string.IsNullOrEmpty(ScriptPath)))
            {
                throw new CloudException(Resources.AmbiguousScriptParameter);
            }

            // get the script
            if (string.IsNullOrEmpty(Script))
            {
                var powerShellDestinationPath = SessionState.Path.GetUnresolvedProviderPathFromPSPath(ScriptPath);
                if (!File.Exists(powerShellDestinationPath))
                {
                    throw new CloudException(string.Format(Resources.ScriptFilePathDoesNotExist,
                                                           powerShellDestinationPath));
                }

                Script = File.ReadAllText(powerShellDestinationPath);
            }

            JobType       jobType;
            JobProperties properties;

            if (USql)
            {
                jobType = JobType.USql;
                var sqlIpProperties = new USqlJobProperties
                {
                    Script = Script
                };

                if (!string.IsNullOrEmpty(CompileMode))
                {
                    CompileMode toUse;
                    if (Enum.TryParse(CompileMode, out toUse))
                    {
                        sqlIpProperties.CompileMode = toUse;
                    }
                }

                if (!string.IsNullOrEmpty(Runtime))
                {
                    sqlIpProperties.RuntimeVersion = Runtime;
                }

                properties = sqlIpProperties;
            }
            else
            {
                throw new CloudException(Resources.InvalidJobType);
            }

            var jobInfo = new JobInformation
                          (
                jobId: DataLakeAnalyticsClient.JobIdQueue.Count == 0 ? Guid.NewGuid() : DataLakeAnalyticsClient.JobIdQueue.Dequeue(),
                name: Name,
                properties: properties,
                type: jobType,
                degreeOfParallelism: DegreeOfParallelism,
                priority: Priority
                          );

            if (ParameterSetName.Equals(USqlJobParameterSetNameAndRecurrence) ||
                ParameterSetName.Equals(USqlJobParameterSetNameAndPipeline) ||
                ParameterSetName.Equals(USqlJobWithScriptPathAndRecurrence) ||
                ParameterSetName.Equals(USqlJobWithScriptPathAndPipeline))
            {
                jobInfo.Related = new JobRelationshipProperties
                {
                    RecurrenceId   = RecurrenceId,
                    RecurrenceName = RecurrenceName
                };

                if (ParameterSetName.Equals(USqlJobParameterSetNameAndPipeline) ||
                    ParameterSetName.Equals(USqlJobWithScriptPathAndPipeline))
                {
                    jobInfo.Related.PipelineId   = PipelineId;
                    jobInfo.Related.PipelineName = PipelineName;
                    jobInfo.Related.PipelineUri  = PipelineUri;
                    jobInfo.Related.RunId        = RunId;
                }
            }

            WriteObject(CompileOnly
                ? DataLakeAnalyticsClient.BuildJob(Account, jobInfo)
                : DataLakeAnalyticsClient.SubmitJob(Account, jobInfo));
        }
        public override void ExecuteCmdlet()
        {
            // error handling for not passing or passing both script and script path
            if ((string.IsNullOrEmpty(Script) && string.IsNullOrEmpty(ScriptPath)) ||
                (!string.IsNullOrEmpty(Script) && !string.IsNullOrEmpty(ScriptPath)))
            {
                throw new CloudException(Resources.AmbiguousScriptParameter);
            }

            // get the script
            if (string.IsNullOrEmpty(Script))
            {
                var powerShellDestinationPath = SessionState.Path.GetUnresolvedProviderPathFromPSPath(ScriptPath);
                if (!File.Exists(powerShellDestinationPath))
                {
                    throw new CloudException(string.Format(Resources.ScriptFilePathDoesNotExist,
                                                           powerShellDestinationPath));
                }

                Script = File.ReadAllText(powerShellDestinationPath);
            }

            JobType       jobType;
            JobProperties properties;

            if (USql)
            {
                jobType = JobType.USql;
                var sqlIpProperties = new USqlJobProperties
                {
                    Script = Script
                };

                if (!string.IsNullOrEmpty(CompileMode))
                {
                    CompileMode toUse;
                    if (Enum.TryParse(CompileMode, out toUse))
                    {
                        sqlIpProperties.CompileMode = toUse;
                    }
                }

                if (!string.IsNullOrEmpty(Runtime))
                {
                    sqlIpProperties.RuntimeVersion = Runtime;
                }

                properties = sqlIpProperties;
            }
            else if (Hive)
            {
                jobType    = JobType.Hive;
                properties = new HiveJobProperties
                {
                    Script = Script
                };
            }
            else
            {
                throw new CloudException(Resources.InvalidJobType);
            }

            var jobInfo = new JobInformation
            {
                JobId               = Guid.NewGuid(),
                Name                = Name,
                Properties          = properties,
                Type                = jobType,
                DegreeOfParallelism = DegreeOfParallelism,
                Priority            = Priority
            };

            WriteObject(CompileOnly
                ? DataLakeAnalyticsClient.BuildJob(Account, jobInfo)
                : DataLakeAnalyticsClient.SubmitJob(Account, jobInfo));
        }
        public override void ExecuteCmdlet()
        {
            if (AnalyticsUnits < 1)
            {
                WriteWarning(Resources.InvalidAnalyticsUnits);
            }

            // Error handling for not passing or passing both script and script path
            if ((string.IsNullOrEmpty(Script) && string.IsNullOrEmpty(ScriptPath)) ||
                (!string.IsNullOrEmpty(Script) && !string.IsNullOrEmpty(ScriptPath)))
            {
                throw new CloudException(Resources.AmbiguousScriptParameter);
            }

            // Get the script
            if (string.IsNullOrEmpty(Script))
            {
                var powerShellDestinationPath = SessionState.Path.GetUnresolvedProviderPathFromPSPath(ScriptPath);
                if (!File.Exists(powerShellDestinationPath))
                {
                    throw new CloudException(string.Format(Resources.ScriptFilePathDoesNotExist,
                                                           powerShellDestinationPath));
                }

                Script = File.ReadAllText(powerShellDestinationPath);
            }

            // Check for script parameters
            if (ScriptParameter != null)
            {
                StringBuilder paramBuilder = new StringBuilder();
                string        paramVar     = null;
                string        paramValue   = null;
                Type          paramType    = null;

                // Build the parameter string in order to prepend it to the script
                foreach (DictionaryEntry param in ScriptParameter)
                {
                    if (param.Value == null)
                    {
                        throw new CloudException(string.Format(Resources.ScriptParameterValueIsNull,
                                                               param.Key.ToString()));
                    }

                    paramVar   = param.Key.ToString();
                    paramValue = param.Value.ToString();
                    paramType  = param.Value.GetType();

                    if (paramType.Equals(typeof(byte)))
                    {
                        paramBuilder.Append(string.Format("DECLARE @{0} byte = {1};\n",
                                                          paramVar,
                                                          paramValue));
                    }
                    else if (paramType.Equals(typeof(sbyte)))
                    {
                        paramBuilder.Append(string.Format("DECLARE @{0} sbyte = {1};\n",
                                                          paramVar,
                                                          paramValue));
                    }
                    else if (paramType.Equals(typeof(int)))
                    {
                        paramBuilder.Append(string.Format("DECLARE @{0} int = {1};\n",
                                                          paramVar,
                                                          paramValue));
                    }
                    else if (paramType.Equals(typeof(uint)))
                    {
                        paramBuilder.Append(string.Format("DECLARE @{0} uint = {1};\n",
                                                          paramVar,
                                                          paramValue));
                    }
                    else if (paramType.Equals(typeof(long)))
                    {
                        paramBuilder.Append(string.Format("DECLARE @{0} long = {1};\n",
                                                          paramVar,
                                                          paramValue));
                    }
                    else if (paramType.Equals(typeof(ulong)))
                    {
                        paramBuilder.Append(string.Format("DECLARE @{0} ulong = {1};\n",
                                                          paramVar,
                                                          paramValue));
                    }
                    else if (paramType.Equals(typeof(float)))
                    {
                        paramBuilder.Append(string.Format("DECLARE @{0} float = {1};\n",
                                                          paramVar,
                                                          paramValue));
                    }
                    else if (paramType.Equals(typeof(double)))
                    {
                        paramBuilder.Append(string.Format("DECLARE @{0} double = {1};\n",
                                                          paramVar,
                                                          paramValue));
                    }
                    else if (paramType.Equals(typeof(decimal)))
                    {
                        paramBuilder.Append(string.Format("DECLARE @{0} decimal = {1};\n",
                                                          paramVar,
                                                          paramValue));
                    }
                    else if (paramType.Equals(typeof(short)))
                    {
                        paramBuilder.Append(string.Format("DECLARE @{0} short = {1};\n",
                                                          paramVar,
                                                          paramValue));
                    }
                    else if (paramType.Equals(typeof(ushort)))
                    {
                        paramBuilder.Append(string.Format("DECLARE @{0} ushort = {1};\n",
                                                          paramVar,
                                                          paramValue));
                    }
                    else if (paramType.Equals(typeof(char)))
                    {
                        paramBuilder.Append(string.Format("DECLARE @{0} char = '{1}';\n",
                                                          paramVar,
                                                          paramValue));
                    }
                    else if (paramType.Equals(typeof(string)))
                    {
                        paramBuilder.Append(string.Format("DECLARE @{0} string = \"{1}\";\n",
                                                          paramVar,
                                                          paramValue));
                    }
                    else if (paramType.Equals(typeof(DateTime)))
                    {
                        DateTime datetime = (DateTime)param.Value;

                        paramBuilder.Append(string.Format("DECLARE @{0} DateTime = new DateTime({1}, {2}, {3}, {4}, {5}, {6}, {7});\n",
                                                          paramVar,
                                                          datetime.Year,
                                                          datetime.Month,
                                                          datetime.Day,
                                                          datetime.Hour,
                                                          datetime.Minute,
                                                          datetime.Second,
                                                          datetime.Millisecond));
                    }
                    else if (paramType.Equals(typeof(bool)))
                    {
                        if ((bool)param.Value)
                        {
                            paramBuilder.Append(string.Format("DECLARE @{0} bool = true;\n", paramVar));
                        }
                        else
                        {
                            paramBuilder.Append(string.Format("DECLARE @{0} bool = false;\n", paramVar));
                        }
                    }
                    else if (paramType.Equals(typeof(Guid)))
                    {
                        paramBuilder.Append(string.Format("DECLARE @{0} Guid = new Guid(\"{1}\");\n",
                                                          paramVar,
                                                          paramValue));
                    }
                    else if (paramType.Equals(typeof(byte[])))
                    {
                        StringBuilder byteArrayBuilder = new StringBuilder(string.Format("DECLARE @{0} byte[] = new byte[] {{", paramVar));
                        byte[]        byteArray        = (byte[])param.Value;

                        if (byteArray.Length > 0)
                        {
                            foreach (byte b in byteArray)
                            {
                                byteArrayBuilder.Append(string.Format("\n  {0},", b.ToString()));
                            }

                            byteArrayBuilder.Append("\n};\n");
                        }
                        else
                        {
                            byteArrayBuilder.Append(" };\n");
                        }

                        paramBuilder.Append(byteArrayBuilder.ToString());
                    }
                    else
                    {
                        throw new CloudException(string.Format(Resources.InvalidScriptParameterType,
                                                               paramType.ToString()));
                    }
                }

                Script = Script.Insert(0, paramBuilder.ToString());
            }

            JobType             jobType;
            CreateJobProperties properties;

            if (USql)
            {
                jobType = JobType.USql;
                var sqlIpProperties = new CreateUSqlJobProperties
                {
                    Script = Script
                };

                if (!string.IsNullOrEmpty(CompileMode))
                {
                    CompileMode toUse;
                    if (Enum.TryParse(CompileMode, out toUse))
                    {
                        sqlIpProperties.CompileMode = toUse;
                    }
                }

                if (!string.IsNullOrEmpty(Runtime))
                {
                    sqlIpProperties.RuntimeVersion = Runtime;
                }

                properties = sqlIpProperties;
            }
            else
            {
                throw new CloudException(Resources.InvalidJobType);
            }

            if (CompileOnly)
            {
                var buildJobParameters = new BuildJobParameters
                {
                    Type       = jobType,
                    Name       = Name,
                    Properties = properties
                };

                WriteObject(DataLakeAnalyticsClient.BuildJob(Account, buildJobParameters));
            }
            else
            {
                var jobId = DataLakeAnalyticsClient.JobIdQueue.Count == 0 ? Guid.NewGuid() : DataLakeAnalyticsClient.JobIdQueue.Dequeue();

                var createJobParameters = new CreateJobParameters
                {
                    Type = jobType,
                    Name = Name,
                    DegreeOfParallelism = AnalyticsUnits,
                    Priority            = Priority,
                    Properties          = properties,
                };

                if (ParameterSetName.Equals(USqlJobParameterSetNameAndRecurrence) ||
                    ParameterSetName.Equals(USqlJobParameterSetNameAndPipeline) ||
                    ParameterSetName.Equals(USqlJobWithScriptPathAndRecurrence) ||
                    ParameterSetName.Equals(USqlJobWithScriptPathAndPipeline))
                {
                    createJobParameters.Related = new JobRelationshipProperties
                    {
                        RecurrenceId   = RecurrenceId,
                        RecurrenceName = RecurrenceName
                    };

                    if (ParameterSetName.Equals(USqlJobParameterSetNameAndPipeline) ||
                        ParameterSetName.Equals(USqlJobWithScriptPathAndPipeline))
                    {
                        createJobParameters.Related.PipelineId   = PipelineId;
                        createJobParameters.Related.PipelineName = PipelineName;
                        createJobParameters.Related.PipelineUri  = PipelineUri;
                        createJobParameters.Related.RunId        = RunId;
                    }
                }

                WriteObject(DataLakeAnalyticsClient.SubmitJob(Account, jobId, createJobParameters));
            }
        }