Beispiel #1
0
 protected WorkspaceSetting GetWorkspaceSetting()
 {
     WorkspaceSetting setting = new WorkspaceSetting
     {
         WorkspaceId = WorkspaceId,
         AuthorizationToken = AuthorizationToken,
         Location = Location
     };
     return setting;
 }                                           
Beispiel #2
0
 private void ValidateWorkspaceSetting(WorkspaceSetting setting)
 {
     if (setting.Location == null || setting.Location == string.Empty)
         throw new ArgumentException("No Location specified.");
     if (setting.WorkspaceId == null || setting.WorkspaceId == string.Empty)
         throw new ArgumentException("No Workspace Id specified.");
     if (setting.AuthorizationToken == null || setting.AuthorizationToken == string.Empty)
         throw new ArgumentException("No Authorization Token specified.");
     SetApiUrl(setting.Location);
 }
Beispiel #3
0
 public string UploadResource(WorkspaceSetting setting, string fileFormat)
 {
     ValidateWorkspaceSetting(setting);
     Util.AuthorizationToken = setting.AuthorizationToken;
     string query = StudioApi + string.Format("resourceuploads/workspaces/{0}/?userStorage=true&dataTypeId={1}", setting.WorkspaceId, fileFormat);
     HttpResult hr = Util.HttpPost(query, string.Empty).Result;
     if (!hr.IsSuccess)
         throw new AmlRestApiException(hr);
     return hr.Payload;
 }
Beispiel #4
0
 public void PatchWebServiceEndpoint(WorkspaceSetting setting, string webServiceId, string endpointName, dynamic patchReq)
 {
     ValidateWorkspaceSetting(setting);
     Util.AuthorizationToken = setting.AuthorizationToken;            
     string body = jss.Serialize(patchReq);
     string url = WebServiceApi + string.Format("workspaces/{0}/webservices/{1}/endpoints/{2}", setting.WorkspaceId, webServiceId, endpointName);
     HttpResult hr = Util.HttpPatch(url, body).Result;
     if (!hr.IsSuccess)
         throw new AmlRestApiException(hr);
 }
Beispiel #5
0
 public void AddWebServiceEndpoint(WorkspaceSetting setting, AddWebServiceEndpointRequest req)
 {
     ValidateWorkspaceSetting(setting);
     Util.AuthorizationToken = setting.AuthorizationToken;
     string queryUrl = WebServiceApi + string.Format("workspaces/{0}/webservices/{1}/endpoints/{2}", setting.WorkspaceId, req.WebServiceId, req.EndpointName);            
     string body = jss.Serialize(req);
     HttpResult hr = Util.HttpPut(queryUrl, body).Result;
     if (!hr.IsSuccess)
         throw new AmlRestApiException(hr);
 }
Beispiel #6
0
 public WebServiceCreationStatus GetWebServiceCreationStatus(WorkspaceSetting setting, string activityId)
 {
     ValidateWorkspaceSetting(setting);
     Util.AuthorizationToken = setting.AuthorizationToken;
     string queryUrl = StudioApi + string.Format("workspaces/{0}/experiments/{1}/webservice", setting.WorkspaceId, activityId);
     HttpResult hr = Util.HttpGet(queryUrl).Result;
     if (hr.IsSuccess)
     {                
         WebServiceCreationStatus status = jss.Deserialize<WebServiceCreationStatus>(hr.Payload);
         return status;
     }
     else
         throw new AmlRestApiException(hr);
 }
Beispiel #7
0
 public WebService GetWebServicesById(WorkspaceSetting setting, string webServiceId)
 {
     ValidateWorkspaceSetting(setting);
     Util.AuthorizationToken = setting.AuthorizationToken;
     string queryUrl = WebServiceApi + string.Format("workspaces/{0}/webservices/{1}", setting.WorkspaceId, webServiceId);
     HttpResult hr = Util.HttpGet(queryUrl).Result;
     if (hr.IsSuccess)
     {
         WebService ws = jss.Deserialize<WebService>(hr.Payload);                
         return ws;
     }
     else
         throw new AmlRestApiException(hr);
 }
Beispiel #8
0
 public UserAsset[] GetTransforms(WorkspaceSetting setting)
 {
     ValidateWorkspaceSetting(setting);
     Util.AuthorizationToken = setting.AuthorizationToken;
     string queryUrl = StudioApi + string.Format("workspaces/{0}/transformmodules", setting.WorkspaceId);
     HttpResult hr = Util.HttpGet(queryUrl).Result;
     if (hr.IsSuccess)
     {
         UserAsset[] tms = jss.Deserialize<UserAsset[]>(hr.Payload);
         return tms;
     }
     throw new AmlRestApiException(hr);
 }
