Beispiel #1
0
        public void Process(HierarchyDef hierarchyDef, FieldDef fieldDef, KeyAttribute attribute)
        {
            ArgumentValidator.EnsureArgumentIsInRange(attribute.Position, 0, WellKnown.MaxKeyFieldNumber - 1,
                                                      "attribute.Position");

            var keyField = new KeyField(fieldDef.Name, attribute.Direction);

            if (hierarchyDef.KeyFields.Count > attribute.Position)
            {
                var current = hierarchyDef.KeyFields[attribute.Position];
                if (current != null)
                {
                    throw new DomainBuilderException(string.Format(Strings.ExKeyFieldsXAndXHaveTheSamePositionX, current.Name,
                                                                   fieldDef.Name, attribute.Position));
                }

                hierarchyDef.KeyFields[attribute.Position] = keyField;
            }
            else
            {
                // Adding null stubs for not yet processed key fields
                while (hierarchyDef.KeyFields.Count < attribute.Position)
                {
                    hierarchyDef.KeyFields.Add(null);
                }

                // Finally adding target key field at the specified position
                hierarchyDef.KeyFields.Add(keyField);
            }
        }
 /// <summary>
 /// Initializes a new instance of this type.
 /// </summary>
 /// <param name="lruCapacity">The <see cref="LruCapacity"/> property value.</param>
 /// <param name="mfuCapacity">The <see cref="MfuCapacity"/> property value.</param>
 /// <param name="efficiencyFactor">The <see cref="EfficiencyFactor"/> property value.</param>
 /// <param name="keyExtractor"><see cref="ICache{TKey, TItem}.KeyExtractor"/> property value.</param>
 /// <param name="chainedCache"><see cref="ChainedCache"/> property value.</param>
 public MfLruCache(int lruCapacity, int mfuCapacity, int efficiencyFactor,
                   Converter <TItem, TKey> keyExtractor, ICache <TKey, TItem> chainedCache)
 {
     if (lruCapacity <= 0)
     {
         ArgumentValidator.EnsureArgumentIsInRange(lruCapacity, 1, int.MaxValue, "lruCapacity");
     }
     if (mfuCapacity < 0)
     {
         ArgumentValidator.EnsureArgumentIsInRange(lruCapacity, 0, int.MaxValue, "mfuCapacity");
     }
     ArgumentValidator.EnsureArgumentNotNull(keyExtractor, "keyExtractor");
     this.lruCapacity      = lruCapacity;
     this.mfuCapacity      = mfuCapacity;
     capacity              = lruCapacity + mfuCapacity;
     this.efficiencyFactor = efficiencyFactor;
     if (efficiencyFactor < 0)
     {
         timeShift = -efficiencyFactor - 1; // Constant timeShift is defined
     }
     this.KeyExtractor = keyExtractor;
     this.chainedCache = chainedCache;
     // items = new Dictionary<TKey, CachedItem>(1 + capacity);
     items = new Dictionary <TKey, CachedItem>();
 }
Beispiel #3
0
 /// <summary>
 /// Initializes new instance of this type.
 /// </summary>
 /// <param name="type">The type.</param>
 /// <param name="typeName">Name of the type.</param>
 /// <param name="length">The length.</param>
 /// <param name="precision">The precision.</param>
 /// <param name="scale">The scale.</param>
 public SqlValueType(SqlType type, string typeName, int?length, int?precision, int?scale)
 {
     if ((type == SqlType.Unknown) != (typeName != null))
     {
         throw new ArgumentException(Strings.ExInvalidArgumentsNonNullTypeNameIsAllowedIfAndOnlyIfTypeEqualsSqlTypeUnknown);
     }
     if (precision.HasValue && precision != 0 && length.HasValue && length != 0)
     {
         throw new ArgumentException(Strings.ExInvalidArgumentsPrecisionAndLengthShouldNotBeUsedTogether);
     }
     if (precision.HasValue != scale.HasValue)
     {
         throw new ArgumentException(Strings.ExInvalidArgumentsScaleAndPrecisionShouldBeUsedTogether);
     }
     if (typeName != null)
     {
         ArgumentValidator.EnsureArgumentNotNullOrEmpty(typeName, "typeName");
     }
     if (length != null)
     {
         ArgumentValidator.EnsureArgumentIsGreaterThan(length.Value, 0, "length");
     }
     if (precision != null)
     {
         ArgumentValidator.EnsureArgumentIsInRange(scale.Value, 0, precision.Value, "scale");
     }
     Type      = type;
     TypeName  = typeName;
     Length    = length;
     Precision = precision;
     Scale     = scale;
 }
