Exemple #1
0
        private void CheckRecursionStackAndPush(object instance)
        {
            int hitLevel;

            if (recursionStack == null)
            {
                recursionStack = new MutableList();
            }
            else if (instance != null && (hitLevel = recursionStack.IndexOfReference(instance)) >= 0)
            {
#if DEBUG
                Helpers.DebugWriteLine("Stack:");
                foreach (object obj in recursionStack)
                {
                    Helpers.DebugWriteLine(obj == null ? "<null>" : obj.ToString());
                }
                Helpers.DebugWriteLine(instance == null ? "<null>" : instance.ToString());
#endif
                throw new ProtoException("Possible recursion detected (offset: " + (recursionStack.Count - hitLevel).ToString() + " level(s)): " + instance.ToString());
            }
            recursionStack.Add(instance);
        }
        internal void SetKeyedObject(int key, object value)
        {
            int num = key;

            key = num - 1;
            if (num == 0)
            {
                if (value == null)
                {
                    throw new ArgumentNullException("value");
                }
                if (this.rootObject != null && this.rootObject != value)
                {
                    throw new ProtoException("The root object cannot be reassigned");
                }
                this.rootObject = value;
                return;
            }
            MutableList list = this.List;

            if (key < list.Count)
            {
                object item = list[key];
                if (item == null)
                {
                    list[key] = value;
                    return;
                }
                if (!object.ReferenceEquals(item, value))
                {
                    throw new ProtoException("Reference-tracked objects cannot change reference");
                }
            }
            else if (key != list.Add(value))
            {
                throw new ProtoException("Internal error; a key mismatch occurred");
            }
        }
        internal void SetKeyedObject(int key, object value, bool lateSet)
        {
            if (key-- == Root)
            {
                if (_rootObject != null && ((object)_rootObject != (object)value))
                {
                    throw new ProtoException("The root object cannot be reassigned");
                }
                _rootObject = value;
            }
            else
            {
                MutableList list = List;

                while (key > list.Count)
                {
                    list.Add(null);
                }

                if (key < list.Count)
                {
                    object oldVal = list[key];
                    if (oldVal == null || lateSet)
                    {
                        list[key] = value;
                    }
                    else if (!ReferenceEquals(oldVal, value))
                    {
                        throw new ProtoException("Reference-tracked objects cannot change reference");
                    } // otherwise was the same; nothing to do
                }
                else if (key != list.Add(value))
                {
                    throw new ProtoException("Internal error; a key mismatch occurred");
                }
            }
        }
Exemple #4
0
        internal void SetKeyedObject(int key, object value)
        {
            if (key-- == 0)
            {
                if (value == null)
                {
                    throw new ArgumentNullException("value");
                }
                if (rootObject != null && rootObject != value)
                {
                    throw new ProtoException("The root object cannot be reassigned");
                }
                rootObject = value;
                return;
            }
            MutableList list = List;

            if (key < list.Count)
            {
                object obj = list[key];
                if (obj == null)
                {
                    list[key] = value;
                    return;
                }
                if (obj == value)
                {
                    return;
                }
                throw new ProtoException("Reference-tracked objects cannot change reference");
            }
            if (key == list.Add(value))
            {
                return;
            }
            throw new ProtoException("Internal error; a key mismatch occurred");
        }
    public Option <ReadOnlyList <CommandSubmission> > Submit(IEnumerable <ICommandSpec> commands, SystemNode target, CorrelationToken?ct)
    {
        var index = dict(commands.GroupBy(x => x.CommandName).Select(g => (g.Key, g.Select(y => y))));
        var all   = MutableList.Create <CommandSubmission>();

        foreach (var commandName in index.Keys)
        {
            var sorted  = index[commandName];
            var pattern = Pattern(commandName);
            if (!pattern)
            {
                return(pattern.ToNone <ReadOnlyList <CommandSubmission> >());
            }

            var submissions = pattern.MapValueOrDefault(p => p.Queue.Enqueue(sorted, target, ct));
            if (!submissions)
            {
                return(submissions.ToNone <ReadOnlyList <CommandSubmission> >());
            }

            all.AddRange(submissions.Items());
        }
        return(all.ToReadOnlyList());
    }