Beispiel #9
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);
 }
Beispiel #10
0
 public Module[] GetModules(WorkspaceSetting setting)
 {
     ValidateWorkspaceSetting(setting);
     Util.AuthorizationToken = setting.AuthorizationToken;
     string query = StudioApi + string.Format("workspaces/{0}/modules", setting.WorkspaceId);
     HttpResult hr = Util.HttpGet(query).Result;
     if (!hr.IsSuccess)
         throw new AmlRestApiException(hr);            
     Module[] modules = jss.Deserialize<Module[]>(hr.Payload);
     return modules;
 }
Beispiel #11
0
 public string GetCustomModuleBuildJobStatus(WorkspaceSetting setting, string activityGroupId)
 {
     ValidateWorkspaceSetting(setting);
     Util.AuthorizationToken = setting.AuthorizationToken;
     string query = StudioApi + string.Format("workspaces/{0}/modules/custom?activityGroupId={1}", setting.WorkspaceId, activityGroupId);
     HttpResult hr = Util.HttpGet(query).Result;
     if (!hr.IsSuccess)
         throw new AmlRestApiException(hr);
     string jobStatus = hr.Payload;
     return jobStatus;
 }
Beispiel #12
0
 public string BeginParseCustomModuleJob(WorkspaceSetting setting, string moduleUploadMetadata)
 {
     ValidateWorkspaceSetting(setting);
     Util.AuthorizationToken = setting.AuthorizationToken;
     string query = StudioApi + string.Format("workspaces/{0}/modules/custom", setting.WorkspaceId);
     HttpResult hr = Util.HttpPost(query, moduleUploadMetadata).Result;
     if (!hr.IsSuccess)
         throw new AmlRestApiException(hr);
     string activityId = hr.Payload.Replace("\"", "");
     return activityId;            
 }
Beispiel #13
0
 public string GetDatasetSchemaGenStatus(WorkspaceSetting setting, string dataSourceId)
 {
     ValidateWorkspaceSetting(setting);
     Util.AuthorizationToken = setting.AuthorizationToken;            
     string query = StudioApi + string.Format("workspaces/{0}/datasources/{1}", setting.WorkspaceId, dataSourceId);
     HttpResult hr = Util.HttpGet(query).Result;
     if (!hr.IsSuccess)
         throw new AmlRestApiException(hr);
     dynamic parsed = jss.Deserialize<object>(hr.Payload);
     string schemaJobStatus = parsed["SchemaStatus"];
     return schemaJobStatus;
 }
Beispiel #14
0
 public string StartDatasetSchemaGen(WorkspaceSetting setting, string dataTypeId, string uploadFileId, string datasetName, string description, string uploadFileName)
 {
     ValidateWorkspaceSetting(setting);
     Util.AuthorizationToken = setting.AuthorizationToken;            
     dynamic schemaJob = new
     {
         DataSource = new
         {
             Name = datasetName,
             DataTypeId = dataTypeId,
             Description = description,
             FamilyId = string.Empty,
             Owner = "PowerShell",
             SourceOrigin = "FromResourceUpload"
         },
         UploadId = uploadFileId,
         UploadedFromFileName = Path.GetFileName(uploadFileName),
         ClientPoll = true
     };
     string query = StudioApi + string.Format("workspaces/{0}/datasources", setting.WorkspaceId);
     HttpResult hr = Util.HttpPost(query, jss.Serialize(schemaJob)).Result;
     if (!hr.IsSuccess)
         throw new AmlRestApiException(hr);
     string dataSourceId = hr.Payload.Replace("\"", "");
     return dataSourceId;
 }
Beispiel #15
0
 public async Task<string> UploadResourceInChunksAsnyc(WorkspaceSetting setting, int numOfBlocks, int blockId, string uploadId, string fileName, string fileFormat)
 {
     ValidateWorkspaceSetting(setting);
     Util.AuthorizationToken = setting.AuthorizationToken;
     string query = StudioApi + string.Format("blobuploads/workspaces/{0}/?numberOfBlocks={1}&blockId={2}&uploadId={3}&dataTypeId={4}", 
         setting.WorkspaceId, numOfBlocks, blockId, uploadId, fileFormat);
     HttpResult hr = await Util.HttpPostFile(query, fileName);
     if (!hr.IsSuccess)
         throw new AmlRestApiException(hr);
     return hr.Payload;
 }
Beispiel #16
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);
        }
Beispiel #17
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);
 }
