Esempio n. 1
0
        public ProbeField(ProbeTable table, string name, string prompt, string comment, string dataType)
        {
            if (table == null) throw new ArgumentNullException("table");
            if (string.IsNullOrWhiteSpace(name)) throw new ArgumentException("Field name is blank.");

            Table = table;
            Name = name;
            Prompt = prompt;
            Comment = comment;
            DataType = dataType;
        }
Esempio n. 2
0
        private bool ReadCreateTable()
        {
            var startPos = _parser.Position;
            var ret = false;
            try
            {
                if (!_parser.Read() || _parser.TokenText != "table") return false;

                // Table name
                if (!_parser.Read() || !_rxName.IsMatch(_parser.TokenText)) return false;
                var tableName = _parser.TokenText;

                // Table number
                if (!_parser.Read() || _parser.TokenType != TokenType.Number) throw new ProbeException("Expected table number to follow 'create table'.");
                var tableNumber = int.Parse(_parser.TokenText);
                var tableNumber2 = -1;

                var pos = _parser.Position;
                if (!_parser.Read()) return false;
                if (_parser.TokenType == TokenType.Number) tableNumber2 = int.Parse(_parser.TokenText);
                else _parser.Position = pos;

                string tablePrompt = string.Empty;

                var createDone = false;
                while (!createDone)
                {
                    if (!_parser.Read()) throw new ProbeException("Unexpected end of file in create table statement.");
                    switch (_parser.TokenText)
                    {
                        case "(":
                            createDone = true;
                            break;
                        case "updates":
                            break;
                        case "database":
                            if (!_parser.Read() || _parser.TokenType != TokenType.Number) throw new ProbeException("Expected database number to follow 'database'.");
                            break;
                        case "display":
                            break;
                        case "modal":
                            break;
                        case "nopick":
                            break;
                        case "pick":
                            break;
                        case "snapshot":
                            if (!_parser.Read() || _parser.TokenType != TokenType.Number) throw new ProbeException("Expected frequency to follow 'snapshot'.");
                            break;
                        case "prompt":
                            if (!_parser.Read() || _parser.TokenType != TokenType.StringLiteral) throw new ProbeException("Expected string to follow 'prompt'.");
                            tablePrompt = Parser.StringLiteralToString(_parser.TokenText);
                            break;
                        case "comment":
                            if (!_parser.Read() || _parser.TokenType != TokenType.StringLiteral) throw new ProbeException("Expected string to follow 'comment'.");
                            break;
                        default:
                            throw new ProbeException(string.Format("Unexpected token '{0}' in create table statement.", _parser.TokenText));
                    }
                }

                var table1 = new ProbeTable(tableNumber, tableName, tablePrompt);
                var table2 = tableNumber2 > 0 ? new ProbeTable(tableNumber2, tableName + "2", tablePrompt) : null;
                var tables = table2 == null ? new ProbeTable[] { table1 } : new ProbeTable[] { table1, table2 };
                foreach (var table in tables) table.SetFieldsLoaded();

                ReadTableFields(")", tables);

                _tables.AddRange(tables);
                return ret = true;
            }
            catch (ProbeException ex)
            {
                ProbeNppPlugin.Instance.Output.WriteLine(OutputStyle.Warning, string.Format("Exception when processing 'create table' for table '{0}': {1}", _tableName, ex.ToString()));
                return ret = false;
            }
            finally
            {
                if (!ret) _parser.Position = startPos;
            }
        }
