Beispiel #1
0
 private void SubEvents()
 {
     Manager io = _io;
     Subs = ImmutableQueue.Create<On.IHandle>();
     Subs = Subs.Enqueue(Client.On.Create(io, Manager.EVENT_OPEN, new ListenerImpl(OnOpen)));
     Subs = Subs.Enqueue(Client.On.Create(io, Manager.EVENT_PACKET, new ListenerImpl((data) => OnPacket((Packet)data))));
     Subs = Subs.Enqueue(Client.On.Create(io, Manager.EVENT_CLOSE, new ListenerImpl((data) => OnClose((string)data))));
 }
        private void TrackChanges(Action block)
        {
            var before = _membersByAge.FirstOrDefault();
            block();
            var after = _membersByAge.FirstOrDefault();

            // todo: fix neq comparison
            if (!Equals(before, after))
                _changes = _changes.Enqueue(new OldestChanged(MemberAddressOrDefault(after)));
        }
 public ImmutableQueueEnumerable(ImmutableQueue <T> source) => this.source = source;
Beispiel #4
0
        public static void ArrayAsRootObject()
        {
            const string ExpectedJson         = @"[1,true,{""City"":""MyCity""},null,""foo""]";
            const string ReversedExpectedJson = @"[""foo"",null,{""City"":""MyCity""},true,1]";

            string[] expectedObjects = { @"""foo""", @"null", @"{""City"":""MyCity""}", @"true", @"1" };

            var address = new Address();

            address.Initialize();

            var    array = new object[] { 1, true, address, null, "foo" };
            string json  = JsonSerializer.Serialize(array);

            Assert.Equal(ExpectedJson, json);

            var dictionary = new Dictionary <string, string> {
                { "City", "MyCity" }
            };
            var arrayWithDictionary = new object[] { 1, true, dictionary, null, "foo" };

            json = JsonSerializer.Serialize(arrayWithDictionary);
            Assert.Equal(ExpectedJson, json);

            json = JsonSerializer.Serialize <object>(array);
            Assert.Equal(ExpectedJson, json);

            List <object> list = new List <object> {
                1, true, address, null, "foo"
            };

            json = JsonSerializer.Serialize(list);
            Assert.Equal(ExpectedJson, json);

            json = JsonSerializer.Serialize <object>(list);
            Assert.Equal(ExpectedJson, json);

            IEnumerable ienumerable = new List <object> {
                1, true, address, null, "foo"
            };

            json = JsonSerializer.Serialize(ienumerable);
            Assert.Equal(ExpectedJson, json);

            json = JsonSerializer.Serialize <object>(ienumerable);
            Assert.Equal(ExpectedJson, json);

            IList ilist = new List <object> {
                1, true, address, null, "foo"
            };

            json = JsonSerializer.Serialize(ilist);
            Assert.Equal(ExpectedJson, json);

            json = JsonSerializer.Serialize <object>(ilist);
            Assert.Equal(ExpectedJson, json);

            ICollection icollection = new List <object> {
                1, true, address, null, "foo"
            };

            json = JsonSerializer.Serialize(icollection);
            Assert.Equal(ExpectedJson, json);

            json = JsonSerializer.Serialize <object>(icollection);
            Assert.Equal(ExpectedJson, json);

            IEnumerable <object> genericIEnumerable = new List <object> {
                1, true, address, null, "foo"
            };

            json = JsonSerializer.Serialize(genericIEnumerable);
            Assert.Equal(ExpectedJson, json);

            json = JsonSerializer.Serialize <object>(genericIEnumerable);
            Assert.Equal(ExpectedJson, json);

            IList <object> genericIList = new List <object> {
                1, true, address, null, "foo"
            };

            json = JsonSerializer.Serialize(genericIList);
            Assert.Equal(ExpectedJson, json);

            json = JsonSerializer.Serialize <object>(genericIList);
            Assert.Equal(ExpectedJson, json);

            ICollection <object> genericICollection = new List <object> {
                1, true, address, null, "foo"
            };

            json = JsonSerializer.Serialize(genericICollection);
            Assert.Equal(ExpectedJson, json);

            json = JsonSerializer.Serialize <object>(genericICollection);
            Assert.Equal(ExpectedJson, json);

            IReadOnlyCollection <object> genericIReadOnlyCollection = new List <object> {
                1, true, address, null, "foo"
            };

            json = JsonSerializer.Serialize(genericIReadOnlyCollection);
            Assert.Equal(ExpectedJson, json);

            json = JsonSerializer.Serialize <object>(genericIReadOnlyCollection);
            Assert.Equal(ExpectedJson, json);

            IReadOnlyList <object> genericIReadonlyList = new List <object> {
                1, true, address, null, "foo"
            };

            json = JsonSerializer.Serialize(genericIReadonlyList);
            Assert.Equal(ExpectedJson, json);

            json = JsonSerializer.Serialize <object>(genericIReadonlyList);
            Assert.Equal(ExpectedJson, json);

            ISet <object> iset = new HashSet <object> {
                1, true, address, null, "foo"
            };

            json = JsonSerializer.Serialize(iset);
            Assert.Equal(ExpectedJson, json);

            json = JsonSerializer.Serialize <object>(iset);
            Assert.Equal(ExpectedJson, json);

            Stack <object> stack = new Stack <object>(new List <object> {
                1, true, address, null, "foo"
            });

            json = JsonSerializer.Serialize(stack);
            Assert.Equal(ReversedExpectedJson, json);

            json = JsonSerializer.Serialize <object>(stack);
            Assert.Equal(ReversedExpectedJson, json);

            Queue <object> queue = new Queue <object>(new List <object> {
                1, true, address, null, "foo"
            });

            json = JsonSerializer.Serialize(queue);
            Assert.Equal(ExpectedJson, json);

            json = JsonSerializer.Serialize <object>(queue);
            Assert.Equal(ExpectedJson, json);

            HashSet <object> hashset = new HashSet <object>(new List <object> {
                1, true, address, null, "foo"
            });

            json = JsonSerializer.Serialize(hashset);
            Assert.Equal(ExpectedJson, json);

            json = JsonSerializer.Serialize <object>(hashset);
            Assert.Equal(ExpectedJson, json);

            LinkedList <object> linkedlist = new LinkedList <object>(new List <object> {
                1, true, address, null, "foo"
            });

            json = JsonSerializer.Serialize(linkedlist);
            Assert.Equal(ExpectedJson, json);

            json = JsonSerializer.Serialize <object>(linkedlist);
            Assert.Equal(ExpectedJson, json);

            ImmutableArray <object> immutablearray = ImmutableArray.CreateRange(new List <object> {
                1, true, address, null, "foo"
            });

            json = JsonSerializer.Serialize(immutablearray);
            Assert.Equal(ExpectedJson, json);

            json = JsonSerializer.Serialize <object>(immutablearray);
            Assert.Equal(ExpectedJson, json);

            IImmutableList <object> iimmutablelist = ImmutableList.CreateRange(new List <object> {
                1, true, address, null, "foo"
            });

            json = JsonSerializer.Serialize(iimmutablelist);
            Assert.Equal(ExpectedJson, json);

            json = JsonSerializer.Serialize <object>(iimmutablelist);
            Assert.Equal(ExpectedJson, json);

            IImmutableStack <object> iimmutablestack = ImmutableStack.CreateRange(new List <object> {
                1, true, address, null, "foo"
            });

            json = JsonSerializer.Serialize(iimmutablestack);
            Assert.Equal(ReversedExpectedJson, json);

            json = JsonSerializer.Serialize <object>(iimmutablestack);
            Assert.Equal(ReversedExpectedJson, json);

            IImmutableQueue <object> iimmutablequeue = ImmutableQueue.CreateRange(new List <object> {
                1, true, address, null, "foo"
            });

            json = JsonSerializer.Serialize(iimmutablequeue);
            Assert.Equal(ExpectedJson, json);

            json = JsonSerializer.Serialize <object>(iimmutablequeue);
            Assert.Equal(ExpectedJson, json);

            IImmutableSet <object> iimmutableset = ImmutableHashSet.CreateRange(new List <object> {
                1, true, address, null, "foo"
            });

            json = JsonSerializer.Serialize(iimmutableset);
            foreach (string obj in expectedObjects)
            {
                Assert.Contains(obj, json);
            }

            json = JsonSerializer.Serialize <object>(iimmutableset);
            foreach (string obj in expectedObjects)
            {
                Assert.Contains(obj, json);
            }

            ImmutableHashSet <object> immutablehashset = ImmutableHashSet.CreateRange(new List <object> {
                1, true, address, null, "foo"
            });

            json = JsonSerializer.Serialize(immutablehashset);
            foreach (string obj in expectedObjects)
            {
                Assert.Contains(obj, json);
            }

            json = JsonSerializer.Serialize <object>(immutablehashset);
            foreach (string obj in expectedObjects)
            {
                Assert.Contains(obj, json);
            }

            ImmutableList <object> immutablelist = ImmutableList.CreateRange(new List <object> {
                1, true, address, null, "foo"
            });

            json = JsonSerializer.Serialize(immutablelist);
            Assert.Equal(ExpectedJson, json);

            json = JsonSerializer.Serialize <object>(immutablelist);
            Assert.Equal(ExpectedJson, json);

            ImmutableStack <object> immutablestack = ImmutableStack.CreateRange(new List <object> {
                1, true, address, null, "foo"
            });

            json = JsonSerializer.Serialize(immutablestack);
            Assert.Equal(ReversedExpectedJson, json);

            json = JsonSerializer.Serialize <object>(immutablestack);
            Assert.Equal(ReversedExpectedJson, json);

            ImmutableQueue <object> immutablequeue = ImmutableQueue.CreateRange(new List <object> {
                1, true, address, null, "foo"
            });

            json = JsonSerializer.Serialize(immutablequeue);
            Assert.Equal(ExpectedJson, json);

            json = JsonSerializer.Serialize <object>(immutablequeue);
            Assert.Equal(ExpectedJson, json);
        }
