예제 #1
0
		async void HandleRequest (HttpListenerContext c)
		{
			try {

				var path = c.Request.Url.AbsolutePath;
				var resString = "";

				Log ("REQ ON THREAD {0} {1}", Thread.CurrentThread.ManagedThreadId, path);

				if (path == "/stopVisualizing") {
					try {
						resString = await Task.Factory.StartNew (() => {
							visualizer.StopVisualizing ();
							return "";
						}, CancellationToken.None, TaskCreationOptions.None, mainScheduler);
					} catch (Exception ex) {
						Log (ex, "/stopVisualizing");
					}
				}
				else {
					var reqStr = await new StreamReader (c.Request.InputStream, Encoding.UTF8).ReadToEndAsync ().ConfigureAwait (false);

//					Log (reqStr);

					var req = JsonConvert.DeserializeObject<EvalRequest> (reqStr);

					var resp = await Task.Factory.StartNew (() => {
						var r = new EvalResponse ();
						try {
							r = vm.Eval (req.Code);
						}
						catch (Exception ex) {
							Log (ex, "vm.Eval");
						}
						try {
							Visualize (req, r);
						}
						catch (Exception ex) {
							Log (ex, "Visualize");
						}
						return Tuple.Create (r, JsonConvert.SerializeObject (r));
					}, CancellationToken.None, TaskCreationOptions.None, mainScheduler);

					Log (resp.Item2);

					resString = resp.Item2;
				}

				var bytes = Encoding.UTF8.GetBytes (resString);
				c.Response.StatusCode = 200;
				c.Response.ContentLength64 = bytes.LongLength;
				await c.Response.OutputStream.WriteAsync (bytes, 0, bytes.Length).ConfigureAwait (false);

			} catch (Exception ex) {
				Log (ex, "HandleRequest");
				c.Response.StatusCode = 500;
			} finally {
				c.Response.Close ();
			}
		}
예제 #2
0
    void Awake()
    {
        _scannerIn    = FindObjectOfType <ScannerInHandler>();
        _evalResponse = FindObjectOfType <EvalResponse>();
        _gameManager  = TaskSettingsManager.TaskSettings;

        //get stim duration from config
        float.TryParse(_gameManager.StimDuration, out _stimDuration);

        //loading sprites into array...
        _spriteArray    = Resources.LoadAll <Sprite>("Sprites/Digits");
        _waitingSprites = Resources.LoadAll <Sprite>("Sprites/Others");

        //array of digits to guide order of stimuli presentation...
        _practiceBlock.InsertRange(_practiceBlock.Count, new List <int> {
            6, 0, 3, 7, 0, 8, 9, 6, 1, 4, 5, 0, 3, 9, 6, 2, 0, 7, 6, 5, 0, 8, 5, 0, 2, 5, 1, 6, 8, 0, 4, 3, 0, 4, 2, 5, 8, 1, 0, 7, 6, 0, 2, 0, 7, 8, 0, 3, 9, 0, 4, 2, 1, 0, 8, 3, 0, 5, 9, 4, 0, 9, 7, 1, 0, 3, 5, 2, 8, 9, 0, 7, 0, 2, 1, 4, 0, 6, 4, 7, 6, 0, 3, 7, 0, 8, 9, 6, 1, 4, 5, 0, 3, 9, 6, 2, 0, 7, 6, 5, 0, 8, 5, 0, 2, 5, 1, 6, 8, 0, 4, 3, 0, 4, 2, 5, 8, 1, 0, 7, 6, 0, 2, 0, 7, 8, 0, 3, 9, 0, 4, 2, 1, 0, 8, 3, 0, 5, 9, 4, 0, 9, 7, 1, 0, 3, 5, 2, 8, 9, 0, 7, 0, 2, 1, 4, 0, 6, 4, 7
        });
        _trialBlock.InsertRange(_trialBlock.Count, new List <int> {
            6, 0, 3, 7, 0, 8, 9, 6, 1, 4, 5, 0, 3, 9, 6, 2, 0, 7, 6, 5, 0, 8, 5, 0, 2, 5, 1, 6, 8, 0, 4, 3, 0, 4, 2, 5, 8, 1, 0, 7, 6, 0, 2, 0, 7, 8, 0, 3, 9, 0, 4, 2, 1, 0, 8, 3, 0, 5, 9, 4, 0, 9, 7, 1, 0, 3, 5, 2, 8, 9, 0, 7, 0, 2, 1, 4, 0, 6, 4, 7
        });
        _jitterFull.InsertRange(_jitterFull.Count, new List <float> {
            1500, 1250, 750, 1250, 1000, 750, 750, 1500, 1000, 750, 1000, 1000, 750, 1500, 750, 750, 1000, 1500, 750, 1250, 1000, 1000, 1250, 750, 1500, 750, 1000, 1000, 750, 750, 1000, 1750, 750, 750, 1250, 750, 750, 750, 750, 1000, 750, 750, 750, 750, 750, 1750, 1250, 750, 750, 750, 1000, 1500, 1000, 1250, 1000, 1250, 1000, 750, 1250, 750, 1250, 750, 1000, 1000, 750, 1750, 750, 1000, 750, 750, 1250, 1000, 750, 1250, 1000, 1500, 750, 1000, 1250, 750
        });

        ////debug purposes only
        _deBug.InsertRange(_deBug.Count, new List <int> {
            6, 0, 3, 7, 0
        });
    }