Exemple #6
0
        private void Initialize(string fileName)
        {
            if (fileName == null)
            {
                throw new ArgumentNullException("fileName");
            }

            IntPtr hModule = IntPtr.Zero;

            try
            {
                hModule = NativeMethods.LoadLibraryEx(fileName, IntPtr.Zero, LOAD_LIBRARY_AS_DATAFILE);
                if (hModule == IntPtr.Zero)
                {
                    throw new Win32Exception();
                }

                FileName = GetFileName(hModule);

                // Enumerate the icon resource and build .ico files in memory.

                var tmpData = MutableList.Create <byte[]>();

                ENUMRESNAMEPROC callback = (h, t, name, l) =>
                {
                    // Refer to the following URL for the data structures used here:
                    // http://msdn.microsoft.com/en-us/library/ms997538.aspx

                    // RT_GROUP_ICON resource consists of a GRPICONDIR and GRPICONDIRENTRY's.

                    var dir = GetDataFromResource(hModule, RT_GROUP_ICON, name);

                    // Calculate the size of an entire .icon file.

                    int count = BitConverter.ToUInt16(dir, 4);  // GRPICONDIR.idCount
                    int len   = 6 + 16 * count;                 // sizeof(ICONDIR) + sizeof(ICONDIRENTRY) * count
                    for (int i = 0; i < count; ++i)
                    {
                        len += BitConverter.ToInt32(dir, 6 + 14 * i + 8);   // GRPICONDIRENTRY.dwBytesInRes
                    }
                    using (var dst = new BinaryWriter(new MemoryStream(len)))
                    {
                        // Copy GRPICONDIR to ICONDIR.

                        dst.Write(dir, 0, 6);

                        int picOffset = 6 + 16 * count; // sizeof(ICONDIR) + sizeof(ICONDIRENTRY) * count

                        for (int i = 0; i < count; ++i)
                        {
                            // Load the picture.

                            ushort id  = BitConverter.ToUInt16(dir, 6 + 14 * i + 12);   // GRPICONDIRENTRY.nID
                            var    pic = GetDataFromResource(hModule, RT_ICON, (IntPtr)id);

                            // Copy GRPICONDIRENTRY to ICONDIRENTRY.

                            dst.Seek(6 + 16 * i, SeekOrigin.Begin);

                            dst.Write(dir, 6 + 14 * i, 8);  // First 8bytes are identical.
                            dst.Write(pic.Length);          // ICONDIRENTRY.dwBytesInRes
                            dst.Write(picOffset);           // ICONDIRENTRY.dwImageOffset

                            // Copy a picture.

                            dst.Seek(picOffset, SeekOrigin.Begin);
                            dst.Write(pic, 0, pic.Length);

                            picOffset += pic.Length;
                        }

                        tmpData.Add(((MemoryStream)dst.BaseStream).ToArray());
                    }

                    return(true);
                };
                NativeMethods.EnumResourceNames(hModule, RT_GROUP_ICON, callback, IntPtr.Zero);

                iconData = tmpData.ToArray();
            }
            finally
            {
                if (hModule != IntPtr.Zero)
                {
                    NativeMethods.FreeLibrary(hModule);
                }
            }
        }
Exemple #7
0
        /// <summary>
        /// Modifies the current SelectionSet&lt;T&gt; object to contain only elements that are present
        /// either in that object or in the specified collection, but not both.
        /// </summary>
        ///
        /// <param name="other">
        /// The collection to compare to the current SelectionSet&lt;T&gt; object.
        /// </param>

        public void SymmetricExceptWith(IEnumerable <T> other)
        {
            MutableList.SymmetricExceptWith(other);
            SynchronizeOrderedList();
            Touch();
        }
Exemple #8
0
        /// <summary>
        /// Determines whether a SelectionSet&lt;T&gt; object and the specified collection contain the
        /// same elements.
        /// </summary>
        ///
        /// <param name="other">
        /// The collection to compare to the current SelectionSet&lt;T&gt; object.
        /// </param>
        ///
        /// <returns>
        /// true if it succeeds, false if it fails.
        /// </returns>

        public bool SetEquals(IEnumerable <T> other)
        {
            return(MutableList.SetEquals(other));
        }
Exemple #9
0
        /// <summary>
        /// Determines whether the current SelectionSet&lt;T&gt; object and a specified collection share
        /// common elements.
        /// </summary>
        ///
        /// <param name="other">
        /// The collection to compare to the current System.Collections.Generic.HashSet&lt;T&gt;
        /// object.
        /// </param>
        ///
        /// <returns>
        /// true if the sets share at least one common element; , false if not.
        /// </returns>

        public bool Overlaps(IEnumerable <T> other)
        {
            return(MutableList.Overlaps(other));
        }
Exemple #10
0
        /// <summary>
        /// Determines whether a SelectionSet&lt;T&gt; object is a superset of the specified collection.
        /// </summary>
        ///
        /// <param name="other">
        /// The collection to compare to the current SelectionSet&lt;T&gt; object.
        /// </param>
        ///
        /// <returns>
        /// true if is is a proper superset, false if not.
        /// </returns>

        public bool IsSupersetOf(IEnumerable <T> other)
        {
            return(MutableList.IsSupersetOf(other));
        }
