public void Test_DecrementOperation()
        {
            const string key = "Test_DecrementOperation";

            //delete key if exists
            var delete = new Delete(key, GetVBucket(), Transcoder, OperationLifespanTimeout);
            var result = IOService.Execute(delete);
            Console.WriteLine("Deleting key {0}: {1}", key, result.Success);

            //increment the key
            var operation = new Increment(key, 1, 1, 0, GetVBucket(), Transcoder, OperationLifespanTimeout);
            var result1 = IOService.Execute(operation);
            Assert.IsTrue(result1.Success);
            Assert.AreEqual(result1.Value, 1);

            //key should be 1
            var get = new Get<string>(key, GetVBucket(), Transcoder, OperationLifespanTimeout);
            var result3 = IOService.Execute(get);
            Assert.AreEqual(result1.Value.ToString(CultureInfo.InvariantCulture), result3.Value);

            //decrement the key
            var decrement = new Decrement(key, 1, 1, 0, GetVBucket(), Transcoder, OperationLifespanTimeout);
            var result2 = IOService.Execute(decrement);
            Assert.IsTrue(result2.Success);
            Assert.AreEqual(result2.Value, 0);

            //key should be 0
            get = new Get<string>(key, GetVBucket(), Transcoder, OperationLifespanTimeout);
            result3 = IOService.Execute(get);
            Assert.AreEqual(0.ToString(CultureInfo.InvariantCulture), result3.Value);
        }
 //     throws jjtraveler.VisitFailure
 public virtual void testBacktrack()
 {
     Increment i = new Increment();
     Object initialState = i.getState();
     (new Backtrack(i)).visit(n0);
     Assertion.AssertNotNull(i.localState);
     Assertion.AssertTrue(! initialState.Equals(i.localState));
     Assertion.AssertEquals(initialState,i.getState());
 }
Exemple #3
0
        private static void HandleArguments(Arguments CommandLine, ref string sProjectPath, ref string sWxsFile, ref Version vGivenVersion, ref Increment incVersion)
        {
            if (CommandLine["h"] != null || CommandLine["help"] != null || CommandLine["?"] != null)
            {
                Console.WriteLine("Usage: ");
                Console.WriteLine("\t --project-path=<path>\t Specifiy the path to the project you want to process");
                Console.WriteLine("\t --wix-file=<file.wxs>\t (Optional)Specifiy the path with the wxs file you want to update");
                Console.WriteLine("\t --inc=[major|minor|release|build]\t Specifiy which part of the version string you want to increment");
                Console.WriteLine("\t --version=<0.0.0.0>\t specifiy a version to set (--inc is ignored if set)");
                Console.WriteLine("\t --help \t Display help");
                Environment.Exit(0);
            }

            if (CommandLine["project-path"] != null)
            {
                sProjectPath = CommandLine["project-path"];
                if (!Directory.Exists(sProjectPath))
                {
                    Console.Error.WriteLine("The given project path \"{0}\" does not exist!", sProjectPath);
                    Environment.Exit(-1);
                }
            }

            if (CommandLine["wix-file"] != null)
            {
                sWxsFile = CommandLine["wix-file"];
                if (!File.Exists(sWxsFile))
                {
                    Console.Error.WriteLine("The given installation file \"{0}\" does not exist!", sWxsFile);
                    Environment.Exit(-1);
                }
            }

            if (CommandLine["inc"] != null)
            {
                try { incVersion = GetInc(CommandLine["inc"]); }
                catch (ArgumentException)
                {
                    Console.Error.WriteLine("The given argument is invalid! Use \"major\", \"minor\", \"release\" or \"build\" as increment values.");
                    Environment.Exit(-1);
                }
            }
            else
                incVersion = Increment.Build;

            if (CommandLine["version"] != null)
                try { vGivenVersion = Version.Parse(CommandLine["version"]); }
                catch(FormatException)
                {
                    vGivenVersion = null;
                    Console.Error.WriteLine("There was an error parsing the given version. Use the foloowing format: \"1.0.0.1\".");
                    Environment.Exit(-1);
                }
        }
 public void Test_Clone()
 {
     var operation = new Increment("key", 1, 1, 0, GetVBucket(), Transcoder, OperationLifespanTimeout)
     {
         Cas = 1123
     };
     var cloned = operation.Clone();
     Assert.AreEqual(operation.CreationTime, cloned.CreationTime);
     Assert.AreEqual(operation.Cas, cloned.Cas);
     Assert.AreEqual(operation.VBucket.Index, cloned.VBucket.Index);
     Assert.AreEqual(operation.Key, cloned.Key);
     Assert.AreEqual(operation.Opaque, cloned.Opaque);
 }
Exemple #5
0
        private void run()
        {
            Increment inc = new Increment(this.incrementer);
            for (int i = 0; i < 100; i++)
            {
                lock (loadPB)
                {
                    loadPB.Invoke(inc, i);
                }
//#if !DEBUG
                Thread.Sleep(30);
//#endif
            }
            this.Invoke(new Notify(this.closer), null);
        }
        public void DeleteAKeyThatIsNotDeletableTest()
        {
            string keyName = "deleteANotDeletablekeytest";
            var    input   = new Increment()
            {
                Key = keyName, InitialStart = 1, IsDeletable = false
            };
            IncrementController controller = CreateControllerInstance();

            controller.Post(input);

            List <string> keys = GetStringListFromHttpResponse(controller.Get());

            CollectionAssert.Contains(keys, keyName);       // verify the key was created

            controller.Delete(keyName);

            keys = GetStringListFromHttpResponse(controller.Get());
            CollectionAssert.Contains(keys, keyName); // verify keyName was not removed
        }
        public override bool Equals(object obj)
        {
            if (this == obj)
            {
                return(true);
            }

            IForStatement statement = obj as IForStatement;

            if (statement == null)
            {
                return(false);
            }

            return
                (Initializer.Equals(statement.Initializer) &&
                 Increment.Equals(statement.Increment) &&
                 Body.Equals(statement.Body) &&
                 Condition.Equals(statement.Condition));
        }
Exemple #8
0
        public override Expression Simplify()
        {
            if (Initializer != null)
            {
                Initializer = (BlockExpression)Initializer.Simplify();
            }

            if (Condition != null)
            {
                Condition = Condition.Simplify();
            }

            if (Increment != null)
            {
                Increment = (BlockExpression)Increment.Simplify();
            }

            Block = (BlockExpression)Block.Simplify();

            return(this);
        }
