public void BeginTransaction(out ChainedHeader chainTip, out int? unspentTxCount, out int? unspentOutputCount, out int? totalTxCount, out int? totalInputCount, out int? totalOutputCount, out ImmutableSortedDictionary<UInt256, ChainedHeader>.Builder headers, out ImmutableSortedDictionary<UInt256, UnspentTx>.Builder unspentTransactions, out ImmutableDictionary<int, BlockSpentTxes>.Builder blockSpentTxes, out ImmutableDictionary<UInt256, IImmutableList<UnmintedTx>>.Builder blockUnmintedTxes, out long chainTipVersion, out long unspentTxCountVersion, out long unspentOutputCountVersion, out long totalTxCountVersion, out long totalInputCountVersion, out long totalOutputCountVersion, out long headersVersion, out long unspentTxesVersion, out long blockSpentTxesVersion, out long blockUnmintedTxesVersion)
        {
            lock (this.lockObject)
            {
                chainTip = this.chainTip;
                unspentTxCount = this.unspentTxCount;
                unspentOutputCount = this.unspentOutputCount;
                totalTxCount = this.totalTxCount;
                totalInputCount = this.totalInputCount;
                totalOutputCount = this.totalOutputCount;
                headers = this.headers.ToImmutable().ToBuilder();
                unspentTransactions = this.unspentTransactions.ToImmutable().ToBuilder();
                blockSpentTxes = this.blockSpentTxes.ToImmutable().ToBuilder();
                blockUnmintedTxes = this.blockUnmintedTxes.ToImmutable().ToBuilder();

                chainTipVersion = this.chainTipVersion;
                unspentTxCountVersion = this.unspentTxCountVersion;
                unspentOutputCountVersion = this.unspentOutputCountVersion;
                totalTxCountVersion = this.totalTxCountVersion;
                totalInputCountVersion = this.totalInputCountVersion;
                totalOutputCountVersion = this.totalOutputCountVersion;
                headersVersion = this.headersVersion;
                unspentTxesVersion = this.unspentTxesVersion;
                blockSpentTxesVersion = this.blockSpentTxesVersion;
                blockUnmintedTxesVersion = this.blockUnmintedTxesVersion;
            }
        }
        internal MemoryStorageManager(ChainedHeader chainTip = null, int? unspentTxCount = null, int? unspentOutputCount = null, int? totalTxCount = null, int? totalInputCount = null, int? totalOutputCount = null, ImmutableSortedDictionary<UInt256, ChainedHeader> headers = null, ImmutableSortedDictionary<UInt256, UnspentTx> unspentTransactions = null, ImmutableDictionary<int, BlockSpentTxes> spentTransactions = null)
        {
            blockStorage = new MemoryBlockStorage();
            blockTxesStorage = new MemoryBlockTxesStorage();
            chainStateStorage = new MemoryChainStateStorage(chainTip, unspentTxCount, unspentOutputCount, totalTxCount, totalInputCount, totalOutputCount, headers, unspentTransactions, spentTransactions);
            unconfirmedTxesStorage = new MemoryUnconfirmedTxesStorage();

            chainStateCursorCache = new DisposableCache<IChainStateCursor>(1024,
                createFunc: () => new MemoryChainStateCursor(chainStateStorage),
                prepareAction: cursor =>
                {
                    // rollback any open transaction before returning the cursor to the cache
                    if (cursor.InTransaction)
                        cursor.RollbackTransaction();
                });

            unconfirmedTxesCursorCache = new DisposableCache<IUnconfirmedTxesCursor>(1024,
                createFunc: () => new MemoryUnconfirmedTxesCursor(unconfirmedTxesStorage),
                prepareAction: cursor =>
                {
                    // rollback any open transaction before returning the cursor to the cache
                    if (cursor.InTransaction)
                        cursor.RollbackTransaction();
                });
        }
 public MemoryChainStateStorage(ChainedHeader chainTip = null, int? unspentTxCount = null, int? totalTxCount = null, int? totalInputCount = null, int? totalOutputCount = null, int? unspentOutputCount = null, ImmutableSortedDictionary<UInt256, ChainedHeader> headers = null, ImmutableSortedDictionary<UInt256, UnspentTx> unspentTransactions = null, ImmutableDictionary<int, BlockSpentTxes> blockSpentTxes = null, ImmutableDictionary<UInt256, IImmutableList<UnmintedTx>> blockUnmintedTxes = null)
 {
     this.chainTip = chainTip;
     this.unspentTxCount = unspentTxCount ?? 0;
     this.unspentOutputCount = unspentOutputCount ?? 0;
     this.totalTxCount = totalTxCount ?? 0;
     this.totalInputCount = totalInputCount ?? 0;
     this.totalOutputCount = totalOutputCount ?? 0;
     this.headers = headers?.ToBuilder() ?? ImmutableSortedDictionary.CreateBuilder<UInt256, ChainedHeader>();
     this.unspentTransactions = unspentTransactions?.ToBuilder() ?? ImmutableSortedDictionary.CreateBuilder<UInt256, UnspentTx>();
     this.blockSpentTxes = blockSpentTxes?.ToBuilder() ?? ImmutableDictionary.CreateBuilder<int, BlockSpentTxes>();
     this.blockUnmintedTxes = blockUnmintedTxes?.ToBuilder() ?? ImmutableDictionary.CreateBuilder<UInt256, IImmutableList<UnmintedTx>>();
 }
 public MemoryChainStateStorage(ChainedHeader chainTip = null, int? unspentTxCount = null, int? totalTxCount = null, int? totalInputCount = null, int? totalOutputCount = null, int? unspentOutputCount = null, ImmutableSortedDictionary<UInt256, ChainedHeader> headers = null, ImmutableSortedDictionary<UInt256, UnspentTx> unspentTransactions = null, ImmutableDictionary<int, BlockSpentTxes> blockSpentTxes = null, ImmutableDictionary<UInt256, IImmutableList<UnmintedTx>> blockUnmintedTxes = null)
 {
     this.chainTip = CommittedRecord<ChainedHeader>.Initial(chainTip);
     this.unspentTxCount = CommittedRecord<int>.Initial(unspentTxCount ?? 0);
     this.unspentOutputCount = CommittedRecord<int>.Initial(unspentOutputCount ?? 0);
     this.totalTxCount = CommittedRecord<int>.Initial(totalTxCount ?? 0);
     this.totalInputCount = CommittedRecord<int>.Initial(totalInputCount ?? 0);
     this.totalOutputCount = CommittedRecord<int>.Initial(totalOutputCount ?? 0);
     this.headers = CommittedRecord<ImmutableSortedDictionary<UInt256, ChainedHeader>.Builder>.Initial(
         headers?.ToBuilder() ?? ImmutableSortedDictionary.CreateBuilder<UInt256, ChainedHeader>());
     this.unspentTransactions = CommittedRecord<ImmutableSortedDictionary<UInt256, UnspentTx>.Builder>.Initial(
         unspentTransactions?.ToBuilder() ?? ImmutableSortedDictionary.CreateBuilder<UInt256, UnspentTx>());
     this.unspentTxOutputs = CommittedRecord<ImmutableSortedDictionary<TxOutputKey, TxOutput>.Builder>.Initial(
         ImmutableSortedDictionary.CreateBuilder<TxOutputKey, TxOutput>());
     this.blockSpentTxes = CommittedRecord<ImmutableDictionary<int, BlockSpentTxes>.Builder>.Initial(
         blockSpentTxes?.ToBuilder() ?? ImmutableDictionary.CreateBuilder<int, BlockSpentTxes>());
     this.blockUnmintedTxes = CommittedRecord<ImmutableDictionary<UInt256, IImmutableList<UnmintedTx>>.Builder>.Initial(
         blockUnmintedTxes?.ToBuilder() ?? ImmutableDictionary.CreateBuilder<UInt256, IImmutableList<UnmintedTx>>());
 }
Beispiel #5
0
 /// <summary>
 /// Creates a <see cref="VectorClock"/> from some initial seed values.
 /// </summary>
 /// <param name="seedValues">Preliminary values that will be used by the vectorclock.</param>
 /// <returns>A new <see cref="VectorClock"/>.</returns>
 public static VectorClock Create(ImmutableSortedDictionary <Node, long> seedValues)
 {
     return(new VectorClock(seedValues));
 }
Beispiel #6
0
        public void Remove_EmptyDictionary_DoesNothing()
        {
            ImmutableSortedDictionary <int, string> dictionary = ImmutableSortedDictionary <int, string> .Empty;

            Assert.Equal(0, dictionary.Remove(2).Count);
        }
