Skip to content

Virtual machine written in C #. It allows you to perform / emulate the compiled .net code (IL). The code is executed instruction by instruction. (Virtual machine emulates all instructions from IL) Execute code can be hibernated and then restarted (even on another machine after serialization)

License

neurosystemeu/Virtual-Machine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 

Repository files navigation

New version on

https://github.com/cv-lang/application-server

Virtual-Machine

Version during the translation - I'm sorry for the mistakes

Virtual machine written in C #. It allows you to perform / emulate the compiled .net code (IL). The code is executed instruction by instruction. (Virtual machine emulates all instructions from IL) Execute code can be hibernated and then restarted (even on another machine after serialization)

##Example

simple process / workflow written in C# with hibernation - serialization

An example of a process that will be executed on the virtual-machine.

public class HibernateWorkflowSimple
{
    public int InputParametr { get; set; }
    public string Start()
    {
        //do some work
        for (int i = 0; i < 10; i++)
        {
            SomeInterpretedFunction();
        }

        //hibernate executed method
        VirtualMachine.VirtualMachine.Hibernate();

        //after resume
        //do some work
        for (int i = 0; i < 10; i++)
        {
            SomeInterpretedFunction();
        }

        return "Helow World " + InputParametr;
    }

    public void SomeInterpretedFunction()
    {
        //do some work
        InputParametr++;
    }
}

full code

launching

var proces = new HibernateWorkflowSimple() { InputParametr = 10 };
var vm = new VirtualMachine.VirtualMachine();
vm.Start(proces); //execution to the end or to hibernate. At production should check the status of a virtual machine
var serializedVMXml = vm.Serialize(); 

/////////////////////
// we can deserialize and execute on a different computer
var vmNew = VirtualMachine.VirtualMachine.Deserialize(serializedVMXml);
var retFromSerializedVM = vmNew.Resume();

//compare the result with the normal execution process
var inProcProces = new HibernateWorkflowSimple() { InputParametr = 10 };
var retInProcProces = inProcProces.Start();
Assert.AreEqual(retInProcProces, retFromSerializedVM);

Full test

the process with interpreted functions (subfunctions)

public class HibernateWorkflow
{
    public int InputParametr { get; set; }
    public string Start()
    {
        //do some work
        for (int i = 0; i < 10; i++)
        {
            SomeInterpretedFunction();
        }

        //after restore (in another thread/computer)
        //do some work
        for (int i = 0; i < 10; i++)
        {
            SomeInterpretedFunction();
        }

        return "Helow World " + InputParametr;
    }

    [Interpret]
    public void SomeInterpretedFunction()
    {
        //do some work
        InputParametr++;

        //hibernate executed method
        VirtualMachine.VirtualMachine.Hibernate();
    }
}

full code

launching

 var proces = new HibernateWorkflowSimple() { InputParametr = 10 };
var vm = new VirtualMachine.VirtualMachine();
vm.Start(proces);
var serializedVMXml = vm.Serialize();
object retFromSerializedVM = "";

while (vm.Status == VirtualMachineState.Hibernated)
{
    vm = VirtualMachine.VirtualMachine.Deserialize(serializedVMXml);
    retFromSerializedVM = vm.Resume();
    serializedVMXml = vm.Serialize();
}

var inProcProces = new HibernateWorkflowSimple() { InputParametr = 10 };
var retInProcProces = inProcProces.Start();
Assert.AreEqual(retInProcProces, retFromSerializedVM);

Dependencies

Mono.Cecil - will be removed

Mono.Reflection

sharpSerializer

Used in

Native-Workflow - workflow engine for long run process/workflow. Allow to serialize executed workflow and resume. It has a fluent GUI through a process can communicate with the user. (WWW and Console GUI)

About

Virtual machine written in C #. It allows you to perform / emulate the compiled .net code (IL). The code is executed instruction by instruction. (Virtual machine emulates all instructions from IL) Execute code can be hibernated and then restarted (even on another machine after serialization)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages