Exemple #1
0
        public static void ReadPrimitiveStack()
        {
            Stack result   = JsonSerializer.Deserialize <Stack>(Encoding.UTF8.GetBytes(@"[1,2]"));
            int   expected = 2;

            foreach (JsonElement i in result)
            {
                Assert.Equal(expected--, i.GetInt32());
            }

            result = JsonSerializer.Deserialize <Stack>(Encoding.UTF8.GetBytes(@"[]"));

            int         count = 0;
            IEnumerator e     = result.GetEnumerator();

            while (e.MoveNext())
            {
                count++;
            }
            Assert.Equal(0, count);

            StackWrapper wrapper = JsonSerializer.Deserialize <StackWrapper>(@"[1,2]");

            expected = 2;

            foreach (JsonElement i in wrapper)
            {
                Assert.Equal(expected--, i.GetInt32());
            }
        }
        public async Task ReadPrimitiveStack()
        {
            Stack result = await Serializer.DeserializeWrapper <Stack>(@"[1,2]");

            int expected = 2;

            foreach (JsonElement i in result)
            {
                Assert.Equal(expected--, i.GetInt32());
            }

            result = await Serializer.DeserializeWrapper <Stack>(@"[]");

            int         count = 0;
            IEnumerator e     = result.GetEnumerator();

            while (e.MoveNext())
            {
                count++;
            }
            Assert.Equal(0, count);

            StackWrapper wrapper = await Serializer.DeserializeWrapper <StackWrapper>(@"[1,2]");

            expected = 2;

            foreach (JsonElement i in wrapper)
            {
                Assert.Equal(expected--, i.GetInt32());
            }
        }
        public void Initialize()
        {
            MyIListWrapper = new WrapperForIList()
            {
                "Hello"
            };
            MyIDictionaryWrapper = new WrapperForIDictionary()
            {
                { "key", "value" }
            };
            MyHashtableWrapper = new HashtableWrapper(new List <KeyValuePair <string, object> > {
                new KeyValuePair <string, object>("key", "value")
            });
            MyArrayListWrapper = new ArrayListWrapper()
            {
                "Hello"
            };
            MySortedListWrapper = new SortedListWrapper()
            {
                { "key", "value" }
            };
            MyStackWrapper = new StackWrapper();
            MyQueueWrapper = new QueueWrapper();

            MyStackWrapper.Push("Hello");
            MyQueueWrapper.Enqueue("Hello");
        }
Exemple #4
0
        private void MoveLeft()
        {
            // Decide if we can move
            StackWrapper current = CurrentController;

            if (_stack.Count <= 1)
            {
                return;
            }

            // Create graphics port
            Graphics g = this.CreateGraphics();

            // Get image of the current view
            Bitmap   bmp1  = new Bitmap(ClientRectangle.Width, ClientRectangle.Height);
            Graphics bmp1G = Graphics.FromImage(bmp1);

            GoPaint(bmp1G, ClientRectangle);

            // Remove controller from stack
            _stack.RemoveAt(_stack.Count - 1);

            // Get image of new view
            Bitmap   bmp2  = new Bitmap(ClientRectangle.Width, ClientRectangle.Height);
            Graphics bmp2G = Graphics.FromImage(bmp2);

            GoPaint(bmp2G, ClientRectangle);

            // Animate transition between views
            Pen pen = new Pen(Color.Gray, 3);

            for (int i = 1; i < 4; i++)
            {
                int x = ClientRectangle.Width * i / 5;

                g.DrawImage(bmp1, x, 0);
                g.DrawImage(bmp2, x - ClientRectangle.Width, 0);
                g.DrawLine(pen, x, 0, x, ClientRectangle.Height);

                Thread.Sleep(25);
            }

            pen.Dispose();

            // Clean up images
            bmp1G.Dispose();
            bmp1.Dispose();

            bmp2G.Dispose();
            bmp2.Dispose();

            g.Dispose();

            // Finally, draw new view
            Refresh();

            OnSelectedIndexChanged(EventArgs.Empty);
        }
 private void StackRunner(int iterations, StackWrapper <Data> stack)
 {
     for (int i = 0; i < iterations; i++)
     {
         Data data = stack.Pop();
         data.Counter += 1;
         stack.Push(data);
     }
 }
Exemple #6
0
        public IStackWrapper <T> ToWrapper <T> ()
        {
            var wrapper = new StackWrapper <T>(this.clonedCore);

            this.clonedCore.EntryType = typeof(T);
            this.clonedCore.Serve(cloned: true);

            return(wrapper);
        }