Beispiel #7
0
 protected void ContainsValueTestHelper <TKey, TValue>(ImmutableSortedDictionary <TKey, TValue> map, TKey key, TValue value)
 {
     Assert.False(map.ContainsValue(value));
     Assert.True(map.Add(key, value).ContainsValue(value));
 }
        static void Main(string[] args)
        {
            // 不可变栈和队列
            ImmutableStack <int> stack = ImmutableStack <int> .Empty;

            stack = stack.Push(13);
            stack = stack.Push(7);
            foreach (int item in stack)
            {
                Console.WriteLine(item);
            }
            int lastItem;

            stack = stack.Pop(out lastItem);
            Console.WriteLine(lastItem);

            // 队列和栈类似
            ImmutableQueue <int> queue = ImmutableQueue <int> .Empty;

            queue = queue.Enqueue(13);
            queue = queue.Enqueue(7);
            // 在7之前显示13
            foreach (int item in queue)
            {
                Console.WriteLine(item);
            }
            int nextItem;

            queue = queue.Dequeue(out nextItem);
            // 只显示13
            Console.WriteLine(nextItem);


            //不可变列表
            ImmutableList <int> list = ImmutableList <int> .Empty;

            list = list.Insert(0, 13);
            list = list.Insert(0, 7);
            // 在13之前显示7
            foreach (int item in list)
            {
                Console.WriteLine(item);
            }
            list = list.RemoveAt(1);

            //不可变set
            //hash的
            ImmutableHashSet <int> hashSet = ImmutableHashSet <int> .Empty;

            hashSet = hashSet.Add(13);
            hashSet = hashSet.Add(7);
            // 以不可预知的顺序显示7和13
            foreach (int item in hashSet)
            {
                Console.WriteLine(item);
            }
            hashSet = hashSet.Remove(7);
            //sorted
            ImmutableSortedSet <int> sortedSet = ImmutableSortedSet <int> .Empty;

            sortedSet = sortedSet.Add(13);
            sortedSet = sortedSet.Add(7);
            // 在13之前显示7
            foreach (int item in sortedSet)
            {
                Console.WriteLine(item);
            }
            int smallestItem = sortedSet[0];

            // smallestItem == 7
            sortedSet = sortedSet.Remove(7);

            //不可变Dictionary
            //无排序
            ImmutableDictionary <int, string> dictionary =
                ImmutableDictionary <int, string> .Empty;

            dictionary = dictionary.Add(10, "Ten");
            dictionary = dictionary.Add(21, "Twenty-One");
            dictionary = dictionary.SetItem(10, "Diez");
            // 以不可预知的顺序显示10Diez和21Twenty-One
            foreach (KeyValuePair <int, string> item in dictionary)
            {
                Console.WriteLine(item.Key + item.Value);
            }
            string ten = dictionary[10];

            // ten == "Diez"
            dictionary = dictionary.Remove(21);
            //有排序
            ImmutableSortedDictionary <int, string> sortedDictionary =
                ImmutableSortedDictionary <int, string> .Empty;

            sortedDictionary = sortedDictionary.Add(10, "Ten");
            sortedDictionary = sortedDictionary.Add(21, "Twenty-One");
            sortedDictionary = sortedDictionary.SetItem(10, "Diez");
            // 在21Twenty-One之前显示10Diez
            foreach (KeyValuePair <int, string> item in sortedDictionary)
            {
                Console.WriteLine(item.Key + item.Value);
            }
            ten = sortedDictionary[10];
            // ten == "Diez"
            sortedDictionary = sortedDictionary.Remove(21);

            //线程安全的字典
            var    cd        = new ConcurrentDictionary <int, string>();
            string newvalue  = cd.AddOrUpdate(0, key => "Zero", (key, oldvalue) => "Zero");
            bool   keyExists = cd.TryGetValue(0, out string currentvalue);

            if (keyExists)
            {
                Console.WriteLine(currentvalue);
            }
            bool keyExisted = cd.TryRemove(0, out currentvalue);
            {
                Console.WriteLine(currentvalue);
            }

            //阻塞队列
            BlockingCollection <int> blockQueue = new BlockingCollection <int>();

            blockQueue.Add(7);
            blockQueue.Add(13);
            blockQueue.CompleteAdding(); //标记完成
            //消费者消费
            foreach (int item in blockQueue.GetConsumingEnumerable())
            {
                Console.WriteLine(item);
            }

            // 异步队列
            Channel <int> channelQueue = Channel.CreateUnbounded <int>();
            //生产者代码
            ChannelWriter <int> writer = channelQueue.Writer;
            var t  = writer.WriteAsync(7);
            var t2 = writer.WriteAsync(13);

            writer.Complete();
            Task.WhenAll(t.AsTask(), t2.AsTask()).Wait();
            //消费者代码
            ChannelReader <int> reader = channelQueue.Reader;

            ReaderCode(reader).Wait();
            //使用TPL完成
            var asyncQueue = new BufferBlock <int>();
            //生产者代码
            var t3 = asyncQueue.SendAsync(7);
            var t4 = asyncQueue.SendAsync(13);

            asyncQueue.Complete();
            Task.WhenAll(t3, t4).Wait();
            //消费者代码
            TPLReaderCode(asyncQueue).Wait();


            //节流队列的几种创建方式
            Channel <int>     cq = Channel.CreateBounded <int>(1);
            BufferBlock <int> b  = new BufferBlock <int>(new DataflowBlockOptions {
                BoundedCapacity = 1
            });
            BlockingCollection <int> bb = new BlockingCollection <int>(boundedCapacity: 1);

            //采样队列的几种创建方式
            cq = Channel.CreateBounded <int>(new BoundedChannelOptions(1)
            {
                FullMode = BoundedChannelFullMode.DropOldest
            });

            //使用ActionBlock来定义阻塞异步队列
            BlockAsyncQueue().Wait();
        }
Beispiel #9
0
 internal ReleaseTrackingData(ImmutableSortedDictionary <string, ReleaseTrackingDataForRule> releaseTrackingDataByRuleIdMap)
 {
     ReleaseTrackingDataByRuleIdMap = releaseTrackingDataByRuleIdMap;
 }
Beispiel #10
0
 private VectorClock(ImmutableSortedDictionary <Node, long> versions)
 {
     _versions = versions;
 }
Beispiel #11
0
 private DbContextOptions(
     ImmutableSortedDictionary <Type, (IDbContextOptionsExtension Extension, int Ordinal)> extensions)
Beispiel #12
0
        public static void DictionaryOfString()
        {
            const string JsonString          = @"{""Hello"":""World"",""Hello2"":""World2""}";
            const string ReorderedJsonString = @"{""Hello2"":""World2"",""Hello"":""World""}";

            {
                Dictionary <string, string> obj = JsonSerializer.Parse <Dictionary <string, string> >(JsonString);
                Assert.Equal("World", obj["Hello"]);
                Assert.Equal("World2", obj["Hello2"]);

                string json = JsonSerializer.ToString(obj);
                Assert.Equal(JsonString, json);

                json = JsonSerializer.ToString <object>(obj);
                Assert.Equal(JsonString, json);
            }

            {
                IDictionary <string, string> obj = JsonSerializer.Parse <IDictionary <string, string> >(JsonString);
                Assert.Equal("World", obj["Hello"]);
                Assert.Equal("World2", obj["Hello2"]);

                string json = JsonSerializer.ToString(obj);
                Assert.Equal(JsonString, json);

                json = JsonSerializer.ToString <object>(obj);
                Assert.Equal(JsonString, json);
            }

            {
                IReadOnlyDictionary <string, string> obj = JsonSerializer.Parse <IReadOnlyDictionary <string, string> >(JsonString);
                Assert.Equal("World", obj["Hello"]);
                Assert.Equal("World2", obj["Hello2"]);

                string json = JsonSerializer.ToString(obj);
                Assert.Equal(JsonString, json);

                json = JsonSerializer.ToString <object>(obj);
                Assert.Equal(JsonString, json);
            }

            {
                ImmutableDictionary <string, string> obj = JsonSerializer.Parse <ImmutableDictionary <string, string> >(JsonString);
                Assert.Equal("World", obj["Hello"]);
                Assert.Equal("World2", obj["Hello2"]);

                string json = JsonSerializer.ToString(obj);
                Assert.True(JsonString == json || ReorderedJsonString == json);

                json = JsonSerializer.ToString <object>(obj);
                Assert.True(JsonString == json || ReorderedJsonString == json);
            }

            {
                IImmutableDictionary <string, string> obj = JsonSerializer.Parse <IImmutableDictionary <string, string> >(JsonString);
                Assert.Equal("World", obj["Hello"]);
                Assert.Equal("World2", obj["Hello2"]);

                string json = JsonSerializer.ToString(obj);
                Assert.True(JsonString == json || ReorderedJsonString == json);

                json = JsonSerializer.ToString <object>(obj);
                Assert.True(JsonString == json || ReorderedJsonString == json);
            }

            {
                ImmutableSortedDictionary <string, string> obj = JsonSerializer.Parse <ImmutableSortedDictionary <string, string> >(JsonString);
                Assert.Equal("World", obj["Hello"]);
                Assert.Equal("World2", obj["Hello2"]);

                string json = JsonSerializer.ToString(obj);
                Assert.True(JsonString == json);

                json = JsonSerializer.ToString <object>(obj);
                Assert.True(JsonString == json);
            }
        }
