Exemplo n.º 1
0
        public static ClassIndex Parse(string data)
        {
            string sDocCount = data.Substring(0, 10);

            if (!int.TryParse(sDocCount, out int docCount))
            {
                throw new ArgumentException("Invalid format");
            }

            var tokens = from p in data.Substring(10).Split("&")
                         let pieces                                                             = p.Split("=")
                                                              let token                         = System.Web.HttpUtility.UrlDecode(pieces[0])
                                                                                      let count = int.Parse(pieces[1])
                                                                                                  select new { token, count };

            ClassIndex index = new ClassIndex();

            index.DocumentCount = docCount;
            foreach (var p in tokens)
            {
                index.Tokens.AddOrUpdate(p.token, p.count, (t, val) => p.count);
            }

            return(index);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Parse a ClassIndex serialised with ToSerialised()
        /// </summary>
        /// <returns>The parse.</returns>
        /// <param name="data">Data.</param>
        public static ClassIndex Parse(string data)
        {
            string sDocCount = data.Substring(0, 10);

            if (!int.TryParse(sDocCount, out int docCount))
            {
                throw new ArgumentException("Invalid format");
            }

            string encodedTokens = data.Substring(10);

            ClassIndex index = new ClassIndex();

            index.DocumentCount = docCount;
            index.TokensString  = encodedTokens;

            return(index);
        }