Exemplo n.º 1
0
        /// <summary>
        /// Deserialize the class data from a stream.
        /// </summary>
        /// <param name="reader">The <see cref="T:MySpace.Common.IO.IPrimitiveReader"/> that extracts used to extra data from a stream.</param>
        /// <param name="version">The value of <see cref="P:MySpace.Common.IVersionSerializable.CurrentVersion"/> that was written to the stream when it was originally serialized to a stream;
        /// the version of the <paramref name="reader"/> data.</param>
        public void Deserialize(IPrimitiveReader reader, int version)
        {
            using (reader.CreateRegion())
            {
                //KeyBagMapping
                ushort count = reader.ReadUInt16();
                if (count > 0)
                {
                    ResultItemBag resultItemBag = null;
                    byte[]        compositeKey;
                    ushort        len;
                    KeyBagMapping = new Dictionary <byte[], ResultItemBag>(new ByteArrayEqualityComparer());
                    for (int i = 0; i < count; i++)
                    {
                        len = reader.ReadUInt16();
                        if (len > 0)
                        {
                            //CompositeKey
                            compositeKey = reader.ReadBytes(len);

                            //ResultItemBag
                            if (reader.ReadBoolean())
                            {
                                resultItemBag = new ResultItemBag(BaseComparer, compositeKey);
                                Serializer.Deserialize(reader.BaseStream, resultItemBag);
                            }
                            KeyBagMapping.Add(compositeKey, resultItemBag);
                            SortedResultItemBagList.Add(resultItemBag);
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        public bool Add(byte[] compositeKey, ResultItem resultItem)
        {
            bool          retVal = false;
            ResultItemBag resultItemBag;

            if (KeyBagMapping.TryGetValue(compositeKey, out resultItemBag))
            {
                SortedResultItemBagList.Remove(resultItemBag);
                resultItemBag.Add(resultItem);
                retVal = true;
            }
            else
            {
                resultItemBag = new ResultItemBag(BaseComparer, compositeKey);
                resultItemBag.Add(resultItem);
                KeyBagMapping.Add(compositeKey, resultItemBag);
            }
            SortedResultItemBagList.Add(resultItemBag);
            return(retVal);
        }
Exemplo n.º 3
0
        public bool Add(byte[] compositeKey, ResultItemBag resultItemBag)
        {
            bool          retVal = false;
            ResultItemBag storedResultItemBag;

            if (KeyBagMapping.TryGetValue(compositeKey, out storedResultItemBag))
            {
                SortedResultItemBagList.Remove(storedResultItemBag);
                foreach (ResultItem resultItem in resultItemBag)
                {
                    storedResultItemBag.Add(resultItem);
                }
                SortedResultItemBagList.Add(storedResultItemBag);
                retVal = true;
            }
            else
            {
                KeyBagMapping.Add(compositeKey, resultItemBag);
                SortedResultItemBagList.Add(resultItemBag);
            }
            return(retVal);
        }