Beispiel #5
0
        public void Initialize()
        {
            {
                SimpleTestClass obj1 = new SimpleTestClass();
                obj1.Initialize();

                SimpleTestClass obj2 = new SimpleTestClass();
                obj2.Initialize();

                MyIImmutableList = ImmutableList.CreateRange(new List <SimpleTestClass> {
                    obj1, obj2
                });
            }
            {
                SimpleTestClass obj1 = new SimpleTestClass();
                obj1.Initialize();

                SimpleTestClass obj2 = new SimpleTestClass();
                obj2.Initialize();

                MyIImmutableStack = ImmutableStack.CreateRange(new List <SimpleTestClass> {
                    obj1, obj2
                });
            }
            {
                SimpleTestClass obj1 = new SimpleTestClass();
                obj1.Initialize();

                SimpleTestClass obj2 = new SimpleTestClass();
                obj2.Initialize();

                MyIImmutableQueue = ImmutableQueue.CreateRange(new List <SimpleTestClass> {
                    obj1, obj2
                });
            }
            {
                SimpleTestClass obj1 = new SimpleTestClass();
                obj1.Initialize();

                SimpleTestClass obj2 = new SimpleTestClass();
                obj2.Initialize();

                MyIImmutableSet = ImmutableHashSet.CreateRange(new List <SimpleTestClass> {
                    obj1, obj2
                });
            }
            {
                SimpleTestClass obj1 = new SimpleTestClass();
                obj1.Initialize();

                SimpleTestClass obj2 = new SimpleTestClass();
                obj2.Initialize();

                MyImmutableHashSet = ImmutableHashSet.CreateRange(new List <SimpleTestClass> {
                    obj1, obj2
                });
            }
            {
                SimpleTestClass obj1 = new SimpleTestClass();
                obj1.Initialize();

                SimpleTestClass obj2 = new SimpleTestClass();
                obj2.Initialize();

                MyImmutableList = ImmutableList.CreateRange(new List <SimpleTestClass> {
                    obj1, obj2
                });
            }
            {
                SimpleTestClass obj1 = new SimpleTestClass();
                obj1.Initialize();

                SimpleTestClass obj2 = new SimpleTestClass();
                obj2.Initialize();

                MyImmutableStack = ImmutableStack.CreateRange(new List <SimpleTestClass> {
                    obj1, obj2
                });
            }
            {
                SimpleTestClass obj1 = new SimpleTestClass();
                obj1.Initialize();

                SimpleTestClass obj2 = new SimpleTestClass();
                obj2.Initialize();

                MyImmutableQueue = ImmutableQueue.CreateRange(new List <SimpleTestClass> {
                    obj1, obj2
                });
            }
        }
 public StringIImmutableQueueWrapper(List <string> items)
 {
     _queue = ImmutableQueue.CreateRange(items);
 }
