Exemple #1
0
        public void TestCtorOverflow()
        {
            try
            {
                List <string> RamContentsData = new List <string>
                {
                    "10101010",
                    "01010101",
                    "10101010",
                    "01010101",
                    "10101010",
                    "01010101",
                    "10101010",
                    "01010101",
                    "10101010",
                    "01010101",
                    "10101010",
                    "01010101",
                    "10101010",
                    "01010101",
                    "01010101",
                    "01010101",
                    "01010101"
                };

                RAMProgram program = new RAMProgram(RamContentsData);

                Assert.Fail("Ctor did not catch overflow");
            }
            catch (ArgumentOutOfRangeException e)
            {
                System.Console.Out.WriteLine(e);
                Assert.IsTrue(true);
            }
        }
Exemple #2
0
        public void TestRamContentsEmpty()
        {
            RAM ram = new RAM();

            string[] ADDRS = new string[16] {
                "0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"
            };
            try
            {
                List <string> RamContentsData = new List <string>();

                RAMProgram rmp = new RAMProgram(RamContentsData);
                ram.LoadProgram(rmp);

                for (int i = 0; i < 15; i++)
                {
                    // Since the RAMProgram was empty, the RAMProgam should fill will all zeros, so the RAM should be filled will all zeros.
                    Assert.IsTrue(string.Equals(ram.GetWordAt(ADDRS[i]), "00000000"));
                }
            }
            catch (Exception e)
            {
                Assert.Fail(e.ToString());
            }
            ram.ClearRAM();
        }
Exemple #3
0
        public void LoadProgram(RAMProgram rp)
        {
            ClearRAM();
            List <string> rpc = rp.RamContents;

            foreach (string s in rpc)
            {
                RamContents.Add(s);
            }
        }
Exemple #4
0
        public void TestRamContentFull()
        {
            RAM ram = new RAM();

            string[] ADDRS = new string[16] {
                "0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"
            };

            try
            {
                List <string> RamContentsData = new List <string>
                {
                    "10101010",
                    "01010101",
                    "10101010",
                    "01010101",
                    "10101010",
                    "01010101",
                    "10101010",
                    "01010101",
                    "10101010",
                    "01010101",
                    "10101010",
                    "01010101",
                    "10101010",
                    "01010101",
                    "10101010",
                    "01010101"
                };

                RAMProgram rmp = new RAMProgram(RamContentsData);
                ram.LoadProgram(rmp);

                // Check to make sure the RAM entries and the list<string> share the same values
                for (int i = 0; i < 15; i++)
                {
                    Assert.IsTrue(Equals(RamContentsData[i], ram.GetWordAt(ADDRS[i])));
                }
                // Check to see it i == i+1, should be false
                for (int i = 0; i < 14; i++)
                {
                    Assert.IsFalse(Equals(RamContentsData[i], ram.GetWordAt(ADDRS[i + 1])));
                }
            }
            catch (Exception e)
            {
                Assert.Fail(e.ToString());
            }
            ram.ClearRAM();
        }
Exemple #5
0
        // *************************************************************************
        // Init Engine
        // *************************************************************************
        public void Init(RAMProgram program, IDecoder decoder, string InstructionSetName = DefaultInstructionSetName)
        {
            // Get Instruction Set
            InstructionSet = OpCodeLoader.GetSet(InstructionSetName);

            _decoder = decoder;

            // Init RAM
            if (program == null)
            {
                Program = new RAMProgram(new List <string>());
            }

            Program = program;
        }
Exemple #6
0
        public void TestCtorReg()
        {
            // Test 2
            try
            {
                List <string> RamContentsData = new List <string>
                {
                    "10101010",
                    "01010101",
                    "10101010",
                    "01010101",
                    "10101010",
                    "01010101",
                    "10101010"
                };
                RAMProgram program = new RAMProgram(RamContentsData);

                List <string> RamContentsResults = program.RamContents;

                if (RamContentsResults.Count != 15)
                {
                    Assert.Fail();
                }
                // Make sure the program copied correctly
                for (int i = 0; i < RamContentsData.Count; i++)
                {
                    Assert.IsTrue(RamContentsResults[i] == RamContentsData[i], $"At index {i}, RamContentsResults != RamContentsData");
                }
                // Make sure the end of the program is padded with 0's
                for (int i = RamContentsData.Count; i < 15; i++)
                {
                    Assert.IsTrue(RamContentsResults[i] == "00000000");
                }
            }
            catch (ArgumentOutOfRangeException e)
            {
                Assert.Fail(e.ToString());
            }
        }
