Exemplo n.º 1
0
 public override void SetContentOffset(CGPoint contentOffset, bool animated)
 {
     base.SetContentOffset(contentOffset, animated);
     currentIndex = (int)Math.Round(ContentOffset.X / Constants.DeviceWidth);
     currentItem  = stackItems [currentIndex];
     Console.WriteLine("CURRENT INDEX " + currentIndex);
 }
Exemplo n.º 2
0
        void CheckItem(IExecutionEngine engine, IStackItem item)
        {
            int c = engine.ResultStack.Count;

            engine.ResultStack.Push(item);
            Assert.AreEqual(engine.ResultStack.Count, c + 1);

            Assert.IsTrue(engine.ResultStack.TryPeek(0, out IStackItem obj));

            // PEEK

            obj.Dispose();
            obj = engine.ResultStack.Peek(0);
            Assert.IsNotNull(obj);

            Assert.AreEqual(obj.Type, item.Type);
            Assert.IsTrue(obj.Equals(item));

            // POP

            obj.Dispose();
            obj = engine.ResultStack.Pop();
            Assert.AreEqual(engine.ResultStack.Count, c);

            Assert.IsNotNull(obj);

            Assert.AreEqual(obj.Type, item.Type);
            Assert.IsTrue(obj.Equals(item));
            obj.Dispose();
        }
Exemplo n.º 3
0
        bool updateCurrentElement()
        {
            int item = (int)Math.Round(ContentOffset.X / Constants.DeviceWidth);

            if (item >= NumberOfItems || item < 0)
            {
                itemChanged = false;
                return(itemChanged);
            }
            if (item != currentIndex)
            {
                prevIndex    = currentIndex;
                currentIndex = item;
                stackItems [prevIndex].moveToOriginalFrameAnimated(false);

                currentItem = stackItems [currentIndex];
                currentItem.moveToFullScreenWindowAnimated(false);
                itemChanged = true;
            }
            else
            {
                itemChanged = false;
            }
            return(itemChanged);
        }
Exemplo n.º 4
0
        private IStackItem DeserializeStackItem(IExecutionEngine engine, BinaryReader reader)
        {
            EStackItemType type = (EStackItemType)reader.ReadByte();

            switch (type)
            {
            case EStackItemType.ByteArray:
                return(engine.CreateByteArray(reader.ReadVarBytes()));

            case EStackItemType.Bool:
                return(engine.CreateBool(reader.ReadBoolean()));

            case EStackItemType.Integer:
                return(engine.CreateInteger(new BigInteger(reader.ReadVarBytes())));

            case EStackItemType.Array:
            case EStackItemType.Struct:
            {
                IArrayStackItem array;

                if (type == EStackItemType.Struct)
                {
                    array = engine.CreateStruct();
                }
                else
                {
                    array = engine.CreateArray();
                }

                ulong count = reader.ReadVarInt();
                while (count-- > 0)
                {
                    array.Add(DeserializeStackItem(engine, reader));
                }

                return(array);
            }

            case EStackItemType.Map:
            {
                IMapStackItem map = engine.CreateMap();

                ulong count = reader.ReadVarInt();
                while (count-- > 0)
                {
                    IStackItem key   = DeserializeStackItem(engine, reader);
                    IStackItem value = DeserializeStackItem(engine, reader);

                    map[key] = value;

                    key.Dispose();
                    value.Dispose();
                }

                return(map);
            }

            default: throw new FormatException();
            }
        }
Exemplo n.º 5
0
        public void WriteHtmlFile(IStackItem item)
        {
            //transform to html
            XslCompiledTransform transformer = new XslCompiledTransform();

            using (StringReader stringReader = new StringReader(_xsltString))
            {
                XmlReaderSettings settings = new XmlReaderSettings();
                settings.DtdProcessing = DtdProcessing.Parse;
                using (XmlReader xmlReader = XmlReader.Create(stringReader, settings))
                {
                    transformer.Load(xmlReader);
                }
                settings = null;
            }

            string htmlString;

            using (StringReader stringReader = new StringReader(item.FileContent))
            {
                using (XmlReader xmlReader = XmlReader.Create(stringReader))
                {
                    using (StringWriter writer = new StringWriter())
                    {
                        transformer.Transform(xmlReader, null, writer);
                        htmlString = writer.ToString();
                    }
                }
            }

            //write to file
            string pathToHtmlFile = Path.Combine(_htmlDirectoryInfo.FullName, item.FileNameNoExtension + ".html");

            File.AppendAllText(pathToHtmlFile, htmlString);
        }