Exemple #7
0
        private void RunAction()
        {
            StackWrapper current = CurrentController;

            if (current.Controller.Items.Count == 0)
            {
                return;
            }

            PodItem item = (PodItem)current.Controller.Items[current.Index];

            //if (!item.IsLeaf)
            //    return;

            item.RunAction();
        }
Exemple #8
0
        private void MoveUp(int count)
        {
            StackWrapper current = CurrentController;

            if (current.Index > 0)
            {
                current.Index -= count;
                if (current.Index < 0)
                {
                    current.Index = 0;
                }

                AdjustScroll();
                Refresh();

                OnSelectedIndexChanged(EventArgs.Empty);
            }
        }
Exemple #9
0
        private void MoveDown(int count)
        {
            // Decide if we can move
            StackWrapper current = CurrentController;
            int          max     = current.Controller.Items.Count - 1;

            if (current.Index < max)
            {
                current.Index += count;
                if (current.Index > max)
                {
                    current.Index = max;
                }

                AdjustScroll();
                Refresh();

                OnSelectedIndexChanged(EventArgs.Empty);
            }
        }
Exemple #10
0
        /// <summary>
        /// <para>Create a new <see cref="IStackWrapper{TEntry}"/> from the entry point <typeparamref name="T"/> </para>
        /// <para>If no settings are specified the default ones <seealso cref="StackWrapperSettings.Default"/> will be used.</para>
        /// </summary>
        /// <typeparam name="T">The type of the entry point</typeparam>
        /// <param name="settings">settings for this StackWrapper</param>
        /// <returns>The Initialized StackWrapper</returns>
        /// <exception cref="InvalidEntryTypeException"></exception>
        /// <exception cref="NotAServiceException"></exception>
        /// <exception cref="ServiceNotFoundException"></exception>
        /// <exception cref="ImplementationNotFoundException"></exception>
        /// <exception cref="StackInjectorException"></exception>
        public static IStackWrapper <T> From <T> (StackWrapperSettings settings = null)
        {
            if (settings == null)
            {
                settings = StackWrapperSettings.Default;
            }

            // create the core and wrap it
            var core = new InjectionCore(settings)
            {
                EntryType = typeof(T)
            };

            var wrapper = new StackWrapper <T>(core);

            // initialize the injection process
            core.Serve();


            return(wrapper);
        }
Exemple #11
0
        private void AdjustScroll()
        {
            StackWrapper current = CurrentController;

            int rows = this.Height / _font.Height;
            int max  = current.Controller.Items.Count - rows;

            if (max <= 0)
            {
                // List is too small for scrolling
                current.Scroll = 0;
                return;
            }

            if (current.Index < current.Scroll)
            {
                current.Scroll = current.Index;
            }
            else if (current.Index >= current.Scroll + rows)
            {
                current.Scroll = current.Index - rows + 1;
            }
        }
    // Update is called once per frame
    void Updatea()
    {
        Stack <int> si = new Stack <int>();

        si.Push(1);
        si.Push(2);
        Stack <string> vs = new Stack <string>();

        vs.Push("aaa");
        vs.Push("bbb");
        var a = new StackWrapper();

        a.si = si;
        a.ss = vs;
        string json = JsonUtility.ToJson(a);

        print(a);
        var w = new StackWrapper();

        JsonUtility.FromJsonOverwrite(json, w);
        print(w.si);
        print(w.ss);
    }
Exemple #13
0
        private void MoveRight()
        {
            // Decide if we can move
            StackWrapper current = CurrentController;

            if (current.Controller.Items.Count == 0)
            {
                return;
            }

            PodItem item = (PodItem)current.Controller.Items[current.Index];

            if (item.IsLeaf)
            {
                return;
            }

            PodController child = item.GetChildController();

            if (child == null)
            {
                return;
            }

            child.Refresh();

            // Create graphics port
            Graphics g = this.CreateGraphics();

            // Get image of the current view
            Bitmap   bmp1  = new Bitmap(ClientRectangle.Width, ClientRectangle.Height);
            Graphics bmp1G = Graphics.FromImage(bmp1);

            GoPaint(bmp1G, ClientRectangle);

            // Add new controller to stack
            _stack.Add(new StackWrapper(child));

            // Get image of new view
            Bitmap   bmp2  = new Bitmap(ClientRectangle.Width, ClientRectangle.Height);
            Graphics bmp2G = Graphics.FromImage(bmp2);

            GoPaint(bmp2G, ClientRectangle);

            // Animate transition between views
            Pen pen = new Pen(Color.Gray, 3);

            for (int i = 1; i < 4; i++)
            {
                int x = ClientRectangle.Width * (5 - i) / 5;

                g.DrawImage(bmp1, x - ClientRectangle.Width, 0);
                g.DrawImage(bmp2, x, 0);
                g.DrawLine(pen, x, 0, x, ClientRectangle.Height);

                Thread.Sleep(25);
            }

            pen.Dispose();

            // Clean up images
            bmp1G.Dispose();
            bmp1.Dispose();

            bmp2G.Dispose();
            bmp2.Dispose();

            g.Dispose();

            // Finally, draw new view
            Refresh();

            OnSelectedIndexChanged(EventArgs.Empty);
        }
