public async Task <ActionResult> Index1() { string form = Request.Form.ToString(); var activationCode = this.Request.Form["code"].ToString(); var url = $"{authorityUri}/token"; string signInReturnUrl = Request.Url.ToString(); Dictionary <string, string> postData = new Dictionary <string, string> { { "grant_type", "authorization_code" }, { "client_id", clientID }, { "redirect_uri", signInReturnUrl }, { "client_secret", clientsecret }, { "code", activationCode } }; HttpClient client = new HttpClient(); HttpResponseMessage response = await client.PostAsync(url, new FormUrlEncodedContent(postData)); string responseContent = await response.Content.ReadAsStringAsync(); JObject responseObj = JsonConvert.DeserializeObject <JObject>(responseContent); string tokentype = responseObj["token_type"].Value <string>(); string accesstoken = responseObj["access_token"].Value <string>(); string refreshtoken = responseObj["refresh_token"].Value <string>(); string token_header = tokentype + " " + accesstoken; Session["token_header"] = token_header; Session["ws_id"] = "..."; // Enter your Workspace Id CustomTranslatorAPIClient clientapp = new CustomTranslatorAPIClient(); return(View()); }
public async Task <ActionResult> ParallelFile() { string token_header = null; if (Session["token_header"] != null) { token_header = Session["token_header"].ToString(); } CustomTranslatorAPIClient clientapp = new CustomTranslatorAPIClient(); // Start upload single parallel document string sourcelanguagefilepath = @"..."; // Enter local path for source language file string targetlanguagefilepath = @"..."; // Enter local path for target language file DocumentDetailsForImportRequest documentdetails = new DocumentDetailsForImportRequest(); documentdetails.DocumentName = "..."; // Enter document name documentdetails.DocumentType = "training"; //values = training/ tuning/ testing documentdetails.IsParallel = true; // Enter if this is a parallel document. values = true, false documentdetails.FileDetails = new List <FileForImportRequest>(); FileForImportRequest sourcelanguagefile = new FileForImportRequest(); sourcelanguagefile.Name = Path.GetFileName(sourcelanguagefilepath); sourcelanguagefile.Language = "..."; // Enter source language. Example: de. //Determined from the call to GetCategories sourcelanguagefile.OverwriteIfExists = true; // Enter if you want to overwrite if file exists. values = true, false FileForImportRequest targetlanguagefile = new FileForImportRequest(); targetlanguagefile.Name = Path.GetFileName(targetlanguagefilepath); targetlanguagefile.Language = "..."; // Enter target language. Example: en. //Determined from the call to GetCategories targetlanguagefile.OverwriteIfExists = true; // Enter if you want to overwrite if file exists. values = true, false string result = await clientapp.ImportDocument(token_header, Session["ws_id"].ToString(), sourcelanguagefilepath, targetlanguagefilepath, documentdetails, sourcelanguagefile, targetlanguagefile); string jobId = getJobId(result.Trim()); Response.Write("<br /><br />JobId: " + jobId + "<br />"); result = await clientapp.GetDocumentUploadStatus(jobId, token_header); CurrentFileUploadStatus status = getUploadStatus(result); foreach (FileProcessingStatus fps in status.fileProcessingStatus) { Response.Write("<br />File Name: " + fps.id); // Use this File Is when training a model Response.Write("<br />File Name: " + fps.fileName); Response.Write("<br />Upload Status: " + fps.status.displayName); } return(View()); }
public async Task <ActionResult> Create() { string token_header = null; if (Session["token_header"] != null) { token_header = Session["token_header"].ToString(); } CustomTranslatorAPIClient clientapp = new CustomTranslatorAPIClient(); ProjectCreateRequest newproject = new ProjectCreateRequest(); newproject.name = "..."; // Enter Project Name newproject.languagePairId = 18; //Determined from the call to GetLanguagePairs newproject.categoryid = 1; //Determined from the call to GetCategories newproject.categoryDescriptor = "..."; // Enter Project Category Descriptor newproject.label = "..."; // Enter Project Label newproject.description = "..."; // Enter Project Decription string categoryresult = await clientapp.GetCategories(token_header); List <Category> categorylist = getCategoryList(categoryresult); Category category = categorylist.Find(c => c.id == newproject.categoryid); string lpresult = await clientapp.GetLanguagePairs(token_header); List <LanguagePair> languagePairList = getLanguagePairList(lpresult); LanguagePair languagePair = languagePairList.Find(lp => lp.id == newproject.languagePairId); string result = await clientapp.CreateProject(token_header, newproject, Session["ws_id"].ToString()); string[] resultarray = result.Split('/'); if (resultarray.Length > 1) { string newprojectid = resultarray[resultarray.Length - 1]; Response.Write("<br/>New Project Created"); Response.Write("<br/>Project Id: " + newprojectid); Response.Write("<br/>Project Name: " + newproject.name); Response.Write("<br/>Language Pair: " + languagePair.sourceLanguage.displayName + " to " + languagePair.targetLanguage.displayName); Response.Write("<br/>Project Category: " + category.name); Response.Write("<br/>Project Label: " + newproject.label); Response.Write("<br/>Project Description: " + newproject.description); } else { Response.Write("<br/>Could not create project: " + result); } return(View()); }
// GET: Model public async Task <ActionResult> Index(int?id) { string token_header = null; if (Session["token_header"] != null) { token_header = Session["token_header"].ToString(); } CustomTranslatorAPIClient clientapp = new CustomTranslatorAPIClient(); if (id == null) { return(View()); } long modelid = (long)id; string result = await clientapp.GetModel(modelid, token_header); TrainingModel m = getTrainingDetail(result); Response.Write("<br />Model Id: " + m.id); Response.Write("<br />Model Name: " + m.name); Response.Write("<br />Model Status: " + m.modelStatus); Response.Write("<br/>"); foreach (Document d in m.documents) { Response.Write("<br/>Document Name: " + d.documentInfo.name); Response.Write("<br/>Aligned Sentence Count: " + d.processedDocumentInfo.alignedSentenceCount); Response.Write("<br/>Used Sentence Count: " + d.processedDocumentInfo.usedSentenceCount); int i = 1; foreach (FileInDocument f in d.documentInfo.files) { Response.Write("<br/>File " + i + " : " + f.fileName); Response.Write("<br/>Language: " + f.language.displayName); i++; } } Response.Write("<br/>"); Response.Write("<br />Bleu Score: " + m.bleuScoreCIPunctuated); Response.Write("<br />Training Sentence Count: " + m.trainingSentenceCount); Response.Write("<br />Tuning Sentence Count: " + m.tuningSentenceCount); Response.Write("<br />Testing Sentence Count: " + m.testingSentenceCount); return(View()); }
public async Task <ActionResult> Deploy(int?id) { string token_header = null; if (Session["token_header"] != null) { token_header = Session["token_header"].ToString(); } if (id == null) { return(View()); } long modelid = (long)id; CustomTranslatorAPIClient clientapp = new CustomTranslatorAPIClient(); DeploymentConfiguration regionaldeployment1 = new DeploymentConfiguration(); regionaldeployment1.region = 1; // North America = 1 regionaldeployment1.isDeployed = true; // true = deployment ; false = undeployment DeploymentConfiguration regionaldeployment2 = new DeploymentConfiguration(); regionaldeployment2.region = 2; // Europe = 2 regionaldeployment2.isDeployed = true; // true = deployment ; false = undeployment DeploymentConfiguration regionaldeployment3 = new DeploymentConfiguration(); regionaldeployment3.region = 3; // Asia Pacific regionaldeployment3.isDeployed = true; // true = deployment ; false = undeployment List <DeploymentConfiguration> deploymentconfig = new List <DeploymentConfiguration>(); deploymentconfig.Add(regionaldeployment1); deploymentconfig.Add(regionaldeployment2); deploymentconfig.Add(regionaldeployment3); string result = await clientapp.CreateModelDeploymentRequest(modelid, deploymentconfig, token_header); Response.Write(result); return(View()); }
public async Task <ActionResult> ComboFile() { string token_header = null; if (Session["token_header"] != null) { token_header = Session["token_header"].ToString(); } CustomTranslatorAPIClient clientapp = new CustomTranslatorAPIClient(); string filepath = @"..."; // Enter local path for combo file DocumentDetailsForImportRequest documentdetails = new DocumentDetailsForImportRequest(); documentdetails.DocumentName = "..."; // Enter document name documentdetails.DocumentType = "training"; //values = training/ tuning/ testing documentdetails.IsParallel = true; // Enter if this is a parallel document. values = true, false documentdetails.FileDetails = new List <FileForImportRequest>(); string result = await clientapp.ImportComboDocument(token_header, Session["ws_id"].ToString(), filepath, documentdetails); string jobId = getJobId(result.Trim()); Response.Write("<br /><br />JobId: " + jobId + "<br />"); result = await clientapp.GetDocumentUploadStatus(jobId, token_header); CurrentFileUploadStatus status = getUploadStatus(result); foreach (FileProcessingStatus fps in status.fileProcessingStatus) { Response.Write("<br />File Name: " + fps.id); // Use this File Is when training a model Response.Write("<br />File Name: " + fps.fileName); Response.Write("<br />Upload Status: " + fps.status.displayName); } return(View()); }
public async Task <ActionResult> Create() { string token_header = null; if (Session["token_header"] != null) { token_header = Session["token_header"].ToString(); } CustomTranslatorAPIClient clientapp = new CustomTranslatorAPIClient(); ModelCreateRequest model = new ModelCreateRequest(); // Create new object for Model and add values model.name = "..."; // Enter model name model.projectId = "..."; // Enter project id model.documentIds = new List <int>(); model.documentIds.Add(...); // Add multiple documents using DocumentID. DocumentID is int. model.isTuningAuto = true; // Enter if tuning set will be set to auto. values = true, false model.isTestingAuto = true; // Enter if testing set will be set to auto. values = true, false model.isAutoDeploy = false; // Enter if this model will be automatically deployed. values = true, false model.autoDeployThreshold = 0; // Enter the value of auto deploy threshold value string result = await clientapp.GetProject(model.projectId, token_header); Project project = getProjectDetail(result); result = await clientapp.CreateModel(token_header, model); string[] resultarray = result.Split('/'); if (resultarray.Length > 1) { string newtrainingid = resultarray[resultarray.Length - 1]; Response.Write("<br/>New Model Created"); Response.Write("<br/>Model Id: " + newtrainingid); Response.Write("<br/>Model Name: " + model.name); Response.Write("<br/>Project Name: " + project.name); Response.Write("<br/>Language Pair: " + project.languagePair.sourceLanguage.displayName + " to " + project.languagePair.targetLanguage.displayName); foreach (int fileid in model.documentIds) { result = await clientapp.GetDocument(fileid, token_header); DocumentInfo doc = getDocumentDetail(result); Response.Write("<br/>Document : " + doc.name); int i = 1; foreach (FileInDocument f in doc.files) { Response.Write("<br/>File " + i + " :"); Response.Write("<br/>File Name: " + f.fileName); Response.Write("<br/>Language: " + f.language.displayName); i++; } } } else { Response.Write("<br/>Could not create project: " + result); } return(View()); }