Ejemplo n.º 1
0
        public override void Run(Process scenario, CpuCommandContext context)
        {
            var results =
                Assertions.Select(assert =>
            {
                var valueLeft  = assert.CompareLeft.ReadFromTarget(scenario, context);
                var valueRight = assert.CompareRight.ReadFromTarget(scenario, context);
                var match      = string.Equals(valueLeft, valueRight);

                Console.Write($"TEST {assert.CompareLeft}:{valueLeft} = {assert.CompareRight}:{valueRight} {match}");

                return(match);
            });

            if (results.All(x => x))
            {
                Console.Write($"TEST PASSED.");
                context.Scenario.Printer.Append("ACCESS GRANTED|");
            }
            else
            {
                Console.Write($"TEST FAILED.");
                context.Scenario.Printer.Append("ACCESS DENIED|");
            }
        }
Ejemplo n.º 2
0
        public override void WriteToTarget(Process scenario, string input, CpuCommandContext context)
        {
            input = Pad4(input);

            AddressableRegion region;

            if (Coordinate.DriveId != null)
            {
                region = context.Scenario.Disks[Coordinate.DriveId.Value];
            }
            else
            {
                region = scenario.Memory;
            }

            var chunks = Split(input, 4).ToList();
            MemoryCoordinate?lastPut = null;

            for (int i = 0; i < chunks.Count; i++)
            {
                if (lastPut == null)
                {
                    region.Write(Coordinate, chunks[i]);
                    lastPut = Coordinate;
                }
                else
                {
                    var put = region.NextAddress(lastPut.Value);
                    region.Write(put, chunks[i]);
                    lastPut = put;
                }
            }
        }
Ejemplo n.º 3
0
        public override void Run(Process scenario, CpuCommandContext context)
        {
            var advanceAmountRaw = Amount.ReadFromTarget(scenario, context);
            var advanceAmount    = Int32.Parse(advanceAmountRaw);

            var currentValue       = Target.ReadFromTarget(scenario, context);
            var currentMediaTarget = MediaTarget.FromText(currentValue);

            AddressableRegion region;

            if (currentMediaTarget.Coordinate.DriveId == null)
            {
                region = scenario.Memory;
            }
            else
            {
                region = context.Scenario.Disks[currentMediaTarget.Coordinate.DriveId.Value];
            }

            Console.WriteLine($"Seeking {currentMediaTarget.Coordinate} by {advanceAmount}");
            //0:0A0:1A
            var current = currentMediaTarget.Coordinate;

            for (int i = 0; i < advanceAmount; i++)
            {
                current = region.NextAddress(current);
            }

            Console.WriteLine($"Seeked to {current}");

            Target.WriteToTarget(scenario, current.ToString(), context);
        }
Ejemplo n.º 4
0
        public override void Run(Process scenario, CpuCommandContext context)
        {
            var disks = context.Scenario.FindDisks(SearchConstraints);

            var coordList =
                disks.SelectMany(x => x.FilterCoordinates(SearchConstraints))
                .OrderBy(x => x.DriveId)
                .ThenBy(x => x.Y)
                .ThenBy(x => x.X);

            string fullText = string.Empty;

            foreach (var coord in coordList)
            {
                var drive     = context.Scenario.Disks[coord.DriveId.Value];
                var readValue = drive.Read(coord);
                fullText += readValue;
            }

            var lines = fullText.Split(new[] { '|' });

            var dynamicCommands = FileReader.ReadCpuCommands(lines);

            foreach (var dynamicCommand in dynamicCommands)
            {
                scenario.CpuLog.Log("~:" + dynamicCommand.ToString());
                dynamicCommand.Run(scenario, context);
            }
        }
Ejemplo n.º 5
0
        public override void WriteToTarget(Process scenario, string input, CpuCommandContext context)
        {
            var reference    = ReferenceLocation.ReadFromTarget(scenario, context);
            var actualTarget = Target.ResolveTarget(reference);

            actualTarget.WriteToTarget(scenario, input, context);
        }
Ejemplo n.º 6
0
        public override string ReadFromTarget(Process scenario, CpuCommandContext context)
        {
            if (!context.Variables.ContainsKey(Number))
            {
                return(string.Empty);
            }

            return(context.Variables[Number]);
        }