Beispiel #18
0
 public Experiment[] GetExperiments(WorkspaceSetting setting)
 {
     ValidateWorkspaceSetting(setting);
     Util.AuthorizationToken = setting.AuthorizationToken;
     string queryUrl = StudioApi + string.Format("workspaces/{0}/experiments", setting.WorkspaceId);
     HttpResult hr = Util.HttpGet(queryUrl).Result;
     if (hr.IsSuccess)
     {
         Experiment[] exps = jss.Deserialize<Experiment[]>(hr.Payload);
         // only display user's own experiments.
         exps = exps.Where(e => e.Category == "user" || string.IsNullOrEmpty(e.Category)).ToArray();
         return exps;
     }
     else
         throw new AmlRestApiException(hr);
 }
Beispiel #19
0
 public string ExportAmlWebServiceDefinitionFromExperiment(WorkspaceSetting setting, string experimentId)
 {
     ValidateWorkspaceSetting(setting);
     Util.AuthorizationToken = setting.AuthorizationToken;
     string queryUrl = StudioApi + string.Format("workspaces/{0}/experiments/{1}/webservicedefinition", setting.WorkspaceId, experimentId);
     HttpResult hr = Util.HttpGet(queryUrl).Result;
     if (hr.IsSuccess)
         return hr.Payload;
     throw new AmlRestApiException(hr);
 }
Beispiel #20
0
 public Experiment GetExperimentById(WorkspaceSetting setting, string experimentId, out string rawJson)
 {
     ValidateWorkspaceSetting(setting);
     Util.AuthorizationToken = setting.AuthorizationToken;
     rawJson = string.Empty;
     string queryUrl = StudioApi + string.Format("workspaces/{0}/experiments/{1}", setting.WorkspaceId, experimentId);
     HttpResult hr = Util.HttpGet(queryUrl).Result;
     if (hr.IsSuccess)
     {
         rawJson = hr.Payload;
         Experiment exp = jss.Deserialize<Experiment>(hr.Payload);                
         return exp;
     }
     else
         throw new AmlRestApiException(hr);
 }
Beispiel #21
0
        public void PromoteUserAsset(WorkspaceSetting setting, string experimentId, string nodeId, string nodeOutputName, string assetName, string assetDescription, UserAssetType assetType, string familyId)
        {
            ValidateWorkspaceSetting(setting);
            Util.AuthorizationToken = setting.AuthorizationToken;

            string queryUrl = StudioApi + string.Format("workspaces/{0}/{1}", setting.WorkspaceId, assetType == UserAssetType.Transform ? "transformmodules" : (assetType == UserAssetType.TrainedModel ? "trainedmodels" : "datasources"));
            string postPayloadInJson = string.Empty;
            switch (assetType)
            {
                case UserAssetType.Transform:
                    var transformPayload = new
                    {
                        ExperimentId = experimentId,
                        ModuleNodeId = nodeId,
                        OutputName = nodeOutputName,
                        Transform = new
                        {
                            Name = assetName,
                            DataTypeId = "iTransformDotNet",
                            Description = assetDescription,
                            SourceOrigin = "FromOutputPromotion",
                            FamilyId = familyId
                        }
                    };
                    postPayloadInJson = jss.Serialize(transformPayload);
                    break;
                case UserAssetType.TrainedModel:
                    var trainedModelPayload = new
                    {
                        ExperimentId = experimentId,
                        ModuleNodeId = nodeId,
                        OutputName = nodeOutputName,
                        TrainedModel = new
                        {
                            Name = assetName,
                            DataTypeId = "iLearnerDotNet",
                            Description = assetDescription,
                            SourceOrigin = "FromOutputPromotion",
                            FamilyId = familyId
                        }
                    };
                    postPayloadInJson = jss.Serialize(trainedModelPayload);
                    break;
                case UserAssetType.Dataset:
                    var datasetPayload = new
                    {
                        ExperimentId = experimentId,
                        ModuleNodeId = nodeId,
                        OutputName = nodeOutputName,
                        DataSource = new
                        {
                            Name = assetName,
                            DataTypeId = "Dataset",
                            Description = assetDescription,
                            SourceOrigin = "FromOutputPromotion",
                            FamilyId = familyId
                        }
                    };
                    postPayloadInJson = jss.Serialize(datasetPayload);
                    break;
            }
            HttpResult hr = Util.HttpPost(queryUrl, postPayloadInJson).Result;
            if (hr.IsSuccess)
            {
                return;
            }
            throw new AmlRestApiException(hr);
        }
Beispiel #22
0
 public void SaveExperiment(WorkspaceSetting setting, Experiment exp, string rawJson)
 {
     SubmitExperiment(setting, exp, rawJson, string.Empty, false, false);
 }
