private void asyncFile_Click(object sender, RoutedEventArgs e) { CreateClientContext(); TranslationJob job = new TranslationJob(cc, this.culture.Text); string input = this.inputFile.Text; string output = this.outputFile.Text; job.AddFile(input, output); job.Name = this.jobName.Text; job.Start(); cc.Load(job); ThreadPool.QueueUserWorkItem(new WaitCallback(CreateThreadForAsync), job); }
static void AsyncFile(string culture, string input, string output, string name) { TranslationJob job = new TranslationJob(cc, culture); Console.WriteLine("Adding files"); Console.WriteLine("Input: " + input); Console.WriteLine("Output: " + output); job.AddFile(input, output); job.Name = name; //test job.Start(); cc.Load(job); cc.ExecuteQuery(); Console.WriteLine("JobId: " + job.JobId); Console.WriteLine("JobName: " + job.Name); Console.WriteLine("Done"); }
/// <summary> /// submit an async job to translate a file /// </summary> /// <param name="culture">target langauge</param> /// <param name="input">full URL of input file</param> /// <param name="output">full URL of output file</param> static void AddAsyncFile(string culture, string input, string output, string user) { SPServiceContext sc = SPServiceContext.GetContext(new SPSite(site)); TranslationJob job = new TranslationJob(sc, CultureInfo.GetCultureInfo(culture)); Encoding encoding = new System.Text.UTF8Encoding(); if (!String.IsNullOrEmpty(user)) { job.UserToken = ConvertHexStringToByteArray(user); //job.UserToken = encoding.GetBytes(user); } Console.WriteLine("Input: " + input); Console.WriteLine("Output: " + output); Console.WriteLine("targetlang {0}:", job.TargetLanguage.Name); job.AddFile(input, output); Console.WriteLine("Submitting the job"); job.Start(); if (job.UserToken != null) { Console.WriteLine("User Token:" + encoding.GetString(job.UserToken)); } ListJobItemInfo(job); }