Beispiel #7
0
 /// <summary>
 /// Restarts the zmachine.
 /// </summary>
 protected override void Restart()
 {
     this.musicEffect = null;
     this.soundEffects = null;
     this.memoryStreams = null;
     this.displayStreamOpen = true;
     this.ActiveDisplayWindow = DisplayWindow.Lower;
     this.UpperWindowHeight = 0;
     this.lastSound = 0;
     base.Restart();
 }
Beispiel #8
0
        private void Destroy()
        {
            foreach (var sub in Subs)
            {
                sub.Destroy();
            }
            Subs = Subs.Clear();

            _io.Destroy(this);
        }
Beispiel #9
0
 protected QueuedAwaitableStateMachineBase(TState initialState, AwaitableConfiguration <TState, TTrigger> config)
     : base(initialState, config)
 {
     actionsQueue = ImmutableQueue.Create <Func <Task> >();
 }
 public void Deserialize(byte[] buffer, ref int offset, ref ImmutableQueue <TItem> value)
 {
     TItem[] array = null;
     _itemsFormatter.Deserialize(buffer, ref offset, ref array);
     value = ImmutableQueue.CreateRange(array);
 }
        public void Serialize(ref byte[] buffer, ref int offset, ImmutableQueue <TItem> value)
        {
            var array = value.ToArray();

            _itemsFormatter.Serialize(ref buffer, ref offset, array);
        }