Beispiel #4
0
 public TypeInfo(Type type, bool isNullable)
 {
     ArgumentValidator.EnsureArgumentNotNull(type, "type");
     if (isNullable && type.IsValueType && !type.IsNullable())
     {
         ArgumentValidator.EnsureArgumentIsInRange(true, false, false, "isNullable");
     }
     Type       = type;
     IsNullable = isNullable;
 }
Beispiel #5
0
        /// <inheritdoc/>
        public void RemoveRange(int index, int count)
        {
            ArgumentValidator.EnsureArgumentIsInRange(index, 0, this.count - 1, "index");
            ArgumentValidator.EnsureArgumentIsInRange(count, 0, this.count - index, "count");

            if (count < 0 || (count > this.count - index))
            {
                throw new ArgumentOutOfRangeException("count");
            }

            int bufferIndex = ConvertToBufferIndex(index);

            if (this.count > 0)
            {
                int tailLength = this.count - count - index;
                if (tailLength > 0)
                {
                    if (tailPos - bufferIndex > 0)
                    {
                        Array.Copy(items, bufferIndex + count, items, bufferIndex, this.count - count - index);
                    }
                    else
                    {
                        int endBufferIndex    = ConvertToBufferIndex(index + count);
                        int firstChunkLength  = Math.Min(count, items.Length - bufferIndex);
                        int secondChunkLength = Math.Max(0, count - firstChunkLength);
                        if (firstChunkLength > 0)
                        {
                            Array.Copy(items, endBufferIndex, items, bufferIndex, Math.Min(firstChunkLength, tailLength));
                        }
                        if (secondChunkLength > 0 && tailLength > firstChunkLength)
                        {
                            Array.Copy(items, endBufferIndex + firstChunkLength, items, 0, tailLength - firstChunkLength);
                        }
                    }
                }
                int startFillPosition = ConvertToBufferIndex(this.count - count);
                int newTail           = startFillPosition;
                if (tailPos < startFillPosition)
                {
                    for (int i = startFillPosition; i < items.Length; i++)
                    {
                        items[i] = default(T);
                    }
                    startFillPosition = 0;
                }
                for (int i = startFillPosition; i < tailPos; i++)
                {
                    items[i] = default(T);
                }

                tailPos     = newTail;
                this.count -= count;
            }
        }
Beispiel #6
0
        /// <inheritdoc/>
        public void Insert(int index, T item)
        {
            ArgumentValidator.EnsureArgumentIsInRange(index, 0, count, "index");

            if (count == items.Length)
            {
                EnsureCapacity(count + 1);
            }

            int bufferIndex = ConvertToBufferIndex(index);
            int headIndex   = headPos + 1;

            if (headIndex == items.Length)
            {
                headIndex = 0;
            }
            if (bufferIndex == tailPos)
            {
                AddTail(item);
            }
            else if (bufferIndex == headIndex)
            {
                AddHead(item);
            }
            else if (bufferIndex < tailPos)
            {
                int dataToMoveLength = tailPos - bufferIndex;
                Array.Copy(items, bufferIndex, items, bufferIndex + 1, dataToMoveLength);
                items[bufferIndex] = item;
                // Shift to "next free" position
                if ((++tailPos) == items.Length)
                {
                    tailPos = 0;
                }
                count++;
                version++;
            }
            else if (bufferIndex > headIndex)
            {
                int dataToMoveLength = bufferIndex - headIndex;
                Array.Copy(items, headPos + 1, items, headPos, dataToMoveLength);
                items[bufferIndex - 1] = item;
                // Shift to "previous free" position
                if ((--headPos) == -1)
                {
                    headPos += items.Length;
                }
                count++;
                version++;
            }
            else
            {
                throw Exceptions.InternalError("Deque.Insert: Wrong buffer index detected.", CoreLog.Instance);
            }
        }
Beispiel #7
0
 /// <inheritdoc/>
 public T this[int index] {
     get {
         ArgumentValidator.EnsureArgumentIsInRange(index, 0, count - 1, "index");
         return(items[ConvertToBufferIndex(index)]);
     }
     set {
         ArgumentValidator.EnsureArgumentIsInRange(index, 0, count - 1, "index");
         items[ConvertToBufferIndex(index)] = value;
         version++;
     }
 }
