Example #1
0
 public AppDomainIsolator(AppDomainOptions options = null)
 {
     _options = options ?? AppDomainOptions.GetDefault();
 }
Example #2
0
 public AppDomainIsolator(AppDomainOptions options = null)
 {
     _options = options ?? AppDomainOptions.GetDefault();
 }
        private void Run()
        {
            var appOptions = new AppDomainOptions();
            appOptions.Permissions.AddPermission(new SecurityPermission(SecurityPermissionFlag.UnmanagedCode));

            var isolator = new AppDomainIsolator(appOptions);
            var environment = new DefaultEnvironment();
            environment.Register(sInfo.assemblyPath);

            InteractionObject accessApi = new InteractionObject();

            using (var jail = Jail.Create(isolator, environment)) {
                var watch = new Stopwatch();
                var localSInfo = sInfo;
                main.window.updateScriptInfo(localSInfo);
                IAbstractScript mainClass = jail.Resolve<IAbstractScript>(sInfo.mainScript.FullName);

                mainClass._setApi(null);

                new RunUntil(() => mainClass.init(), delegate () { return localSInfo.run; });

                new Thread(() => mainClass.start()).Start();

                while (localSInfo.run) {
                    watch.Start();

                    new RunUntil(() => mainClass.tick(), delegate () { return localSInfo.run; });

                    var time = watch.ElapsedMilliseconds;
                    watch.Reset();

                    if(debug) Console.WriteLine(time);

                    Thread.Sleep(100);
                    // This will fail since the isolator has not been given
                    // FileIO permissions to that location.
                    //byte[] data = bar.ReadFile("C:\\Temp\\File.txt");
                }
                new Thread(() => mainClass.dispose()).Start();
            }
        }