Exemple #7
0
        public void TestCtorOverflow()
        {
            try
            {
                Random        random          = new Random();
                List <string> RamContentsData = new List <string>();

                // Just fill up ram with random data for the heck of it
                for (int i = 0; i <= 0xFFFF; i++)
                {
                    RamContentsData.Add(string.Join("", Convert.ToString(random.Next(), 2).PadLeft(8).Take(8)));
                }

                RAMProgram program = new RAMProgram(RamContentsData);

                Assert.Fail("Ctor did not catch overflow");
            }
            catch (ArgumentOutOfRangeException e)
            {
                Console.Out.WriteLine(e);
                Assert.IsTrue(true);
            }
        }
Exemple #8
0
        // *************************************************************************
        // Init Engine
        // *************************************************************************
        public void Init(RAMProgram program, IDecoder decoder, string InstructionSetName = DefaultInstructionSetName)
        {
            //string log_name = "runtime_log.txt";
            //// Clear Old Log
            //if (File.Exists(log_name))
            //{
            //    File.Delete(log_name);
            //}
            //File.Create(log_name).Close();  // must close the file or the handle will stay open and be locked

            //// Init Logger
            //Log.Logger = new LoggerConfiguration()
            //    .WriteTo.File(log_name)
            //   // .WriteTo.Console()
            //    .CreateLogger();

            //Serilog.Debugging.SelfLog.Enable(msg => Debug.WriteLine(msg));
            //Serilog.Debugging.SelfLog.Enable(Console.Error);

            //Log.Information("SAP1Emu: Begin Engine Initialization");

            // Get Instruction Set
            //Log.Information($"SAP1Emu: Using Instruction Set: \"{InstructionSetName}\"");
            InstructionSet = OpCodeLoader.GetSet(InstructionSetName);
            _decoder       = decoder;

            //_decoder = new InstructionDecoder();

            // Init RAM
            if (program == null)
            {
                this.Program = new RAMProgram(new List <string>());
            }
            this.Program = program;

            //Log.Information("SAP1Emu: Finished Engine Initialization");
        }
Exemple #9
0
        public void TestRamFull()
        {
            RAM ram = new RAM();

            try
            {
                List <string> RamContentsData = new List <string>
                {
                    "10101010",
                    "01010101",
                    "10101010",
                    "01010101",
                    "10101010",
                    "01010101",
                    "10101010",
                    "01010101",
                    "10101010",
                    "01010101",
                    "10101010",
                    "01010101",
                    "10101010",
                    "01010101",
                    "01010101",
                    "01010101"
                };

                RAMProgram rmp = new RAMProgram(RamContentsData);
                ram.LoadProgram(rmp);

                Assert.IsTrue(true);
            }
            catch (Exception e)
            {
                Assert.Fail(e.ToString());
            }
            ram.ClearRAM();
        }
Exemple #10
0
        public void GlobalSetup()
        {
            RP_HLT = new RAMProgram(new List <string>()
            {
                "11110000",
                "00000000",
                "00000000",
                "00000000",
                "00000000",
                "00000000",
                "00000000",
                "00000000",
                "00000000",
                "00000000",
                "00000000",
                "00000000",
                "00000000",
                "00000000",
                "00000000",
                "00000000"
            });

            RP_LDA170 = new RAMProgram(new List <string>()
            {
                "00001111",
                "11100000",
                "11110000",
                "00000000",
                "00000000",
                "00000000",
                "00000000",
                "00000000",
                "00000000",
                "00000000",
                "00000000",
                "00000000",
                "00000000",
                "00000000",
                "00000000",
                "10101010",
            });

            RP_FIB = new RAMProgram(new List <string>()
            {
                "00001110",
                "00011111",
                "00111111",
                "00001111",
                "00111110",
                "00001101",
                "00011100",
                "00111101",
                "10011010",
                "01000000",
                "11100000",
                "11110000",
                "00000001",
                "11111001",
                "00000001",
                "00000001",
            });
        }