Beispiel #8
0
 /// <summary>
 /// Initializes new instance of this type.
 /// </summary>
 /// <param name="maxSize"><see cref="MaxSize"/> property value.</param>
 /// <param name="keyExtractor"><see cref="ICache{TKey, TItem}.KeyExtractor"/> property value.</param>
 /// <param name="cacheConverter"><see cref="CacheConverter"/> property value.</param>
 /// <param name="chainedCache"><see cref="ChainedCache"/> property value.</param>
 public LruCache(long maxSize, Converter <TItem, TKey> keyExtractor,
                 Biconverter <TItem, TCached> cacheConverter, ICache <TKey, TItem> chainedCache)
 {
     if (maxSize <= 0)
     {
         ArgumentValidator.EnsureArgumentIsInRange(maxSize, 1, long.MaxValue, "maxSize");
     }
     ArgumentValidator.EnsureArgumentNotNull(keyExtractor, "keyExtractor");
     this.maxSize        = maxSize;
     this.KeyExtractor   = keyExtractor;
     this.cacheConverter = cacheConverter;
     this.chainedCache   = chainedCache;
     // deque = new TopDeque<TKey, TCached>(1 + (int) maxSize);
     deque = new TopDeque <TKey, TCached>();
 }
Beispiel #9
0
        /// <inheritdoc/>
        public void CopyTo(T[] array, int arrayIndex)
        {
            ArgumentValidator.EnsureArgumentNotNull(array, "array");
            ArgumentValidator.EnsureArgumentIsInRange(arrayIndex, 0, int.MaxValue, "arrayIndex");

            if (array.Length < totalItemCount + arrayIndex)
            {
                throw new ArgumentException();
            }

            foreach (var item in this)
            {
                array[arrayIndex++] = item;
            }
        }
Beispiel #10
0
 /// <summary>
 /// Initializes new instance of this type.
 /// </summary>
 /// <param name="maxSize"><see cref="MaxSize"/> property value.</param>
 /// <param name="keyExtractor"><see cref="KeyExtractor"/> property value.</param>
 /// <param name="sizeExtractor"><see cref="SizeExtractor"/> property value.</param>
 /// <param name="chainedCache"><see cref="ChainedCache"/> property value.</param>
 public LruCache(long maxSize, Converter <TItem, TKey> keyExtractor,
                 Func <TItem, long> sizeExtractor, ICache <TKey, TItem> chainedCache)
 {
     if (maxSize <= 0)
     {
         ArgumentValidator.EnsureArgumentIsInRange(maxSize, 1, long.MaxValue, "maxSize");
     }
     ArgumentValidator.EnsureArgumentNotNull(keyExtractor, "keyExtractor");
     ArgumentValidator.EnsureArgumentNotNull(sizeExtractor, "sizeExtractor");
     this.maxSize       = maxSize;
     this.keyExtractor  = keyExtractor;
     this.sizeExtractor = sizeExtractor;
     this.chainedCache  = chainedCache;
     // deque = new TopDeque<TKey, KeyValuePair<TKey, TItem>>(1 + (int) maxSize);
     deque = new TopDeque <TKey, KeyValuePair <TKey, TItem> >();
 }
Beispiel #11
0
        /// <summary>
        /// Gets or sets the element at the specified index.
        /// </summary>
        /// <param name="index">Index of the item</param>
        /// <exception cref="ArgumentOutOfRangeException">The index is greater or equal count of items.</exception>
        public T this[int index]
        {
            get
            {
                if (index < 0 || index >= count)
                {
                    ArgumentValidator.EnsureArgumentIsInRange(index, 0, count - 1, "index");
                }
                switch (index)
                {
                case 0:
                    return(slot1);

                case 1:
                    return(slot2);

                default:
                    return(slot3);
                }
            }
            set
            {
                if (index < 0 || index >= count)
                {
                    ArgumentValidator.EnsureArgumentIsInRange(index, 0, count - 1, "index");
                }
                switch (index)
                {
                case 0:
                    slot1 = value;
                    break;

                case 1:
                    slot2 = value;
                    break;

                default:
                    slot3 = value;
                    break;
                }
            }
        }
Beispiel #12
0
        /// <inheritdoc/>
        public void RemoveAt(int index)
        {
            ArgumentValidator.EnsureArgumentIsInRange(index, 0, count - 1, "index");

            int bufferIndex = ConvertToBufferIndex(index);

            if (tailPos - bufferIndex == 1)
            {
                ExtractTail();
            }
            else if (bufferIndex - headPos == 1)
            {
                ExtractHead();
            }
            else if (bufferIndex > headPos)
            {
                int dataToMoveLength = bufferIndex - headPos - 1;
                // Shift to the "tail element" position
                headPos++;
                Array.Copy(items, headPos, items, headPos + 1, dataToMoveLength);
                items[headPos] = default(T);
                count--;
                version++;
            }
            else if (bufferIndex < tailPos)
            {
                int dataToMoveLength = tailPos - bufferIndex - 1;
                // Shift to the "head element" position
                tailPos--;
                Array.Copy(items, bufferIndex + 1, items, bufferIndex, dataToMoveLength);
                items[tailPos] = default(T);
                count--;
                version++;
            }
            else
            {
                throw Exceptions.InternalError("Deque.RemoveAt: Wrong buffer index detected.", CoreLog.Instance);
            }
        }
