Ejemplo n.º 1
0
        public virtual PSJob CreatePSJob(CreatePSJobParameter parameter)
        {
            if (parameter == null)
            {
                throw new ArgumentNullException("parameter");
            }

            PSJob job = null;

            parameter.ConfirmAction(
                parameter.Force,
                string.Format(
                    CultureInfo.InvariantCulture,
                    Resources.JobExists,
                    parameter.JobName,
                    parameter.ResourceGroupName),
                string.Format(
                    CultureInfo.InvariantCulture,
                    Resources.JobCreating,
                    parameter.JobName,
                    parameter.ResourceGroupName),
                parameter.JobName,
                () =>
            {
                job = CreateOrUpdatePSJob(parameter.ResourceGroupName, parameter.JobName, parameter.RawJsonContent);
            },
                () => CheckJobExists(parameter.ResourceGroupName, parameter.JobName));
            return(job);
        }
 private bool CheckJobExists(string resourceGroupName, string jobName)
 {
     try
     {
         PSJob job = GetJob(resourceGroupName, jobName, string.Empty);
         return(true);
     }
     catch (CloudException e)
     {
         //Get throws Exception message with NotFound Status
         if (e.Response.StatusCode == HttpStatusCode.NotFound)
         {
             return(false);
         }
         else
         {
             throw;
         }
     }
 }
        public virtual PSJob CreatePSJob(CreatePSJobParameter parameter)
        {
            if (parameter == null)
            {
                throw new ArgumentNullException("parameter");
            }

            PSJob  job       = null;
            Action createJob = () =>
            {
                job = CreateOrUpdatePSJob(parameter.ResourceGroupName, parameter.JobName, parameter.RawJsonContent);
            };

            if (parameter.Force)
            {
                // If user decides to overwrite anyway, then there is no need to check if the linked service exists or not.
                createJob();
            }
            else
            {
                bool jobExists = CheckJobExists(parameter.ResourceGroupName, parameter.JobName);

                parameter.ConfirmAction(
                    !jobExists,
                    string.Format(
                        CultureInfo.InvariantCulture,
                        Resources.JobExists,
                        parameter.JobName,
                        parameter.ResourceGroupName),
                    string.Format(
                        CultureInfo.InvariantCulture,
                        Resources.JobCreating,
                        parameter.JobName,
                        parameter.ResourceGroupName),
                    parameter.JobName,
                    createJob);
            }

            return(job);
        }