Ejemplo n.º 7
0
        public IReadOnlyCollection <string> GetSearchValues(Process scenario, CpuCommandContext context)
        {
            List <string> searchValues = new List <string>();

            foreach (var f in For)
            {
                searchValues.Add(f.ReadFromTarget(scenario, context));
            }

            return(searchValues);
        }
Ejemplo n.º 8
0
        public void RunNextStep(Process process, int CurrentStep, CpuCommandContext context)
        {
            process.Memory.CoolOff();
            foreach (var drive in context.Scenario.Disks)
            {
                drive.CoolOff();
            }

            var command = AllCommands[CurrentStep];

            process.CpuLog.Log(CurrentStep + ": " + command.ToString());

            command.Run(process, context);
        }
Ejemplo n.º 9
0
        public override void Run(Process scenario, CpuCommandContext context)
        {
            var disks = context.Scenario.FindDisks(From);

            foreach (var disk in disks)
            {
                var coordinates = disk.FilterCoordinates(From);

                foreach (var memoryCoordinate in coordinates)
                {
                    var dumpVal = disk.Read(memoryCoordinate);
                    Target.WriteToTarget(scenario, dumpVal, context);
                }
            }
        }
Ejemplo n.º 10
0
        public override string ReadFromTarget(Process scenario, CpuCommandContext context)
        {
            var reference = ReferenceLocation.ReadFromTarget(scenario, context);

            Console.WriteLine("DeRef Raw: " + reference);

            var actualTarget = Target.ResolveTarget(reference);

            Console.WriteLine("DeRef Parsed: " + actualTarget);

            var actualValue = actualTarget.ReadFromTarget(scenario, context);

            Console.WriteLine("DeRef Actual: " + actualValue);

            return(actualValue);
        }
Ejemplo n.º 11
0
        public override string ReadFromTarget(Process scenario, CpuCommandContext context)
        {
            string fromValue;

            if (Coordinate.DriveId != null)
            {
                var drive = context.Scenario.Disks[Coordinate.DriveId.Value];
                fromValue = drive.Read(Coordinate);
            }
            else
            {
                var memory = scenario.Memory;
                fromValue = memory.Read(Coordinate);
            }

            return(fromValue);
        }
Ejemplo n.º 12
0
        public override void Run(Process scenario, CpuCommandContext context)
        {
            var resolvedForExpression = For.GetSearchValues(scenario, context);



            var disks = context.Scenario.FindDisks(SearchConstraints);

            foreach (var disk in disks)
            {
                var found = disk.Find(SearchConstraints, resolvedForExpression);
                if (found == null)
                {
                    continue;
                }

                context.Variables["Index"] = found.Value.ToString();
                return;
            }
        }
Ejemplo n.º 13
0
 public override void WriteToTarget(Process scenario, string input, CpuCommandContext context)
 {
     context.Variables[Number] = input;
 }
Ejemplo n.º 14
0
 public abstract void WriteToTarget(Process scenario, string input, CpuCommandContext context);
Ejemplo n.º 15
0
 public abstract string ReadFromTarget(Process scenario, CpuCommandContext context);
Ejemplo n.º 16
0
 public override string ReadFromTarget(Process scenario, CpuCommandContext context)
 {
     return(Value);
 }
Ejemplo n.º 17
0
 public override void WriteToTarget(Process scenario, string input, CpuCommandContext context)
 {
     context.Scenario.Printer.Append(input);
 }
Ejemplo n.º 18
0
 public override string ReadFromTarget(Process scenario, CpuCommandContext context)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 19
0
 public override void WriteToTarget(Process scenario, string input, CpuCommandContext context)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 20
0
        public override void Run(Process scenario, CpuCommandContext context)
        {
            var value = From.ReadFromTarget(scenario, context);

            To.WriteToTarget(scenario, value, context);
        }
Ejemplo n.º 21
0
 public override string ReadFromTarget(Process scenario, CpuCommandContext context)
 {
     return(context.Scenario.KeyboardInput.Text ?? string.Empty);
 }
Ejemplo n.º 22
0
 public abstract void Run(Process scenario, CpuCommandContext context);