Exemple #9
0
        static void Main(string[] args)
        {
            string[] commands = File.ReadAllLines(@"C:\Github\AdventOfCode\Day3\cables.txt");

            List <Wire> wires = new List <Wire>();

            foreach (string cmd in commands)
            {
                Wire  wire     = new Wire();
                Line  zero     = new Line(0, wire);
                Point previous = new Point(0, 0, zero);
                wire.AddCoordinate(previous);
                wire.AddLine(zero);

                Increment linecrement = new Increment(0);

                foreach (string action in cmd.Split(","))
                {
                    Line line = new Line(linecrement.Get(), wire);

                    string direction = action[0..1];
Exemple #10
0
        public override void SetParent(Expression parent)
        {
            base.SetParent(parent);

            if (Initializer != null)
            {
                Initializer.SetParent(this);
            }

            if (Condition != null)
            {
                Condition.SetParent(this);
            }

            if (Increment != null)
            {
                Increment.SetParent(this);
            }

            Block.SetParent(this);
        }
        public async Task <ICounterResult> IncrementAsync(string id, IncrementOptions?options = null)
        {
            //sanity check for deferred bootstrapping errors
            _bucket.ThrowIfBootStrapFailed();

            options ??= new IncrementOptions();
            using var rootSpan = RootSpan(OperationNames.Increment);
            using var op       = new Increment(_bucket.Name, id)
                  {
                      Cid             = Cid,
                      CName           = Name,
                      Delta           = options.DeltaValue,
                      Initial         = options.InitialValue,
                      DurabilityLevel = options.DurabilityLevel,
                      Transcoder      = _transcoder,
                      Span            = rootSpan
                  };

            await RetryUntilTimeoutOrSuccessAsync(options.TokenValue, options.TimeoutValue, op).ConfigureAwait(false);

            return(new CounterResult(op.GetValue(), op.Cas, null, op.MutationToken));
        }
        public void Test_IncrementOperation()
        {
            const string key = "Test_IncrementOperation";

            var delete = new Delete(key, GetVBucket(), Converter, Serializer);
            var result = IOStrategy.Execute(delete);
            Console.WriteLine("Deleting key {0}: {1}", key, result.Success);

            var increment = new Increment(key, 0, 1, 0, GetVBucket(), Converter, Serializer);
            var result1 = IOStrategy.Execute(increment);
            Assert.IsTrue(result1.Success);
            Assert.AreEqual(result1.Value, uint.MinValue);

            var result2 = IOStrategy.Execute(increment);
            Assert.IsTrue(result2.Success);
            Assert.AreEqual(1, result2.Value);

            var getOperation = new Get<string>(key, GetVBucket(), Converter, Serializer);
            var result3 = IOStrategy.Execute(getOperation);
            var value = result3.Value;
            Assert.AreEqual(result2.Value.ToString(CultureInfo.InvariantCulture), result3.Value);
        }
 public CounterViewModel()
 {
     title.Value  = "last value: ---";
     Title        = title.ToReadOnlyReactiveProperty();
     CounterValue = counter
                    .ObserveProperty(x => x.Value)
                    .Select(x => x.ToString())
                    .ToReadOnlyReactiveProperty();
     Increment.Subscribe(_ => counter.Increment());
     Decrement.Subscribe(_ => counter.Decrement());
     Reset.Subscribe(async _ =>
     {
         // Async Sample
         var count = await Task.Run(() =>
         {
             Task.Delay(1500).Wait();
             return(CounterValue.Value);
         });
         title.Value = $"last value: {count}";
         counter.Reset();
     });
 }
        public void UseCase_retrieve_with_versions()
        {
            const string PATH = "usecase_test";

            if (Directory.Exists(PATH))
            {
                Directory.Delete(PATH, true);
            }
            var sut = new FilesInFolderEventstore(PATH);

            var resultA = sut.Record(new Version("a"), new Increment {
                Id = "a"
            });
            var resultB = sut.Record(new Version("b"), new Increment {
                Id = "b"
            });

            resultA = sut.Record(resultA.version, new Increment {
                Id = "a"
            });
            resultB = sut.Record(resultB.version, new Decrement {
                Id = "b"
            });
            sut.Record(resultA.version, new Increment {
                Id = "a"
            });

            var result = sut.ReplayWithVersion(MapToVersionId);

            Assert.Equal("3", result.versions[0].Number);
            Assert.Equal("2", result.versions[1].Number);

            string MapToVersionId(Event e) => e switch
            {
                Increment i => i.Id,
                Decrement d => d.Id
            };
        }
        public override IOperation Clone()
        {
            var cloned = new Increment
            {
                Key                     = Key,
                Content                 = Content,
                Transcoder              = Transcoder,
                VBucketId               = VBucketId,
                Opaque                  = Opaque,
                Delta                   = Delta,
                Initial                 = Initial,
                Attempts                = Attempts,
                Cas                     = Cas,
                CreationTime            = CreationTime,
                MutationToken           = MutationToken,
                LastConfigRevisionTried = LastConfigRevisionTried,
                BucketName              = BucketName,
                ErrorCode               = ErrorCode,
                Expires                 = Expires
            };

            return(cloned);
        }
Exemple #16
0
        public void Test_IncrementOperation()
        {
            const string key = "Test_IncrementOperation";

            var delete = new Delete(key, GetVBucket(), Transcoder, OperationLifespanTimeout);
            var result = IOStrategy.Execute(delete);
            Console.WriteLine("Deleting key {0}: {1}", key, result.Success);

            var increment = new Increment(key, 0, 1, 0, GetVBucket(), Transcoder, OperationLifespanTimeout);
            var result1 = IOStrategy.Execute(increment);
            Assert.IsTrue(result1.Success);
            Assert.AreEqual(result1.Value, uint.MinValue);

            increment.Reset();
            var result2 = IOStrategy.Execute(increment);
            Assert.IsTrue(result2.Success);
            Assert.AreEqual(1, result2.Value);

            var getOperation = new Get<string>(key, GetVBucket(), Transcoder, OperationLifespanTimeout);
            var result3 = IOStrategy.Execute(getOperation);
            var value = result3.Value;
            Assert.AreEqual(result2.Value.ToString(CultureInfo.InvariantCulture), result3.Value);
        }
        public void PostNewKeyTest()
        {
            // Arrange
            string keyName = "addkeytest";
            var    input   = new Increment()
            {
                Key = keyName, InitialStart = 0, IsDeletable = true
            };
            IncrementController controller = CreateControllerInstance();

            // delete the key if it exists and recreate...
            controller.Delete(keyName);
            controller.Post(input);

            long result = GetLongfromHttpResponse(controller.Get(keyName));

            Assert.AreEqual(input.InitialStart + 1, result);    // we just did a GET, so the returned value should be InitialStart + 1

            controller.Delete(keyName);
            List <string> keyList = GetStringListFromHttpResponse(controller.Get());

            CollectionAssert.DoesNotContain(keyList, keyName);  // verify keyName was removed
        }
Exemple #18
0
        public int CompareTo(ObjectId other)
        {
            var r = Timestamp.CompareTo(other.Timestamp);

            if (r != 0)
            {
                return(r);
            }

            r = Machine.CompareTo(other.Machine);
            if (r != 0)
            {
                return(r);
            }

            r = Pid.CompareTo(other.Pid);
            if (r != 0)
            {
                return(r < 0 ? -1 : 1);
            }

            return(Increment.CompareTo(other.Increment));
        }
        private void DLC_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if (e.PropertyName != "DLC")
            {
                return;
            }

            if (Payload.Count >= (int)DLC)
            {
                while (Payload.Count > (int)DLC)
                {
                    Application.Current.Dispatcher.Invoke((Action)(() => { Payload.RemoveAt(0); }));
                }
            }
            else
            {
                while (Payload.Count < (int)DLC)
                {
                    Application.Current.Dispatcher.Invoke((Action)(() => { Payload.Insert(0, 0); }));
                }
            }

            if (Increment.Count >= (int)DLC)
            {
                while (Increment.Count > (int)DLC)
                {
                    Application.Current.Dispatcher.Invoke((Action)(() => { Increment.RemoveAt(0); }));
                }
            }
            else
            {
                while (Increment.Count < (int)DLC)
                {
                    Application.Current.Dispatcher.Invoke((Action)(() => { Increment.Insert(0, 0); }));
                }
            }
        }
Exemple #20
0
        public async Task <ICounterResult> IncrementAsync(string id, IncrementOptions?options = null)
        {
            //sanity check for deferred bootstrapping errors
            _bucket.ThrowIfBootStrapFailed();

            options ??= IncrementOptions.Default;
            using var rootSpan = RootSpan(OperationNames.Increment);
            using var op       = new Increment(_bucket.Name, id)
                  {
                      Cid             = Cid,
                      CName           = Name,
                      Delta           = options.DeltaValue,
                      Initial         = options.InitialValue,
                      DurabilityLevel = options.DurabilityLevel,
                      Span            = rootSpan,
                      Expires         = options.ExpiryValue.ToTtl()
                  };
            _operationConfigurator.Configure(op, options);

            using var cts = CreateRetryTimeoutCancellationTokenSource(options, op);
            await _bucket.RetryAsync(op, cts.Token).ConfigureAwait(false);

            return(new CounterResult(op.GetValue(), op.Cas, null, op.MutationToken));
        }
Exemple #21
0
 void Given(Increment e) =>
 _value++;
Exemple #22
0
        public string GetPropertiesAsXml()
        {
            StringBuilder sbResult = new StringBuilder();

            sbResult.Append("<" + (String.IsNullOrEmpty(ColumnName) ? "_" : ColumnName) + GetRegexProperties());
            if (!String.IsNullOrEmpty((PrecedingRegEx ?? "").TrimEnd('"')))
            {
                sbResult.Append(" Prefix = '" + PrecedingRegEx + "'");
            }
            if (!String.IsNullOrEmpty((TrailingRegEx ?? "").TrimEnd('"')))
            {
                sbResult.Append(" Suffix = '" + TrailingRegEx + "'");
            }
            if (ColumnType != RegexColumnType.STRING)
            {
                sbResult.Append(" Type = '" + ColumnType.ToString() + "'");
            }
            if (!String.IsNullOrEmpty(ValueMatchingCondition))
            {
                sbResult.Append(" Condition = '" + ValueMatchingCondition + "'");
            }
            if (AutoIncrement)
            {
                sbResult.Append(" AutoIncrement = '" + AutoIncrement.ToString() + "'");
            }
            if (AutoIncrement)
            {
                sbResult.Append(" StartValue = '" + StartValue.ToString() + "'");
            }
            if (AutoIncrement)
            {
                sbResult.Append(" Increment = '" + Increment.ToString() + "'");
            }
            if (!String.IsNullOrEmpty(Expression))
            {
                sbResult.Append(" Expression = '" + Expression + "'");
            }
            if (IsForeignKey)
            {
                sbResult.Append(" ForeignKey = '" + IsForeignKey.ToString() + "'");
            }
            if (IsUnique)
            {
                sbResult.Append(" PrimaryKey = '" + IsUnique.ToString() + "'");
            }

            if (!String.IsNullOrEmpty(DisplayName))
            {
                sbResult.Append(" DisplayName = '" + DisplayName + "'");
            }
            if (!String.IsNullOrEmpty(Description))
            {
                sbResult.Append(" Description = '" + Description + "'");
            }
            if (!String.IsNullOrEmpty(Default))
            {
                sbResult.Append(" Default = '" + Default + "'");
            }
            sbResult.Append(" />");
            return(sbResult.ToString());
        }
Exemple #23
0
        private static Version WriteVersion(string sProjectPath, Version version, Increment incVersion)
        {
            string sAssemblyInfo = string.Format(CultureInfo.InvariantCulture, "{0}\\Properties\\AssemblyInfo.cs", sProjectPath);
            if (File.Exists(sAssemblyInfo))
            {
                Regex reg = new Regex(@"(\[assembly: Assembly.*Version\()""(.*)""(\)])");
                string sText = string.Empty;
                using (TextReader reader = new StreamReader(sAssemblyInfo))
                {
                    sText = reader.ReadToEnd();
                    reader.Close();
                }

                if (null == version || version.Build == -1)
                {
                    try
                    {
                        version = Version.Parse(reg.Match(sText).Groups[2].Value);
                    }
                    catch (FormatException)
                    {
                        Console.Error.WriteLine("Error when I tried to parse the version.");
                        Environment.Exit(-1);
                    }

                    int iMajor = version.Major;
                    int iMinor = version.Minor;
                    int iRelease = version.Build;
                    int iBuild = version.Revision;

                    switch (incVersion)
                    {
                        case Increment.Major:
                            iMajor++;
                            goto default;
                        case Increment.Minor:
                            iMinor++;
                            goto default;
                        case Increment.Release:
                            iRelease++;
                            goto default;
                        case Increment.Build:
                            iBuild++;
                            goto default;
                        default:
                            version = new Version(iMajor, iMinor, iRelease, iBuild);
                            break;
                    }
                }

                string sTemp = reg.Replace(sText, string.Format(CultureInfo.InvariantCulture, "$1\"{0}\"$3", version.ToString()));

                //make a backup
                string sBackup = string.Format(CultureInfo.InvariantCulture, "{0}\\{1}", Path.GetTempPath(), Path.GetFileName(sAssemblyInfo));
                File.Copy(sAssemblyInfo, sBackup, true);
                Console.WriteLine("Made a backup @\"{0}\"", sBackup);

                using (TextWriter writer = new StreamWriter(sAssemblyInfo, false, Encoding.UTF8))
                {
                    writer.Write(sTemp);
                    writer.Close();
                }
            }
            else
            {
                Console.Error.WriteLine("AssemblyInfo.cs not found!");
                Environment.Exit(-1);
            }
            return version;
        }
 /// <summary>
 /// Creates a statementLine using the given member data.
 /// </summary>
 /// <returns>Returns the generated CodeStatement.</returns>
 public CodeStatement CreateStatement()
 {
     return(new CodeIterationStatement(Init.CreateStatement(), Expressions[0].CreateExpression(),
                                       Increment.CreateStatement(), StatementLines.Select(s => s.CreateStatement()).ToArray()));
 }
Exemple #25
0
 public static R Increase <T, R>(T value)
 => Increment <T, R> .Invoke(value);
Exemple #26
0
        public void StartCounter(float term, bool refresh, string id, Increment inc, bool loop = false)
        {
            CheckCounterAvailabillity(id);

            if (Start != null)
                Start(this, new CounterEventArgs(term, id, refresh, inc, loop));
        }
 protected override bool Visit(Increment inc) => false;
 private void MenuItem_Click(object sender, RoutedEventArgs e)
 {
     PART_IncrementTextBox.Text = Increment.ToString();
     PART_Popup.IsOpen          = true;
 }
 protected override Type Visit(Increment inc)
 {
     return(_types.TypeOf(inc.Name) ?? Type.Unassigned);
 }
 public virtual void VisitIncrement(Increment n)
 {
 }
Exemple #31
0
        public void StartCounter(float term, Increment increment, bool loop = false)
        {
            CheckCounterAvailabillity("counter_0");

            if (Start != null)
                Start(null, new CounterEventArgs(term, "counter_0", true, increment, loop));
        }
Exemple #32
0
 void When(Increment e) =>
 Then(new Incremented(_value));
Exemple #33
0
        /// <summary>
        /// Increments the value of a key by the delta. If the key doesn't exist, it will be created
        /// and seeded with the defaut initial value 1.
        /// </summary>
        /// <param name="key">The key to us for the counter.</param>
        /// <param name="delta">The number to increment the key by.</param>
        /// <param name="initial">The initial value to use. If the key doesn't exist, this value will returned.</param>
        /// <param name="expiration">The time-to-live (ttl) for the counter in seconds.</param>
        /// <returns>If the key doesn't exist, the server will respond with the initial value. If not the incremented value will be returned.</returns>
        public IOperationResult <long> Increment(string key, ulong delta, ulong initial, uint expiration)
        {
            var operation = new Increment(key, initial, delta, expiration, null, _converter, _transcoder);

            return(SendWithRetry(operation));
        }
    private void Init()
    {
        _glSerialisable = new GameLogicSerialisable();

        Counter = 0;

        _default   = new Default( );
        _increment = new Increment( );
        _decrement = new Decrement( );
    }
Exemple #35
0
 public override void VisitIncrement(Increment n)
 {
     ApplyIncrementDecrement(n.Expression, OpCodes.Add);
 }
Exemple #36
0
        public CounterEventArgs(float term, string id, bool refresh, Increment inc, bool loop = false)
        {
            ID = id;
            Refresh = refresh;
            Loop = false;

            switch (inc)
            {
                case Increment.HOURS:
                    Term = (int)(term * CounterManager.C_hour);
                    break;
                case Increment.MINUTES:
                    Term = (int)(term * CounterManager.C_minute);
                    break;
                case Increment.SECONDS:
                    Term = (int)(term * CounterManager.C_seconds);
                    break;
                case Increment.MILLISECONDS:
                    Term = (int)(term);
                    break;
                default:
                    Term = -1;
                    break;
            }
        }
Exemple #37
0
        public string Get(string propertyName)
        {
            switch (propertyName)
            {
            //ELEMENT
            case nameof(ClassId):
                return(ClassId.ToString());

            case nameof(AutomationId):
                return(AutomationId.ToString());

            case nameof(Id):
                return(Id.ToString());

            case nameof(StyleId):
                return(StyleId.ToString());

            //VISUAL ELEMENT
            case nameof(AnchorX):
                return(AnchorX.ToString());

            case nameof(AnchorY):
                return(AnchorY.ToString());

            case nameof(BackgroundColor):
                return(BackgroundColor.ToHex());

            case nameof(Width):
                return(this.Width.ToString());

            case nameof(Height):
                return(this.Height.ToString());

            case nameof(IsEnabled):
                return(IsEnabled.ToString());

            case nameof(WidthRequest):
                return(this.WidthRequest.ToString());

            case nameof(HeightRequest):
                return(this.HeightRequest.ToString());

            case nameof(IsFocused):
                return(IsFocused.ToString());

            case nameof(IsVisible):
                return(IsVisible.ToString());

            case nameof(InputTransparent):
                return(InputTransparent.ToString());

            case nameof(X):
                return(this.X.ToString());

            case nameof(Y):
                return(this.Y.ToString());

            case nameof(Opacity):
                return(this.Opacity.ToString());

            case nameof(TranslationX):
                return(this.TranslationX.ToString());

            case nameof(TranslationY):
                return(this.TranslationY.ToString());

            case nameof(Rotation):
                return(this.Rotation.ToString());

            case nameof(RotationX):
                return(this.RotationX.ToString());

            case nameof(RotationY):
                return(this.RotationY.ToString());

            case nameof(Scale):
                return(this.Scale.ToString());

            //VIEW
            case nameof(Margin):
                return(this.Margin.ToString());

            case nameof(VerticalOptions):
                return(this.VerticalOptions.ToString());

            case nameof(HorizontalOptions):
                return(this.HorizontalOptions.ToString());

            //STEPPER
            case nameof(Maximum):
                return(Maximum.ToString());

            case nameof(Minimum):
                return(Minimum.ToString());

            case nameof(Value):
                return(Value.ToString());

            case nameof(Increment):
                return(Increment.ToString());

            default:
                return(string.Empty);
            }
        }
Exemple #38
0
        public void Parse()
        {
            var current = _reader.BaseStream.Position;

            _reader.BaseStream.Seek(_offset, SeekOrigin.Begin);
            bool parsing     = true;
            bool branched    = false;
            int  branchBytes = 0;

            while (parsing)
            {
                //now reader the instructions
                var type    = _reader.ReadByteAsEnum <InstructionType>();
                var aligned = InstructionAlignment.IsAligned(type);

                if (aligned)
                {
                    var padding = _reader.Align(4);
                    if (padding > 0)
                    {
                        Items.Add(new Padding(padding));
                        if (branched)
                        {
                            branchBytes -= (int)padding;

                            if (branchBytes <= 0)
                            {
                                branched    = false;
                                branchBytes = 0;
                            }
                        }
                    }
                }

                InstructionBase instruction = null;
                List <Value>    parameters  = new List <Value>();

                switch (type)
                {
                case InstructionType.ToNumber:
                    instruction = new ToNumber();
                    break;

                case InstructionType.NextFrame:
                    instruction = new NextFrame();
                    break;

                case InstructionType.Play:
                    instruction = new Play();
                    break;

                case InstructionType.Stop:
                    instruction = new Stop();
                    break;

                case InstructionType.Add:
                    instruction = new Add();
                    break;

                case InstructionType.Subtract:
                    instruction = new Subtract();
                    break;

                case InstructionType.Multiply:
                    instruction = new Multiply();
                    break;

                case InstructionType.Divide:
                    instruction = new Divide();
                    break;

                case InstructionType.Not:
                    instruction = new Not();
                    break;

                case InstructionType.StringEquals:
                    instruction = new StringEquals();
                    break;

                case InstructionType.Pop:
                    instruction = new Pop();
                    break;

                case InstructionType.ToInteger:
                    instruction = new ToInteger();
                    break;

                case InstructionType.GetVariable:
                    instruction = new GetVariable();
                    break;

                case InstructionType.SetVariable:
                    instruction = new SetVariable();
                    break;

                case InstructionType.StringConcat:
                    instruction = new StringConcat();
                    break;

                case InstructionType.GetProperty:
                    instruction = new GetProperty();
                    break;

                case InstructionType.SetProperty:
                    instruction = new SetProperty();
                    break;

                case InstructionType.Trace:
                    instruction = new Trace();
                    break;

                case InstructionType.Delete:
                    instruction = new Delete();
                    break;

                case InstructionType.Delete2:
                    instruction = new Delete2();
                    break;

                case InstructionType.DefineLocal:
                    instruction = new DefineLocal();
                    break;

                case InstructionType.CallFunction:
                    instruction = new CallFunction();
                    break;

                case InstructionType.Return:
                    instruction = new Return();
                    break;

                case InstructionType.NewObject:
                    instruction = new NewObject();
                    break;

                case InstructionType.InitArray:
                    instruction = new InitArray();
                    break;

                case InstructionType.InitObject:
                    instruction = new InitObject();
                    break;

                case InstructionType.TypeOf:
                    instruction = new InitObject();
                    break;

                case InstructionType.Add2:
                    instruction = new Add2();
                    break;

                case InstructionType.LessThan2:
                    instruction = new LessThan2();
                    break;

                case InstructionType.Equals2:
                    instruction = new Equals2();
                    break;

                case InstructionType.ToString:
                    instruction = new ToString();
                    break;

                case InstructionType.PushDuplicate:
                    instruction = new PushDuplicate();
                    break;

                case InstructionType.GetMember:
                    instruction = new GetMember();
                    break;

                case InstructionType.SetMember:
                    instruction = new SetMember();
                    break;

                case InstructionType.Increment:
                    instruction = new Increment();
                    break;

                case InstructionType.Decrement:
                    instruction = new Decrement();
                    break;

                case InstructionType.CallMethod:
                    instruction = new CallMethod();
                    break;

                case InstructionType.Enumerate2:
                    instruction = new Enumerate2();
                    break;

                case InstructionType.EA_PushThis:
                    instruction = new PushThis();
                    break;

                case InstructionType.EA_PushZero:
                    instruction = new PushZero();
                    break;

                case InstructionType.EA_PushOne:
                    instruction = new PushOne();
                    break;

                case InstructionType.EA_CallFunc:
                    instruction = new CallFunc();
                    break;

                case InstructionType.EA_CallMethodPop:
                    instruction = new CallMethodPop();
                    break;

                case InstructionType.BitwiseXOr:
                    instruction = new BitwiseXOr();
                    break;

                case InstructionType.Greater:
                    instruction = new Greater();
                    break;

                case InstructionType.EA_PushThisVar:
                    instruction = new PushThisVar();
                    break;

                case InstructionType.EA_PushGlobalVar:
                    instruction = new PushGlobalVar();
                    break;

                case InstructionType.EA_ZeroVar:
                    instruction = new ZeroVar();
                    break;

                case InstructionType.EA_PushTrue:
                    instruction = new PushTrue();
                    break;

                case InstructionType.EA_PushFalse:
                    instruction = new PushFalse();
                    break;

                case InstructionType.EA_PushNull:
                    instruction = new PushNull();
                    break;

                case InstructionType.EA_PushUndefined:
                    instruction = new PushUndefined();
                    break;

                case InstructionType.GotoFrame:
                    instruction = new GotoFrame();
                    parameters.Add(Value.FromInteger(_reader.ReadInt32()));
                    break;

                case InstructionType.GetURL:
                    instruction = new GetUrl();
                    parameters.Add(Value.FromString(_reader.ReadStringAtOffset()));
                    parameters.Add(Value.FromString(_reader.ReadStringAtOffset()));
                    break;

                case InstructionType.SetRegister:
                    instruction = new SetRegister();
                    parameters.Add(Value.FromInteger(_reader.ReadInt32()));
                    break;

                case InstructionType.ConstantPool:
                {
                    instruction = new ConstantPool();
                    var count     = _reader.ReadUInt32();
                    var constants = _reader.ReadFixedSizeArrayAtOffset <uint>(() => _reader.ReadUInt32(), count);

                    foreach (var constant in constants)
                    {
                        parameters.Add(Value.FromConstant(constant));
                    }
                }
                break;

                case InstructionType.GotoLabel:
                    instruction = new GotoLabel();
                    parameters.Add(Value.FromString(_reader.ReadStringAtOffset()));
                    break;

                case InstructionType.DefineFunction2:
                {
                    instruction = new DefineFunction2();
                    var name       = _reader.ReadStringAtOffset();
                    var nParams    = _reader.ReadUInt32();
                    var nRegisters = _reader.ReadByte();
                    var flags      = _reader.ReadUInt24();

                    //list of parameter strings
                    var paramList = _reader.ReadFixedSizeListAtOffset <FunctionArgument>(() => new FunctionArgument()
                        {
                            Register  = _reader.ReadInt32(),
                            Parameter = _reader.ReadStringAtOffset(),
                        }, nParams);

                    parameters.Add(Value.FromString(name));
                    parameters.Add(Value.FromInteger((int)nParams));
                    parameters.Add(Value.FromInteger((int)nRegisters));
                    parameters.Add(Value.FromInteger((int)flags));
                    foreach (var param in paramList)
                    {
                        parameters.Add(Value.FromInteger(param.Register));
                        parameters.Add(Value.FromString(param.Parameter));
                    }
                    //body size of the function
                    parameters.Add(Value.FromInteger(_reader.ReadInt32()));
                    //skip 8 bytes
                    _reader.ReadUInt64();
                }
                break;

                case InstructionType.PushData:
                {
                    instruction = new PushData();

                    var count     = _reader.ReadUInt32();
                    var constants = _reader.ReadFixedSizeArrayAtOffset <uint>(() => _reader.ReadUInt32(), count);

                    foreach (var constant in constants)
                    {
                        parameters.Add(Value.FromConstant(constant));
                    }
                }
                break;

                case InstructionType.BranchAlways:
                    instruction = new BranchAlways();
                    if (!branched)
                    {
                        branchBytes = _reader.ReadInt32();
                        parameters.Add(Value.FromInteger(branchBytes));

                        if (branchBytes > 0)
                        {
                            branchBytes += (int)instruction.Size + 1;
                            branched     = true;
                        }
                    }
                    else
                    {
                        parameters.Add(Value.FromInteger(_reader.ReadInt32()));
                    }
                    break;

                case InstructionType.GetURL2:
                    instruction = new GetUrl2();
                    break;

                case InstructionType.DefineFunction:
                {
                    instruction = new DefineFunction();
                    var name = _reader.ReadStringAtOffset();
                    //list of parameter strings
                    var paramList = _reader.ReadListAtOffset <string>(() => _reader.ReadStringAtOffset());

                    parameters.Add(Value.FromString(name));
                    parameters.Add(Value.FromInteger(paramList.Count));
                    foreach (var param in paramList)
                    {
                        parameters.Add(Value.FromString(param));
                    }
                    //body size of the function
                    parameters.Add(Value.FromInteger(_reader.ReadInt32()));
                    //skip 8 bytes
                    _reader.ReadUInt64();
                }
                break;

                case InstructionType.BranchIfTrue:
                    instruction = new BranchIfTrue();
                    if (!branched)
                    {
                        branchBytes = _reader.ReadInt32();
                        parameters.Add(Value.FromInteger(branchBytes));

                        if (branchBytes > 0)
                        {
                            branchBytes += (int)instruction.Size + 1;
                            branched     = true;
                        }
                    }
                    else
                    {
                        parameters.Add(Value.FromInteger(_reader.ReadInt32()));
                    }
                    break;

                case InstructionType.GotoFrame2:
                    instruction = new GotoFrame2();
                    parameters.Add(Value.FromInteger(_reader.ReadByte()));
                    break;

                case InstructionType.EA_PushString:
                    instruction = new PushString();
                    //the constant id that should be pushed
                    parameters.Add(Value.FromString(_reader.ReadStringAtOffset()));
                    break;

                case InstructionType.EA_PushConstantByte:
                    instruction = new PushConstantByte();
                    //the constant id that should be pushed
                    parameters.Add(Value.FromConstant(_reader.ReadByte()));
                    break;

                case InstructionType.EA_GetStringVar:
                    instruction = new GetStringVar();
                    parameters.Add(Value.FromString(_reader.ReadStringAtOffset()));
                    break;

                case InstructionType.EA_SetStringVar:
                    instruction = new SetStringMember();
                    parameters.Add(Value.FromString(_reader.ReadStringAtOffset()));
                    break;

                case InstructionType.EA_GetStringMember:
                    instruction = new GetStringMember();
                    parameters.Add(Value.FromString(_reader.ReadStringAtOffset()));
                    break;

                case InstructionType.EA_SetStringMember:
                    instruction = new SetStringMember();
                    parameters.Add(Value.FromString(_reader.ReadStringAtOffset()));
                    break;

                case InstructionType.EA_PushValueOfVar:
                    instruction = new PushValueOfVar();
                    //the constant id that should be pushed
                    parameters.Add(Value.FromConstant(_reader.ReadByte()));
                    break;

                case InstructionType.EA_GetNamedMember:
                    instruction = new GetNamedMember();
                    parameters.Add(Value.FromConstant(_reader.ReadByte()));
                    break;

                case InstructionType.EA_CallNamedFuncPop:
                    instruction = new CallNamedFuncPop();
                    parameters.Add(Value.FromConstant(_reader.ReadByte()));
                    break;

                case InstructionType.EA_CallNamedFunc:
                    instruction = new CallNamedFunc();
                    parameters.Add(Value.FromConstant(_reader.ReadByte()));
                    break;

                case InstructionType.EA_CallNamedMethodPop:
                    instruction = new CallNamedMethodPop();
                    parameters.Add(Value.FromConstant(_reader.ReadByte()));
                    break;

                case InstructionType.EA_PushFloat:
                    instruction = new PushFloat();
                    parameters.Add(Value.FromFloat(_reader.ReadSingle()));
                    break;

                case InstructionType.EA_PushByte:
                    instruction = new PushByte();
                    parameters.Add(Value.FromInteger(_reader.ReadByte()));
                    break;

                case InstructionType.EA_PushShort:
                    instruction = new PushShort();
                    parameters.Add(Value.FromInteger(_reader.ReadUInt16()));
                    break;

                case InstructionType.End:
                    instruction = new End();

                    if (!branched)
                    {
                        parsing = false;
                    }
                    break;

                case InstructionType.EA_CallNamedMethod:
                    instruction = new CallNamedMethod();
                    parameters.Add(Value.FromConstant(_reader.ReadByte()));
                    break;

                case InstructionType.Var:
                    instruction = new Var();

                    break;

                default:
                    throw new InvalidDataException("Unimplemented bytecode instruction:" + type.ToString());
                }

                if (instruction != null)
                {
                    instruction.Parameters = parameters;
                    Items.Add(instruction);
                }

                if (branched)
                {
                    branchBytes -= (int)instruction.Size + 1;

                    if (branchBytes <= 0)
                    {
                        branched = false;
                    }
                }
            }
            _reader.BaseStream.Seek(current, SeekOrigin.Begin);
        }
Exemple #39
0
 public static T Increase <T>(T value)
 => Increment <T, T> .Invoke(value);
Exemple #40
0
        void MakeBranch(Vector2i Origin, int Size, int Movement, double Roughness, int Depth, double heightstart)
        {
            Increment increment        = GetIncrement(Center.X - Origin.X, Center.Y - Origin.Y);
            Increment inc1             = increment;
            double    OriginDistance   = Math.Max(Math.Sqrt(increment.X * increment.X + increment.Y * increment.Y), 1);
            double    DistanceModifier = Size / Movement * (Depth + 1);

            increment = GetIncrement((increment.X / OriginDistance + (random.NextDouble() - 0.5) * AngleRandomer) * DistanceModifier,
                                     (increment.Y / OriginDistance + (random.NextDouble() - 0.5) * AngleRandomer) * DistanceModifier);
            if (Depth == 0)
            {
                double ang = Math.Atan2(increment.Y, increment.X);
                for (int i = 0; i < UsedAngles.Count; i++)
                {
                    if (Math.Abs(UsedAngles[i] - ang) < (Math.PI * 1.5 / Movement))
                    {
                        if (bounces++ < 15)
                        {
                            MakeBranch(Origin, Size, Movement, Roughness, Depth, heightstart);
                            return;
                        }
                    }
                }
                UsedAngles.Add(ang);
            }

            Vector2i Destination = FixBounds(new Vector2i((int)Math.Round(Center.X + increment.X),
                                                          (int)Math.Round(Center.Y + increment.Y)), Size);

            List <Vector2i> Points    = MakeLine(Origin, Destination, Size, Roughness);
            int             PointSize = Points.Count;

            if (PointSize == 0)
            {
                return;
            }

            Destination = Points[PointSize - 1];
            double distX = Center.X - Destination.X;
            double distY = Center.Y - Destination.Y;
            double DestinationDistance = Math.Max(Math.Sqrt(distX * distX + distY * distY), 1);

            double HeightStart = heightstart;
            double HeightDecay = (HeightStart - Height * ((MaxDistance - DestinationDistance) / MaxDistance)) / PointSize;

            int Branching = 0;

            Vector2i Previous = new Vector2i((int)(Origin.X / DetailScaler / SHRINKER + ADDER), (int)(Origin.Y / DetailScaler / SHRINKER / SHRINKER + ADDER));
            Vector2i prev2    = Previous;
            Vector2i Next;

            for (int i = 0; i < PointSize; i++)
            {
                double HeightValue = HeightStart - HeightDecay * (i + 1);

                Vector2i point = Points[i];

                Vector2i ScaledPoint = new Vector2i((int)(point.X / DetailScaler / SHRINKER + ADDER), (int)(point.Y / DetailScaler / SHRINKER + ADDER));

                if (prev2.X == ScaledPoint.X && prev2.Y == ScaledPoint.Y)
                {
                    prev2 = new Vector2i(ScaledPoint.X - Math.Sign(inc1.X), ScaledPoint.Y - Math.Sign(inc1.Y));
                    if (prev2.X == ScaledPoint.X && prev2.Y == ScaledPoint.Y)
                    {
                        prev2 = new Vector2i(ScaledPoint.X - 1, ScaledPoint.Y - 1);
                    }
                }


                Next = ScaledPoint;
                int n = 1;
                while (i + n < PointSize)
                {
                    Next = new Vector2i((int)(Points[i + n].X / DetailScaler / SHRINKER + ADDER), (int)(Points[i + n].Y / DetailScaler / SHRINKER + ADDER));
                    if (Next.X != ScaledPoint.X || Next.Y != ScaledPoint.Y)
                    {
                        break;
                    }
                    n++;
                }
                if (i + n >= PointSize)
                {
                    Next = new Vector2i((int)(Destination.X / DetailScaler / SHRINKER + ADDER), (int)(Destination.Y / DetailScaler / SHRINKER + ADDER));
                    if (Next.X == ScaledPoint.X && Next.Y == ScaledPoint.Y)
                    {
                        Next = new Vector2i(ScaledPoint.X + Math.Sign(increment.X), ScaledPoint.Y + Math.Sign(increment.Y));
                    }
                }
                NodePoint ScaledNodePoint = GetNodePoint(prev2, ScaledPoint, Next, HeightValue);

                if (!Nodes.ContainsKey(ScaledPoint))
                {
                    Nodes.Add(ScaledPoint, ScaledNodePoint);
                    prev2    = Previous;
                    Previous = ScaledPoint;
                }
                ToHandle.Add(new KeyValuePair <Vector2i, double>(new Vector2i((int)(point.X / SHRINKER + ADDER * DetailScaler), (int)(point.Y / SHRINKER + ADDER * DetailScaler)), HeightValue));

                if (random.NextDouble() < 0.2 && Depth < Movement && Branching < 5)
                {
                    Branching++;
                    MakeBranch(Destination, Size, Movement, Roughness, Depth + 1, HeightStart - HeightDecay * (PointSize + 1));
                }
            }
        }
Exemple #41
0
 /// <devdoc>
 /// <para>Indicates whether the <see cref='System.Windows.Forms.NumericUpDown.Increment'/> property should be
 ///    persisted.</para>
 /// </devdoc>
 private bool ShouldSerializeIncrement()
 {
     return(!Increment.Equals(NumericUpDown.DefaultIncrement));
 }
Exemple #42
0
        public static InstructionCollection Parse(Stream input, long instructionsPosition)
        {
            var instructions = new SortedList <int, InstructionBase>();

            using (var helper = new InstructionParseHelper(input, instructionsPosition))
            {
                var reader = helper.GetReader();
                while (helper.CanParse(instructions))
                {
                    //now reader the instructions
                    var instructionPosition = helper.CurrentPosition;
                    var type             = reader.ReadByteAsEnum <InstructionType>();
                    var requireAlignment = InstructionAlignment.IsAligned(type);

                    if (requireAlignment)
                    {
                        reader.Align(4);
                    }

                    InstructionBase instruction = null;
                    var             parameters  = new List <Value>();

                    switch (type)
                    {
                    case InstructionType.ToNumber:
                        instruction = new ToNumber();
                        break;

                    case InstructionType.NextFrame:
                        instruction = new NextFrame();
                        break;

                    case InstructionType.Play:
                        instruction = new Play();
                        break;

                    case InstructionType.Stop:
                        instruction = new Stop();
                        break;

                    case InstructionType.Add:
                        instruction = new Add();
                        break;

                    case InstructionType.Subtract:
                        instruction = new Subtract();
                        break;

                    case InstructionType.Multiply:
                        instruction = new Multiply();
                        break;

                    case InstructionType.Divide:
                        instruction = new Divide();
                        break;

                    case InstructionType.Not:
                        instruction = new Not();
                        break;

                    case InstructionType.StringEquals:
                        instruction = new StringEquals();
                        break;

                    case InstructionType.Pop:
                        instruction = new Pop();
                        break;

                    case InstructionType.ToInteger:
                        instruction = new ToInteger();
                        break;

                    case InstructionType.GetVariable:
                        instruction = new GetVariable();
                        break;

                    case InstructionType.SetVariable:
                        instruction = new SetVariable();
                        break;

                    case InstructionType.StringConcat:
                        instruction = new StringConcat();
                        break;

                    case InstructionType.GetProperty:
                        instruction = new GetProperty();
                        break;

                    case InstructionType.SetProperty:
                        instruction = new SetProperty();
                        break;

                    case InstructionType.Trace:
                        instruction = new Trace();
                        break;

                    case InstructionType.Random:
                        instruction = new RandomNumber();
                        break;

                    case InstructionType.Delete:
                        instruction = new Delete();
                        break;

                    case InstructionType.Delete2:
                        instruction = new Delete2();
                        break;

                    case InstructionType.DefineLocal:
                        instruction = new DefineLocal();
                        break;

                    case InstructionType.CallFunction:
                        instruction = new CallFunction();
                        break;

                    case InstructionType.Return:
                        instruction = new Return();
                        break;

                    case InstructionType.Modulo:
                        instruction = new Modulo();
                        break;

                    case InstructionType.NewObject:
                        instruction = new NewObject();
                        break;

                    case InstructionType.InitArray:
                        instruction = new InitArray();
                        break;

                    case InstructionType.InitObject:
                        instruction = new InitObject();
                        break;

                    case InstructionType.TypeOf:
                        instruction = new TypeOf();
                        break;

                    case InstructionType.Add2:
                        instruction = new Add2();
                        break;

                    case InstructionType.LessThan2:
                        instruction = new LessThan2();
                        break;

                    case InstructionType.Equals2:
                        instruction = new Equals2();
                        break;

                    case InstructionType.ToString:
                        instruction = new ToString();
                        break;

                    case InstructionType.PushDuplicate:
                        instruction = new PushDuplicate();
                        break;

                    case InstructionType.GetMember:
                        instruction = new GetMember();
                        break;

                    case InstructionType.SetMember:
                        instruction = new SetMember();
                        break;

                    case InstructionType.Increment:
                        instruction = new Increment();
                        break;

                    case InstructionType.Decrement:
                        instruction = new Decrement();
                        break;

                    case InstructionType.CallMethod:
                        instruction = new CallMethod();
                        break;

                    case InstructionType.Enumerate2:
                        instruction = new Enumerate2();
                        break;

                    case InstructionType.EA_PushThis:
                        instruction = new PushThis();
                        break;

                    case InstructionType.EA_PushZero:
                        instruction = new PushZero();
                        break;

                    case InstructionType.EA_PushOne:
                        instruction = new PushOne();
                        break;

                    case InstructionType.EA_CallFunc:
                        instruction = new CallFunc();
                        break;

                    case InstructionType.EA_CallMethodPop:
                        instruction = new CallMethodPop();
                        break;

                    case InstructionType.BitwiseXOr:
                        instruction = new BitwiseXOr();
                        break;

                    case InstructionType.Greater:
                        instruction = new Greater();
                        break;

                    case InstructionType.EA_PushThisVar:
                        instruction = new PushThisVar();
                        break;

                    case InstructionType.EA_PushGlobalVar:
                        instruction = new PushGlobalVar();
                        break;

                    case InstructionType.EA_ZeroVar:
                        instruction = new ZeroVar();
                        break;

                    case InstructionType.EA_PushTrue:
                        instruction = new PushTrue();
                        break;

                    case InstructionType.EA_PushFalse:
                        instruction = new PushFalse();
                        break;

                    case InstructionType.EA_PushNull:
                        instruction = new PushNull();
                        break;

                    case InstructionType.EA_PushUndefined:
                        instruction = new PushUndefined();
                        break;

                    case InstructionType.GotoFrame:
                        instruction = new GotoFrame();
                        parameters.Add(Value.FromInteger(reader.ReadInt32()));
                        break;

                    case InstructionType.GetURL:
                        instruction = new GetUrl();
                        parameters.Add(Value.FromString(reader.ReadStringAtOffset()));
                        parameters.Add(Value.FromString(reader.ReadStringAtOffset()));
                        break;

                    case InstructionType.SetRegister:
                        instruction = new SetRegister();
                        parameters.Add(Value.FromInteger(reader.ReadInt32()));
                        break;

                    case InstructionType.ConstantPool:
                    {
                        instruction = new ConstantPool();
                        var count     = reader.ReadUInt32();
                        var constants = reader.ReadFixedSizeArrayAtOffset <uint>(() => reader.ReadUInt32(), count);

                        foreach (var constant in constants)
                        {
                            parameters.Add(Value.FromConstant(constant));
                        }
                    }
                    break;

                    case InstructionType.GotoLabel:
                        instruction = new GotoLabel();
                        parameters.Add(Value.FromString(reader.ReadStringAtOffset()));
                        break;

                    case InstructionType.DefineFunction2:
                    {
                        instruction = new DefineFunction2();
                        var name       = reader.ReadStringAtOffset();
                        var nParams    = reader.ReadUInt32();
                        var nRegisters = reader.ReadByte();
                        var flags      = reader.ReadUInt24();

                        //list of parameter strings
                        var paramList = reader.ReadFixedSizeListAtOffset <FunctionArgument>(() => new FunctionArgument()
                            {
                                Register  = reader.ReadInt32(),
                                Parameter = reader.ReadStringAtOffset(),
                            }, nParams);

                        parameters.Add(Value.FromString(name));
                        parameters.Add(Value.FromInteger((int)nParams));
                        parameters.Add(Value.FromInteger((int)nRegisters));
                        parameters.Add(Value.FromInteger((int)flags));
                        foreach (var param in paramList)
                        {
                            parameters.Add(Value.FromInteger(param.Register));
                            parameters.Add(Value.FromString(param.Parameter));
                        }
                        //body size of the function
                        parameters.Add(Value.FromInteger(reader.ReadInt32()));
                        //skip 8 bytes
                        reader.ReadUInt64();
                    }
                    break;

                    case InstructionType.PushData:
                    {
                        instruction = new PushData();

                        var count     = reader.ReadUInt32();
                        var constants = reader.ReadFixedSizeArrayAtOffset <uint>(() => reader.ReadUInt32(), count);

                        foreach (var constant in constants)
                        {
                            parameters.Add(Value.FromConstant(constant));
                        }
                    }
                    break;

                    case InstructionType.BranchAlways:
                    {
                        instruction = new BranchAlways();
                        var offset = reader.ReadInt32();
                        parameters.Add(Value.FromInteger(offset));
                        helper.ReportBranchOffset(offset);
                    }
                    break;

                    case InstructionType.GetURL2:
                        instruction = new GetUrl2();
                        break;

                    case InstructionType.DefineFunction:
                    {
                        instruction = new DefineFunction();
                        var name = reader.ReadStringAtOffset();
                        //list of parameter strings
                        var paramList = reader.ReadListAtOffset <string>(() => reader.ReadStringAtOffset());

                        parameters.Add(Value.FromString(name));
                        parameters.Add(Value.FromInteger(paramList.Count));
                        foreach (var param in paramList)
                        {
                            parameters.Add(Value.FromString(param));
                        }
                        //body size of the function
                        parameters.Add(Value.FromInteger(reader.ReadInt32()));
                        //skip 8 bytes
                        reader.ReadUInt64();
                    }
                    break;

                    case InstructionType.BranchIfTrue:
                    {
                        instruction = new BranchIfTrue();
                        var offset = reader.ReadInt32();
                        parameters.Add(Value.FromInteger(offset));
                        helper.ReportBranchOffset(offset);
                    }
                    break;

                    case InstructionType.GotoFrame2:
                        instruction = new GotoFrame2();
                        parameters.Add(Value.FromInteger(reader.ReadInt32()));
                        break;

                    case InstructionType.EA_PushString:
                        instruction = new PushString();
                        //the constant id that should be pushed
                        parameters.Add(Value.FromString(reader.ReadStringAtOffset()));
                        break;

                    case InstructionType.EA_PushConstantByte:
                        instruction = new PushConstantByte();
                        //the constant id that should be pushed
                        parameters.Add(Value.FromConstant(reader.ReadByte()));
                        break;

                    case InstructionType.EA_GetStringVar:
                        instruction = new GetStringVar();
                        parameters.Add(Value.FromString(reader.ReadStringAtOffset()));
                        break;

                    case InstructionType.EA_SetStringVar:
                        instruction = new SetStringVar();
                        parameters.Add(Value.FromString(reader.ReadStringAtOffset()));
                        break;

                    case InstructionType.EA_GetStringMember:
                        instruction = new GetStringMember();
                        parameters.Add(Value.FromString(reader.ReadStringAtOffset()));
                        break;

                    case InstructionType.EA_SetStringMember:
                        instruction = new SetStringMember();
                        parameters.Add(Value.FromString(reader.ReadStringAtOffset()));
                        break;

                    case InstructionType.EA_PushValueOfVar:
                        instruction = new PushValueOfVar();
                        //the constant id that should be pushed
                        parameters.Add(Value.FromConstant(reader.ReadByte()));
                        break;

                    case InstructionType.EA_GetNamedMember:
                        instruction = new GetNamedMember();
                        parameters.Add(Value.FromConstant(reader.ReadByte()));
                        break;

                    case InstructionType.EA_CallNamedFuncPop:
                        instruction = new CallNamedFuncPop();
                        parameters.Add(Value.FromConstant(reader.ReadByte()));
                        break;

                    case InstructionType.EA_CallNamedFunc:
                        instruction = new CallNamedFunc();
                        parameters.Add(Value.FromConstant(reader.ReadByte()));
                        break;

                    case InstructionType.EA_CallNamedMethodPop:
                        instruction = new CallNamedMethodPop();
                        parameters.Add(Value.FromConstant(reader.ReadByte()));
                        break;

                    case InstructionType.EA_PushFloat:
                        instruction = new PushFloat();
                        parameters.Add(Value.FromFloat(reader.ReadSingle()));
                        break;

                    case InstructionType.EA_PushByte:
                        instruction = new PushByte();
                        parameters.Add(Value.FromInteger(reader.ReadByte()));
                        break;

                    case InstructionType.EA_PushShort:
                        instruction = new PushShort();
                        parameters.Add(Value.FromInteger(reader.ReadUInt16()));
                        break;

                    case InstructionType.End:
                        instruction = new End();
                        break;

                    case InstructionType.EA_CallNamedMethod:
                        instruction = new CallNamedMethod();
                        parameters.Add(Value.FromConstant(reader.ReadByte()));
                        break;

                    case InstructionType.Var:
                        instruction = new Var();
                        break;

                    case InstructionType.EA_PushRegister:
                        instruction = new PushRegister();
                        parameters.Add(Value.FromInteger(reader.ReadByte()));
                        break;

                    case InstructionType.EA_PushConstantWord:
                        instruction = new PushConstantWord();
                        parameters.Add(Value.FromConstant(reader.ReadUInt16()));
                        break;

                    case InstructionType.EA_CallFuncPop:
                        instruction = new CallFunctionPop();
                        break;

                    case InstructionType.StrictEqual:
                        instruction = new StrictEquals();
                        break;

                    default:
                        throw new InvalidDataException("Unimplemented bytecode instruction:" + type.ToString());
                    }

                    if (instruction != null)
                    {
                        instruction.Parameters = parameters;
                        instructions.Add(instructionPosition, instruction);
                    }
                }
            }

            return(new InstructionCollection(instructions));
        }