Beispiel #13
0
        /// <summary>
        /// Initializes a new instance of the <see cref="OptionPositionCollection"/> class
        /// </summary>
        /// <param name="positions">All positions</param>
        /// <param name="rights">Index of position symbols by option right</param>
        /// <param name="sides">Index of position symbols by position side (short/long/none)</param>
        /// <param name="strikes">Index of position symbols by strike price</param>
        /// <param name="expirations">Index of position symbols by expiration</param>
        public OptionPositionCollection(
            ImmutableDictionary <Symbol, OptionPosition> positions,
            ImmutableDictionary <OptionRight, ImmutableHashSet <Symbol> > rights,
            ImmutableDictionary <PositionSide, ImmutableHashSet <Symbol> > sides,
            ImmutableSortedDictionary <decimal, ImmutableHashSet <Symbol> > strikes,
            ImmutableSortedDictionary <DateTime, ImmutableHashSet <Symbol> > expirations
            )
        {
            _sides       = sides;
            _rights      = rights;
            _strikes     = strikes;
            _positions   = positions;
            _expirations = expirations;

            if (_rights.Count != 2)
            {
                // ensure we always have both rights indexed, even if empty
                ImmutableHashSet <Symbol> value;
                if (!_rights.TryGetValue(OptionRight.Call, out value))
                {
                    _rights = _rights.SetItem(OptionRight.Call, ImmutableHashSet <Symbol> .Empty);
                }
                if (!_rights.TryGetValue(OptionRight.Put, out value))
                {
                    _rights = _rights.SetItem(OptionRight.Put, ImmutableHashSet <Symbol> .Empty);
                }
            }

            if (_sides.Count != 3)
            {
                // ensure we always have all three sides indexed, even if empty
                ImmutableHashSet <Symbol> value;
                if (!_sides.TryGetValue(PositionSide.None, out value))
                {
                    _sides = _sides.SetItem(PositionSide.None, ImmutableHashSet <Symbol> .Empty);
                }
                if (!_sides.TryGetValue(PositionSide.Short, out value))
                {
                    _sides = _sides.SetItem(PositionSide.Short, ImmutableHashSet <Symbol> .Empty);
                }
                if (!_sides.TryGetValue(PositionSide.Long, out value))
                {
                    _sides = _sides.SetItem(PositionSide.Long, ImmutableHashSet <Symbol> .Empty);
                }
            }

            if (!positions.IsEmpty)
            {
                // assumption here is that 'positions' includes the underlying equity position and
                // ONLY option contracts, so all symbols have the underlying equity symbol embedded
                // via the Underlying property, except of course, for the underlying itself.
                var underlying = positions.First().Key;
                if (underlying.HasUnderlying)
                {
                    underlying = underlying.Underlying;
                }

                // OptionPosition is struct, so no worry about null ref via .Quantity
                var underlyingQuantity = positions.GetValueOrDefault(underlying).Quantity;
                UnderlyingPosition = new OptionPosition(underlying, underlyingQuantity);
            }
#if DEBUG
            var errors = Validate().ToList();
            if (errors.Count > 0)
            {
                throw new ArgumentException("OptionPositionCollection validation failed: "
                                            + Environment.NewLine + string.Join(Environment.NewLine, errors)
                                            );
            }
#endif
        }