Beispiel #12
0
        public void Should_property_function_as_a_queue()
        {
            ImmutableQueue <int> queue = ImmutableQueue <int> .EmptyQueue.AddLast(27).AddLast(47);

            queue.SequenceEqual(new[] { 27, 47 }).ShouldBeTrue();
        }
Beispiel #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TimedInput"/> struct.
 /// </summary>
 /// <param name="inputValues">
 /// The input values.
 /// </param>
 /// <param name="elapsedTime">
 /// The elapsed time since the last time marker minus the time spent at any [MORE] prompts.
 /// </param>
 internal TimedInput(ImmutableQueue<InputValue> inputValues, long elapsedTime)
 {
     this.elapsedTime = elapsedTime;
     this.inputValues = inputValues;
 }
 public void Add(T value)
 {
     q = q.Enqueue(value);
 }
Beispiel #15
0
 public void Empty()
 {
     // We already test Create(), so just prove that Empty has the same effect.
     Assert.Same(ImmutableQueue.Create <int>(), ImmutableQueue <int> .Empty);
 }
Beispiel #16
0
        private void OnEvent(Packet packet)
        {
            var log = LogManager.GetLogger(Global.CallerName());
            //var jarr =(string) ((JValue) packet.Data).Value;
            //var job = JToken.Parse(jarr);


            //var arr = job.ToArray();

            //var args = job.Select(token => token.Value<string>()).Cast<object>().ToList();
            var args = packet.GetDataAsList();



            log.Info(string.Format("emitting event {0}", args));
            if (packet.Id >= 0)
            {
                log.Info("attaching ack callback to event");
                args.Add(new AckImp(this, packet.Id));
            }

            if (Connected)
            {
                var eventString = (string) args[0];
                args.Remove(args[0]);
                base.Emit(eventString, args.ToArray());
            }
            else
            {
                ReceiveBuffer = ReceiveBuffer.Enqueue(args);
            }
        }  
Beispiel #17
0
        public void TestPeekEx()
        {
            var s = ImmutableQueue.Create <int>();

            s.Peek();
        }
