Exemple #1
0
        protected override ScriptEventResult OnScriptCall(SciterElement element, MethodInfo method, SciterValue[] args)
        {
            var r = SciterImage.Create(args[0]);
            var b = r.Save(ImageEncoding.Png);

            File.WriteAllBytes("d:/test.png", b);

            return(ScriptEventResult.Successful());
        }
Exemple #2
0
        public async Task Invalid_return_type_on_method_fails_to_execute(string methodName)
        {
            var    cSource           = new CancellationTokenSource(TimeSpan.FromSeconds(3));
            string actualMethodName  = null;
            var    scriptEventResult = ScriptEventResult.Successful();

            await Task.Run(() =>
            {
                var sciterWindow =
                    new SciterWindow()
                    .CreateMainWindow(320, 240)
                    .CenterWindow()
                    .SetTitle(nameof(SciterGraphicsTests));

                var host = new TestHost(sciterWindow);

                host.AttachEventHandler(() => new TestEventHandler(
                                            onScriptCallCallback: (element, info, args, result) =>
                {
                    actualMethodName  = info.Name;
                    scriptEventResult = result;
                    sciterWindow?.Close();
                }));

                var pageData = "<html><head><style></style>" +
                               "<script type=\"text/tiscript\"> " +
                               $"view.{methodName}();" +
                               "</script>" +
                               "</head></html>";

                host.Window.LoadHtml(pageData);

                host.Window.Show();

                TranslateAndDispatch(cSource.Token);
            }, cSource.Token);

            Assert.NotNull(actualMethodName);
            Assert.AreEqual(methodName, actualMethodName);
            Assert.IsFalse(scriptEventResult.IsSuccessful);
            Assert.IsNull(scriptEventResult.Value);
            Assert.IsFalse(cSource.IsCancellationRequested);
        }