protected override void ProcessRecord()
{
ProgressRecord pr = new ProgressRecord(1, "Deploy Web Service", "Predictive Experiment Name: ");
pr.CurrentOperation = "Getting Predictive Experiment...";
pr.PercentComplete = 1;
WriteProgress(pr);
string rawJson = string.Empty;
Experiment exp = Sdk.GetExperimentById(GetWorkspaceSetting(), PredictiveExperimentId, out rawJson);
if (exp.Status.StatusCode != "Finished")
{
// if (exp.Status.StatusCode == "InDraft")
// WriteWarning("Experiment is in draft mode. You should run the experiment first before deploying the web service.");
// else
//throw new Exception(string.Format("Experiment status is {0}. Web service cannot be created.", exp.Status.StatusCode));
throw new Exception("Experiment must be in Finished state. The current state is: " + exp.Status.StatusCode);
}
pr.StatusDescription += exp.Description;
pr.CurrentOperation = "Deploying web service";
pr.PercentComplete = 2;
WriteProgress(pr);
WebServiceCreationStatus status = Sdk.DeployWebServiceFromPredictiveExperiment(GetWorkspaceSetting(), PredictiveExperimentId, Update.IsPresent);
while (status.Status != "Completed")
{
if (pr.PercentComplete == 100)
pr.PercentComplete = 1;
pr.PercentComplete++;
WriteProgress(pr);
status = Sdk.GetWebServiceCreationStatus(GetWorkspaceSetting(), status.ActivityId);
}
pr.PercentComplete = 100;
WriteProgress(pr);
WriteObject(Sdk.GetWebServicesById(GetWorkspaceSetting(), status.WebServiceGroupId));
}
}