Beispiel #18
0
        public override Emitter Emit(string eventString, params object[] args)
        {
            var log = LogManager.GetLogger(Global.CallerName());

            if (Events.Contains(eventString))
            {
                base.Emit(eventString, args);
                return this;
            }

            var _args = new List<object> {eventString};
            _args.AddRange(args);

            var jsonArgs = Parser.Packet.Args2JArray(_args);

            var parserType = HasBinaryData.HasBinary(jsonArgs) ? Parser.Parser.BINARY_EVENT : Parser.Parser.EVENT;
            var packet = new Packet(parserType, jsonArgs);

            var lastArg = _args[_args.Count - 1];
            if (lastArg is IAck)
            {
                log.Info(string.Format("emitting packet with ack id {0}", Ids));
                Acks = Acks.Add(Ids, (IAck)lastArg);
                jsonArgs = Parser.Packet.Remove(jsonArgs, jsonArgs.Count - 1);
                packet.Data = jsonArgs;
                packet.Id = Ids++;
            }

            if (Connected)
            {
                Packet(packet);
            }
            else
            {
                SendBuffer = SendBuffer.Enqueue(packet);
            }
            return this;
        }
Beispiel #19
0
        public void TestDequeueEx()
        {
            var s = ImmutableQueue.Create <int>();

            s.Dequeue();
        }
Beispiel #20
0
 /// <summary>
 /// Writes input values to the input log.
 /// </summary>
 /// <param name="inputValues">
 /// The input values.
 /// </param>
 protected override void WriteToInputLog(ImmutableQueue<InputValue> inputValues)
 {
     var inputOperation = this.InputOperation;
     if (inputOperation.Timed)
     {
         this.FrontEnd.WriteToInputLog(inputValues, inputOperation.ElapsedTime);
     }
     else
     {
         base.WriteToInputLog(inputValues);
     }
 }
        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
            };
        }
Beispiel #22
0
        /// <summary>
        /// Processes a sound that has finished playing.
        /// </summary>
        /// <param name="sound">
        /// The sound.
        /// </param>
        private void ProcessFinishedSound(int sound)
        {
            if (this.musicEffect.Sound == sound)
            {
                if (!this.LoopSound(this.musicEffect))
                {
                    this.musicEffect = null;
                }

                return;
            }

            if (this.soundEffects != null)
            {
                var soundEffect = this.soundEffects.Front;
                if (sound == soundEffect.Sound)
                {
                    if (!this.LoopSound(soundEffect) || this.soundEffects.Tail != null)
                    {
                        this.soundEffects = this.soundEffects.Tail;
                    }

                    this.PlayNextSound();
                }
            }
        }
Beispiel #23
0
 public Cond(ImmutableQueue <GmInstruction> trueCode, ImmutableQueue <GmInstruction> falseCode)
 {
     TrueCode  = trueCode;
     FalseCode = falseCode;
 }
        public void SerializationTests_ImmutableCollections_Queue()
        {
            var original = ImmutableQueue.Create("1", "2", "3");

            RoundTripCollectionSerializationTest(original);
        }
Beispiel #25
0
 /// <summary>
 /// Updates the input.
 /// </summary>
 /// <param name="inputValues">
 /// The input values.
 /// </param>
 internal void UpdateInput(ImmutableQueue<InputValue> inputValues)
 {
     this.unprocessedInputValues = inputValues;
 }
Beispiel #26
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"
            });
        }
Beispiel #27
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));
            MyEnum           = SampleEnum.Two;

            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)) };
            MyEnumArray           = new SampleEnum[] { SampleEnum.Two };

            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"
            };
            MyStringIEnumerableT         = new string[] { "Hello" };
            MyStringIListT               = new string[] { "Hello" };
            MyStringICollectionT         = new string[] { "Hello" };
            MyStringIReadOnlyCollectionT = new string[] { "Hello" };
            MyStringIReadOnlyListT       = new string[] { "Hello" };

            MyStringToStringDict = new Dictionary <string, string> {
                { "key", "value" }
            };
            MyStringToStringIDict = new Dictionary <string, string> {
                { "key", "value" }
            };
            MyStringToStringIReadOnlyDict = new Dictionary <string, string> {
                { "key", "value" }
            };

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

            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
            };
        }
 public ImmutableQueueEnumerator(ImmutableQueue <T> source) => e = source.GetEnumerator();
 public CollectionDisposableObjects(IEnumerable <IDisposable> disposables) : base(ImmutableQueue.CreateRange(disposables))
 {
 }
 /// <summary>
 /// Creates a disposable that disposes a collection of disposables.
 /// </summary>
 /// <param name="disposables">The disposables to dispose. May not be <c>null</c>, and entries may not be <c>null</c>.</param>
 /// <param name="flags">Flags that control how asynchronous disposal is handled.</param>
 public CollectionAsyncDisposable(IEnumerable <IAsyncDisposable> disposables, AsyncDisposeFlags flags)
     : base(ImmutableQueue.CreateRange(disposables))
 {
     _flags = flags;
 }
