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

ProcessRecord() protected method

protected ProcessRecord ( ) : void
return void
        protected override void ProcessRecord()
        {            
            string rawJson = string.Empty;
            Experiment exp = Sdk.GetExperimentById(GetWorkspaceSetting(), ExperimentId, out rawJson);
            JavaScriptSerializer jss = new JavaScriptSerializer();
            dynamic graph = jss.Deserialize<object>(rawJson);
            List<GraphNode> nodes = new List<GraphNode>();
            bool foundNode = false;
            bool foundPort = false;
            foreach (var node in graph["NodeStatuses"])
                if (string.Compare(node["NodeId"], NodeId, true) == 0)
                {
                    foundNode = true;                    
                    foreach (var port in node["OutputEndpoints"])
                        if (string.Compare(port["Name"], OutputPortName, true) == 0)
                        {
                            foundPort = true;
                            if (File.Exists(DownloadFileName))
                                throw new Exception(DownloadFileName + " aleady exists.");

                            ProgressRecord pr = new ProgressRecord(1, "Download file", string.Format("Download file \"{0}\" from Azure ML Studio", DownloadFileName));
                            pr.PercentComplete = 1;
                            pr.CurrentOperation = "Downloading...";
                            WriteProgress(pr);

                            string sasUrl = port["BaseUri"] + port["Location"] + port["AccessCredential"];
                            Task task = Sdk.DownloadFileAsync(sasUrl, DownloadFileName);
                            while (!task.IsCompleted)
                            {
                                if (pr.PercentComplete < 100)
                                    pr.PercentComplete++;
                                else
                                    pr.PercentComplete = 1;
                                Thread.Sleep(500);
                                WriteProgress(pr);
                            }
                            pr.PercentComplete = 100;
                            WriteProgress(pr);

                            WriteObject(DownloadFileName + " is downloaded successfully.");
                            return;
                        }
                }
            if (!foundNode)
                throw new Exception("Node not found! Please make sure the node exists, and you have run the experiment at least once.");
            if (!foundPort)
                throw new Exception("Port not found! Please make sure you supplied the correct port name.");
        }
    }
DownloadExperimentNodeOutput