public override void ExecuteCmdlet()
        {
            NewWorkItemParameters parameters = new NewWorkItemParameters(this.BatchContext, this.Name, this.AdditionalBehaviors)
            {
                Schedule = this.Schedule,
                JobSpecification = this.JobSpecification,
                JobExecutionEnvironment = this.JobExecutionEnvironment,
                Metadata = this.Metadata
            };

            BatchClient.CreateWorkItem(parameters);
        }
Пример #2
0
        /// <summary>
        /// Creates a new WorkItem
        /// </summary>
        /// <param name="parameters">The parameters to use when creating the WorkItem</param>
        public void CreateWorkItem(NewWorkItemParameters parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }
            if (string.IsNullOrWhiteSpace(parameters.WorkItemName))
            {
                throw new ArgumentNullException("WorkItemName");
            }

            using (IWorkItemManager wiManager = parameters.Context.BatchOMClient.OpenWorkItemManager())
            {
                ICloudWorkItem workItem = wiManager.CreateWorkItem(parameters.WorkItemName);

                if (parameters.Schedule != null)
                {
                    workItem.Schedule = parameters.Schedule.omObject;
                }

                if (parameters.JobSpecification != null)
                {
                    Utils.Utils.JobSpecificationSyncCollections(parameters.JobSpecification);
                    workItem.JobSpecification = parameters.JobSpecification.omObject;
                }

                if (parameters.JobExecutionEnvironment != null)
                {
                    Utils.Utils.JobExecutionEnvironmentSyncCollections(parameters.JobExecutionEnvironment);
                    workItem.JobExecutionEnvironment = parameters.JobExecutionEnvironment.omObject;
                }

                if (parameters.Metadata != null)
                {
                    workItem.Metadata = new List <IMetadataItem>();
                    foreach (DictionaryEntry d in parameters.Metadata)
                    {
                        MetadataItem metadata = new MetadataItem(d.Key.ToString(), d.Value.ToString());
                        workItem.Metadata.Add(metadata);
                    }
                }
                WriteVerbose(string.Format(Resources.NBWI_CreatingWorkItem, parameters.WorkItemName));
                workItem.Commit(parameters.AdditionalBehaviors);
            }
        }
        /// <summary>
        /// Creates a new workitem
        /// </summary>
        /// <param name="parameters">The parameters to use when creating the workitem</param>
        public void CreateWorkItem(NewWorkItemParameters parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            using (IWorkItemManager wiManager = parameters.Context.BatchOMClient.OpenWorkItemManager())
            {
                ICloudWorkItem workItem = wiManager.CreateWorkItem(parameters.WorkItemName);

                if (parameters.Schedule != null)
                {
                    workItem.Schedule = parameters.Schedule.omObject;
                }

                if (parameters.JobSpecification != null)
                {
                    Utils.Utils.JobSpecificationSyncCollections(parameters.JobSpecification);
                    workItem.JobSpecification = parameters.JobSpecification.omObject;
                }

                if (parameters.JobExecutionEnvironment != null)
                {
                    Utils.Utils.JobExecutionEnvironmentSyncCollections(parameters.JobExecutionEnvironment);
                    workItem.JobExecutionEnvironment = parameters.JobExecutionEnvironment.omObject;
                }

                if (parameters.Metadata != null)
                {
                    workItem.Metadata = new List<IMetadataItem>();
                    foreach (DictionaryEntry d in parameters.Metadata)
                    {
                        MetadataItem metadata = new MetadataItem(d.Key.ToString(), d.Value.ToString());
                        workItem.Metadata.Add(metadata);
                    }
                }
                WriteVerbose(string.Format(Resources.NBWI_CreatingWorkItem, parameters.WorkItemName));
                workItem.Commit(parameters.AdditionalBehaviors);
            }
        }
        /// <summary>
        /// Creates a test workitem for use in Scenario tests.
        /// </summary>
        public static void CreateTestWorkItem(BatchController controller, BatchAccountContext context, string workItemName, TimeSpan? recurrenceInterval)
        {
            YieldInjectionInterceptor interceptor = CreateHttpRecordingInterceptor();
            BatchClientBehavior[] behaviors = new BatchClientBehavior[] { interceptor };
            BatchClient client = new BatchClient(controller.BatchManagementClient, controller.ResourceManagementClient);

            PSJobExecutionEnvironment jobExecutionEnvironment = new PSJobExecutionEnvironment();
            jobExecutionEnvironment.PoolName = DefaultPoolName;
            PSWorkItemSchedule schedule = null;
            if (recurrenceInterval != null)
            {
                schedule = new PSWorkItemSchedule();
                schedule.RecurrenceInterval = recurrenceInterval;
            }

            NewWorkItemParameters parameters = new NewWorkItemParameters(context, workItemName, behaviors)
            {
                JobExecutionEnvironment = jobExecutionEnvironment,
                Schedule = schedule
            };

            client.CreateWorkItem(parameters);
        }