Exemple #1
0
        private void RefreshData()
        {
            if (_dataLock.TryEnterWriteLock(1000)) {
                try {
                    Stopwatch watch = Stopwatch.StartNew();

                    _attributes = new AttributeTable();
                    _attributes.ConnectionString = _connString;
                    _attributes.Load();

                    _facts = new FactTable();
                    _facts.ConnectionString = _connString;
                    _facts.Load();

                    _contexts = new ContextTable();
                    _contexts.ConnectionString = _connString;
                    _contexts.Load();

                    _resources = new ResourceTable();
                    _resources.ConnectionString = _connString;
                    _resources.Load();

                    _lastUpdate = DateTime.UtcNow;
                    watch.Stop();

                    Trace.WriteLine("QueryEngin.RefreshData: " + watch.ElapsedMilliseconds + "ms");
                }
                finally {
                    _dataLock.ExitWriteLock();
                }
            }
        }
Exemple #2
0
        private void InitializeData(Object threadContext)
        {
            Stopwatch watch = Stopwatch.StartNew();

            _parser = new Parser();
            _store = new EvalStore();
            StringBuilder cmd = new StringBuilder();

            _attributes = new AttributeTable();
            _attributes.Load();
            statusStrip.Text = "Loading Attributes...";

            _facts = new FactTable();
            _facts.Load();
            statusStrip.Text = "Loading Facts...";

            _contexts = new ContextTable();
            _contexts.Load();
            statusStrip.Text = "Loading Contexts...";

            _resources = new ResourceTable();
            _resources.Load();
            statusStrip.Text = "Loading Resources...";

            watch.Stop();

            _popupMenu = new AutocompleteMenu(queryCode);
            _popupMenu.SearchPattern = @"[\w\.:=!<>]";
            _popupMenu.AllowTabKey = true;

            List<AutocompleteItem> items = new List<AutocompleteItem>();
            for (int i = 0; i < _facts.ColumnDefinitions.Count; i++) {
                items.Add(new AutocompleteItem(_facts.ColumnDefinitions[i].Name));
            }

            items.Add(new AutocompleteItem("select"));
            items.Add(new AutocompleteItem("where"));
            items.Add(new AutocompleteItem("order"));
            items.Add(new AutocompleteItem("group"));
            items.Add(new AutocompleteItem("by"));
            items.Add(new AutocompleteItem("limit"));
            items.Add(new AutocompleteItem("desc"));
            items.Add(new AutocompleteItem("asc"));
            items.Add(new AutocompleteItem("between"));

            for (int i=0; i<_resources.Cols; i++) {
                items.Add(new AutocompleteItem(_resources.ColumnDefinitions[i].Name));
            }

            items.Add(new AutocompleteItem("Context"));
            items.Add(new AutocompleteItem("value"));
            items.Add(new AutocompleteItem("time"));

            foreach (string func in _parser.GetFunctionNames()) {
                SnippetAutocompleteItem n = new SnippetAutocompleteItem(func + "(^)");
                n.ToolTipText = n.Text;
                n.ToolTipTitle = "";
                items.Add(n);
            }

            _popupMenu.Items.SetAutocompleteItems(items);
            queryCode.Language = FastColoredTextBoxNS.Language.SQL;

            _store.Enter();
            _store.Put<Element>("pi", new Element(3.131492653586));
            _store.Put<Element>("e", new Element(2.71828183));
            _store.Put<Table>(_facts.Name, _facts);
            _store.Put<Table>(_attributes.Name, _attributes);
            _store.Put<Table>(_contexts.Name, _contexts);
            _store.Put<Table>(_resources.Name, _resources);

            Trace.WriteLine("InitializeData              : " + watch.ElapsedMilliseconds + "ms");
            toolStrip1.Enabled = true;
            statusStrip.Text = "OK";
        }