Exemple #11
0
        public static void Main(string[] args)
        {
            IDecoder _decoder = new InstructionDecoder();

            _ = Parser.Default.ParseArguments <Options>(args)
                .WithParsed(o =>
            {
                List <string> source_file_contents = new List <string>();;
                FileType fileType = FileType.B;

                if (!string.IsNullOrEmpty(o.SourceFile))
                {
                    if (!File.Exists(o.SourceFile))
                    {
                        Console.Error.WriteLine($"SAP1EMU: error: {o.SourceFile}: No such file");
                        Console.Error.WriteLine($"SAP1EMU: fatal error: no input file");
                        Console.Error.WriteLine("emulation terminated");
                        CheckEnvAndExit();
                    }
                    else        // Check if file is valid
                    {
                        source_file_contents = new List <string>(File.ReadAllLines(o.SourceFile));
                        int loc = source_file_contents.Count;

                        if (o.SourceFile.Length >= 3)
                        {
                            string ftype = o.SourceFile.Substring(o.SourceFile.Length - 2, 2);
                            if (ftype == ".s")
                            {
                                fileType = FileType.S;
                            }
                            else if (ftype == ".b")
                            {
                                fileType = FileType.B;
                            }
                            else
                            {
                                Console.Error.WriteLine($"SAP1EMU: error: {o.SourceFile}: Invalid file extension: Must be <FileName>.s or <FileName>.b");
                                Console.Error.WriteLine($"SAP1EMU: fatal error: no valid input file");
                                Console.Error.WriteLine("emulation terminated.");
                                CheckEnvAndExit();
                            }
                        }

                        if (loc == 0)
                        {
                            Console.Error.WriteLine($"SAP1EMU: error: {o.SourceFile}: File is empty");
                            Console.Error.WriteLine($"SAP1EMU: fatal error: no valid input file");
                            Console.Error.WriteLine("emulation terminated");
                            CheckEnvAndExit();
                        }
                        if (loc > 16)
                        {
                            Console.Error.WriteLine($"SAP1EMU: error: {o.SourceFile}: invalid file: Contains more than 16 lines of code.");
                            Console.Error.WriteLine($"SAP1EMU: fatal error: no valid input file");
                            Console.Error.WriteLine("emulation terminated");
                            CheckEnvAndExit();
                        }
                    }
                    if (!string.IsNullOrEmpty(o.FOframe))
                    {
                        if (o.FOframe.ToLower() != "no-format" && o.FOframe.ToLower() != "std")
                        {
                            Console.Error.WriteLine($"SAP1EMU: warning: {o.SourceFile}: invalid format argument {o.FOframe}: Defaulting to \"std\".");
                            o.FOframe = "std";
                        }
                    }

                    if (o.InstructionSetName.ToLower() != "sap1emu" && o.InstructionSetName.ToLower() != "malvino" && o.InstructionSetName.ToLower() != "beneater")
                    {
                        Console.Error.WriteLine($"SAP1EMU: warning: {o.InstructionSetName}: invalid argument:  Defaulting to \"SAP1Emu\".");
                        o.InstructionSetName = "SAP1Emu";
                    }

                    List <string> compiled_binary = null;

                    if (fileType == FileType.S)
                    {
                        try
                        {
                            compiled_binary = Assemble.Parse(source_file_contents, o.InstructionSetName);
                        }
                        catch (ParseException pe)
                        {
                            //Console.SetOut(new StreamWriter(Console.OpenStandardOutput()));
                            //Console.SetError(new StreamWriter(Console.OpenStandardError()));

                            var tempColor = Console.ForegroundColor;
                            if (Console.BackgroundColor == ConsoleColor.Red)
                            {
                                Console.ForegroundColor = ConsoleColor.Cyan;
                            }
                            else
                            {
                                Console.ForegroundColor = ConsoleColor.Red;
                            }
                            Console.Error.WriteLine($"SAP1ASM: fatal error: " + pe.Message + " " + pe.InnerException.Message);
                            Console.ForegroundColor = tempColor;
                            Console.Error.WriteLine("assembly terminated");

                            Console.Error.Flush();

                            CheckEnvAndExit();
                        }
                    }
                    else
                    {
                        compiled_binary = source_file_contents;
                    }

                    RAMProgram rmp    = new RAMProgram(compiled_binary);
                    EngineProc engine = new EngineProc();

                    //StringBuilder sb_out = new StringBuilder();
                    //TextWriter writer_out = new StringWriter(sb_out);
                    //Console.SetOut(writer_out);

                    //StringBuilder sb_error = new StringBuilder();
                    //TextWriter writer_error = new StringWriter(sb_error);
                    //Console.SetError(writer_error);

                    engine.Init(rmp, _decoder, o.InstructionSetName);
                    try
                    {
                        engine.Run();
                    }
                    catch (EngineRuntimeException ere)
                    {
                        var tempColor = Console.ForegroundColor;
                        if (Console.BackgroundColor == ConsoleColor.Red)
                        {
                            Console.ForegroundColor = ConsoleColor.Cyan;
                        }
                        else
                        {
                            Console.ForegroundColor = ConsoleColor.Red;
                        }

                        //Console.SetOut(new StreamWriter(Console.OpenStandardOutput()));
                        //Console.SetError(new StreamWriter(Console.OpenStandardError()));

                        Console.Error.WriteLine($"SAP1EMU: fatal error: " + ere.Message);
                        Console.ForegroundColor = tempColor;
                        Console.Error.WriteLine("emulation terminated");

                        Console.Error.Flush();

                        CheckEnvAndExit();
                    }

                    string engine_output = "************************************************************\n"
                                           + "Final Output Register Value: " + engine.GetOutputReg()
                                           + "\n************************************************************\n\n";

                    List <Frame> FrameStack = engine.FrameStack();

                    if (o.fframe)
                    {
                        engine_output += "\n" + engine.FinalFrame();
                    }
                    else if (o.Fframe)
                    {
                        StringBuilder sb = new StringBuilder();
                        StringWriter fw  = new StringWriter(sb);

                        foreach (Frame frame in FrameStack)
                        {
                            fw.WriteLine(frame.ToString());
                        }
                        fw.Flush();

                        engine_output += "\n" + sb.ToString();
                    }
                    else if (o.FOframe != null)
                    {
                        engine_output = null;        // Clear the output

                        StringBuilder sb = new StringBuilder();
                        StringWriter fw  = new StringWriter(sb);

                        foreach (Frame frame in FrameStack)
                        {
                            if (frame.TState == 6)
                            {
                                if (o.FOframe.ToLower() == "std")
                                {
                                    fw.WriteLine(frame.OutputRegister());
                                }
                                else if (o.FOframe.ToLower() == "no-format")
                                {
                                    string temp = frame.OReg;
                                    if (string.IsNullOrEmpty(temp))
                                    {
                                        temp = "00000000";
                                    }
                                    fw.WriteLine(temp);
                                }
                            }
                        }
                        fw.Flush();

                        engine_output += sb.ToString();
                    }

                    var standardOutput = new StreamWriter(Console.OpenStandardOutput())
                    {
                        AutoFlush = true
                    };
                    Console.SetOut(standardOutput);

                    var standardError = new StreamWriter(Console.OpenStandardError())
                    {
                        AutoFlush = true
                    };
                    Console.SetError(standardError);

                    //string stdout = sb_out.ToString();
                    //string stderror = sb_error.ToString();

                    File.WriteAllText(o.OutputFile, engine_output);

                    // Start the Single Stepping Debug Session if Debug Flag is set

                    Debug_Proc(o, source_file_contents, FrameStack);
                    Console.Out.WriteLine("Debug Session Complete");

                    //foreach(Frame f in FrameStack)
                    //{
                    //    foreach(string s in f.RAM)
                    //    {
                    //        Console.Out.WriteLine(s);
                    //    }
                    //    Console.Out.WriteLine("\n");
                    //}
                }
            });
        }
        public ActionResult Post([FromBody] EmulatorPacket emulatorPacket)
        {
            EntityEntry <EmulationSessionMap> session;

            try
            {
                session = _sap1EmuContext.Add <EmulationSessionMap>(new EmulationSessionMap
                {
                    EmulationID      = Guid.NewGuid(),
                    ConnectionID     = null,
                    SessionStart     = DateTime.UtcNow,
                    EmulatorId       = _emulatorId,
                    StatusId         = StatusFactory.GetStatus(StatusType.Pending).Id,
                    InstructionSetId = _instructionSets[emulatorPacket.SetName]
                });
                _sap1EmuContext.CodeSubmissions.Add(new CodeSubmission()
                {
                    EmulationID = session.Entity.EmulationID,
                    Code        = emulatorPacket.CodeList,
                });
                _sap1EmuContext.SaveChanges();
            }
            catch (KeyNotFoundException)
            {
                return(BadRequest(
                           // TODO: Set Type to supported_sets url
                           new ProblemDetails()
                {
                    Status = StatusCodes.Status400BadRequest,
                    Type = "",
                    Title = "Invalid SetName...",
                    Detail = $"The Instruction Set `{emulatorPacket.SetName}` does not exist.",
                    Instance = HttpContext.Request.Path
                }
                           ));
            }


            try
            {
                List <string> compiled_binary = Assemble.Parse(emulatorPacket.CodeList, emulatorPacket.SetName);
                RAMProgram    rmp             = new RAMProgram(compiled_binary);

                EngineProc engine = new EngineProc();
                engine.Init(rmp, _decoder, emulatorPacket.SetName);
                engine.Run();

                session.Entity.SessionEnd = DateTime.UtcNow;
                session.Entity.StatusId   = StatusFactory.GetStatus(StatusType.Ok).Id;

                _sap1EmuContext.SaveChanges();
                return(Ok(engine.FrameStack()));
            }
            catch (ParseException pe)
            {
                session.Entity.SessionEnd = DateTime.UtcNow;
                session.Entity.StatusId   = StatusFactory.GetStatus(StatusType.ParsingError).Id;


                if (pe.InnerException != null)
                {
                    string msg = (pe.Message + " " + pe.InnerException.Message);
                    _sap1EmuContext.ErrorLog.Add(new ErrorLog()
                    {
                        EmulationID = session.Entity.EmulationID,
                        ErrorMsg    = msg
                    });

                    _sap1EmuContext.SaveChanges();
                    return(BadRequest(msg));
                }
                else
                {
                    _sap1EmuContext.ErrorLog.Add(new ErrorLog()
                    {
                        EmulationID = session.Entity.EmulationID,
                        ErrorMsg    = pe.Message
                    });

                    _sap1EmuContext.SaveChanges();
                    return(BadRequest(pe.Message));
                }
            }
            catch (EngineRuntimeException ere)
            {
                session.Entity.SessionEnd = DateTime.UtcNow;
                session.Entity.StatusId   = StatusFactory.GetStatus(StatusType.EmulationError).Id;

                if (ere.InnerException != null)
                {
                    string msg = (ere.Message + " " + ere.InnerException.Message);
                    _sap1EmuContext.ErrorLog.Add(new ErrorLog()
                    {
                        EmulationID = session.Entity.EmulationID,
                        ErrorMsg    = msg
                    });

                    _sap1EmuContext.SaveChanges();
                    return(BadRequest(ere.Message + " " + ere.InnerException.Message));
                }
                else
                {
                    _sap1EmuContext.ErrorLog.Add(new ErrorLog()
                    {
                        EmulationID = session.Entity.EmulationID,
                        ErrorMsg    = ere.Message
                    });

                    _sap1EmuContext.SaveChanges();
                    return(BadRequest(ere.Message));
                }
            }
            catch (Exception e)
            {
                session.Entity.SessionEnd = DateTime.UtcNow;
                session.Entity.StatusId   = StatusFactory.GetStatus(StatusType.SystemError).Id;

                _sap1EmuContext.ErrorLog.Add(new ErrorLog()
                {
                    EmulationID = session.Entity.EmulationID,
                    ErrorMsg    = e.Message
                });

                _sap1EmuContext.SaveChanges();
                return(StatusCode(StatusCodes.Status500InternalServerError, e.Message));
            }
        }
