Example #1
0
        private static bool DoTestsMatchFilterRequest(string[] testTags, KeyValuePair<string, string>[] filterTags)
        {
            //If no tags were requested, then then it is a match
            if (!filterTags.Any())
            {
                return true;
            }

            var includeTags = filterTags.Where(t => t.Value.Equals("true", StringComparison.OrdinalIgnoreCase))
                                        .Select(t => t.Key)
                                        .ToArray();
            var excludeTags = filterTags.Where(t => t.Value.Equals("false", StringComparison.OrdinalIgnoreCase))
                                        .Select(t => t.Key)
                                        .ToArray();

            return !excludeTags.Intersect(testTags, StringComparer.OrdinalIgnoreCase).Any()  &&
                   includeTags.Intersect(testTags, StringComparer.OrdinalIgnoreCase).Count() == includeTags.Count();
        }
 protected RestfulResourceController()
 {
     _allResponseFactories = new [] {
             new KeyValuePair<string, ResponseFactoryDelegate<ActionResult>>("*/*", WildcardResponseFactory),
             new KeyValuePair<string, ResponseFactoryDelegate<ActionResult>>("text/html", TextHtmlResponseFactory),
             new KeyValuePair<string, ResponseFactoryDelegate<ActionResult>>("application/json", ApplicationJsonResponseFactory),
             new KeyValuePair<string, ResponseFactoryDelegate<ActionResult>>("text/xml", TextXmlResponseFactory),
         };
     _responseFactories = _allResponseFactories.Where(f => SupportedAcceptHeaders.Contains(f.Key));
 }
Example #3
0
        public void CopyTo()
        {
            var trie = new Trie<bool>();

            trie.Add("ABC", true);
            trie.Add("AB", false);
            trie.Add("ADE", true);
            trie.Add("ABCDE", false);

            var destinationArray = new KeyValuePair<string, bool>[6];

            ((ICollection<KeyValuePair<string, bool>>)trie).CopyTo(destinationArray, 1);

            var result = destinationArray.Where(i => i.Key != null).OrderBy(i => i.Key).ToArray();

            var expected = new[]
                {
                    new KeyValuePair<string, bool>("AB", false),
                    new KeyValuePair<string, bool>("ABC", true),
                    new KeyValuePair<string, bool>("ABCDE", false),
                    new KeyValuePair<string, bool>("ADE", true)
                };

            Assert.AreEqual(new KeyValuePair<string, bool>(), destinationArray[0]);
            Assert.AreEqual(new KeyValuePair<string, bool>(), destinationArray[destinationArray.Length - 1]);
            Assert.IsTrue(expected.SequenceEqual(result));
        }
Example #4
0
 private void ChangeWhereClauseTable(KeyValuePair<DataTable, DataTable>[] tables, 
     ref List<SqlFilterCondition> whereClause)
 {
     DataTable prevTable = null;
     for (int i = 0; i < whereClause.Count; i++)
     {
         SqlFilterCondition cond = whereClause[i];
         if (cond.Table != prevTable)
         {
             var q = tables.Where(t => t.Key.TableName == cond.Table.TableName);
             if (q.Count() == 1) prevTable = q.ElementAt(0).Value;
         }
         if (prevTable != null)
         {
             cond.Table = prevTable;
             whereClause[i] = cond;
         }
     }
 }
Example #5
0
        /// <summary>
        /// Serializes the navigator popular rooms news.
        /// </summary>
        /// <param name="reply">The reply.</param>
        /// <param name="rooms">The rooms.</param>
        /// <param name="category">The category.</param>
        /// <param name="direct">if set to <c>true</c> [direct].</param>
        public void SerializeNavigatorPopularRoomsNews(ref ServerMessage reply, KeyValuePair<RoomData, uint>[] rooms,
                                                       int category, bool direct)
        {
            if (rooms == null || !rooms.Any())
            {
                reply.AppendInteger(0);
                return;
            }

            List<RoomData> roomsCategory = new List<RoomData>();
            foreach (KeyValuePair<RoomData, uint> pair in rooms.Where(pair => pair.Key.Category.Equals(category)))
            {
                roomsCategory.Add(pair.Key);
                if (roomsCategory.Count == (direct ? 40 : 8)) break;
            }
            reply.AppendInteger(roomsCategory.Count);
            foreach (RoomData data in roomsCategory) data.Serialize(reply, false);
        }
 private string projectFromArgs(KeyValuePair<string,string>[] arguments)
 {
     var sublimeProject = arguments
         .Where(p => p.Key == "--editor.sublime.project")
         .Select(p => p.Value)
         .FirstOrDefault();
     return sublimeProject;
 }
Example #7
0
        private static void WriteConstants(StringBuilder outputString, HashSet<string> usedConstants, ref KeyValuePair<string,string>[] remainingConstants, string prefix, string constantsName = null, Func<string, bool> additionalAcceptanceConstantFilter = null, Func<string, bool> additionalRejectConstantFilter = null)
        {
            if (string.IsNullOrEmpty(constantsName))
                constantsName = FormatEnumName(prefix, "");

            var constants = remainingConstants.Where(k => (k.Key.StartsWith(prefix) || (additionalAcceptanceConstantFilter != null && additionalAcceptanceConstantFilter(k.Key))) && (additionalRejectConstantFilter == null || additionalRejectConstantFilter(k.Key))).ToArray();
            remainingConstants = remainingConstants.Except(constants).ToArray();

            outputString.AppendLine("    enum " + constantsName);
            outputString.AppendLine("    {");
            foreach (var c in constants)
            {
                string cname = FormatEnumName(c.Key, prefix);

                while (usedConstants.Contains(cname))
                    cname += "_";
                usedConstants.Add(cname);

                outputString.AppendFormat("        {0} = {1},", cname, c.Value);
                outputString.AppendLine();
            }

            outputString.AppendLine("    };");
        }