Exemple #14
0
        private void GoPaint(Graphics g, Rectangle clipRect)
        {
            g.Clear(this.BackColor);

            Pen pen = new Pen(Color.White);

            StackWrapper current = CurrentController;

            if (current == null)
            {
                g.DrawString("No controller set", _font, pen.Brush, 5, 5);
            }
            else
            {
                int rows = this.Height / _font.Height;

                for (int i = 0; i < rows; i++)
                {
                    Pen rowPen = pen;
                    int index  = i + current.Scroll;

                    if (index >= current.Controller.Items.Count)
                    {
                        break;
                    }

                    PodItem item = (PodItem)current.Controller.Items[index];
                    int     y    = i * _font.Height;

                    // Selected item background
                    if (index == current.Index)
                    {
                        Rectangle bgRect = new Rectangle(0, y, this.Width, _font.Height);
                        g.FillRectangle(pen.Brush, bgRect);

                        rowPen = new Pen(Color.Black);
                    }

                    // Text
                    Rectangle textRect = new Rectangle(5, y, this.Width - 25, _font.Height);
                    g.DrawString(item.Name, _font, rowPen.Brush, textRect);

                    // Arrow
                    if (!item.IsLeaf)
                    {
                        Point[] points = new Point[3];

                        int xoffset = this.Width - 15;
                        int yoffset = (_font.Height / 2) - 5;

                        points[0] = new Point(xoffset, y + yoffset);
                        points[1] = new Point(xoffset, y + yoffset + 10);
                        points[2] = new Point(xoffset + 10, y + yoffset + 5);

                        g.FillPolygon(rowPen.Brush, points);
                    }

                    if (rowPen != pen)
                    {
                        rowPen.Dispose();
                    }
                }
            }

            pen.Dispose();
        }
 // Call only when testing serialization.
 public void Initialize()
 {
     MyStackWrapper = new StackWrapper(new List <object> {
         "Hello"
     });
 }
        public void PerformanceComparison()
        {
            int count       = 120000;
            int iterations  = 10000;
            int threadCount = 2;

            var cPool = new ConcurrentRingBufferImpl <Data>(count);

            cPool.Initialize(() => new Data(), true);


            var stack = new Stack <Data>(count);

            for (int x = 0; x < count; x++)
            {
                stack.Push(new Data());
            }

            var wrapper = new StackWrapper <Data>(stack);

            Action action = () =>
            {
                this.StackRunner(iterations, wrapper);
                //this.StackRunner2(iterations, wrapper2);
                //this.PoolRunner(iterations, cPool);
            };

            TimeSpan begin = TimeSpan.Zero;
            DateTime now   = DateTime.Now;

            while (true)
            {
                begin += RunPerformanceTest(action, threadCount);
                GC.Collect(2, GCCollectionMode.Forced);

                if ((DateTime.Now - now) > TimeSpan.FromSeconds(10))
                {
                    break;
                }
            }


            Console.WriteLine((DateTime.Now - now));
            int totalCount = 0;
            int totalUsage = 0;

            foreach (var item in stack)
            {
                if (item.Counter > 0)
                {
                    totalUsage += 1;
                }
                totalCount += item.Counter;
            }

            foreach (var item in cPool.Data)
            {
                if (item.Counter > 0)
                {
                    totalUsage += 1;
                }
                totalCount += item.Counter;
            }
            Console.WriteLine("Counter:" + totalCount);
            Console.WriteLine("Usage:" + totalUsage);
            Console.WriteLine("Thrown away (pool):" + cPool.ThrownAwayObjects);
            Console.WriteLine("Created (pool):" + cPool.Created);
        }
Exemple #17
0
 public ExecutionContextWrapper(Neo.VM.ExecutionContext context)
 {
     NativeContext   = context;
     EvaluationStack = new StackWrapper(context.EvaluationStack);
     AltStack        = new StackWrapper(context.AltStack);
 }