示例#1
0
        public override void ExecuteCmdlet()
        {
            if (taskCmdlet != null)
            {
                if (ShouldProcess(this.Name, Resources.createTask))
                {
                    if (this.ParameterSetName.Equals(ComponentObjectParameterSet))
                    {
                        this.ResourceGroupName = InputObject.ResourceGroupName;
                        this.ServiceName       = InputObject.Name;
                    }

                    if (this.ParameterSetName.Equals(ResourceIdParameterSet))
                    {
                        DmsResourceIdentifier ids = new DmsResourceIdentifier(this.ResourceId);
                        this.ResourceGroupName = ids.ResourceGroupName;
                        this.ServiceName       = ids.ServiceName;
                    }

                    ProjectTask response = null;
                    try
                    {
                        ProjectTaskProperties properties = taskCmdlet.ProcessTaskCmdlet();
                        var         utcStartedOn         = System.DateTime.UtcNow;
                        ProjectTask taskInput            = new ProjectTask {
                            Properties = properties
                        };

                        response = DataMigrationClient.ServiceTasks.CreateOrUpdate(taskInput, ResourceGroupName, ServiceName, Name);

                        // wait for the task to finish: not queued or running state:
                        while (this.Wait.IsPresent && response != null && response.Properties != null &&
                               (response.Properties.State == "Queued" || response.Properties.State == "Running"))
                        {
                            System.Threading.Thread.Sleep(System.TimeSpan.FromSeconds(TaskWaitSleepIntervalInSeconds));
                            WriteVerbose($"{response.Id} {response.Name} {response.Properties.State} Elapsed: {System.DateTime.UtcNow - utcStartedOn}");
                            response = DataMigrationClient.ServiceTasks.Get(ResourceGroupName, ServiceName, Name, this.expandParameterOfTask);
                        }
                    }
                    catch (ApiErrorException ex)
                    {
                        ThrowAppropriateException(ex);
                    }

                    WriteObject(new PSProjectTask(response));
                }
            }
            else
            {
                throw new PSArgumentException("Invalid Argument List");
            }
        }
        public override void ExecuteCmdlet()
        {
            if (taskCmdlet != null)
            {
                if (ShouldProcess(this.Name, Resources.createTask))
                {
                    if (this.ParameterSetName.Equals(ComponentObjectParameterSet))
                    {
                        this.ResourceGroupName = InputObject.ResourceGroupName;
                        this.ServiceName       = InputObject.ServiceName;
                        this.ProjectName       = InputObject.Name;
                    }

                    if (this.ParameterSetName.Equals(ResourceIdParameterSet))
                    {
                        DmsResourceIdentifier ids = new DmsResourceIdentifier(this.ResourceId);
                        this.ResourceGroupName = ids.ResourceGroupName;
                        this.ServiceName       = ids.ServiceName;
                        this.ProjectName       = ids.ProjectName;
                    }

                    ProjectTask response = null;
                    try
                    {
                        ProjectTaskProperties properties = taskCmdlet.ProcessTaskCmdlet();

                        var utcStartedOn = System.DateTime.UtcNow;
                        // need swagger of -pr line 64 of tasks.json add.
                        // uncomment the following line once we get new sdk.
                        // give all tasks a start time, so that portal can calculate how long it is running.
                        // properties.ClientData.Add("startedOn", utcStartedOn.ToString("o"));

                        ProjectTask taskInput = new ProjectTask()
                        {
                            Properties = properties
                        };

                        response = DataMigrationClient.Tasks.CreateOrUpdate(taskInput, ResourceGroupName, ServiceName, ProjectName, Name);

                        // wait for the task to finish: not queued or running state:
                        while (this.Wait.IsPresent && response != null && response.Properties != null &&
                               (response.Properties.State == "Queued" || response.Properties.State == "Running"))
                        {
                            System.Threading.Thread.Sleep(System.TimeSpan.FromSeconds(TaskWaitSleepIntervalInSeconds));
                            WriteVerbose($"{taskInput.Id} {taskInput.Name} {taskInput.Properties.State} Elapsed: {System.DateTime.UtcNow - utcStartedOn}");
                            response = DataMigrationClient.Tasks.Get(ResourceGroupName, ServiceName, ProjectName, Name, this.expandParameterOfTask);
                        }
                    }
                    catch (ApiErrorException ex)
                    {
                        ThrowAppropriateException(ex);
                    }

                    WriteObject(new PSProjectTask(response));
                }
            }
            else
            {
                throw new PSArgumentException("Invalid Argument List");
            }
        }