Exemple #1
0
        protected override void OnLoad(EventArgs evt)
        {
            base.OnLoad(evt);

            var contentControl = new SciterControl();

            var openButton = new ButtonControl() { Selector = "#open" };
            var reloadButton = new ButtonControl() { Selector = "#reload" };
            var content = new BindableControl() { Selector = "#content" };

            Action resizeContent = () =>
                {
                    var rect = content.Element.GetLocation(ElementLocation.ContentBox);
                    contentControl.Top = rect.Top;
                    contentControl.Left = rect.Left;
                    contentControl.Width = rect.Width;
                    contentControl.Height = rect.Height;
                };

            content.Attached += (s, e) => resizeContent();
            content.Size += (s, e) => resizeContent();

            reloadButton.Click += (s, e) =>
                {
                    contentControl.Reload();
                };

            openButton.Click += (s, e) =>
                {
                    var dlg = new OpenFileDialog() { Filter = "Html files (*.htm)|*.htm|All files (*.*)|*.*" };
                    if (dlg.ShowDialog() == DialogResult.OK)
                        contentControl.LoadHtmlResource(FileProtocol.ProtocolPrefix + dlg.FileName);
                };

            SciterControls.Add(openButton);
            SciterControls.Add(reloadButton);
            SciterControls.Add(content);

            ScriptingMethodCall += (s, e) =>
                {
                    switch (e.MethodName)
                    {
                        case "application_name": // Returns application title
                            e.ReturnValue = Text;
                            break;
                    }
                };

            contentControl.HandleCreated += (s, e) => contentControl.RegisterClass<Scripting.Application>();
            contentControl.ScriptingMethodCall += (s, e) =>
                {
                    switch (e.MethodName)
                    {
                        case "application_name": // Returns application title
                            e.ReturnValue = Text;
                            break;
                        case "sum": // Returns sum of two arguments
                            e.ReturnValue = Convert.ToDouble(e.Arguments[0]) + Convert.ToDouble(e.Arguments[1]);
                            break;
                        case "echo":
                            e.ReturnValue = e.Arguments[0];
                            break;
                        case "dict":
                            e.ReturnValue = new { first = 1, second = 2, third = 3 };
                            break;
                        case "callback":
                            contentControl.Call("callback", "hello");
                            contentControl.Call("callback", 1);
                            contentControl.Call("callback", true);
                            contentControl.Call("callback", 1.0);
                            contentControl.Call("callback", DateTime.Now);
                            contentControl.Call("callback", 1M);
                            contentControl.Call("callback", new byte[] { 0x1, 0x2, 0x3} );
                            break;
                    }
                };

            Controls.Add(contentControl);
            LoadHtmlResource<MainForm>("Html/Default.htm");
        }
Exemple #2
0
        /// <summary>
        /// Form initialization
        /// </summary>
        protected override void OnLoad(EventArgs args)
        {
            base.OnLoad(args);
            AutoValidate = AutoValidate.EnablePreventFocusChange;

            var options = new TestOptions()
            {
                DatabasePath = GetDefaultDatabasePath(),
                RecordsCount = 1000
            };

            var container = new Container();
            Disposed += (s, evt) => container.Dispose();

            // Update window title
            DocumentComplete += (s, evt) => Text = String.IsNullOrEmpty(Text) ? RootElement.Find("title").Text : Text;

            var providers_list = new BindingSource();

            var providers = new ListBoxControl() { Selector = "#database_provider", DataSource = providers_list };
            providers.Format += (s, e) => e.Value = ((Type)e.Value).Name;

            var new_database = new CheckBoxControl() { Selector = "#new_database" };
            new_database.DataBindings.Add("Checked", options, "CreateDatabase");

            var records_count = new TextBoxControl() { Selector = "#records_count" };
            records_count.DataBindings.Add("Text", options, "RecordsCount", true);

            var records_count_binding = records_count.DataBindings["Text"];
            records_count_binding.BindingComplete += (s, e) =>
            {
                if (options.RecordsCount < 0)
                {
                    records_count.Attributes["error"] = "true";
                    e.Cancel = true;
                }
                else
                    records_count.Attributes["error"] = null;
            };

            var selection_test = new CheckBoxControl() { Selector = "#selection_test" };
            selection_test.DataBindings.Add("Checked", options, "SelectionTest");

            var resultset_test = new CheckBoxControl() { Selector = "#resultset_test" };
            resultset_test.DataBindings.Add("Checked", options, "ResultSetTest");

            var metrics_grid = new DataGridControl() { Selector = "#metrics_grid" };
            var start_button = new ButtonControl() { Selector = "#start_tests" };
            start_button.Click += delegate
            {
                if (PerformValidation())
                {
                    metrics_grid.DataSource = Enumerable.Empty<Metric>();
                    metrics_grid.Element.Update(true);

                    var metricResults = RunProviderTests((Type)providers_list.Current, options);
                    metrics_grid.DataSource = metricResults;
                }
            };

            providers_list.CurrentItemChanged += (s, e) =>
            {
                var exists = IsDatabaseExists((Type)providers_list.Current, options);
                if (exists)
                {
                    new_database.IsEnabled = true;
                }
                else
                {
                    options.CreateDatabase = true;
                    new_database.IsEnabled = false;
                }
            };
            providers_list.DataSource = new Type[]
            {
                typeof(Provider.SqlCe.SqlCeProviderTest),
                typeof(Provider.SQLite.SQLiteProviderTest)
            };

            container.Add(providers_list);

            SciterControls.Add(records_count);
            SciterControls.Add(new_database);
            SciterControls.Add(selection_test);
            SciterControls.Add(resultset_test);
            SciterControls.Add(metrics_grid);
            SciterControls.Add(providers);
            SciterControls.Add(start_button);

            LoadHtmlResource<MainForm>("Html/Default.htm");
        }