Exemplo n.º 6
0
        public override void Set(IStackItem key, IStackItem value) =>

        NeoVM.MapStackItem_Set
        (
            _handle,
            key == null ? IntPtr.Zero : ((INativeStackItem)key).Handle,
            value == null ? IntPtr.Zero : ((INativeStackItem)value).Handle
        );
 /// <summary>
 /// Add a stackItem to the stack.
 /// </summary>
 /// <param name="stackObject"></param>
 public void Add(IStackItem stackItem)
 {
     if (!finishingExecution)
     {
         LIFOStack.Push(stackItem);
         stackItemCollection.Add(stackItem);
         manualResetEvent.Set();
     }
 }
Exemplo n.º 8
0
        public override IEnumerator <KeyValuePair <IStackItem, IStackItem> > GetEnumerator()
        {
            for (int x = 0, c = Count; x < c; x++)
            {
                IStackItem key   = Engine.ConvertFromNative(NeoVM.MapStackItem_GetKey(_handle, x));
                IStackItem value = Engine.ConvertFromNative(NeoVM.MapStackItem_GetValue(_handle, x));

                yield return(new KeyValuePair <IStackItem, IStackItem>(key, value));
            }
        }
 private void ProcessIStackItem(IStackItem item, bool silenceEvents = false)
 {
     if (!item.IsProcessed)
     {
         item.Process();
         item.IsProcessed = true;
         if (!silenceEvents)
         {
             ItemProcessed?.BeginInvoke(this, item, null, null);
         }
     }
 }
