コード例 #1
0
        private async Task ProcessTranslation(HttpListenerRequest req, HttpListenerResponse resp)
        {
            string?japanese = GetTextParam(req);

            OnRequest?.Invoke(req.RemoteEndPoint, japanese);
            if (japanese == null)
            {
                return;
            }

            string?korean = await Translator.Translate(japanese ?? "").ConfigureAwait(false);

            resp.ContentType = "text/plain; charset=utf-8";
            byte[] buf = Encoding.UTF8.GetBytes(korean);
            resp.ContentLength64 = buf.LongLength;
            await resp.OutputStream.WriteAsync(buf, 0, buf.Length);
        }
コード例 #2
0
        public async Task ProcessQueue()
        {
            CancellationToken token = Cancellation.Token;

            while (!token.IsCancellationRequested)
            {
                List <Work> works = await GetWorksOfThisRound(token).ConfigureAwait(false);

                IEnumerable <string> texts = works.Select(x => x.Text);
                string mergedStart         = string.Join("\n", texts);
                System.Diagnostics.Debug.WriteLine($"[[[{mergedStart}]]]");
                string mergedEnd = await Translator.Translate(mergedStart).ConfigureAwait(false) ?? "";

                string[] translateds = SplitBySegmentNewline(mergedEnd, texts).ToArray();

                for (int i = 0; i < works.Count; i++)
                {
                    works[i].Client.TrySetResult(translateds[i]);
                }
            }
        }