Esempio n. 3
0
        private bool ReadCreateRelationship()
        {
            var startPos = _parser.Position;
            var ret = false;
            try
            {
                if (!_parser.Read() || _parser.TokenText != "relationship") return false;

                if (!_parser.Read() || _parser.TokenType != TokenType.Word) throw new ProbeException("Expected relationship name after 'create relationship'.");
                var relName = _parser.TokenText;

                if (!_parser.Read() || _parser.TokenType != TokenType.Number) throw new ProbeException("Expected relationship number after name.");
                var relNumber = int.Parse(_parser.TokenText);

                Position pos;
                string relPrompt = "";
                string relComment = "";
                if (_parser.Peek(out pos) && _parser.TokenText == "prompt")
                {
                    _parser.Position = pos;
                    if (!_parser.Read() || _parser.TokenType != TokenType.StringLiteral) throw new ProbeException("Expected string literal after 'prompt'.");
                    relPrompt = Parser.StringLiteralToString(_parser.TokenText);
                }

                if (_parser.Peek(out pos) && _parser.TokenText == "comment")
                {
                    _parser.Position = pos;
                    if (!_parser.Read() || _parser.TokenType != TokenType.StringLiteral) throw new ProbeException("Expected string literal after 'comment'.");
                    relComment = Parser.StringLiteralToString(_parser.TokenText);
                }

                if (!_parser.Read() || (_parser.TokenText != "one" && _parser.TokenText != "many")) throw new ProbeException("Expected 'one' or 'many' after relationship number.");
                if (!_parser.Read() || _parser.TokenType != TokenType.Word) throw new ProbeException("Expected parent table name for relationship.");
                if (!_parser.Read() || _parser.TokenText != "to") throw new ProbeException("Expected 'to' after relationship parent table name.");
                if (!_parser.Read() || (_parser.TokenText != "one" && _parser.TokenText != "many")) throw new ProbeException("Expected 'one' or 'many' after relationship 'to'.");
                if (!_parser.Read() || _parser.TokenType != TokenType.Word) throw new ProbeException("Expected child table name for relationship.");

                if (_parser.Peek(out pos) && _parser.TokenText == "order")
                {
                    _parser.Position = pos;
                    if (!_parser.Read() || _parser.TokenText != "by") throw new ProbeException("Expected 'by' after 'order' in relationship.");
                    if (_parser.Peek(out pos) && _parser.TokenText == "unique")
                    {
                        _parser.Position = pos;
                    }

                    while (true)
                    {
                        if (!_parser.Read()) throw new ProbeException("Unexpected end of file in relationship column list.");
                        if (_parser.TokenText == "(") break;
                        if (_parser.TokenType != TokenType.Word) throw new ProbeException("Expected column name in relationship column list.");
                    }
                }
                else
                {
                    if (!_parser.Read() || _parser.TokenText != "(") throw new ProbeException("Expected '(' after relationship.");
                }

                var table = new ProbeTable(relNumber, relName, relPrompt);
                ReadTableFields(")", new ProbeTable[] { table });
                table.SetFieldsLoaded();
                _tables.Add(table);
                _relInds.Add(new ProbeRelInd { Name = relName });
                return ret = true;
            }
            catch (ProbeException ex)
            {
                ProbeNppPlugin.Instance.Output.WriteLine(OutputStyle.Warning, string.Format("Exception when processing 'create relationship' for table '{0}': {1}", _tableName, ex.ToString()));
                return ret = false;
            }
            finally
            {
                if (!ret) _parser.Position = startPos;
            }
        }
Esempio n. 4
0
        private static void GetTableList_Callback(string line)
        {
            try
            {
                if (string.IsNullOrEmpty(line) || string.IsNullOrEmpty(line.Trim())) return;

                if (line.Length >= 48)
                {
                    int number;
                    if (!Int32.TryParse(line.Substring(0, 4), out number)) return;

                    string name = line.Substring(6, 8).Trim();
                    if (string.IsNullOrEmpty(name)) return;

                    string prompt = line.Substring(17, 31).Trim();
                    if (string.IsNullOrEmpty(prompt)) prompt = name;

                    _tables[name] = new ProbeTable(number, name, prompt);
                }
            }
            catch (Exception ex)
            {
                Plugin.Output.WriteLine(OutputStyle.Error, "Exception when getting table list: {0}", ex);
            }
        }