コード例 #1
0
        private static void TrasnaltePerServer(List <GetWordForTranslate_Result> dataList, int serverId)
        {
            foreach (var data in dataList)
            {
                var dateTime = DateTime.Now;
                using (var service2 = new ResourceService())
                {
                    if (!string.IsNullOrEmpty(data.Word) &&
                        "en" != data.LanguageCode.ToLower())
                    {
                        try
                        {
                            var resultT = TranslatorServiceCompare.TranslateGetAll(
                                "en",
                                data.LanguageCode,
                                data.Word,
                                serverId);
                            resultT.Wait();

                            data.Translated = resultT.Result;
                            var objectT = JsonConvert.DeserializeObject <CallBankService>(data.Translated);
                            if (!string.IsNullOrEmpty(data.Translated) && !string.IsNullOrEmpty(objectT.Text))
                            {
                                service2.SaveResourceTranslatedCompare(data, objectT);
                                Console.ForegroundColor = ConsoleColor.White;
                                Console.WriteLine(
                                    $"{serverId}\t{TranslatorService.ServerList[serverId]}\t{data.Word}\t{data.LanguageCode}\t{objectT.Text}\t{DateTime.Now:HH:mm:ss}");
                            }
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e.Message);
                        }
                    }
                }

                var waitMilisecond = 1400;
                var sleep          = (DateTime.Now - dateTime).TotalMilliseconds;
                //Console.WriteLine($"Time To call all {sleep}");
                if (sleep < waitMilisecond)
                {
                    var wait = waitMilisecond - (int)sleep;
                    Task.Delay(wait).Wait();
                    //Console.WriteLine($"Time need wait {wait}");
                    var rondomNumber = new Random().Next(1, 100);
                    Task.Delay(rondomNumber).Wait();
                }
            }
            if (serverId == 0)
            {
                System.Diagnostics.Process.Start(Assembly.GetExecutingAssembly().Location);
                Environment.Exit(-1);
            }
        }
コード例 #2
0
        private static void MakeWordOpensive()
        {
            var files     = Directory.GetFiles(@"C:\Users\President\Downloads", "*.txt");
            var mainWords = new List <string>();

            foreach (var file in files)
            {
                var lines = File.ReadLines(file).Where(x => !string.IsNullOrEmpty(x)).ToList();
                var ret1  = lines.Select(x =>
                                         x.Split(new[] { " - " }, StringSplitOptions.RemoveEmptyEntries).FirstOrDefault()).ToList();
                if (ret1.Any(string.IsNullOrEmpty))
                {
                }
                mainWords.AddRange(ret1);
            }

            mainWords = mainWords.Select(x => x.Replace(" ", "")).Distinct().ToList().OrderBy(x => x.ToLower()).ToList();
            var newList     = mainWords.Where(x => x.Contains(" ")).ToList();
            var FinalResult = new List <string>();

            //throw new NotImplementedException();
            foreach (var word in mainWords)
            {
                Thread.Sleep(1600);
                var resultT = TranslatorServiceCompare.TranslateGetAll(
                    "en",
                    "fa",
                    word, 0);
                resultT.Wait();
                Console.WriteLine("Translate :" + word);
                var ret     = resultT.Result;
                var objectT = JsonConvert.DeserializeObject <CallBankService>(ret);
                FinalResult.Add(word.Trim().ToLower());
                if (objectT.IsVerb)
                {
                    FinalResult.Add(word.Trim().ToLower() + "ing");
                    FinalResult.Add(word.Trim().ToLower() + "er");
                }
            }

            File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + "\\ResultOpensive.txt",
                              FinalResult.Aggregate((x, y) => x + "," + y).Trim(','), Encoding.UTF8);
        }