public async Task <ClassiiiUser> AuthenticateAsync(T4ooUser t4ooUser, string authCode) { string encryptedPassword = new RC4(authCode).Enc(t4ooUser.password); Dictionary <string, object> t4ooUserDict = new Dictionary <string, object> { { "orgId", t4ooUser.orgId }, { "userId", t4ooUser.userId }, { "password", encryptedPassword } }; var content = await HttpUtils.SendAsync(HttpMethod.Post, baseUrl + "/authenticate", null, t4ooUserDict); var byteArray = await content.ReadAsByteArrayAsync(); var responseString = Encoding.UTF8.GetString(byteArray, 0, byteArray.Length); var definition = new { status = "", data = new { accessKey = "", secretKey = "" } }; var serverResp = JsonConvert.DeserializeAnonymousType(responseString, definition); if (serverResp.status != ResponseStatus.Success) { return(null); } return(new ClassiiiUser { AccessKey = serverResp.data.accessKey, SecretKey = serverResp.data.secretKey }); }
static async System.Threading.Tasks.Task Main(string[] args) { //Console.WriteLine("Hello World!"); UserInfo.init("config.json"); FileTranslateFlow flow = new FileTranslateFlow("https://translate.classiii.info/api/v1"); //FileTranslateFlow flow = new FileTranslateFlow("http://*****:*****@"C:\mydocuments\morning.docx" }; string[] langs = { "en" }; int fieldId = 1; bool done = false; //done = await flow.T4ooFlowAsync(t4ooUser, files, langs, fieldId); //Debug.Assert(done); ClassiiiUser classiiiUser = new ClassiiiUser { AccessKey = UserInfo.CLASSIII_ACCESS_KEY, SecretKey = UserInfo.CLASSIII_SECRET_KEY, ContractId = UserInfo.FILE_CONTRACT_ID }; done = await flow.ClassiiiFlowAsync(classiiiUser, files, langs, fieldId); Debug.Assert(done); }
public async Task <bool> T4ooFlowAsync(T4ooUser t4ooUser, string[] files, string[] langs, int fieldId) { string authCode = await client.GetAuthCodeAsync(t4ooUser); ClassiiiUser classiiiUser = await client.AuthenticateAsync(t4ooUser, authCode); return(await ClassiiiFlowAsync(classiiiUser, files, langs, fieldId)); }
public async Task <string> GetAuthCodeAsync(T4ooUser t4ooUser) { Dictionary <string, object> t4ooUserDict = new Dictionary <string, object> { { "orgId", t4ooUser.orgId }, { "userId", t4ooUser.userId } }; var content = await HttpUtils.SendAsync(HttpMethod.Post, baseUrl + "/auth-code", null, t4ooUserDict); var byteArray = await content.ReadAsByteArrayAsync(); var responseString = Encoding.UTF8.GetString(byteArray, 0, byteArray.Length); var definition = new { status = "", data = new { id = "" } }; var serverResp = JsonConvert.DeserializeAnonymousType(responseString, definition); if (serverResp.status != ResponseStatus.Success) { return(null); } return(serverResp.data.id); }