Exemple #13
0
        public IActionResult StartEmulation([FromBody] SAP2CodePacket sap2CodePacket)
        {
            EmulationSessionMap session = null;

            try
            {
                session = _sap1EmuContext.EmulationSessionMaps
                          .Single(esm => esm.EmulationID == sap2CodePacket.EmulationID);
            }
            catch (InvalidOperationException)
            {
                return(BadRequest(sap2CodePacket.EmulationID));
            }


            if (session.StatusId != (int)StatusType.Pending)
            {
                string message = string.Empty;
                switch ((StatusType)session.StatusId)
                {
                case StatusType.Ok:
                    message = "Emulation Complete: Please use 'GET: /session/{id}/recall' instead";
                    break;

                case StatusType.SQLError:
                case StatusType.ParsingError:
                case StatusType.EmulationError:
                case StatusType.SystemError:
                    message = "Emulation Errored: Please create new session";
                    break;

                case StatusType.InProgress:
                    message = "Emulation In Progress: Please use 'POST: /{id}/resume' instead";
                    break;

                default:
                    message = "Unknown Host Error";
                    break;
                }

                return(BadRequest(
                           new
                {
                    EmulationID = sap2CodePacket.EmulationID,
                    Status = StatusFactory.GetStatus((StatusType)session.StatusId),
                    Message = message
                }
                           ));
            }


            // This will save the plain code
            try
            {
                _sap1EmuContext.CodeSubmissions.Add(
                    new CodeSubmission()
                {
                    EmulationID = session.EmulationID,
                    Code        = sap2CodePacket.Code
                }
                    );
                _sap1EmuContext.SaveChanges();
            }
            catch (Exception e)
            {
                _sap1EmuContext.ErrorLog.Add(
                    new ErrorLog
                {
                    EmulationID = session.EmulationID,
                    ErrorMsg    = "NON-FATAL SQL ERROR:\t" + e.Message + (e.InnerException != null ? "\t" + e.InnerException.Message : "")
                }
                    );
                //session.SessionEnd = DateTime.UtcNow;
                session.StatusId = (int)StatusType.SQLError;

                _sap1EmuContext.SaveChanges();
            }


            SAP2BinaryPacket sap2BinaryPacket;

            // Assemble
            try
            {
                sap2BinaryPacket = new SAP2BinaryPacket()
                {
                    EmulationID = sap2CodePacket.EmulationID,
                    Code        = Assemble.Parse((List <string>)sap2CodePacket.Code),
                    SetName     = sap2CodePacket.SetName
                };
            }
            catch (ParseException pe)
            {
                session.StatusId   = (int)StatusType.ParsingError;
                session.SessionEnd = DateTime.UtcNow;

                string errorMsg = pe.Message + (pe.InnerException != null ? "\n" + pe.InnerException.Message : "");
                _sap1EmuContext.ErrorLog.Add(
                    new ErrorLog
                {
                    EmulationID = session.EmulationID,
                    ErrorMsg    = errorMsg
                }
                    );

                _sap1EmuContext.SaveChanges();
                return(BadRequest(
                           new
                {
                    EmulationID = sap2CodePacket.EmulationID,
                    Status = StatusFactory.GetStatus((StatusType)session.StatusId),
                    Message = errorMsg
                }
                           ));
            }


            // Save Binary
            try
            {
                _sap1EmuContext.CodeSubmissionsBinary.Add(
                    new CodeSubmission()
                {
                    EmulationID = session.EmulationID,
                    Code        = sap2BinaryPacket.Code
                }
                    );
                _sap1EmuContext.SaveChanges();
            }
            catch (Exception e)
            {
                _sap1EmuContext.ErrorLog.Add(
                    new ErrorLog
                {
                    EmulationID = session.EmulationID,
                    ErrorMsg    = "NON-FATAL SQL ERROR:\t" + e.Message + (e.InnerException != null ? "\t" + e.InnerException.Message : "")
                }
                    );

                session.SessionEnd = DateTime.UtcNow;
                session.StatusId   = (int)StatusType.SystemError;

                _sap1EmuContext.SaveChanges();
            }


            // Run Emulator
            try
            {
                RAMProgram rmp = new RAMProgram((List <string>)sap2BinaryPacket.Code);

                EngineProc engine = new EngineProc();
                engine.Init(rmp, _decoder, sap2BinaryPacket.SetName);
                engine.Run();

                session.StatusId   = (int)StatusType.Ok;
                session.SessionEnd = DateTime.UtcNow;
                _sap1EmuContext.SaveChanges();

                return(Ok(engine.FrameStack()));
            }
            catch (EngineRuntimeException ere)
            {
                session.StatusId   = (int)StatusType.EmulationError;
                session.SessionEnd = DateTime.UtcNow;

                string errorMsg = ere.Message + (ere.InnerException != null ? "\n" + ere.InnerException.Message : "");
                _sap1EmuContext.ErrorLog.Add(
                    new ErrorLog
                {
                    EmulationID = session.EmulationID,
                    ErrorMsg    = errorMsg
                }
                    );
                _sap1EmuContext.SaveChanges();
                return(BadRequest(
                           new
                {
                    EmulationID = sap2CodePacket.EmulationID,
                    Status = StatusFactory.GetStatus((StatusType)session.StatusId),
                    Message = errorMsg
                }
                           ));
            }
        }