예제 #3
0
        public async Task AssertThat_CSharpUtilsGlobals_Work()
        {
            var service = new EvalCSharpHandler();

            EvalResponse response = await service.EvalCSharpPrivate(new EvalRequest { Code = "ListOf(1, 2, 3)" });

            Assert.Equal("System.Collections.Generic.List`1[System.Int32]", response.Result);
        }
예제 #4
0
        public async Task AssertThat_CSharpUtilsExtenders_Work()
        {
            var service = new EvalCSharpHandler();

            EvalResponse response = await service.EvalCSharpPrivate(new EvalRequest { Code = "new List<String>().NotContains(\"empty\")" });

            Assert.Equal("True", response.Result);
        }
예제 #5
0
        public async Task AssertThat_CSharpUtils_Works()
        {
            var service = new EvalCSharpHandler();

            EvalResponse response = await service.EvalCSharpPrivate(new EvalRequest { Code = "Optional.OfNullable(\"text\")" });

            Assert.Equal("Optional(text)", response.Result);
        }
예제 #6
0
        public async Task AssertThat_ClassDeclarations_Work()
        {
            var service = new EvalCSharpHandler();

            EvalResponse response = await service.EvalCSharpPrivate(new EvalRequest { Code = "public class Test { public String Foo => \"Hullo!\"; } new Test().Foo" });

            Assert.Equal("Hullo!", response.Result);
        }
예제 #7
0
        public async Task AssertThat_LinqImportsWork()
        {
            var service = new EvalCSharpHandler();

            EvalResponse response = await service.EvalCSharpPrivate(new EvalRequest { Code = "new [] { 0, 1, 2, 3, 4, }.Where(it => it < 3).Select(it => it.ToString()).ToList().Aggregate((l, r) => l + \", \" + r)" });

            Assert.Equal("0, 1, 2", response.Result);
        }
예제 #8
0
        public async Task AssertThat_ImportsWork()
        {
            var service = new EvalCSharpHandler();

            EvalResponse response = await service.EvalCSharpPrivate(new EvalRequest { Code = "Int32.MaxValue" });

            Assert.Equal("2147483647", response.Result);
        }
예제 #9
0
        public async Task AssertThat_ConsoleLogging_IsEvaluated()
        {
            var service = new EvalCSharpHandler();

            EvalResponse response = await service.EvalCSharpPrivate(new EvalRequest { Code = "Console.WriteLine(\"Hello, World!\")" });

            Assert.Equal("Result: null\r\nOutput:\r\nHello, World!\r\n", response.Result);
        }
예제 #10
0
        public async Task AssertThat_HelloWorld_IsEvaluated()
        {
            var service = new EvalCSharpHandler();

            EvalResponse response = await service.EvalCSharpPrivate(new EvalRequest { Code = "\"Hello, World!\"" });

            Assert.Equal("Hello, World!", response.Result);
        }
예제 #11
0
partial         void PlatformVisualize(EvalRequest req, EvalResponse resp)
        {
            var val = resp.Result;
            var ty = val != null ? val.GetType () : typeof(object);

            Log ("{0} value = {1}", ty.FullName, val);

            ShowViewer (GetViewer (req, resp));
        }
