예제 #1
0
파일: Parse.cs 프로젝트: simwak/Confused
        /// <summary>
        ///     Parses a .conf-file from a string into a KeyValueStore
        /// </summary>
        /// <param name="conf">A string representing a .conf-file</param>
        public static KeyValueStore String(string conf)
        {
            var dictionary = new KeyValueStore();

            using (var reader = new StringReader(conf))
            {
                string   line;
                KeyValue container = null;

                while ((line = reader.ReadLine()) != null)
                {
                    line = line.Split('#')[0].Trim();

                    if (line.StartsWith('[') && line.EndsWith(']'))
                    {
                        var sectionName = line.TrimStart('[').TrimEnd(']');
                        container = new KeyValue();

                        dictionary.Add(sectionName, container);
                    }
                    else if (!string.IsNullOrEmpty(line))
                    {
                        var elements = line.Split('=');
                        container?.Add(elements[0].Trim(), elements[1].Trim());
                    }
                }
            }

            return(dictionary);
        }
예제 #2
0
        private void AddNode(T nodeId)
        {
            if (store.ContainsKey(nodeId))
            {
                return;
            }
            byte[] input = null;
            string name  = null;
            string node  = nodeId.ToString();

            uint[]       keys   = new uint[circlePoints];
            List <Point> points = null;

            try
            {
                lock (locker)
                {
                    points = new List <Point>(circle.Count + circlePoints);
                    points.AddRange(circle);


                    for (int i = 0; i < circlePoints; i++)
                    {
                        name    = node + i.ToPadded(3);
                        input   = Encoding.UTF8.GetBytes(name);
                        keys[i] = hash.Hash(input);
                        points.Add(new Point(keys[i], nodeId));
                    }

                    points.Sort(compare);
                    circle = points;
                    store.Add(nodeId, keys);    //Should this be using Upsert?
                }
            }
            finally
            {
                input  = null;
                name   = null;
                points = null;
                node   = null;
                keys   = null;
            }
        }