Beispiel #14
0
        public void Initialize()
        {
            MyInt16               = 1;
            MyInt32               = 2;
            MyInt64               = 3;
            MyUInt16              = 4;
            MyUInt32              = 5;
            MyUInt64              = 6;
            MyByte                = 7;
            MySByte               = 8;
            MyChar                = 'a';
            MyString              = "Hello";
            MyBooleanTrue         = true;
            MyBooleanFalse        = false;
            MySingle              = 1.1f;
            MyDouble              = 2.2d;
            MyDecimal             = 3.3m;
            MyDateTime            = new DateTime(2019, 1, 30, 12, 1, 2, DateTimeKind.Utc);
            MyDateTimeOffset      = new DateTimeOffset(2019, 1, 30, 12, 1, 2, new TimeSpan(1, 0, 0));
            MyGuid                = new Guid("1B33498A-7B7D-4DDA-9C13-F6AA4AB449A6");
            MyUri                 = new Uri("https://github.com/dotnet/corefx");
            MyEnum                = SampleEnum.Two;
            MyInt64Enum           = SampleEnumInt64.MinNegative;
            MyUInt64Enum          = SampleEnumUInt64.Max;
            MyInt16Array          = new short[] { 1 };
            MyInt32Array          = new int[] { 2 };
            MyInt64Array          = new long[] { 3 };
            MyUInt16Array         = new ushort[] { 4 };
            MyUInt32Array         = new uint[] { 5 };
            MyUInt64Array         = new ulong[] { 6 };
            MyByteArray           = new byte[] { 7 };
            MySByteArray          = new sbyte[] { 8 };
            MyCharArray           = new char[] { 'a' };
            MyStringArray         = new string[] { "Hello" };
            MyBooleanTrueArray    = new bool[] { true };
            MyBooleanFalseArray   = new bool[] { false };
            MySingleArray         = new float[] { 1.1f };
            MyDoubleArray         = new double[] { 2.2d };
            MyDecimalArray        = new decimal[] { 3.3m };
            MyDateTimeArray       = new DateTime[] { new DateTime(2019, 1, 30, 12, 1, 2, DateTimeKind.Utc) };
            MyDateTimeOffsetArray = new DateTimeOffset[] { new DateTimeOffset(2019, 1, 30, 12, 1, 2, new TimeSpan(1, 0, 0)) };
            MyGuidArray           = new Guid[] { new Guid("1B33498A-7B7D-4DDA-9C13-F6AA4AB449A6") };
            MyUriArray            = new Uri[] { new Uri("https://github.com/dotnet/corefx") };
            MyEnumArray           = new SampleEnum[] { SampleEnum.Two };
            MySimpleStruct        = new SimpleStruct {
                One = 11, Two = 1.9999
            };
            MySimpleTestStruct = new SimpleTestStruct {
                MyInt64 = 64, MyString = "Hello", MyInt32Array = new int[] { 32 }
            };

            MyInt16TwoDimensionArray    = new int[2][];
            MyInt16TwoDimensionArray[0] = new int[] { 10, 11 };
            MyInt16TwoDimensionArray[1] = new int[] { 20, 21 };

            MyInt16TwoDimensionList = new List <List <int> >();
            MyInt16TwoDimensionList.Add(new List <int> {
                10, 11
            });
            MyInt16TwoDimensionList.Add(new List <int> {
                20, 21
            });

            MyInt16ThreeDimensionArray       = new int[2][][];
            MyInt16ThreeDimensionArray[0]    = new int[2][];
            MyInt16ThreeDimensionArray[1]    = new int[2][];
            MyInt16ThreeDimensionArray[0][0] = new int[] { 11, 12 };
            MyInt16ThreeDimensionArray[0][1] = new int[] { 13, 14 };
            MyInt16ThreeDimensionArray[1][0] = new int[] { 21, 22 };
            MyInt16ThreeDimensionArray[1][1] = new int[] { 23, 24 };

            MyInt16ThreeDimensionList = new List <List <List <int> > >();
            var list1 = new List <List <int> >();

            MyInt16ThreeDimensionList.Add(list1);
            list1.Add(new List <int> {
                11, 12
            });
            list1.Add(new List <int> {
                13, 14
            });
            var list2 = new List <List <int> >();

            MyInt16ThreeDimensionList.Add(list2);
            list2.Add(new List <int> {
                21, 22
            });
            list2.Add(new List <int> {
                23, 24
            });

            MyStringList = new List <string>()
            {
                "Hello"
            };

            MyStringIEnumerable = new string[] { "Hello" };
            MyStringIList       = new string[] { "Hello" };
            MyStringICollection = new string[] { "Hello" };

            MyStringIEnumerableT         = new string[] { "Hello" };
            MyStringIListT               = new string[] { "Hello" };
            MyStringICollectionT         = new string[] { "Hello" };
            MyStringIReadOnlyCollectionT = new string[] { "Hello" };
            MyStringIReadOnlyListT       = new string[] { "Hello" };
            MyStringISetT = new HashSet <string> {
                "Hello"
            };

            MyStringToStringKeyValuePair = new KeyValuePair <string, string>("myKey", "myValue");
            MyStringToStringIDict        = new Dictionary <string, string> {
                { "key", "value" }
            };

            MyStringToStringGenericDict = new Dictionary <string, string> {
                { "key", "value" }
            };
            MyStringToStringGenericIDict = new Dictionary <string, string> {
                { "key", "value" }
            };
            MyStringToStringGenericIReadOnlyDict = new Dictionary <string, string> {
                { "key", "value" }
            };

            MyStringToStringImmutableDict       = ImmutableDictionary.CreateRange(MyStringToStringGenericDict);
            MyStringToStringIImmutableDict      = ImmutableDictionary.CreateRange(MyStringToStringGenericDict);
            MyStringToStringImmutableSortedDict = ImmutableSortedDictionary.CreateRange(MyStringToStringGenericDict);

            MyStringStackT = new Stack <string>(new List <string>()
            {
                "Hello", "World"
            });
            MyStringQueueT = new Queue <string>(new List <string>()
            {
                "Hello", "World"
            });
            MyStringHashSetT = new HashSet <string>(new List <string>()
            {
                "Hello"
            });
            MyStringLinkedListT = new LinkedList <string>(new List <string>()
            {
                "Hello"
            });
            MyStringSortedSetT = new SortedSet <string>(new List <string>()
            {
                "Hello"
            });

            MyStringIImmutableListT = ImmutableList.CreateRange(new List <string> {
                "Hello"
            });
            MyStringIImmutableStackT = ImmutableStack.CreateRange(new List <string> {
                "Hello"
            });
            MyStringIImmutableQueueT = ImmutableQueue.CreateRange(new List <string> {
                "Hello"
            });
            MyStringIImmutableSetT = ImmutableHashSet.CreateRange(new List <string> {
                "Hello"
            });
            MyStringImmutableHashSetT = ImmutableHashSet.CreateRange(new List <string> {
                "Hello"
            });
            MyStringImmutableListT = ImmutableList.CreateRange(new List <string> {
                "Hello"
            });
            MyStringImmutableStackT = ImmutableStack.CreateRange(new List <string> {
                "Hello"
            });
            MyStringImmutablQueueT = ImmutableQueue.CreateRange(new List <string> {
                "Hello"
            });
            MyStringImmutableSortedSetT = ImmutableSortedSet.CreateRange(new List <string> {
                "Hello"
            });

            MyListOfNullString = new List <string> {
                null
            };
        }
        internal static ReleaseTrackingData ReadReleaseTrackingData(
            string path,
            SourceText sourceText,
            Action <string, Version, string, SourceText, TextLine> onDuplicateEntryInRelease,
            Action <TextLine, InvalidEntryKind, string, SourceText> onInvalidEntry,
            bool isShippedFile)
        {
            var releaseTrackingDataByRulesBuilder = new Dictionary <string, ReleaseTrackingDataForRuleBuilder>();
            var currentVersion = UnshippedVersion;
            ReleaseTrackingHeaderKind?   expectedHeaderKind   = isShippedFile ? ReleaseTrackingHeaderKind.ReleaseHeader : ReleaseTrackingHeaderKind.TableHeaderTitle;
            ReleaseTrackingRuleEntryKind?currentRuleEntryKind = null;

            using var versionsBuilder = PooledHashSet <Version> .GetInstance();

            foreach (TextLine line in sourceText.Lines)
            {
                string lineText = line.ToString().Trim();
                if (string.IsNullOrWhiteSpace(lineText) || lineText.StartsWith(";", StringComparison.Ordinal))
                {
                    // Skip blank and comment lines.
                    continue;
                }

                // Parse release header if applicable.
                switch (expectedHeaderKind)
                {
                case ReleaseTrackingHeaderKind.ReleaseHeader:
                    // Parse new release, if any.
                    if (lineText.StartsWith(ReleasePrefix, StringComparison.OrdinalIgnoreCase))
                    {
                        // Expect new table after this line.
                        expectedHeaderKind = ReleaseTrackingHeaderKind.TableHeaderTitle;

                        // Parse the release version.
                        string versionString = lineText.Substring(ReleasePrefix.Length).Trim();
                        if (!Version.TryParse(versionString, out var version))
                        {
                            OnInvalidEntry(line, InvalidEntryKind.Header);
                            return(ReleaseTrackingData.Default);
                        }
                        else
                        {
                            currentVersion = version;
                            versionsBuilder.Add(version);
                        }

                        continue;
                    }

                    OnInvalidEntry(line, InvalidEntryKind.Header);
                    return(ReleaseTrackingData.Default);

                case ReleaseTrackingHeaderKind.TableHeaderTitle:
                    if (lineText.StartsWith(TableTitleNewRules, StringComparison.OrdinalIgnoreCase))
                    {
                        expectedHeaderKind   = ReleaseTrackingHeaderKind.TableHeaderNewOrRemovedRulesLine1;
                        currentRuleEntryKind = ReleaseTrackingRuleEntryKind.New;
                    }
                    else if (lineText.StartsWith(TableTitleRemovedRules, StringComparison.OrdinalIgnoreCase))
                    {
                        expectedHeaderKind   = ReleaseTrackingHeaderKind.TableHeaderNewOrRemovedRulesLine1;
                        currentRuleEntryKind = ReleaseTrackingRuleEntryKind.Removed;
                    }
                    else if (lineText.StartsWith(TableTitleChangedRules, StringComparison.OrdinalIgnoreCase))
                    {
                        expectedHeaderKind   = ReleaseTrackingHeaderKind.TableHeaderChangedRulesLine1;
                        currentRuleEntryKind = ReleaseTrackingRuleEntryKind.Changed;
                    }
                    else
                    {
                        OnInvalidEntry(line, InvalidEntryKind.Header);
                        return(ReleaseTrackingData.Default);
                    }

                    continue;

                case ReleaseTrackingHeaderKind.TableHeaderNewOrRemovedRulesLine1:
                    if (lineText.StartsWith(TableHeaderNewOrRemovedRulesLine1, StringComparison.OrdinalIgnoreCase))
                    {
                        expectedHeaderKind = ReleaseTrackingHeaderKind.TableHeaderNewOrRemovedRulesLine2;
                        continue;
                    }

                    OnInvalidEntry(line, InvalidEntryKind.Header);
                    return(ReleaseTrackingData.Default);

                case ReleaseTrackingHeaderKind.TableHeaderNewOrRemovedRulesLine2:
                    expectedHeaderKind = null;
                    if (lineText.StartsWith(TableHeaderNewOrRemovedRulesLine2, StringComparison.OrdinalIgnoreCase))
                    {
                        continue;
                    }

                    OnInvalidEntry(line, InvalidEntryKind.Header);
                    return(ReleaseTrackingData.Default);

                case ReleaseTrackingHeaderKind.TableHeaderChangedRulesLine1:
                    if (lineText.StartsWith(TableHeaderChangedRulesLine1, StringComparison.OrdinalIgnoreCase))
                    {
                        expectedHeaderKind = ReleaseTrackingHeaderKind.TableHeaderChangedRulesLine2;
                        continue;
                    }

                    OnInvalidEntry(line, InvalidEntryKind.Header);
                    return(ReleaseTrackingData.Default);

                case ReleaseTrackingHeaderKind.TableHeaderChangedRulesLine2:
                    expectedHeaderKind = null;
                    if (lineText.StartsWith(TableHeaderChangedRulesLine2, StringComparison.OrdinalIgnoreCase))
                    {
                        continue;
                    }

                    OnInvalidEntry(line, InvalidEntryKind.Header);
                    return(ReleaseTrackingData.Default);

                default:
                    // We might be starting a new release or table.
                    if (lineText.StartsWith("## ", StringComparison.OrdinalIgnoreCase))
                    {
                        goto case ReleaseTrackingHeaderKind.ReleaseHeader;
                    }
                    else if (lineText.StartsWith("### ", StringComparison.OrdinalIgnoreCase))
                    {
                        goto case ReleaseTrackingHeaderKind.TableHeaderTitle;
                    }

                    break;
                }

                RoslynDebug.Assert(currentRuleEntryKind != null);

                var parts = lineText.Split('|').Select(s => s.Trim()).ToArray();
                if (IsInvalidEntry(parts, currentRuleEntryKind.Value))
                {
                    // Report invalid entry, but continue parsing remaining entries.
                    OnInvalidEntry(line, InvalidEntryKind.Other);
                    continue;
                }

                //  New or Removed rule entry:
                //      "Rule ID | Category | Severity | Notes"
                //      "   0    |     1    |    2     |        3           "
                //
                //  Changed rule entry:
                //      "Rule ID | New Category | New Severity | Old Category | Old Severity | Notes"
                //      "   0    |     1        |     2        |     3        |     4        |        5           "

                string ruleId = parts[0];

                InvalidEntryKind?invalidEntryKind = TryParseFields(parts, categoryIndex: 1, severityIndex: 2,
                                                                   out var category, out var defaultSeverity, out var enabledByDefault);
                if (invalidEntryKind.HasValue)
                {
                    OnInvalidEntry(line, invalidEntryKind.Value);
                }

                ReleaseTrackingLine releaseTrackingLine;
                if (currentRuleEntryKind.Value == ReleaseTrackingRuleEntryKind.Changed)
                {
                    invalidEntryKind = TryParseFields(parts, categoryIndex: 3, severityIndex: 4,
                                                      out var oldCategory, out var oldDefaultSeverity, out var oldEnabledByDefault);
                    if (invalidEntryKind.HasValue)
                    {
                        OnInvalidEntry(line, invalidEntryKind.Value);
                    }

                    // Verify at least one field is changed for the entry:
                    if (string.Equals(category, oldCategory, StringComparison.OrdinalIgnoreCase) &&
                        defaultSeverity == oldDefaultSeverity &&
                        enabledByDefault == oldEnabledByDefault)
                    {
                        OnInvalidEntry(line, InvalidEntryKind.Other);
                        return(ReleaseTrackingData.Default);
                    }

                    releaseTrackingLine = new ChangedRuleReleaseTrackingLine(ruleId,
                                                                             category, enabledByDefault, defaultSeverity,
                                                                             oldCategory, oldEnabledByDefault, oldDefaultSeverity,
                                                                             line.Span, sourceText, path, isShippedFile);
                }
                else
                {
                    releaseTrackingLine = new NewOrRemovedRuleReleaseTrackingLine(ruleId,
                                                                                  category, enabledByDefault, defaultSeverity, line.Span, sourceText,
                                                                                  path, isShippedFile, currentRuleEntryKind.Value);
                }

                if (!releaseTrackingDataByRulesBuilder.TryGetValue(ruleId, out var releaseTrackingDataForRuleBuilder))
                {
                    releaseTrackingDataForRuleBuilder = new ReleaseTrackingDataForRuleBuilder();
                    releaseTrackingDataByRulesBuilder.Add(ruleId, releaseTrackingDataForRuleBuilder);
                }

                releaseTrackingDataForRuleBuilder.AddEntry(currentVersion, releaseTrackingLine, out var hasExistingEntry);
                if (hasExistingEntry)
                {
                    onDuplicateEntryInRelease(ruleId, currentVersion, path, sourceText, line);
                }
            }

            var builder = ImmutableSortedDictionary.CreateBuilder <string, ReleaseTrackingDataForRule>();

            foreach (var(ruleId, value) in releaseTrackingDataByRulesBuilder)
            {
                var releaseTrackingDataForRule = new ReleaseTrackingDataForRule(ruleId, value);
                builder.Add(ruleId, releaseTrackingDataForRule);
            }

            return(new ReleaseTrackingData(builder.ToImmutable(), versionsBuilder.ToImmutable()));

            // Local functions
            void OnInvalidEntry(TextLine line, InvalidEntryKind invalidEntryKind)
            => onInvalidEntry(line, invalidEntryKind, path, sourceText);
 internal ReleaseTrackingData(ImmutableSortedDictionary <string, ReleaseTrackingDataForRule> releaseTrackingDataByRuleIdMap, ImmutableHashSet <Version> versions)
 {
     ReleaseTrackingDataByRuleIdMap = releaseTrackingDataByRuleIdMap;
     Versions = versions;
 }
Beispiel #17
0
        public MemoryChainStateStorage(ChainedHeader chainTip = null, int?unspentTxCount = null, int?totalTxCount = null, int?totalInputCount = null, int?totalOutputCount = null, int?unspentOutputCount = null, ImmutableSortedDictionary <UInt256, ChainedHeader> headers = null, ImmutableSortedDictionary <UInt256, UnspentTx> unspentTransactions = null, ImmutableDictionary <int, BlockSpentTxes> blockSpentTxes = null, ImmutableDictionary <UInt256, IImmutableList <UnmintedTx> > blockUnmintedTxes = null)
        {
            this.chainTip = CommittedRecord <ChainedHeader> .Initial(chainTip);

            this.unspentTxCount = CommittedRecord <int> .Initial(unspentTxCount ?? 0);

            this.unspentOutputCount = CommittedRecord <int> .Initial(unspentOutputCount ?? 0);

            this.totalTxCount = CommittedRecord <int> .Initial(totalTxCount ?? 0);

            this.totalInputCount = CommittedRecord <int> .Initial(totalInputCount ?? 0);

            this.totalOutputCount = CommittedRecord <int> .Initial(totalOutputCount ?? 0);

            this.headers = CommittedRecord <ImmutableSortedDictionary <UInt256, ChainedHeader> .Builder> .Initial(
                headers?.ToBuilder() ?? ImmutableSortedDictionary.CreateBuilder <UInt256, ChainedHeader>());

            this.unspentTransactions = CommittedRecord <ImmutableSortedDictionary <UInt256, UnspentTx> .Builder> .Initial(
                unspentTransactions?.ToBuilder() ?? ImmutableSortedDictionary.CreateBuilder <UInt256, UnspentTx>());

            this.unspentTxOutputs = CommittedRecord <ImmutableSortedDictionary <TxOutputKey, TxOutput> .Builder> .Initial(
                ImmutableSortedDictionary.CreateBuilder <TxOutputKey, TxOutput>());

            this.blockSpentTxes = CommittedRecord <ImmutableDictionary <int, BlockSpentTxes> .Builder> .Initial(
                blockSpentTxes?.ToBuilder() ?? ImmutableDictionary.CreateBuilder <int, BlockSpentTxes>());

            this.blockUnmintedTxes = CommittedRecord <ImmutableDictionary <UInt256, IImmutableList <UnmintedTx> > .Builder> .Initial(
                blockUnmintedTxes?.ToBuilder() ?? ImmutableDictionary.CreateBuilder <UInt256, IImmutableList <UnmintedTx> >());
        }
Beispiel #18
0
        public async Task <CommandResult> Pokedex(CommandContext context)
        {
            (Optional <User> optionalUser, Optional <string> optionalMode, Optional <User> optionalCompareUser) =
                await context.ParseArgs <Optional <User>, Optional <string>, Optional <User> >();

            User user   = optionalUser.OrElse(context.Message.User);
            bool isSelf = user == context.Message.User;

            if (!optionalMode.IsPresent)
            {
                int numUniqueSpecies = (await _badgeRepo.CountByUserPerSpecies(user.Id)).Count;
                return(new CommandResult
                {
                    Response = isSelf
                        ? $"You have collected {numUniqueSpecies} distinct Pokémon badge(s)"
                        : $"{user.Name} has collected {numUniqueSpecies} distinct Pokémon badge(s)"
                });
            }

            string mode = optionalMode.Value;
            ImmutableSortedDictionary <PkmnSpecies, int> numBadgesPerSpecies =
                await _badgeRepo.CountByUserPerSpecies(user.Id);

            if (mode.Equals(PokedexModeMissing))
            {
                IEnumerable <PkmnSpecies> missingList     = _knownSpecies.Except(numBadgesPerSpecies.Keys);
                IEnumerable <string>      badgesFormatted = missingList.Select(entry => $"{entry}");
                return(new CommandResult
                {
                    Response = isSelf
                        ? $"You are currently missing the following badge(s): {string.Join(", ", badgesFormatted)}"
                        : $"{user.Name} is currently missing the following badge(s): {string.Join(", ", badgesFormatted)}",
                    ResponseTarget = ResponseTarget.WhisperIfLong
                });
            }
            else if (mode.Equals(PokedexModeDupes))
            {
                var dupeList = numBadgesPerSpecies.Where(kvp => kvp.Value > 1).ToList();
                if (!dupeList.Any())
                {
                    return(new CommandResult
                    {
                        Response = isSelf
                            ? $"You do not own any duplicate Pokémon badges"
                            : $"{user.Name} does not own any duplicate Pokémon badges"
                    });
                }
                IEnumerable <string> badgesFormatted = dupeList.Select(kvp => $"{kvp.Key}");
                return(new CommandResult
                {
                    Response = isSelf
                        ? $"You are owning duplicates of the following badge(s): {string.Join(", ", badgesFormatted)}"
                        : $"{user.Name} owns duplicates of the following badge(s): {string.Join(", ", badgesFormatted)}",
                    ResponseTarget = ResponseTarget.WhisperIfLong
                });
            }
            else if (mode.Equals(PokedexModeComplementFromDupes))
            {
                if (!optionalCompareUser.IsPresent)
                {
                    return(new CommandResult
                    {
                        Response = $"Mode {PokedexModeComplementFromDupes} requires a second user argument"
                    });
                }
                ImmutableSortedDictionary <PkmnSpecies, int> compareUser =
                    await _badgeRepo.CountByUserPerSpecies(optionalCompareUser.Value.Id);

                var compareUserDupeList = compareUser.Where(kvp => kvp.Value > 1).Select(kvp => kvp.Key);

                var differenceList = compareUserDupeList.Except(numBadgesPerSpecies.Keys).ToList();
                if (!differenceList.Any())
                {
                    return(new CommandResult
                    {
                        Response = $"{optionalCompareUser.Value.Name} does not own any duplicate Pokémon badges {user.Name} is missing"
                    });
                }
                IEnumerable <string> badgesFormatted = differenceList.Select(entry => $"{entry}");
                return(new CommandResult
                {
                    Response = $"{optionalCompareUser.Value.Name} owns the following duplicate badge(s) {user.Name} is missing: {string.Join(", ", badgesFormatted)}",
                    ResponseTarget = ResponseTarget.WhisperIfLong
                });
            }
            else if (mode.Equals(PokedexModeComplementFrom))
            {
                if (!optionalCompareUser.IsPresent)
                {
                    return(new CommandResult
                    {
                        Response = $"Mode {PokedexModeComplementFrom} requires a second user argument"
                    });
                }
                ImmutableSortedDictionary <PkmnSpecies, int> compareUser =
                    await _badgeRepo.CountByUserPerSpecies(optionalCompareUser.Value.Id);

                var differenceList = compareUser.Keys.Except(numBadgesPerSpecies.Keys).ToList();
                if (!differenceList.Any())
                {
                    return(new CommandResult
                    {
                        Response = $"{optionalCompareUser.Value.Name} does not own any Pokémon badges {user.Name} is missing"
                    });
                }
                IEnumerable <string> badgesFormatted = differenceList.Select(entry => $"{entry}");
                return(new CommandResult
                {
                    Response = $"{optionalCompareUser.Value.Name} owns the following badge(s) {user.Name} is missing: {string.Join(", ", badgesFormatted)}",
                    ResponseTarget = ResponseTarget.WhisperIfLong
                });
            }
            else if (mode.Equals(PokedexModeModes))
            {
                return(new CommandResult
                {
                    Response = $"Supported modes are '{PokedexModeDupes}': Show duplicate badges, '{PokedexModeMissing}': Show missing badges, "
                               + $"'{PokedexModeComplementFrom}' Compares missing badges from User A with owned badges from User B, "
                               + $"'{PokedexModeComplementFromDupes}' Compares missing badges from User A with owned duplicate badges from User B"
                });
            }
            return(new CommandResult
            {
                Response = $"Unsupported mode '{mode}'. Current modes supported: {PokedexModeModes}, {PokedexModeDupes}, {PokedexModeMissing}, {PokedexModeComplementFromDupes}, {PokedexModeComplementFrom}"
            });
        }
Beispiel #19
0
        public static void DictionaryOfDictionary()
        {
            const string JsonString = @"{""Key1"":{""Key1a"":1,""Key1b"":2},""Key2"":{""Key2a"":3,""Key2b"":4}}";

            {
                Dictionary <string, Dictionary <string, int> > obj = JsonSerializer.Parse <Dictionary <string, Dictionary <string, int> > >(JsonString);

                Assert.Equal(2, obj.Count);
                Assert.Equal(2, obj["Key1"].Count);
                Assert.Equal(1, obj["Key1"]["Key1a"]);
                Assert.Equal(2, obj["Key1"]["Key1b"]);
                Assert.Equal(2, obj["Key2"].Count);
                Assert.Equal(3, obj["Key2"]["Key2a"]);
                Assert.Equal(4, obj["Key2"]["Key2b"]);

                string json = JsonSerializer.ToString(obj);
                Assert.Equal(JsonString, json);

                json = JsonSerializer.ToString <object>(obj);
                Assert.Equal(JsonString, json);
            }

            {
                ImmutableSortedDictionary <string, ImmutableSortedDictionary <string, int> > obj = JsonSerializer.Parse <ImmutableSortedDictionary <string, ImmutableSortedDictionary <string, int> > >(JsonString);

                Assert.Equal(2, obj.Count);
                Assert.Equal(2, obj["Key1"].Count);
                Assert.Equal(1, obj["Key1"]["Key1a"]);
                Assert.Equal(2, obj["Key1"]["Key1b"]);
                Assert.Equal(2, obj["Key2"].Count);
                Assert.Equal(3, obj["Key2"]["Key2a"]);
                Assert.Equal(4, obj["Key2"]["Key2b"]);

                string json = JsonSerializer.ToString(obj);
                Assert.Equal(JsonString, json);

                json = JsonSerializer.ToString <object>(obj);
                Assert.Equal(JsonString, json);
            }
        }
Beispiel #20
0
        private static ReleaseTrackingData ReadReleaseTrackingData(
            string path,
            SourceText sourceText,
            Action <Diagnostic> addInvalidFileDiagnostic,
            bool isShippedFile)
        {
            var releaseTrackingDataByRulesBuilder = new Dictionary <string, ReleaseTrackingDataForRuleBuilder>();
            var currentVersion = s_unshippedVersion;

            using var reportedInvalidLines = PooledHashSet <TextLine> .GetInstance();

            ReleaseTrackingHeaderKind?   expectedHeaderKind   = isShippedFile ? ReleaseTrackingHeaderKind.ReleaseHeader : ReleaseTrackingHeaderKind.TableHeaderTitle;
            ReleaseTrackingRuleEntryKind?currentRuleEntryKind = null;

            foreach (TextLine line in sourceText.Lines)
            {
                string lineText = line.ToString().Trim();
                if (string.IsNullOrWhiteSpace(lineText) || lineText.StartsWith(";", StringComparison.Ordinal))
                {
                    // Skip blank and comment lines.
                    continue;
                }

                // Parse release header if applicable.
                switch (expectedHeaderKind)
                {
                case ReleaseTrackingHeaderKind.ReleaseHeader:
                    // Parse new release, if any.
                    if (lineText.StartsWith(ReleasePrefix, StringComparison.OrdinalIgnoreCase))
                    {
                        // Expect new table after this line.
                        expectedHeaderKind = ReleaseTrackingHeaderKind.TableHeaderTitle;

                        // Parse the release version.
                        string versionString = lineText.Substring(ReleasePrefix.Length).Trim();
                        if (!Version.TryParse(versionString, out var version))
                        {
                            ReportInvalidEntryDiagnostic(line, InvalidEntryKind.Header);
                            return(ReleaseTrackingData.Default);
                        }
                        else
                        {
                            currentVersion = version;
                        }

                        continue;
                    }

                    ReportInvalidEntryDiagnostic(line, InvalidEntryKind.Header);
                    return(ReleaseTrackingData.Default);

                case ReleaseTrackingHeaderKind.TableHeaderTitle:
                    if (lineText.StartsWith(TableTitleNewRules, StringComparison.OrdinalIgnoreCase))
                    {
                        expectedHeaderKind   = ReleaseTrackingHeaderKind.TableHeaderNewOrRemovedRulesLine1;
                        currentRuleEntryKind = ReleaseTrackingRuleEntryKind.New;
                    }
                    else if (lineText.StartsWith(TableTitleRemovedRules, StringComparison.OrdinalIgnoreCase))
                    {
                        expectedHeaderKind   = ReleaseTrackingHeaderKind.TableHeaderNewOrRemovedRulesLine1;
                        currentRuleEntryKind = ReleaseTrackingRuleEntryKind.Removed;
                    }
                    else if (lineText.StartsWith(TableTitleChangedRules, StringComparison.OrdinalIgnoreCase))
                    {
                        expectedHeaderKind   = ReleaseTrackingHeaderKind.TableHeaderChangedRulesLine1;
                        currentRuleEntryKind = ReleaseTrackingRuleEntryKind.Changed;
                    }
                    else
                    {
                        ReportInvalidEntryDiagnostic(line, InvalidEntryKind.Header);
                        return(ReleaseTrackingData.Default);
                    }

                    continue;

                case ReleaseTrackingHeaderKind.TableHeaderNewOrRemovedRulesLine1:
                    if (lineText.StartsWith(TableHeaderNewOrRemovedRulesLine1, StringComparison.OrdinalIgnoreCase))
                    {
                        expectedHeaderKind = ReleaseTrackingHeaderKind.TableHeaderNewOrRemovedRulesLine2;
                        continue;
                    }

                    ReportInvalidEntryDiagnostic(line, InvalidEntryKind.Header);
                    return(ReleaseTrackingData.Default);

                case ReleaseTrackingHeaderKind.TableHeaderNewOrRemovedRulesLine2:
                    expectedHeaderKind = null;
                    if (lineText.StartsWith(TableHeaderNewOrRemovedRulesLine2, StringComparison.OrdinalIgnoreCase))
                    {
                        continue;
                    }

                    ReportInvalidEntryDiagnostic(line, InvalidEntryKind.Header);
                    return(ReleaseTrackingData.Default);

                case ReleaseTrackingHeaderKind.TableHeaderChangedRulesLine1:
                    if (lineText.StartsWith(TableHeaderChangedRulesLine1, StringComparison.OrdinalIgnoreCase))
                    {
                        expectedHeaderKind = ReleaseTrackingHeaderKind.TableHeaderChangedRulesLine2;
                        continue;
                    }

                    ReportInvalidEntryDiagnostic(line, InvalidEntryKind.Header);
                    return(ReleaseTrackingData.Default);

                case ReleaseTrackingHeaderKind.TableHeaderChangedRulesLine2:
                    expectedHeaderKind = null;
                    if (lineText.StartsWith(TableHeaderChangedRulesLine2, StringComparison.OrdinalIgnoreCase))
                    {
                        continue;
                    }

                    ReportInvalidEntryDiagnostic(line, InvalidEntryKind.Header);
                    return(ReleaseTrackingData.Default);

                default:
                    // We might be starting a new release or table.
                    if (lineText.StartsWith("## ", StringComparison.OrdinalIgnoreCase))
                    {
                        goto case ReleaseTrackingHeaderKind.ReleaseHeader;
                    }
                    else if (lineText.StartsWith("### ", StringComparison.OrdinalIgnoreCase))
                    {
                        goto case ReleaseTrackingHeaderKind.TableHeaderTitle;
                    }

                    break;
                }

                RoslynDebug.Assert(currentRuleEntryKind != null);

                var parts = lineText.Split('|').Select(s => s.Trim()).ToArray();
                if (IsInvalidEntry(parts, currentRuleEntryKind.Value))
                {
                    // Report invalid entry, but continue parsing remaining entries.
                    ReportInvalidEntryDiagnostic(line, InvalidEntryKind.Other);
                    continue;
                }

                //  New or Removed rule entry:
                //      "Rule ID | Category | Severity | Notes"
                //      "   0    |     1    |    2     |        3           "
                //
                //  Changed rule entry:
                //      "Rule ID | New Category | New Severity | Old Category | Old Severity | Notes"
                //      "   0    |     1        |     2        |     3        |     4        |        5           "

                string ruleId = parts[0];

                InvalidEntryKind?invalidEntryKind = TryParseFields(parts, categoryIndex: 1, severityIndex: 2,
                                                                   out var category, out var defaultSeverity, out var enabledByDefault);
                if (invalidEntryKind.HasValue)
                {
                    ReportInvalidEntryDiagnostic(line, invalidEntryKind.Value);
                }

                ReleaseTrackingLine releaseTrackingLine;
                if (currentRuleEntryKind.Value == ReleaseTrackingRuleEntryKind.Changed)
                {
                    invalidEntryKind = TryParseFields(parts, categoryIndex: 3, severityIndex: 4,
                                                      out var oldCategory, out var oldDefaultSeverity, out var oldEnabledByDefault);
                    if (invalidEntryKind.HasValue)
                    {
                        ReportInvalidEntryDiagnostic(line, invalidEntryKind.Value);
                    }

                    // Verify at least one field is changed for the entry:
                    if (string.Equals(category, oldCategory, StringComparison.OrdinalIgnoreCase) &&
                        defaultSeverity == oldDefaultSeverity &&
                        enabledByDefault == oldEnabledByDefault)
                    {
                        ReportInvalidEntryDiagnostic(line, InvalidEntryKind.Other);
                        return(ReleaseTrackingData.Default);
                    }

                    releaseTrackingLine = new ChangedRuleReleaseTrackingLine(ruleId,
                                                                             category, enabledByDefault, defaultSeverity,
                                                                             oldCategory, oldEnabledByDefault, oldDefaultSeverity,
                                                                             line.Span, sourceText, path, isShippedFile);
                }
                else
                {
                    releaseTrackingLine = new NewOrRemovedRuleReleaseTrackingLine(ruleId,
                                                                                  category, enabledByDefault, defaultSeverity, line.Span, sourceText,
                                                                                  path, isShippedFile, currentRuleEntryKind.Value);
                }

                if (!releaseTrackingDataByRulesBuilder.TryGetValue(ruleId, out var releaseTrackingDataForRuleBuilder))
                {
                    releaseTrackingDataForRuleBuilder = new ReleaseTrackingDataForRuleBuilder();
                    releaseTrackingDataByRulesBuilder.Add(ruleId, releaseTrackingDataForRuleBuilder);
                }

                releaseTrackingDataForRuleBuilder.AddEntry(currentVersion, releaseTrackingLine, out var hasExistingEntry);
                if (hasExistingEntry && reportedInvalidLines.Add(line))
                {
                    // Rule '{0}' has more then one entry for release '{1}' in analyzer release file '{2}'.
                    string           arg1             = ruleId;
                    string           arg2             = currentVersion == s_unshippedVersion ? "unshipped" : currentVersion.ToString();
                    string           arg3             = Path.GetFileName(path);
                    LinePositionSpan linePositionSpan = sourceText.Lines.GetLinePositionSpan(line.Span);
                    Location         location         = Location.Create(path, line.Span, linePositionSpan);
                    var diagnostic = Diagnostic.Create(RemoveDuplicateEntriesForAnalyzerReleaseRule, location, arg1, arg2, arg3);
                    addInvalidFileDiagnostic(diagnostic);
                }
            }

            var builder = ImmutableSortedDictionary.CreateBuilder <string, ReleaseTrackingDataForRule>();

            foreach (var(ruleId, value) in releaseTrackingDataByRulesBuilder)
            {
                var releaseTrackingDataForRule = new ReleaseTrackingDataForRule(ruleId, value);
                builder.Add(ruleId, releaseTrackingDataForRule);
            }

            return(new ReleaseTrackingData(builder.ToImmutable()));

            // Local functions
            void ReportInvalidEntryDiagnostic(TextLine line, InvalidEntryKind invalidEntryKind)
            {
                if (!reportedInvalidLines.Add(line))
                {
                    // Already reported.
                    return;
                }

                var rule = invalidEntryKind switch
                {
                    // Analyzer release file '{0}' has a missing or invalid release header '{1}'.
                    InvalidEntryKind.Header => InvalidHeaderInAnalyzerReleasesFileRule,

                    // Analyzer release file '{0}' has an entry with one or more 'Undetected' fields that need to be manually filled in '{1}'.
                    InvalidEntryKind.UndetectedField => InvalidUndetectedEntryInAnalyzerReleasesFileRule,

                    // Analyzer release file '{0}' has an invalid entry '{1}'.
                    InvalidEntryKind.Other => InvalidEntryInAnalyzerReleasesFileRule,
                    _ => throw new NotImplementedException(),
                };

                string           arg1             = Path.GetFileName(path);
                string           arg2             = line.ToString();
                LinePositionSpan linePositionSpan = sourceText.Lines.GetLinePositionSpan(line.Span);
                Location         location         = Location.Create(path, line.Span, linePositionSpan);
                var diagnostic = Diagnostic.Create(rule, location, arg1, arg2);

                addInvalidFileDiagnostic(diagnostic);
            }
        internal static T Generate <T>()
        {
            if (typeof(T) == typeof(LoginViewModel))
            {
                return((T)(object)CreateLoginViewModel());
            }
            if (typeof(T) == typeof(Location))
            {
                return((T)(object)CreateLocation());
            }
            if (typeof(T) == typeof(IndexViewModel))
            {
                return((T)(object)CreateIndexViewModel());
            }
            if (typeof(T) == typeof(MyEventsListerViewModel))
            {
                return((T)(object)CreateMyEventsListerViewModel());
            }
            if (typeof(T) == typeof(BinaryData))
            {
                return((T)(object)CreateBinaryData(1024));
            }
            if (typeof(T) == typeof(CollectionsOfPrimitives))
            {
                return((T)(object)CreateCollectionsOfPrimitives(1024)); // 1024 values was copied from CoreFX benchmarks
            }
            if (typeof(T) == typeof(XmlElement))
            {
                return((T)(object)CreateXmlElement());
            }
            if (typeof(T) == typeof(SimpleStructWithProperties))
            {
                return (T)(object)new SimpleStructWithProperties {
                           Num = 1, Text = "Foo"
                }
            }
            ;
            if (typeof(T) == typeof(SimpleListOfInt))
            {
                return (T)(object)new SimpleListOfInt {
                           10, 20, 30
                }
            }
            ;
            if (typeof(T) == typeof(ClassImplementingIXmlSerialiable))
            {
                return (T)(object)new ClassImplementingIXmlSerialiable {
                           StringValue = "Hello world"
                }
            }
            ;
            if (typeof(T) == typeof(Dictionary <string, string>))
            {
                return((T)(object)ValuesGenerator.ArrayOfUniqueValues <string>(100).ToDictionary(value => value));
            }
            if (typeof(T) == typeof(ImmutableDictionary <string, string>))
            {
                return((T)(object)ImmutableDictionary.CreateRange(ValuesGenerator.ArrayOfUniqueValues <string>(100).ToDictionary(value => value)));
            }
            if (typeof(T) == typeof(ImmutableSortedDictionary <string, string>))
            {
                return((T)(object)ImmutableSortedDictionary.CreateRange(ValuesGenerator.ArrayOfUniqueValues <string>(100).ToDictionary(value => value)));
            }
            if (typeof(T) == typeof(HashSet <string>))
            {
                return((T)(object)new HashSet <string>(ValuesGenerator.ArrayOfUniqueValues <string>(100)));
            }
            if (typeof(T) == typeof(ArrayList))
            {
                return((T)(object)new ArrayList(ValuesGenerator.ArrayOfUniqueValues <string>(100)));
            }
            if (typeof(T) == typeof(Hashtable))
            {
                return((T)(object)new Hashtable(ValuesGenerator.ArrayOfUniqueValues <string>(100).ToDictionary(value => value)));
            }
            if (typeof(T) == typeof(LargeStructWithProperties))
            {
                return((T)(object)CreateLargeStructWithProperties());
            }
            if (typeof(T) == typeof(int))
            {
                return((T)(object)42);
            }

            throw new NotImplementedException();
        }
Beispiel #22
0
 internal ReleaseTrackingDataForRule(string ruleId, ReleaseTrackingDataForRuleBuilder builder)
 {
     RuleId = ruleId;
     ReleasesByVersionMap = builder.ToImmutable();
 }
 private List <PlayTimeInfo> ConvertToPlayTimeList(ImmutableSortedDictionary <string, int?> playTimes)
 {
     return(playTimes
            .Select(pair => new PlayTimeInfo(pair.Key, Convert.ToInt32(pair.Value)))
            .ToList());
 }
Beispiel #24
0
        private static IReadOnlyDictionary <string, string> TagDirection(AccountingSnapshot item, ImmutableSortedDictionary <string, string> interfaces)
        {
            var result = new Dictionary <string, string>
            {
                { "srcAddress", item.SrcAddress },
                { "dstAddress", item.DstAddress }
            };

            foreach (var i in interfaces)
            {
                if (IPAddress.Parse(item.DstAddress).IsInSubnet(i.Key))
                {
                    result.Add("ip", item.DstAddress);
                    result.Add("direction", "Download");
                    result.Add("interface", interfaces[i.Key]);

                    break;
                }

                if (IPAddress.Parse(item.SrcAddress).IsInSubnet(i.Key))
                {
                    result.Add("ip", item.SrcAddress);
                    result.Add("direction", "Upload");
                    result.Add("interface", interfaces[i.Key]);

                    break;
                }
            }

            return(result);
        }
 public static AssetPairExtPriceSettings Change(AssetPairExtPriceSettings src,
                                                ImmutableSortedDictionary <string, ExchangeExtPriceSettings> exchanges)
 {
     return(new AssetPairExtPriceSettings(src.PresetDefaultExchange, src.OutlierThreshold,
                                          src.MinOrderbooksSendingPeriod, src.Markups, src.RepeatedOutliers, src.Steps, exchanges));
 }
Beispiel #26
0
 public void SetupImmutableSortedDictionary() => _immutablesorteddictionary = Immutable.ImmutableSortedDictionary.CreateRange <T, T>(ValuesGenerator.Dictionary <T, T>(Size));
Beispiel #27
0
 private static void SetNavigationCandidates(
     InternalEntityTypeBuilder entityTypeBuilder,
     ImmutableSortedDictionary <PropertyInfo, Type> navigationCandidates)
 => entityTypeBuilder.HasAnnotation(NavigationCandidatesAnnotationName, navigationCandidates, ConfigurationSource.Convention);
Beispiel #28
0
 protected override IImmutableDictionary <string, TValue> Empty <TValue>(StringComparer comparer)
 {
     return(ImmutableSortedDictionary.Create <string, TValue>(comparer));
 }
        public void CommitTransaction()
        {
            if (!this.inTransaction)
                throw new InvalidOperationException();

            this.chainStateStorage.CommitTransaction(
                this.chainTipModified ? this.chainTip : null,
                this.unspentTxCountModified ? this.unspentTxCount : null,
                this.unspentOutputCountModified ? this.unspentOutputCount : null,
                this.totalTxCountModified ? this.totalTxCount : null,
                this.totalInputCountModified ? this.totalInputCount : null,
                this.totalOutputCountModified ? this.totalOutputCount : null,
                this.headersModified ? this.headers : null,
                this.unspentTxesModified ? this.unspentTransactions : null,
                this.blockSpentTxesModified ? this.blockSpentTxes : null,
                this.blockUnmintedTxesModified ? this.blockUnmintedTxes : null,
                this.chainTipVersion, this.unspentTxCountVersion, this.unspentOutputCountVersion, this.totalTxCountVersion, this.totalInputCountVersion, this.totalOutputCountVersion, this.headersVersion, this.unspentTxesVersion, this.blockSpentTxesVersion, this.blockUnmintedTxesVersion);

            this.chainTip = null;
            this.unspentTxCount = null;
            this.unspentOutputCount = null;
            this.totalTxCount = null;
            this.totalInputCount = null;
            this.totalOutputCount = null;
            this.headers = null;
            this.unspentTransactions = null;
            this.blockSpentTxes = null;
            this.blockUnmintedTxes = null;

            this.inTransaction = false;

            if (!readOnly)
                chainStateStorage.WriteTxLock.Release();
        }
Beispiel #30
0
 public Result(IList <string> filePaths, IList <string> fileHeadings, ImmutableSortedDictionary <string, Dictionary <int, int> > sortedWordsToFileIndexAndCount)
 {
     FilePaths = filePaths;
     SortedWordsToFileIndexAndCount = sortedWordsToFileIndexAndCount;
     FileHeadings = fileHeadings;
 }
        public void CommitTransaction(ChainedHeader chainTip, int? unspentTxCount, int? unspentOutputCount, int? totalTxCount, int? totalInputCount, int? totalOutputCount, ImmutableSortedDictionary<UInt256, ChainedHeader>.Builder headers, ImmutableSortedDictionary<UInt256, UnspentTx>.Builder unspentTransactions, ImmutableDictionary<int, BlockSpentTxes>.Builder blockSpentTxes, ImmutableDictionary<UInt256, IImmutableList<UnmintedTx>>.Builder blockUnmintedTxes, long chainVersion, long unspentTxCountVersion, long unspentOutputCountVersion, long totalTxCountVersion, long totalInputCountVersion, long totalOutputCountVersion, long headersVersion, long unspentTxesVersion, long blockSpentTxesVersion, long blockUnmintedTxesVersion)
        {
            lock (this.lockObject)
            {
                if (chainTip != null && this.chainTipVersion != chainVersion
                    || unspentTxCount != null && unspentTxCountVersion != this.unspentTxCountVersion
                    || unspentOutputCount != null && unspentOutputCountVersion != this.unspentOutputCountVersion
                    || totalTxCount != null && totalTxCountVersion != this.totalTxCountVersion
                    || totalInputCount != null && totalInputCountVersion != this.totalInputCountVersion
                    || totalOutputCount != null && totalOutputCountVersion != this.totalOutputCountVersion
                    || headers != null && headersVersion != this.headersVersion
                    || unspentTransactions != null && unspentTxesVersion != this.unspentTxesVersion
                    || blockSpentTxes != null && blockSpentTxesVersion != this.blockSpentTxesVersion
                    || blockUnmintedTxes != null && blockUnmintedTxesVersion != this.blockUnmintedTxesVersion)
                    throw new InvalidOperationException();

                if (chainTip != null)
                {
                    this.chainTip = chainTip;
                    this.chainTipVersion++;
                }

                if (unspentTxCount != null)
                {
                    this.unspentTxCount = unspentTxCount.Value;
                    this.unspentTxCountVersion++;
                }

                if (unspentOutputCount != null)
                {
                    this.unspentOutputCount = unspentOutputCount.Value;
                    this.unspentOutputCountVersion++;
                }

                if (totalTxCount != null)
                {
                    this.totalTxCount = totalTxCount.Value;
                    this.totalTxCountVersion++;
                }

                if (totalInputCount != null)
                {
                    this.totalInputCount = totalInputCount.Value;
                    this.totalInputCountVersion++;
                }

                if (totalOutputCount != null)
                {
                    this.totalOutputCount = totalOutputCount.Value;
                    this.totalOutputCountVersion++;
                }

                if (headers != null)
                {
                    this.headers = headers.ToImmutable().ToBuilder();
                    this.headersVersion++;
                }

                if (unspentTransactions != null)
                {
                    this.unspentTransactions = unspentTransactions.ToImmutable().ToBuilder();
                    this.unspentTxesVersion++;
                }

                if (blockSpentTxes != null)
                {
                    this.blockSpentTxes = blockSpentTxes.ToImmutable().ToBuilder();
                    this.blockSpentTxesVersion++;
                }

                if (blockUnmintedTxes != null)
                {
                    this.blockUnmintedTxes = blockUnmintedTxes.ToImmutable().ToBuilder();
                    this.blockUnmintedTxesVersion++;
                }
            }
        }
Beispiel #32
0
 /// <summary>
 /// Creates a new <see cref="VectorClock"/>
 /// </summary>
 /// <returns>A new <see cref="VectorClock"/>.</returns>
 public static VectorClock Create()
 {
     return(Create(ImmutableSortedDictionary.Create <Node, long>()));
 }
 public ImmutableSortedDictionary <TKey2, TValue2> Convert(ImmutableSortedDictionary <TKey1, TValue1> source,
                                                           ImmutableSortedDictionary <TKey2, TValue2> destination, ResolutionContext context)
 {
     return(source.Select(p => new KeyValuePair <TKey2, TValue2>(context.Mapper.Map <TKey1, TKey2>(p.Key),
                                                                 context.Mapper.Map <TValue1, TValue2>(p.Value))).ToImmutableSortedDictionary());
 }
Beispiel #34
0
 private static void SetAmbigousNavigations(
     InternalEntityTypeBuilder entityTypeBuilder,
     ImmutableSortedDictionary <PropertyInfo, Type> ambiguousNavigations)
 => entityTypeBuilder.HasAnnotation(AmbiguousNavigationsAnnotationName, ambiguousNavigations, ConfigurationSource.Convention);
Beispiel #35
0
        public override void Initialize()
        {
            base.Initialize();

            MyInt16Array        = new short[] { 1 };
            MyInt32Array        = new int[] { 2 };
            MyInt64Array        = new long[] { 3 };
            MyUInt16Array       = new ushort[] { 4 };
            MyUInt32Array       = new uint[] { 5 };
            MyUInt64Array       = new ulong[] { 6 };
            MyByteArray         = new byte[] { 7 };
            MySByteArray        = new sbyte[] { 8 };
            MyCharArray         = new char[] { 'a' };
            MyStringArray       = new string[] { "Hello" };
            MyBooleanTrueArray  = new bool[] { true };
            MyBooleanFalseArray = new bool[] { false };
            MySingleArray       = new float[] { 1.1f };
            MyDoubleArray       = new double[] { 2.2d };
            MyDecimalArray      = new decimal[] { 3.3m };
            MyDateTimeArray     = new DateTime[] { new DateTime(2019, 1, 30, 12, 1, 2, DateTimeKind.Utc) };
            MyEnumArray         = new SampleEnum[] { SampleEnum.Two };

            MyStringList = new List <string>()
            {
                "Hello"
            };

            MyStringIEnumerable = new string[] { "Hello" };
            MyStringIList       = new string[] { "Hello" };
            MyStringICollection = new string[] { "Hello" };

            MyStringIEnumerableT         = new string[] { "Hello" };
            MyStringIListT               = new string[] { "Hello" };
            MyStringICollectionT         = new string[] { "Hello" };
            MyStringIReadOnlyCollectionT = new string[] { "Hello" };
            MyStringIReadOnlyListT       = new string[] { "Hello" };
            MyStringIReadOnlyListT       = new HashSet <string> {
                "Hello"
            };

            MyStringISetT = new HashSet <string> {
                "Hello"
            };

            MyStringToStringKeyValuePair = new KeyValuePair <string, string>("myKey", "myValue");
            MyStringToStringIDict        = new Dictionary <string, string> {
                { "key", "value" }
            };

            MyStringToStringGenericDict = new Dictionary <string, string> {
                { "key", "value" }
            };
            MyStringToStringGenericIDict = new Dictionary <string, string> {
                { "key", "value" }
            };
            MyStringToStringGenericIReadOnlyDict = new Dictionary <string, string> {
                { "key", "value" }
            };

            MyStringToStringImmutableDict       = ImmutableDictionary.CreateRange((Dictionary <string, string>)MyStringToStringGenericDict);
            MyStringToStringIImmutableDict      = ImmutableDictionary.CreateRange((Dictionary <string, string>)MyStringToStringGenericDict);
            MyStringToStringImmutableSortedDict = ImmutableSortedDictionary.CreateRange((Dictionary <string, string>)MyStringToStringGenericDict);

            MyStringStackT = new Stack <string>(new List <string>()
            {
                "Hello", "World"
            });
            MyStringQueueT = new Queue <string>(new List <string>()
            {
                "Hello", "World"
            });
            MyStringHashSetT = new HashSet <string>(new List <string>()
            {
                "Hello"
            });
            MyStringLinkedListT = new LinkedList <string>(new List <string>()
            {
                "Hello"
            });
            MyStringSortedSetT = new SortedSet <string>(new List <string>()
            {
                "Hello"
            });

            MyStringIImmutableListT = ImmutableList.CreateRange(new List <string> {
                "Hello"
            });
            MyStringIImmutableStackT = ImmutableStack.CreateRange(new List <string> {
                "Hello"
            });
            MyStringIImmutableQueueT = ImmutableQueue.CreateRange(new List <string> {
                "Hello"
            });
            MyStringIImmutableSetT = ImmutableHashSet.CreateRange(new List <string> {
                "Hello"
            });
            MyStringImmutableHashSetT = ImmutableHashSet.CreateRange(new List <string> {
                "Hello"
            });
            MyStringImmutableListT = ImmutableList.CreateRange(new List <string> {
                "Hello"
            });
            MyStringImmutableStackT = ImmutableStack.CreateRange(new List <string> {
                "Hello"
            });
            MyStringImmutablQueueT = ImmutableQueue.CreateRange(new List <string> {
                "Hello"
            });
            MyStringImmutableSortedSetT = ImmutableSortedSet.CreateRange(new List <string> {
                "Hello"
            });
        }
        public void RollbackTransaction()
        {
            if (!this.inTransaction)
                throw new InvalidOperationException();

            this.chainTip = null;
            this.unspentTxCount = null;
            this.unspentOutputCount = null;
            this.totalTxCount = null;
            this.totalInputCount = null;
            this.totalOutputCount = null;
            this.headers = null;
            this.unspentTransactions = null;
            this.blockSpentTxes = null;
            this.blockUnmintedTxes = null;

            this.inTransaction = false;

            if (!readOnly)
                chainStateStorage.WriteTxLock.Release();
        }
 /// <summary>
 /// The PointData
 /// </summary>
 /// <returns></returns>
 public PointData ToPointData()
 {
     return(new PointData(_measurementName, _precision, _time,
                          ImmutableSortedDictionary.CreateRange(_tags),
                          ImmutableSortedDictionary.CreateRange(_fields)));
 }