예제 #12
0
        async Task <HttpResponse> HandleNewXaml(HttpRequest request)
        {
            JsonHttpResponse response = new JsonHttpResponse();

            StreamReader sr   = new StreamReader(request.Body, Encoding.UTF8);
            string       json = await sr.ReadToEndAsync();

            EvalRequest  evalRequest  = Serializer.DeserializeJson <EvalRequest>(json);
            EvalResponse evalResponse = new EvalResponse();

            response.Data = evalResponse;
            EvalResult result = null;

            try
            {
                result = await vm.Eval(evalRequest, mainScheduler, CancellationToken.None);

                evalResponse.Messages = result.Messages;
                evalResponse.Duration = result.Duration;
                Log.Information($"Visualizing result {result.Result}");
                if (result.HasResult)
                {
                    var tcs = new TaskCompletionSource <bool>();
                    Xamarin.Forms.Device.BeginInvokeOnMainThread(async() =>
                    {
                        try
                        {
                            await previewer.Preview(result);
                            tcs.SetResult(true);
                        }
                        catch (Exception ex)
                        {
                            await previewer.NotifyError(new ErrorViewModel("Oh no! An exception!", ex));
                            tcs.SetException(ex);
                        }
                    });
                    await tcs.Task;
                }
                else
                {
                    Xamarin.Forms.Device.BeginInvokeOnMainThread(async() =>
                    {
                        await previewer.NotifyError(new ErrorViewModel("Oh no! An evaluation error!", result));
                    });
                }
                return(response);
            }
            catch (Exception ex)
            {
                Log.Exception(ex);
                response.StatusCode = HttpStatusCode.InternalServerError;
                return(response);
            }
        }
예제 #13
0
		partial void PlatformVisualize (EvalRequest req, EvalResponse resp)
		{
			var val = resp.Result;
			var ty = val != null ? val.GetType () : typeof(object);

			Log ("{0} value = {1}", ty.FullName, val);

			ShowViewerAsync (GetViewer (req, resp)).ContinueWith (t => {
				if (t.IsFaulted) {
					Log ("ShowViewer ERROR {0}", t.Exception);
				}
			});
		}
예제 #14
0
		UIViewController GetViewer (EvalRequest req, EvalResponse resp)
		{
			var vc = resp.Result as UIViewController;

			if (vc != null)
				return vc;


			var v = GetSpecialView (resp.Result);

			if (v != null) {
				vc = new UIViewController ();
				vc.View = v;
			}
			else {
				vc = new ObjectInspector (resp.Result);
			}
			return vc;
		}
예제 #15
0
        async Task HandleEvalRequest(EvalRequest request)
        {
            EvalResponse evalResponse = new EvalResponse();
            EvalResult   result;

            try
            {
                result = await vm.Eval(request, mainScheduler, CancellationToken.None);

                if (result.HasResult)
                {
                    var tcs = new TaskCompletionSource <bool>();
                    Xamarin.Forms.Device.BeginInvokeOnMainThread(async() =>
                    {
                        try
                        {
                            await previewer.Preview(result);
                            tcs.SetResult(true);
                        }
                        catch (Exception ex)
                        {
                            errorViewModel.SetError("Oh no! An exception!", ex);
                            await previewer.NotifyError(errorViewModel);
                            tcs.SetException(ex);
                        }
                    });
                    await tcs.Task;
                }
                else
                {
                    Xamarin.Forms.Device.BeginInvokeOnMainThread(async() =>
                    {
                        errorViewModel.SetError("Oh no! An evaluation error!", result);
                        await previewer.NotifyError(errorViewModel);
                    });
                }
            }
            catch (Exception ex)
            {
                Log.Exception(ex);
            }
        }
예제 #16
0
        async Task HandleEvalRequest(EvalRequestMessage request)
        {
            EvalResponse evalResponse = new EvalResponse();
            EvalResult   result;

            try
            {
                result = await vm.Eval(request, mainScheduler, CancellationToken.None);

                if (result.HasResult || result.ResultType != null)
                {
                    await uiToolkit.RunInUIThreadAsync(async() =>
                    {
                        try
                        {
                            await previewer.Preview(result);
                        }
                        catch (Exception ex)
                        {
                            errorViewModel.SetError("Oh no! An exception!", ex);
                            await previewer.NotifyError(errorViewModel);
                        }
                    });
                }
                else
                {
                    await uiToolkit.RunInUIThreadAsync(async() =>
                    {
                        errorViewModel.SetError("Oh no! An evaluation error!", result);
                        await previewer.NotifyError(errorViewModel);
                    });
                }
            }
            catch (Exception ex)
            {
                Log.Exception(ex);
            }
        }
예제 #17
0
 object GetViewer(EvalRequest req, EvalResponse resp)
 {
     return resp.Result;
 }
예제 #18
0
 // Use this for initialization
 void Awake()
 {
     _taskEngine   = FindObjectOfType <TaskEngine>();
     _configView   = FindObjectOfType <ConfigureViewModel>();
     _evalResponse = FindObjectOfType <EvalResponse>();
 }
예제 #19
0
        async void HandleRequest(HttpListenerContext c)
        {
            try {
                var path      = c.Request.Url.AbsolutePath;
                var resString = "";

                Log("REQ ON THREAD {0} {1}", Thread.CurrentThread.ManagedThreadId, path);

                if (path == "/watchChanges")
                {
                    try {
                        var reqStr = await new StreamReader(c.Request.InputStream, Encoding.UTF8).ReadToEndAsync().ConfigureAwait(false);
                        var req    = JsonConvert.DeserializeObject <WatchChangesRequest> (reqStr);
                        resString = JsonConvert.SerializeObject(await GetWatchChangesAsync(req));
                    } catch (Exception ex) {
                        Log(ex, "/watchChanges");
                    }
                }
                else if (path == "/stopVisualizing")
                {
                    try {
                        resString = await Task.Factory.StartNew(() => {
                            visualizer.StopVisualizing();
                            return("");
                        }, CancellationToken.None, TaskCreationOptions.None, mainScheduler);
                    } catch (Exception ex) {
                        Log(ex, "/stopVisualizing");
                    }
                }
                else
                {
                    var reqStr = await new StreamReader(c.Request.InputStream, Encoding.UTF8).ReadToEndAsync().ConfigureAwait(false);

//					Log (reqStr);

                    var req = JsonConvert.DeserializeObject <EvalRequest> (reqStr);

                    var token = CancellationToken.None;

                    var resp = await Task.Factory.StartNew(() => {
                        WatchStore.Clear();
                        var r = new EvalResult();
                        try {
                            r = vm.Eval(req, mainScheduler, token);
                        }
                        catch (Exception ex) {
                            Log(ex, "vm.Eval");
                        }
                        try {
                            Task.Factory.StartNew(() =>
                            {
                                Visualize(r);
                            }, token, TaskCreationOptions.None, mainScheduler).Wait();
                        }
                        catch (Exception ex) {
                            Log(ex, "Visualize");
                        }
                        var response = new EvalResponse {
                            Messages    = r.Messages,
                            WatchValues = WatchStore.Values,
                            Duration    = r.Duration,
                        };
                        return(Tuple.Create(r, JsonConvert.SerializeObject(response)));
                    }, token);

                    Log(resp.Item2);

                    resString = resp.Item2;
                }

                var bytes = Encoding.UTF8.GetBytes(resString);
                c.Response.StatusCode      = 200;
                c.Response.ContentLength64 = bytes.LongLength;
                await c.Response.OutputStream.WriteAsync(bytes, 0, bytes.Length).ConfigureAwait(false);
            } catch (Exception ex) {
                Log(ex, "HandleRequest");
                c.Response.StatusCode = 500;
            } finally {
                c.Response.Close();
            }
        }
예제 #20
0
partial         void PlatformVisualize(EvalRequest req, EvalResponse resp);
예제 #21
0
 public void Visualize(EvalRequest req, EvalResponse resp)
 {
     PlatformVisualize (req, resp);
 }
예제 #22
0
 async Task UpdateEditorAsync (LinkedCode code, EvalResponse resp)
 {
     await UpdateEditorWatchesAsync (code.Types.SelectMany (x => x.Watches), resp.WatchValues);
 }
예제 #23
0
 async Task UpdateEditorAsync(LinkedCode code, EvalResponse resp)
 {
     await UpdateEditorWatchesAsync(code.Types.SelectMany(x => x.Watches), resp.WatchValues);
 }
예제 #24
0
		void Visualize (EvalRequest req, EvalResponse resp)
		{
			if (!resp.HasResult) {
				return;
			}
			visualizer.Visualize (req, resp);
		}