Beispiel #13
0
        /// <summary>
        /// Adds item to the <see cref="FixedList3{T}"/> list.
        /// </summary>
        /// <param name="item">Item to add.</param>
        /// <exception cref="ArgumentException">The list already have three items.</exception>
        public void Push(T item)
        {
            switch (count)
            {
            case 0:
                slot1 = item;
                break;

            case 1:
                slot2 = item;
                break;

            case 2:
                slot3 = item;
                break;

            default:
                ArgumentValidator.EnsureArgumentIsInRange(count, 0, 2, "count");
                return;
            }
            count++;
        }
Beispiel #14
0
 /// <summary>
 /// Creates tuple descriptor containing tail of the current one.
 /// </summary>
 /// <param name="tailFieldCount">Tail field count.</param>
 /// <returns>Either new or existing tuple descriptor
 /// describing the specified set of fields.</returns>
 public TupleDescriptor Tail(int tailFieldCount)
 {
     ArgumentValidator.EnsureArgumentIsInRange(tailFieldCount, 1, Count, "tailFieldCount");
     return(Create(FieldTypes.Skip(Count - tailFieldCount)));
 }
Beispiel #15
0
        public static Key Materialize(Domain domain, string nodeId,
                                      TypeInfo type, TypeReferenceAccuracy accuracy, params object[] values)
        {
            var keyInfo = type.Key;

            ArgumentValidator.EnsureArgumentIsInRange(values.Length, 1, keyInfo.TupleDescriptor.Count, "values");

            var tuple       = Tuple.Create(keyInfo.TupleDescriptor);
            int typeIdIndex = keyInfo.TypeIdColumnIndex;

            if (typeIdIndex >= 0)
            {
                tuple.SetValue(typeIdIndex, type.TypeId);
            }

            int tupleIndex = 0;

            if (tupleIndex == typeIdIndex)
            {
                tupleIndex++;
            }
            for (int valueIndex = 0; valueIndex < values.Length; valueIndex++)
            {
                var value = values[valueIndex];
                ArgumentValidator.EnsureArgumentNotNull(value, String.Format("values[{0}]", valueIndex));
                var entity = value as Entity;
                if (entity != null)
                {
                    entity.EnsureNotRemoved();
                    value = entity.Key;
                }
                var key = value as Key;
                if (key != null)
                {
                    if (key.TypeReference.Type.Hierarchy == type.Hierarchy)
                    {
                        typeIdIndex = -1; // Key must be fully copied in this case
                    }
                    for (int keyIndex = 0; keyIndex < key.Value.Count; keyIndex++)
                    {
                        tuple.SetValue(tupleIndex++, key.Value.GetValueOrDefault(keyIndex));
                        if (tupleIndex == typeIdIndex)
                        {
                            tupleIndex++;
                        }
                    }
                    continue;
                }
                tuple.SetValue(tupleIndex++, value);
                if (tupleIndex == typeIdIndex)
                {
                    tupleIndex++;
                }
            }
            if (tupleIndex != tuple.Count)
            {
                throw new ArgumentException(String.Format(
                                                Strings.ExSpecifiedValuesArentEnoughToCreateKeyForTypeX, type.Name));
            }

            return(Materialize(domain, nodeId, type, tuple, accuracy, false, null));
        }
Beispiel #16
0
 public TypeInfo(Type type, bool isNullable, int length)
     : this(type, isNullable)
 {
     ArgumentValidator.EnsureArgumentIsInRange(length, 0, int.MaxValue, "length");
     Length = length;
 }
Beispiel #17
0
 /// <summary>
 /// Initializes new instance of this type.
 /// </summary>
 /// <param name="maxNodeSize">The maximal node size.</param>
 public ChainedBuffer(int maxNodeSize)
 {
     ArgumentValidator.EnsureArgumentIsInRange(maxNodeSize, 1, int.MaxValue, "maxNodeSize");
     this.maxNodeSize = maxNodeSize;
     currentNodeSize  = InitialNodeSize;
 }
Beispiel #18
0
 /// <summary>
 /// Creates tuple descriptor containing head of the current one.
 /// </summary>
 /// <param name="headFieldCount">Head field count.</param>
 /// <returns>Either new or existing tuple descriptor
 /// describing the specified set of fields.</returns>
 public TupleDescriptor Head(int headFieldCount)
 {
     ArgumentValidator.EnsureArgumentIsInRange(headFieldCount, 1, Count, "headFieldCount");
     return(Create(FieldTypes.Take(headFieldCount)));
 }