Exemplo n.º 10
0
        public override bool TryGetValue(IStackItem key, out IStackItem value)
        {
            var ret = NeoVM.MapStackItem_Get(_handle, key == null ? IntPtr.Zero : ((INativeStackItem)key).Handle);

            if (ret == IntPtr.Zero)
            {
                value = null;
                return(false);
            }

            value = Engine.ConvertFromNative(ret);
            return(true);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Try to obtain the element at `index` position, without consume them
        /// -1=Last , -2=Last-1 , -3=Last-2
        /// </summary>
        /// <param name="index">Index</param>
        /// <param name="obj">Object</param>
        /// <returns>Return tru eif object exists</returns>
        public override bool TryPeek(int index, out IStackItem obj)
        {
            var ptr = NeoVM.StackItems_Peek(_handle, index);

            if (ptr == IntPtr.Zero)
            {
                obj = null;
                return(false);
            }

            obj = Engine.ConvertFromNative(ptr);
            return(true);
        }
Exemplo n.º 12
0
        public void Process()
        {
            XmlFileReader xfr           = new XmlFileReader(_producerConsumer.GetConfigurationReader().GetXmlFilesDirectory(), _producerConsumer.GetConfigurationReader().GetXmlFilesProcessedDirectory(), _producerConsumer.FileSystemHelper);;
            int           numberOfFiles = _producerConsumer.GetConfigurationReader().GetXmlFilesDirectory().GetFiles().Length;

            while (xfr.GetNextStackItem() != null)
            {
                IStackItem si = xfr.GetNextStackItem();
                _producerConsumer.Queue.Enqueue(si);
                //_producerConsumer.lollypop.Set();
                _producerConsumer.IsDoneReading = false;
            }
            _producerConsumer.IsDoneReading = true;
        }
Exemplo n.º 13
0
        public XmlFileReaderTest()
        {
            _reader = new ConfigurationReader();
            IFileSystemHelper fsh = (IFileSystemHelper)(new Mock <FileSystemHelper>().Object);

            _xfr           = new XmlFileReader(_reader.GetXmlFilesDirectory(), _reader.GetXmlFilesProcessedDirectory(), fsh);
            _numberOfFiles = _reader.GetXmlFilesDirectory().GetFiles().Length;
            _stackItems    = new List <IStackItem>();
            while (_xfr.GetNextStackItem() != null)
            {
                IStackItem si = _xfr.GetNextStackItem();
                _stackItems.Add(si);
            }
        }
Exemplo n.º 14
0
 public void Process()
 {
     Thread.Sleep(100);
     do
     {
         //_producerConsumer.lollypop.WaitOne();
         HtmlFileWriter hfw  = new HtmlFileWriter(_producerConsumer.GetConfigurationReader().GetHtmlFilesDirectory(), _producerConsumer.GetConfigurationReader().GetResourcesDirectory(), _producerConsumer.FileSystemHelper);
         IStackItem     item = null;
         while (_producerConsumer.Queue.TryDequeue(out item))
         {
             hfw.WriteHtmlFile(item);
             // do stuff
         }
         _producerConsumer.IsDoneWriting = true;
     } while (!_producerConsumer.IsDoneReading || !_producerConsumer.Queue.IsEmpty);
 }
Exemplo n.º 15
0
        private bool Runtime_Deserialize(IExecutionEngine engine)
        {
            using (var context = engine.CurrentContext)
            {
                if (context == null)
                {
                    return(false);
                }

                if (!context.EvaluationStack.TryPop(out IStackItem it))
                {
                    return(false);
                }

                var data = it.ToByteArray();
                it.Dispose();

                using (MemoryStream ms = new MemoryStream(data, false))
                    using (BinaryReader reader = new BinaryReader(ms))
                    {
                        IStackItem item = null;

                        try
                        {
                            item = DeserializeStackItem(engine, reader);
                        }
                        catch
                        {
                            if (item != null)
                            {
                                item.Dispose();
                            }
                            return(false);
                        }

                        context.EvaluationStack.Push(item);
                        if (item != null)
                        {
                            item.Dispose();
                        }
                    }
            }

            return(true);
        }
Exemplo n.º 16
0
 private void CheckValue(IStackItem it, object ret)
 {
     if (ret is BigInteger bi)
     {
         Assert.IsTrue(it is IntegerStackItem);
         Assert.AreEqual(bi, ((IntegerStackItem)it).Value);
     }
     else if (ret is byte[] bf)
     {
         Assert.IsTrue(it is ByteArrayStackItem);
         CollectionAssert.AreEqual(bf, ((ByteArrayStackItem)it).Value);
     }
     else if (ret is bool bl)
     {
         Assert.IsTrue(it is BooleanStackItem);
         Assert.AreEqual(bl, ((BooleanStackItem)it).Value);
     }
 }
Exemplo n.º 17
0
        /// <summary>
        /// Try Pop object casting to this type
        /// </summary>
        /// <typeparam name="TStackItem">Object type</typeparam>
        /// <param name="item">Item</param>
        /// <returns>Return false if it is something wrong</returns>
        public override bool TryPop <TStackItem>(out TStackItem item)
        {
            IntPtr ptr = NeoVM.StackItems_Pop(_handle);

            if (ptr == IntPtr.Zero)
            {
                item = default(TStackItem);
                return(false);
            }

            IStackItem ret = Engine.ConvertFromNative(ptr);

            if (ret is TStackItem ts)
            {
                item = (TStackItem)ret;
                return(true);
            }

            item = default(TStackItem);
            return(false);
        }
Exemplo n.º 18
0
 public override int IndexOf(IStackItem item) => NeoVM.ArrayStackItem_IndexOf(Handle, ((INativeStackItem)item).Handle);
Exemplo n.º 19
0
 public override bool Remove(IStackItem key)
 {
     return(NeoVM.MapStackItem_Remove(_handle, key == null ? IntPtr.Zero : ((INativeStackItem)key).Handle) == NeoVM.TRUE);
 }
Exemplo n.º 20
0
 public override bool TryPeek(int index, out IStackItem obj)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 21
0
        private void SerializeStackItem(IStackItem item, BinaryWriter writer)
        {
            switch (item)
            {
            case ByteArrayStackItem _:
            {
                writer.Write((byte)EStackItemType.ByteArray);
                writer.WriteVarBytes(item.ToByteArray());
                break;
            }

            case BooleanStackItem bl:
            {
                writer.Write((byte)EStackItemType.Bool);
                writer.Write(bl.Value);
                break;
            }

            case IntegerStackItem _:
            {
                writer.Write((byte)EStackItemType.Integer);
                writer.WriteVarBytes(item.ToByteArray());
                break;
            }

            case InteropStackItem _: throw new NotSupportedException();

            case ArrayStackItem array:
            {
                if (array.IsStruct)
                {
                    writer.Write((byte)EStackItemType.Struct);
                }
                else
                {
                    writer.Write((byte)EStackItemType.Array);
                }

                writer.WriteVarInt(array.Count);

                foreach (IStackItem subitem in array)
                {
                    SerializeStackItem(subitem, writer);
                }

                break;
            }

            case MapStackItem map:
            {
                writer.Write((byte)EStackItemType.Map);
                writer.WriteVarInt(map.Count);

                foreach (var pair in map)
                {
                    SerializeStackItem(pair.Key, writer);
                    SerializeStackItem(pair.Value, writer);
                }

                break;
            }
            }
        }
Exemplo n.º 22
0
        public void TestFileWriter()
        {
            IStackItem itm = _xfr.GetNextStackItem();

            _hfw.WriteHtmlFile(itm);
        }
Exemplo n.º 23
0
 /// <summary>
 /// Raise OnAltStackChange
 /// </summary>
 /// <param name="stack">Stack</param>
 /// <param name="item">Item</param>
 /// <param name="index">Index</param>
 /// <param name="operation">Operation</param>
 public virtual void RaiseOnAltStackChange(IStackItemsStack stack, IStackItem item, int index, ELogStackOperation operation)
 {
     OnAltStackChange?.Invoke(stack, item, index, operation);
 }
Exemplo n.º 24
0
 public override void Set(int index, IStackItem item) => NeoVM.ArrayStackItem_Set(Handle, ((INativeStackItem)item).Handle, index);
Exemplo n.º 25
0
 public override void Insert(int index, IStackItem item)
 {
     NeoVM.ArrayStackItem_Insert(Handle, ((INativeStackItem)item).Handle, index);
 }
Exemplo n.º 26
0
 public override bool ContainsKey(IStackItem key)
 {
     return(NeoVM.MapStackItem_Get(_handle, key == null ? IntPtr.Zero : ((INativeStackItem)key).Handle) != IntPtr.Zero);
 }
Exemplo n.º 27
0
 public override void Push(IStackItem item)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 28
0
        public void TestArrayStackItem()
        {
            using (var engine = CreateEngine(null))
            {
                for (int x = 0; x < 2; x++)
                {
                    bool isStruct = x == 1;

                    // First test for array, second for Struct

                    using (var ar = isStruct ? engine.CreateStruct() : engine.CreateArray())
                    {
                        Assert.AreEqual(isStruct, ar.IsStruct);

                        // Create two random integer types

                        foreach (var bi in TestBigIntegers)
                        {
                            using (var btest = engine.CreateInteger(bi))
                            {
                                // Check contains

                                Assert.IsFalse(ar.Contains(btest));

                                // Check empty

                                Assert.AreEqual(0, ar.Count);

                                // Add and check count

                                ar.Add(btest);

                                Assert.AreEqual(1, ar.Count);

                                // Check item by position

                                using (var iau = (IntegerStackItem)ar[0])
                                    Assert.AreEqual(iau.Value, btest.Value);

                                // Remove

                                Assert.IsTrue(ar.Remove(btest));
                            }
                        }

                        // Clear

                        ar.Clear();
                        Assert.AreEqual(0, ar.Count);

                        // Add bool and check contains

                        using (var bkill = engine.CreateBool(true))
                        {
                            Assert.AreEqual(ar.IndexOf(bkill), -1);

                            ar.Add(bkill);

                            Assert.AreEqual(ar.IndexOf(ar), -1);

                            Assert.IsTrue(ar.Contains(bkill));
                        }

                        // Create new array

                        IArrayStackItem ar2;

                        {
                            var art = new IStackItem[] { engine.CreateBool(true), engine.CreateBool(false) };
                            ar2 = engine.CreateArray(art);
                            foreach (var it in art)
                            {
                                it.Dispose();
                            }
                        }

                        Assert.IsFalse(ar.Contains(ar2));

                        // Replace bool with array

                        ar[0] = ar2;

                        // Check IndexOf

                        Assert.AreEqual(ar.IndexOf(ar2), 0);

                        // Check count

                        Assert.AreEqual(1, ar.Count);

                        // Remove first element

                        ar.RemoveAt(0);

                        // Check count

                        Assert.AreEqual(0, ar.Count);

                        // Add 1,2,3

                        {
                            var art = new IStackItem[]
                            {
                                engine.CreateInteger(1),
                                engine.CreateInteger(2),
                                engine.CreateInteger(3)
                            };

                            ar.Add(art);

                            foreach (var it in art)
                            {
                                it.Dispose();
                            }
                        }

                        // Remove 2

                        ar.RemoveAt(1);

                        // Check count

                        Assert.AreEqual(2, ar.Count);

                        // Check values 1 and 3

                        using (var iau = (IntegerStackItem)ar[0])
                            Assert.AreEqual(iau.Value, 1);

                        using (var iau = (IntegerStackItem)ar[1])
                            Assert.AreEqual(iau.Value, 3);

                        // Insert bool

                        using (var inte = engine.CreateBool(true))
                            ar.Insert(1, inte);

                        // Check values

                        using (var iau = (IntegerStackItem)ar[0])
                            Assert.AreEqual(iau.Value, 1);
                        using (var iau = (BooleanStackItem)ar[1])
                            Assert.IsTrue(iau.Value);
                        using (var iau = (IntegerStackItem)ar[2])
                            Assert.AreEqual(iau.Value, 3);
                    }
                }
            }
        }
Exemplo n.º 29
0
 public override void Add(IStackItem item) => NeoVM.ArrayStackItem_Add(Handle, ((INativeStackItem)item).Handle);
Exemplo n.º 30
0
 /// <summary>
 /// Push objet to the stack
 /// </summary>
 /// <param name="item">Object</param>
 public override void Push(IStackItem item)
 {
     NeoVM.StackItems_Push(_handle, ((INativeStackItem)item).Handle);
 }