Esempio n. 1
0
        public static void Exec(this ExecWindow window)
        {
            string     cmd      = window.textCmd.Text;
            WebBrowser htmlCtrl = window.result.web1;

            htmlCtrl.NavigateToString(cmd);
            ExecResult.Exec(window, cmd, htmlCtrl);
        }
Esempio n. 2
0
        public static void Init(this ExecWindow window)
        {
#if MSHTML
            WebWpfHelper.Prepare(window.result.web1);
            window.result.webCS.Prepare();
            window.result.webTSql.Prepare();
#endif

            window.textCmd.GotFocus += (s, e) =>
            {
                if (!window.isFirst)
                {
                    window.textCmd.Text = "";
                    window.isFirst      = true;
                }
            };
            object data        = Data;
            var    dataMutable = ExpandoConvert.Muttable(data);
            window.DataContext = dataMutable;

            window.cmdExec.Click  += (s, e) => window.Exec();
            window.cmdPaste.Click += (s, e) => window.Paste();
            window.textCmd.KeyUp  += (s, e) =>
            {
                if (e.Key == Key.Enter &&
                    (e.KeyboardDevice.Modifiers & ModifierKeys.Control) == ModifierKeys.Control &&
                    (s as TextBox).Text.Length > 3)
                {
                    window.Exec();
                }
            };
            window.KeyDown += (s, e) =>
            {
                if (e.Key == Key.F5)
                {
                    window.Exec();
                }
            };
            window.Loaded += (s, e) =>
            {
                window.result.tab1.SelectedIndex = 1;
                window.textCmd.Focus();
            };

            // http://stackoverflow.com/questions/622664/what-is-immutability-and-why-should-i-worry-about-it
            var servers = dataMutable.DynValue("servers") as ObservableCollection <ServerDBName>;
            SetupCombo(window.cboServers, servers, window.DataContext);

            var cmd = ConfigurationManager.AppSettings["cmd"];
            if (!string.IsNullOrWhiteSpace(cmd))
            {
                window.isFirst      = true;
                window.textCmd.Text = cmd;
            }
        }
Esempio n. 3
0
        public static void Paste(this ExecWindow window)
        {
            if (!Clipboard.ContainsText())
            {
                return;
            }
            var text = Clipboard.GetText();

            if (string.IsNullOrWhiteSpace(text))
            {
                return;
            }
            window.isFirst      = true;
            window.textCmd.Text = text;
        }
Esempio n. 4
0
        public static async void Exec(ExecWindow window, string cmd, WebBrowser htmlCtrl)
        {
            var data = window.DataContext as ExpandoObject;

            Ai.Reflection.ExpandoConvert.SetValue <string>(data, "command", cmd);

            Context db = data.DynValue("db") as Context;

            SqlCommand execProc = new SqlCommand
            {
                CommandType = CommandType.Text,
                CommandText = cmd,
                Connection  = db.SqlConnection
            };

            execProc.CommandTimeout = 5; // sec
            var token = new CancellationToken();

            var task = Task.Factory.StartNew <object>(() =>
            {
                string error = string.Empty;
                DbEnumeratorData <ExpandoObject> resSql = db.ExecDynCmd(execProc, onError: (err) =>
                {
                    error = err.Message;
                });

                var head = new XElement("h4", cmd);

                string nameProc  = StringExt.StrExtract(cmd.Replace("EXEC ", ""), "", " ");
                XElement bodyRes = new XElement("body", head);
                XElement bodyCS  = new XElement("body", head);

                List <ExpandoObject> firstSql = FillHtmls(resSql, nameProc, token, bodyRes, bodyCS
                                                          , onError: (err) => error = err.Message);

                var resultObj = new { firstSql = firstSql,
                                      bodyRes  = bodyRes, Error = error, bodyCS = bodyCS };
                return(resultObj);
            },
                                                      cancellationToken: token, creationOptions: TaskCreationOptions.LongRunning,
                                                      scheduler: TaskScheduler.Current);

            await task;
            var   res      = task.Result;
            var   resError = res.GetValue <string>("ERROR");

            if (resError.Length > 0)
            {
                var body = new XElement("body");
                body.Add(cmd); body.Add(new XElement("br"));
                body.Add(resError ?? "Unknown error");
                htmlCtrl.NavigateToString(new XElement("html", body).ToString());
                return;
            }

            var resBodyCS = res.GetValue <XElement>("bodyCS");

            window.result.webCS.BodySet <XElement>(resBodyCS);

            var resBodyRes = res.GetValue <XElement>("bodyRes");

            HtmlResult.BodySet <XElement>(htmlCtrl, resBodyRes);

            var           firstResult = res.GetValue <List <ExpandoObject> >("firstSql");
            ExpandoObject firstObj    = firstResult.ElementAt(0);

            var grid = window.result.grd1;

            Ai.Wpf.GridDataSource.ToDataSource(grid, firstResult, firstObj);
            //grid.SelectionMode = DataGridSelectionMode.Extended;
            //grid.SelectionUnit = DataGridSelectionUnit.CellOrRowHeader;
            // SelectionMode="Extended" or SelectionMode="Multiple"
        }