AzureML.PowerShell.CopyExperiment.ProcessRecord C# (CSharp) Method

ProcessRecord() protected method

protected ProcessRecord ( ) : void
return void
        protected override void ProcessRecord()
        {
            WorkspaceSetting sourceWSSetting = GetWorkspaceSetting();

            if (string.IsNullOrEmpty(DestinationWorkspaceId) || sourceWSSetting.WorkspaceId.ToLower() == DestinationWorkspaceId.ToLower())
            {
                // copying in the same workspace
                ProgressRecord pr = new ProgressRecord(1, "Copy Experiment", "Experiment Name:");
                pr.CurrentOperation = "Getting experiment...";
                pr.PercentComplete = 1;
                WriteProgress(pr);

                string rawJson = string.Empty;
                Experiment exp = Sdk.GetExperimentById(sourceWSSetting, ExperimentId, out rawJson);

                pr.StatusDescription = "Experiment Name: " + exp.Description;
                pr.CurrentOperation = "Copying...";
                pr.PercentComplete = 2;
                WriteProgress(pr);
                Sdk.SaveExperimentAs(sourceWSSetting, exp, rawJson, NewExperimentName);
                pr.PercentComplete = 100;
                WriteProgress(pr);
                WriteObject("A copy of experiment \"" + exp.Description + "\"is created in the current workspace.");
            }
            else
            {
                if (!string.IsNullOrEmpty(NewExperimentName))
                    WriteWarning("New name is ignored when copying Experiment across Workspaces.");

                // if no destination location is set, use the one the current workspace is in.
                if (string.IsNullOrEmpty(DestinationLocation))
                    DestinationLocation = sourceWSSetting.Location;

                var destWSSetting = GetWorkspaceSetting(DestinationLocation, DestinationWorkspaceId, DestinationWorkspaceAuthorizationToken);

                var sourceWS = Sdk.GetWorkspaceFromAmlRP(sourceWSSetting);
                var destWS = Sdk.GetWorkspaceFromAmlRP(destWSSetting);

                // copying across workspaces
                ProgressRecord pr = new ProgressRecord(1, "Copy Experiment", "Experiment Name:");
                pr.CurrentOperation = "Getting experiment...";
                pr.PercentComplete = 1;
                WriteProgress(pr);

                string rawJson = string.Empty;
                Experiment exp = Sdk.GetExperimentById(sourceWSSetting, ExperimentId, out rawJson);

                pr.StatusDescription = "Experiment Name: " + exp.Description;
                pr.CurrentOperation = "Packing experiment from source workspace to storage...";
                pr.PercentComplete = 2;
                WriteProgress(pr);
                PackingServiceActivity activity = Sdk.PackExperiment(sourceWSSetting, ExperimentId);

                pr.CurrentOperation = "Packing experiment from source workspace to storage...";
                pr.PercentComplete = 3;
                WriteProgress(pr);
                activity = Sdk.GetActivityStatus(sourceWSSetting, activity.ActivityId, true);
                while (activity.Status != "Complete")
                {
                    if (pr.PercentComplete < 100)
                        pr.PercentComplete++;
                    else
                        pr.PercentComplete = 1;
                    WriteProgress(pr);
                    activity = Sdk.GetActivityStatus(sourceWSSetting, activity.ActivityId, true);
                }

                pr.CurrentOperation = "Unpacking experiment from storage to destination workspace...";
                if (pr.PercentComplete < 100)
                    pr.PercentComplete++;
                else
                    pr.PercentComplete = 1;
                WriteProgress(pr);

                activity = Sdk.UnpackExperiment(destWSSetting, activity.Location, Location);
                while (activity.Status != "Complete")
                {
                    if (pr.PercentComplete < 100)
                        pr.PercentComplete++;
                    else
                        pr.PercentComplete = 1;
                    WriteProgress(pr);
                    activity = Sdk.GetActivityStatus(destWSSetting, activity.ActivityId, false);
                }
                pr.PercentComplete = 100;
                WriteProgress(pr);
                WriteObject(string.Format("Experiment \"{0}\" has been successfully copied from workspace \"{1}\" to \"{2}\".", exp.Description, sourceWS.FriendlyName, destWS.FriendlyName));
            }
        }
    }
CopyExperiment