public void Generate() {
        _anyError = false;

        var reflectedMethods = new Dictionary<string, MethodInfo>();
        foreach (var type in typeof(RubyOps).Assembly.GetExportedTypes()) {
            if (type.IsDefined(typeof(ReflectionCachedAttribute), false)) {
                Console.WriteLine(type);
                ReflectMethods(reflectedMethods, type);
            }
        }

        var methods = reflectedMethods.Sort((m1, m2) => m1.Key.CompareTo(m2.Key));
        if (_anyError) {
            Environment.ExitCode = 1;
            return;
        }

        using (TextWriter writer = new StreamWriter(File.Open(_outFile, FileMode.Create, FileAccess.Write))) {
            _output = new IndentedTextWriter(writer, "    ");
            _output.NewLine = "\r\n";

            WriteLicenseStatement(writer);

            _output.WriteLine("using System.Reflection;");
            _output.WriteLine("using System.Diagnostics;");
            _output.WriteLine("using IronRuby.Runtime;");
            _output.WriteLine("using IronRuby.Builtins;");
            _output.WriteLine("using Microsoft.Scripting.Utils;");

            _output.WriteLine();
            _output.WriteLine("namespace {0} {{", MethodCacheType.Namespace);
            _output.Indent++;

            _output.WriteLine("public static partial class {0} {{", MethodCacheType.Name);
            _output.Indent++;

            GenerateOps(methods);
            
            _output.WriteLine();

            GenerateStringFactoryOps("CreateRegex");
            GenerateStringFactoryOps("CreateMutableString");
            GenerateStringFactoryOps("CreateSymbol");

            GenerateOptimizedOps("Yield", BlockDispatcher.MaxBlockArity);
            GenerateOptimizedOps("YieldSplat", BlockDispatcher.MaxBlockArity);
            
            _output.Indent--;
            _output.WriteLine("}");

            _output.Indent--;
            _output.WriteLine("}");

            Debug.Assert(_output.Indent == 0);
        }
    }
 public void SortByValueTest()
 {
     IDictionary<string, int> Test = new Dictionary<string, int>();
     Test.Add("Q", 4);
     Test.Add("Z", 2);
     Test.Add("C", 3);
     Test.Add("A", 1);
     Test = Test.Sort(x => x.Value);
     string Value = "";
     foreach (string Key in Test.Keys)
         Value += Test[Key].ToString();
     Assert.Equal("1234", Value);
 }
 public void SortTest()
 {
     IDictionary<string, int> Test = new Dictionary<string, int>();
     Test.Add("Q", 4);
     Test.Add("Z", 2);
     Test.Add("C", 3);
     Test.Add("A", 1);
     Test = Test.Sort();
     string Value = "";
     foreach (string Key in Test.Keys)
         Value += Key;
     Assert.Equal("ACQZ", Value);
 }
        public void Should_Sort_Processor_Chains_Even_When_Added_Out_Of_Order()
        {
            Dictionary<int, IEventProcessor> unsortedChain = new Dictionary<int, IEventProcessor>();

            // mock a few processors
            var procMock1 = new Mock<IEventProcessor>();
            var procMock2 = new Mock<IEventProcessor>();
            var procMock3 = new Mock<IEventProcessor>();

            // add them out of order
            unsortedChain.Add(2, procMock2.Object);
            unsortedChain.Add(3, procMock3.Object);
            unsortedChain.Add(1, procMock1.Object);

            IEnumerable<IEventProcessor> sortedChain = unsortedChain.Sort();

            Assert.AreSame(procMock1.Object, sortedChain.ElementAt(0));
            Assert.AreSame(procMock2.Object, sortedChain.ElementAt(1));
            Assert.AreSame(procMock3.Object, sortedChain.ElementAt(2));
        }
        public WeChatJsConfiguration GenerateWeChatJsConfigurationWithSignature(string jsTicket, string url)
        {
            var jsConfig = new WeChatJsConfiguration { 
                 NonceString = NonceString(),
                 Timestamp = TimeStamp()
            };

            var dataList = new Dictionary<string, string> {
                {"noncestr", jsConfig.NonceString},
                {"timestamp", jsConfig.Timestamp.ToString() },
                {"jsapi_ticket", jsTicket},
                {"url", url}
            }.ToList();

            dataList.Sort(ParameterKeyComparison);
            var queryString = dataList.Aggregate(string.Empty, (query, item) => string.Concat(query, "&", item.Key, "=", item.Value)).TrimStart('&');

            using (var sha1 = new SHA1CryptoServiceProvider())
            {
                var hashed = sha1.ComputeHash(Encoding.Default.GetBytes(queryString));
                jsConfig.Signature = HexStringFromBytes(hashed);
                return jsConfig;
            }
        }
		public void Sort_ComparisonNull()
		{
			Dictionary<int, int> dictionary = new Dictionary<int, int>();
			dictionary.Sort(null);
		}
Example #7
0
        internal int Generate(Crossword crossword, Dictionary dictionary)
        {
            if (dictionary.DictionaryWords.Length == 0)
            {
                return -1;
            }

            int blankIterations = 0;
            int wordsHaveBeenAdded = 0;

            dictionary.Sort(new DictionaryWordComparator(DictionaryWordComparator.SortDirection.Descending, DictionaryWordComparator.SortBy.LetterCount));

            int iterationNumber = 0;
            while (blankIterations < 100)
            {
                iterationNumber++;
                var dictionaryWord = dictionary.GetRandomDictionaryWord(iterationNumber < 10 ? 0.3 : 1);
                var positions = crossword.GetPreviewsPositions(dictionaryWord);

                if (positions != null)
                {
                    if (positions.Count == 0)
                    {
                        blankIterations++;
                        continue;
                    }

                    var position = positions[random.Next(0, positions.Count)]; //  range: [0; positions.Count - 1]
                    var crosswordWord = new CrosswordWord(crossword, dictionaryWord, position.Position, false);
                    crossword.AddWord(crosswordWord);
                    wordsHaveBeenAdded = 1;
                }
                else
                {
                    Orientation orientation = random.Next(2) > 0 ? Orientation.Horizontal : Orientation.Vertical;
                    crossword.AddWord(new CrosswordWord(crossword, dictionaryWord, new CrosswordWordPosition(0, 0, orientation), false));
                    wordsHaveBeenAdded = 1;
                }

                blankIterations = 0;
            }

            return wordsHaveBeenAdded;
        }