Beispiel #31
0
 internal void OnDeserialized(StreamingContext context)
 {
     Route = ImmutableQueue.CreateRange(_routeSerialization);
     _routeSerialization = null;
 }
Beispiel #32
0
 /// <summary>
 /// Writes input values to the input log.
 /// </summary>
 /// <param name="inputValues">
 /// The input values.
 /// </param>
 protected virtual void WriteToInputLog(ImmutableQueue<InputValue> inputValues)
 {
     this.FrontEnd.WriteToInputLog(inputValues);
 }
Beispiel #33
0
 public static ImmutableQueue <T> ImmutableQueueFrom <T>(T value)
 {
     return(ImmutableQueue.Create(value));
 }
Beispiel #34
0
        private void EmitBuffered()
        {
            while (ReceiveBuffer.Count() > 0)
            {
                List<object> data;
                ReceiveBuffer = ReceiveBuffer.Dequeue(out data);
                var eventString = (string) data[0];
                base.Emit(eventString, data.ToArray());
            }
            ReceiveBuffer = ReceiveBuffer.Clear();

           
            while (SendBuffer.Count() > 0)
            {
                Packet packet;
                SendBuffer = SendBuffer.Dequeue(out packet);
                Packet(packet);
            }
            SendBuffer = SendBuffer.Clear();
        }
Beispiel #35
0
 public static ImmutableQueue <T> ImmutableQueueFrom <T>(T value, params T[] values)
 {
     return(ImmutableQueue.CreateRange(EnumerableUtils.GetEnumerableFrom(value, values)));
 }
Beispiel #36
0
 public static ImmutableQueue <T> ImmutableQueueFrom <T>(T first, T second, T third)
 {
     return(ImmutableQueue.Create(first, second, third));
 }
Beispiel #37
0
 public static ImmutableQueue <T> ImmutableQueueFrom <T>(T first, T second, T third, params T[] values)
 {
     return(ImmutableQueue.CreateRange(EnumerableUtils.GetEnumerableFrom(first, second, third, values)));
 }
 private void SendFirstChange()
 {
     object change;
     _changes = _changes.Dequeue(out change);
     Context.Parent.Tell(change);
 }
Beispiel #39
0
 public GmState(ImmutableQueue <GmInstruction> code, ImmutableStack <int> stack, ImmutableStack <(ImmutableQueue <GmInstruction> Code, ImmutableStack <int> Stack)> dump, ImmutableDictionary <int, GmNode> heap, ImmutableDictionary <Name, int> globals)
        private void HandleInitial(ClusterEvent.CurrentClusterState state)
        {
            _membersByAge = state.Members
                .Where(m => (m.Status == MemberStatus.Up || m.Status == MemberStatus.Leaving) && MatchingRole(m))
                .ToImmutableSortedSet(MemberAgeOrdering.Descending);

            var safeToBeOldest = !state.Members.Any(m => m.Status == MemberStatus.Down || m.Status == MemberStatus.Exiting);
            var initial = new InitialOldestState(MemberAddressOrDefault(_membersByAge.FirstOrDefault()), safeToBeOldest);
            _changes = _changes.Enqueue(initial);
        }
Beispiel #41
0
 private ValidationContext Clone(ImmutableQueue <string> path, bool isOptional, ValidationMode mode)
 {
     return(new ValidationContext(AppId, SchemaId, Schema, ContentId, path, isOptional, mode));
 }
