Exemplo n.º 1
0
        protected override void ProcessRecord()
        {
            WriteWarning("Note this Commandlet uses an unsupported API that might break in the future!");
            ProgressRecord pr = new ProgressRecord(1, "Copy from Gallery", "Gallery Experiment");

            pr.PercentComplete  = 1;
            pr.CurrentOperation = "Unpacking experiment from Gallery to workspace...";
            WriteProgress(pr);
            PackingServiceActivity activity = Sdk.UnpackExperimentFromGallery(GetWorkspaceSetting(), PackageUri, GalleryUri, EntityId);

            while (activity.Status != "Complete")
            {
                if (pr.PercentComplete < 100)
                {
                    pr.PercentComplete++;
                }
                else
                {
                    pr.PercentComplete = 1;
                }
                pr.StatusDescription = "Status: " + activity.Status;
                WriteProgress(pr);
                activity = Sdk.GetActivityStatus(GetWorkspaceSetting(), activity.ActivityId, false);
            }
            pr.StatusDescription = "Status: " + activity.Status;
            pr.PercentComplete   = 100;
            WriteProgress(pr);
            WriteObject("Experiment copied from Gallery.");
        }
Exemplo n.º 2
0
        // Note this API is NOT officially supported. It might break in the future and we won't support it if/when it happens.
        public PackingServiceActivity UnpackExperimentFromGallery(WorkspaceSetting setting, string packageUri, string galleryUrl, string entityId)
        {
            ValidateWorkspaceSetting(setting);
            Util.AuthorizationToken = setting.AuthorizationToken;
            string queryUrl = StudioApi + string.Format("workspaces/{0}/packages?api-version=2.0&packageUri={1}&communityUri={2}&entityId={3}", setting.WorkspaceId, HttpUtility.UrlEncode(packageUri), HttpUtility.UrlEncode(galleryUrl), entityId);
            //Console.WriteLine("Upacking from Gallery: PUT " + queryUrl);
            HttpResult hr = Util.HttpPut(setting.AuthorizationToken, queryUrl, string.Empty).Result;

            if (hr.IsSuccess)
            {
                PackingServiceActivity activity = jss.Deserialize <PackingServiceActivity>(hr.Payload);
                return(activity);
            }
            throw new AmlRestApiException(hr);
        }
Exemplo n.º 3
0
        public PackingServiceActivity UnpackExperiment(WorkspaceSetting setting, string packedLocation, string sourceRegion)
        {
            ValidateWorkspaceSetting(setting);
            Util.AuthorizationToken = setting.AuthorizationToken;
            string queryUrl = StudioApi + string.Format("workspaces/{0}/packages?api-version=2.0&packageUri={1}{2}", setting.WorkspaceId, HttpUtility.UrlEncode(packedLocation), "&region=" + sourceRegion.Replace(" ", string.Empty));
            //Console.WriteLine("Unpacking: PUT " + queryUrl);
            HttpResult hr = Util.HttpPut(queryUrl, string.Empty).Result;

            if (hr.IsSuccess)
            {
                PackingServiceActivity activity = jss.Deserialize <PackingServiceActivity>(hr.Payload);
                return(activity);
            }
            throw new AmlRestApiException(hr);
        }
Exemplo n.º 4
0
        public PackingServiceActivity PackExperiment(WorkspaceSetting setting, string experimentId)
        {
            ValidateWorkspaceSetting(setting);
            Util.AuthorizationToken = setting.AuthorizationToken;
            string queryUrl = StudioApi + string.Format("workspaces/{0}/packages?api-version=2.0&experimentid={1}/&clearCredentials=true&includeAuthorId=false", setting.WorkspaceId, experimentId);
            //Console.WriteLine("Packing: POST " + queryUrl);
            HttpResult hr = Util.HttpPost(queryUrl, string.Empty).Result;

            if (hr.IsSuccess)
            {
                PackingServiceActivity activity = jss.Deserialize <PackingServiceActivity>(hr.Payload);
                return(activity);
            }
            throw new AmlRestApiException(hr);
        }
Exemplo n.º 5
0
        public PackingServiceActivity GetActivityStatus(WorkspaceSetting setting, string activityId, bool isPacking)
        {
            ValidateWorkspaceSetting(setting);
            Util.AuthorizationToken = setting.AuthorizationToken;
            string queryUrl = StudioApi + string.Format("workspaces/{0}/packages?{1}ActivityId={2}", setting.WorkspaceId, (isPacking ? "package" : "unpack"), activityId);
            //Console.WriteLine("Getting activity: GET " + queryUrl);
            HttpResult hr = Util.HttpGet(queryUrl, true).Result;

            if (hr.IsSuccess)
            {
                PackingServiceActivity activity = jss.Deserialize <PackingServiceActivity>(hr.Payload);
                return(activity);
            }
            else
            {
                throw new AmlRestApiException(hr);
            }
        }
Exemplo n.º 6
0
        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));
            }
        }