Beispiel #23
0
 public WebServiceCreationStatus DeployWebServiceFromPredictiveExperiment(WorkspaceSetting setting, string predictiveExperimentId, bool updateExistingWebServiceDefaultEndpoint)
 {
     ValidateWorkspaceSetting(setting);
     Util.AuthorizationToken = setting.AuthorizationToken;
     string queryUrl = StudioApi + string.Format("workspaces/{0}/experiments/{1}/webservice?generateNewPortNames=false{2}", setting.WorkspaceId, predictiveExperimentId, updateExistingWebServiceDefaultEndpoint ? "&updateExistingWebService=true" : "");            
     HttpResult hr = Util.HttpPost(queryUrl, string.Empty).Result;
     if (hr.IsSuccess)
     {             
         WebServiceCreationStatus status = jss.Deserialize<WebServiceCreationStatus>(hr.Payload);
         return status;
     }
     else
         throw new AmlRestApiException(hr);
 }
Beispiel #24
0
 public void SaveExperimentAs(WorkspaceSetting setting, Experiment exp, string rawJson, string newName)
 {
     SubmitExperiment(setting, exp, rawJson, newName, true, false);
 }
Beispiel #25
0
 public WebServiceEndPoint GetWebServiceEndpointByName(WorkspaceSetting setting, string webServiceId, string epName)
 {
     ValidateWorkspaceSetting(setting);
     Util.AuthorizationToken = setting.AuthorizationToken;
     string queryUrl = WebServiceApi + string.Format("workspaces/{0}/webservices/{1}/endpoints/{2}", setting.WorkspaceId, webServiceId, epName);
     HttpResult hr = Util.HttpGet(queryUrl).Result;
     if (hr.IsSuccess)
     {
         WebServiceEndPoint ep = jss.Deserialize<WebServiceEndPoint>(hr.Payload);                
         return ep;
     }
     else
         throw new AmlRestApiException(hr);
 }
Beispiel #26
0
 private void SubmitExperiment(WorkspaceSetting setting, Experiment exp, string rawJson, string newName, bool createNewCopy, bool run)
 {
     ValidateWorkspaceSetting(setting);  
     Util.AuthorizationToken = setting.AuthorizationToken;
     string body = CreateSubmitExperimentRequest(exp, rawJson, run, newName, createNewCopy);
     string queryUrl = StudioApi + string.Format("workspaces/{0}/experiments/{1}", setting.WorkspaceId, createNewCopy ? string.Empty : exp.ExperimentId);
     HttpResult hr = Util.HttpPost(queryUrl, body).Result;
     if (!hr.IsSuccess)
         throw new AmlRestApiException(hr);
 }
Beispiel #27
0
 public bool RefreshWebServiceEndPoint(WorkspaceSetting setting, string webServiceId, string endpointName, bool overwriteResources)
 {
     ValidateWorkspaceSetting(setting);
     Util.AuthorizationToken = setting.AuthorizationToken;
     string query = WebServiceApi + string.Format("workspaces/{0}/webservices/{1}/endpoints/{2}/refresh", setting.WorkspaceId, webServiceId, endpointName);
     string body = "{\"OverwriteResources\": \"" + overwriteResources.ToString() + "\"}";
     HttpResult hr = Util.HttpPost(query, body).Result;
     if (hr.StatusCode == 304) // no change detected so no update happened.
         return false;
     if (!hr.IsSuccess)
         throw new AmlRestApiException(hr);
     return true;
 }
Beispiel #28
0
 public void RemoveExperimentById(WorkspaceSetting setting, string ExperimentId)
 {
     ValidateWorkspaceSetting(setting);
     Util.AuthorizationToken = setting.AuthorizationToken;
     string queryUrl = StudioApi + string.Format("workspaces/{0}/experiments/{1}?deleteAncestors=true", setting.WorkspaceId, ExperimentId);
     HttpResult hr = Util.HttpDelete(queryUrl).Result;
     if (!hr.IsSuccess)
         throw new AmlRestApiException(hr);
 }
Beispiel #29
0
 public void RemoveWebServiceEndpoint(WorkspaceSetting setting, string webServiceId, string endpointName)
 {
     ValidateWorkspaceSetting(setting);
     Util.AuthorizationToken = setting.AuthorizationToken;
     string queryUrl = WebServiceApi + string.Format("workspaces/{0}/webservices/{1}/endpoints/{2}", setting.WorkspaceId, webServiceId, endpointName);
     HttpResult hr = Util.HttpDelete(queryUrl).Result;
     if (!hr.IsSuccess)
         throw new AmlRestApiException(hr);
 }
Beispiel #30
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);
 }