Beispiel #42
0
        /// <summary>
        /// Operation 245.
        /// </summary>
        /// <remarks>
        /// Infocom name: SOUND
        ///   Inform name: sound_effect
        ///   This operation manipulates sound effects.
        ///   The standard 1.1 interpretation of 'stop all' and 'unload all' when providing operands (0,3) and (0,4) respectively is followed despite the evidence that this was not Infocom's intent.
        ///   Due to the addition of a second channel for music in standard 1.1, changing this now would be a breaking change.
        ///   This implementation expands upon standard 1.1 by following the behavior of Infocom's sound capable interpreters.
        ///   Sepcifically:
        ///   Omitting the third operand is the same as specifying one repetition at the default volume.
        ///   Omitting the second operand is the same as specifying play.
        ///   Omitting the first operand or providing it with a zero value is the same as specifying the last used sound number.
        ///   The last used sound number is updated on all actions except unload.
        ///   Actions performed with sound numbers one and two (high beep and low beep) never update the last used sound number.
        ///   For two reasons this implementation resets the last sound number on restart or restore and issues an error if an attempt is made to use the last sound number before a valid sound is used:
        ///   1) Infocom interpreters vary in their behavior when attempting to use the last sound before a valid sound is used.
        ///   2) Infocom interpreters do not reset the last sound number during a restart or restore, leading to inconsistent behavior versus initial start up.
        ///   Operands:
        ///   0) Sound number
        ///   1) Action number
        ///   2) Volume.
        /// </remarks>
        protected override void Operation245()
        {
            var sound = this.Operands.First;
            switch (sound)
            {
                case 1:
                    this.FrontEnd.PlayBeep(Beep.High);
                    return;
                case 2:
                    this.FrontEnd.PlayBeep(Beep.Low);
                    return;
            }

            var action = this.Operands.Count > 1 ? this.Operands.Second : (ushort)2;
            if (sound != 0 && action != 4)
            {
                this.lastSound = sound;
            }

            switch (action)
            {
                case 1:
                    if (this.lastSound == 0)
                    {
                        this.FrontEnd.ErrorNotification(ErrorCondition.InvalidSoundAction, "Tried to load last sound before a vaild sound has been used.");
                        break;
                    }

                    this.FrontEnd.LoadSound(this.lastSound);
                    break;
                case 2:
                    if (this.lastSound == 0)
                    {
                        this.FrontEnd.ErrorNotification(ErrorCondition.InvalidSoundAction, "Tried to play last sound before a vaild sound has been used.");
                        break;
                    }

                    this.PlaySound(this.CreateSoundEffect(this.lastSound, this.Operands.Count > 2 ? (byte)this.Operands.Third : byte.MaxValue));
                    break;
                case 3:
                    if (sound == 0)
                    {
                        this.musicEffect = null;
                        this.soundEffects = null;
                        this.FrontEnd.StopAllSounds();
                        break;
                    }

                    this.StopSound(this.lastSound);
                    break;
                case 4:
                    if (sound == 0)
                    {
                        this.FrontEnd.UnloadAllSounds();
                        break;
                    }

                    this.FrontEnd.UnloadSound(sound);
                    break;
                default:
                    this.FrontEnd.ErrorNotification(ErrorCondition.InvalidSoundAction, "Tried to use sound " + this.lastSound + " with action " + action + ".");
                    break;
            }
        }
Beispiel #43
0
 public Logger(ScannerBase scanner)
 {
     this.scanner = scanner;
     log          = ImmutableQueue <LogItem> .Empty;
 }