Exemple #11
0
        /// <summary>
        /// Determines whether a SelectionSet&lt;T&gt; object is a proper subset of the specified
        /// collection.
        /// </summary>
        ///
        /// <param name="other">
        /// The collection to compare to the current SelectionSet&lt;T&gt; object.
        /// </param>
        ///
        /// <returns>
        /// true if it is a proper subset, false if not.
        /// </returns>

        public bool IsProperSubsetOf(IEnumerable <T> other)
        {
            return(MutableList.IsProperSubsetOf(other));
        }
Exemple #12
0
        /// <summary>
        /// Modifies the current SelectionSet&lt;T&gt; object to contain only elements that are present
        /// in that object and in the specified collection.
        /// </summary>
        ///
        /// <param name="other">
        /// The collection to compare to the current SelectionSet&lt;T&gt;
        /// object.
        /// </param>

        public void IntersectWith(IEnumerable <T> other)
        {
            MutableList.IntersectWith(other);
            SynchronizeOrderedList();
            Touch();
        }
Exemple #13
0
        /// <summary>
        /// Test whether the item is present in the SelectionSet
        /// </summary>
        ///
        /// <param name="item">
        /// The item to test for containment.
        /// </param>
        ///
        /// <returns>
        /// true if the object is in this collection, false if not.
        /// </returns>

        public bool Contains(T item)
        {
            return(IsAltered ?
                   MutableList.Contains(item) :
                   OriginalList.Contains(item));
        }
Exemple #14
0
        internal static AddedWithValuesAndRemoved IndexUpdatesWithValuesForRangeSeek <T1>(ReadableTransactionState txState, IndexDescriptor descriptor, IndexQuery.RangePredicate <T1> predicate, IndexOrder indexOrder)
        {
            Value lower = predicate.FromValue();
            Value upper = predicate.ToValue();

            if (lower == null || upper == null)
            {
                throw new System.InvalidOperationException("Use Values.NO_VALUE to encode the lack of a bound");
            }

//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: java.util.NavigableMap<org.neo4j.values.storable.ValueTuple, ? extends org.neo4j.storageengine.api.txstate.LongDiffSets> sortedUpdates = txState.getSortedIndexUpdates(descriptor.schema());
            NavigableMap <ValueTuple, ? extends LongDiffSets> sortedUpdates = txState.GetSortedIndexUpdates(descriptor.Schema());

            if (sortedUpdates == null)
            {
                return(_emptyAddedAndRemovedWithValues);
            }

            ValueTuple selectedLower;
            bool       selectedIncludeLower;

            ValueTuple selectedUpper;
            bool       selectedIncludeUpper;

            if (lower == NO_VALUE)
            {
                selectedLower        = ValueTuple.of(Values.minValue(predicate.ValueGroup(), upper));
                selectedIncludeLower = true;
            }
            else
            {
                selectedLower        = ValueTuple.of(lower);
                selectedIncludeLower = predicate.FromInclusive();
            }

            if (upper == NO_VALUE)
            {
                selectedUpper        = ValueTuple.of(Values.maxValue(predicate.ValueGroup(), lower));
                selectedIncludeUpper = false;
            }
            else
            {
                selectedUpper        = ValueTuple.of(upper);
                selectedIncludeUpper = predicate.ToInclusive();
            }

            MutableList <NodeWithPropertyValues> added = Lists.mutable.empty();
            MutableLongSet removed = LongSets.mutable.empty();

//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: java.util.Map<org.neo4j.values.storable.ValueTuple,? extends org.neo4j.storageengine.api.txstate.LongDiffSets> inRange = sortedUpdates.subMap(selectedLower, selectedIncludeLower, selectedUpper, selectedIncludeUpper);
            IDictionary <ValueTuple, ? extends LongDiffSets> inRange = sortedUpdates.subMap(selectedLower, selectedIncludeLower, selectedUpper, selectedIncludeUpper);

//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: for (java.util.Map.Entry<org.neo4j.values.storable.ValueTuple,? extends org.neo4j.storageengine.api.txstate.LongDiffSets> entry : inRange.entrySet())
            foreach (KeyValuePair <ValueTuple, ? extends LongDiffSets> entry in inRange.SetOfKeyValuePairs())
            {
                ValueTuple   values               = entry.Key;
                Value[]      valuesArray          = values.Values;
                LongDiffSets diffForSpecificValue = entry.Value;

                // The TreeMap cannot perfectly order multi-dimensional types (spatial) and need additional filtering out false positives
                // TODO: If the composite index starts to be able to handle spatial types the line below needs enhancement
                if (predicate.RegularOrder || predicate.AcceptsValue(values.OnlyValue))
                {
                    diffForSpecificValue.Added.each(nodeId => added.add(new NodeWithPropertyValues(nodeId, valuesArray)));
                    removed.addAll(diffForSpecificValue.Removed);
                }
            }
            return(new AddedWithValuesAndRemoved(indexOrder == IndexOrder.DESCENDING ? added.asReversed() : added, removed));
        }