Exemplo n.º 1
0
        /// <summary>
        /// Gera um texto randômico para o captcha
        /// </summary>
        /// <returns></returns>
        public string GetRandomText()
        {
            RandomTextGenerator textGenerator = new RandomTextGenerator();

            textGenerator.Settings.Length = _settings.NumChars;
            return(textGenerator.Generate());
        }
        public void GenerateLengthTest()
        {
            RandomTextGenerator gen = new RandomTextGenerator(20);
            string test             = gen.Generate();

            Trace.WriteLine(test);
            Assert.AreEqual(test.Length, gen.Settings.Length);
        }
Exemplo n.º 3
0
 public IEnumerable <IParam> Parameters()
 {
     for (int i = 0; i < count; i++)
     {
         var newVal = RandomTextGenerator.Generate(7);
         yield return(new DictParams(new BenchDictKeyValue(i, newVal)));
     }
 }
Exemplo n.º 4
0
        private string GenerateRandomText(int length)
        {
            RandomTextGenerator.RandomTextGeneratorSettings Settings =
                new RandomTextGenerator.RandomTextGeneratorSettings {
                Length = length
            };
            RandomTextGenerator rtGenerator = new RandomTextGenerator(Settings);

            return(rtGenerator.Generate());
        }
        public void GenerateLargeTest()
        {
            RandomTextGenerator.RandomTextGeneratorSettings gensettings =
                new RandomTextGenerator.RandomTextGeneratorSettings
            {
                Length       = 1000,
                AllowedChars = "ABCDEFGEHIJKLNMOPQRSTUVXYZ012345789"
            };
            RandomTextGenerator gen = new RandomTextGenerator();
            string test             = gen.Generate();

            Trace.WriteLine(test);
            Assert.AreEqual(test.Length, gen.Settings.Length);
        }
Exemplo n.º 6
0
        public TwoChatsHandler(ChatSpammerSettings spammerSettings, IChatHandler chat1, IChatHandler chat2)
        {
            Settings         = spammerSettings;
            UniqueIdentifier = RandomTextGenerator.Generate(4);
            string dateStr = string.Format("{0:dd.MM.yy_HH.mm.ss}", DateTime.Now);

            UsedFolder = ResourcesAndConsts.Instance().FolderForСorrespondenceAndLogs + "/" + dateStr + "__" + UniqueIdentifier;
            Directory.CreateDirectory(UsedFolder);
            Chat1 = chat1;
            Chat2 = chat2;
            if (spammerSettings.BotScenario != null)
            {
                BotScenario = spammerSettings.BotScenario.Clone() as IBotScenario;
            }
        }
Exemplo n.º 7
0
        public string GetFreeDir()
        {
            Block();
            string res = null;

            foreach (var item in dirNameAndStatus)
            {
                if (item.Value)
                {
                    dirNameAndStatus[item.Key] = false;
                    res = Path.Combine(CacheFolderGlobal, item.Key);
                    break;
                }
            }
            if (res == null)
            {
                string dirName = RandomTextGenerator.Generate(7);
                res = Path.Combine(CacheFolderGlobal, dirName);
                Directory.CreateDirectory(res);
                dirNameAndStatus.Add(dirName, false);
            }
            Unblock();
            return(res);
        }
Exemplo n.º 8
0
        static void TestIDict(int count)
        {
            Console.WriteLine("{");
            Dictionary <string, object> idict = new Dictionary <string, object>(count);

            Stopwatch sw  = new Stopwatch();
            Stopwatch sw2 = new Stopwatch();

            sw.Start();
            List <string> keys     = new List <string>();
            int           magicNum = count / 4;

            for (int i = 0; i < count; i++)
            {
                string newKey = RandomTextGenerator.Generate(20);
                object val    = i.ToString();
                sw2.Start();
                idict.Add(newKey, val);
                sw2.Stop();
                if (i % magicNum == 0)
                {
                    keys.Add(newKey);
                }
            }
            Console.WriteLine($"\tFill time - {count} records: {sw.ElapsedMilliseconds} ms.");
            Console.WriteLine($"\tFill time - {count} records ('Add' calls only): {sw2.ElapsedMilliseconds} ms.");
            sw2.Stop();
            long kbytes = 0;

            if (count > 2000000)
            {
                kbytes = GC.GetTotalMemory(true) / (1024 * 1024);
            }
            else
            {
                kbytes = GetObjSize(idict) / (1024 * 1024);
            }

            Console.WriteLine($"\tSize: {kbytes} MBs.");

            object bufVal;

            foreach (var key in keys)
            {
                int nanoseconds;
                Console.WriteLine("\t" + key + "{");
                sw.Restart();
                bufVal = idict.ContainsKey(key);
                sw.Stop();
                nanoseconds = (int)(sw.ElapsedTicks * 1000000000 / Stopwatch.Frequency);
                Console.WriteLine($"\t\tContains key operation: {nanoseconds} ns.");

                sw.Restart();
                bufVal = idict[key];
                sw.Stop();
                nanoseconds = (int)(sw.ElapsedTicks * 1000000000 / Stopwatch.Frequency);
                Console.WriteLine($"\t\tGet value operation: {nanoseconds} ns.");
                Console.WriteLine($"\t\tValue: {bufVal}");


                sw.Restart();
                bufVal = idict.First(kv => kv.Value == bufVal).Value;
                sw.Stop();
                nanoseconds = (int)(sw.ElapsedTicks * 1000000000 / Stopwatch.Frequency);
                Console.WriteLine($"\t\tFind by value with LINQ: {nanoseconds} ns.");

                sw.Restart();
                foreach (var kv in idict)
                {
                    if (kv.Value == bufVal)
                    {
                        bufVal = kv.Value;
                        break;
                    }
                }
                sw.Stop();
                nanoseconds = (int)(sw.ElapsedTicks * 1000000000 / Stopwatch.Frequency);
                Console.WriteLine($"\t\tFind by value with cycle: {nanoseconds} ns.");


                Console.WriteLine("\t}");
            }

            sw.Restart();
            bufVal = idict.OrderBy(k => k.Key);
            Console.WriteLine($"\tOrder operation: {sw.ElapsedMilliseconds} ms.");

            Console.WriteLine("}\n");
        }