Beispiel #44
0
        /// <summary>
        /// Plays a sound effect.
        /// </summary>
        /// <param name="soundEffect">
        /// The sound effect.
        /// </param>
        /// <remarks>
        /// This manages the sound queue and current music effect whenever a sound is played.
        ///   To enable correct behavior for 'The Lurking Horror' the sound is queued if an input operation has not occurred since the last sound was played.
        ///   Music is never queued, as specified in the Blorb standard.
        /// </remarks>
        private void PlaySound(SoundEffect soundEffect)
        {
            if (this.FrontEnd.SoundIsMusic(soundEffect.Sound))
            {
                if (this.musicEffect != null)
                {
                    this.FrontEnd.StopSound(this.musicEffect.Sound);
                }

                this.musicEffect = soundEffect;
                this.FrontEnd.PlaySound(this.musicEffect.Sound, this.musicEffect.Volume);
                return;
            }

            if (!this.queueSounds && this.soundEffects != null)
            {
                var sound = this.soundEffects.Front.Sound;
                this.soundEffects = null;
                this.FrontEnd.StopSound(sound);
            }

            this.queueSounds = true;
            this.soundEffects = this.soundEffects.Add(soundEffect);
            if (this.soundEffects.Count() == 1)
            {
                this.PlayNextSound();
            }
        }
Beispiel #45
0
        public ObjectWithObjectProperties()
        {
            Address = new Address();
            ((Address)Address).Initialize();

            List = new List <string> {
                "Hello", "World"
            };
            Array       = new string[] { "Hello", "Again" };
            IEnumerable = new List <string> {
                "Hello", "World"
            };
            IList = new List <string> {
                "Hello", "World"
            };
            ICollection = new List <string> {
                "Hello", "World"
            };
            IEnumerableT = new List <string> {
                "Hello", "World"
            };
            IListT = new List <string> {
                "Hello", "World"
            };
            ICollectionT = new List <string> {
                "Hello", "World"
            };
            IReadOnlyCollectionT = new List <string> {
                "Hello", "World"
            };
            IReadOnlyListT = new List <string> {
                "Hello", "World"
            };
            ISetT = new HashSet <string> {
                "Hello", "World"
            };
            StackT = new Stack <string>(new List <string> {
                "Hello", "World"
            });
            QueueT = new Queue <string>(new List <string> {
                "Hello", "World"
            });
            HashSetT = new HashSet <string>(new List <string> {
                "Hello", "World"
            });
            LinkedListT = new LinkedList <string>(new List <string> {
                "Hello", "World"
            });
            SortedSetT = new SortedSet <string>(new List <string> {
                "Hello", "World"
            });
            ImmutableArrayT = ImmutableArray.CreateRange(new List <string> {
                "Hello", "World"
            });
            IImmutableListT = ImmutableList.CreateRange(new List <string> {
                "Hello", "World"
            });
            IImmutableStackT = ImmutableStack.CreateRange(new List <string> {
                "Hello", "World"
            });
            IImmutableQueueT = ImmutableQueue.CreateRange(new List <string> {
                "Hello", "World"
            });
            IImmutableSetT = ImmutableHashSet.CreateRange(new List <string> {
                "Hello", "World"
            });
            ImmutableHashSetT = ImmutableHashSet.CreateRange(new List <string> {
                "Hello", "World"
            });
            ImmutableListT = ImmutableList.CreateRange(new List <string> {
                "Hello", "World"
            });
            ImmutableStackT = ImmutableStack.CreateRange(new List <string> {
                "Hello", "World"
            });
            ImmutableQueueT = ImmutableQueue.CreateRange(new List <string> {
                "Hello", "World"
            });
            ImmutableSortedSetT = ImmutableSortedSet.CreateRange(new List <string> {
                "Hello", "World"
            });

            NullableInt      = new int?(42);
            Object           = new object();
            NullableIntArray = new int?[] { null, 42, null };
        }
Beispiel #46
0
        /// <summary>
        /// Stops a sound that is playing.
        /// </summary>
        /// <param name="sound">
        /// The sound.
        /// </param>
        private void StopSound(ushort sound)
        {
            if (this.musicEffect.Sound == sound)
            {
                this.musicEffect = null;
                this.FrontEnd.StopSound(sound);
                return;
            }

            if (this.soundEffects != null && this.soundEffects.Front.Sound == sound)
            {
                this.FrontEnd.StopSound(this.soundEffects.Front.Sound);
                this.soundEffects = this.soundEffects.Tail;
                this.PlayNextSound();
            }
        }
Beispiel #47
0
 public Global(int argCount, ImmutableQueue <GmInstruction> code)
 {
     ArgCount = argCount;
     Code     = code;
 }