/// <summary>This method should return a reader that actually return data.
        /// This implementation prepares a LmiHandler for further queries
        /// </summary>
        /// <returns>A reader which returns the rows from the data.</returns>
        protected override DataRowReader ExecuteQueryCore2()
        {
            // Check we have already connected to the data source.
            if (lmiHandler == null)
            {
                lmiHandler = new LmiHandler(dataSource.Host, dataSource.Query, dataSource.UserName, dataSource.UserPass,
                                            dataSource.QueryId, dataSource.IsCorrelation, dataSource.From, dataSource.To);
            }

            // Retrieve the reader from the inner text file data source connection.
            return(new LmiDataRowReader(lmiHandler));
        }
示例#2
0
        /// <summary>Create a new connection and prompt if needed.
        /// </summary>
        /// <param name="serviceProvider">The service provider.</param>
        /// <param name="promptMode">The prompt mode.</param>
        /// <returns>A connection to the data source.</returns>
        protected override DataSourceConnection ConnectCore(
            IServiceProvider serviceProvider, DataSourcePromptMode promptMode)
        {
            // Retrieve the prompt service.
            PromptService promptService = GetService <PromptService>(serviceProvider);

            CredentialsService credentialsService = GetService <CredentialsService>(serviceProvider);

            // Check if it allowed to show a UI
            bool isPromptingAllowed = promptService.IsPromptingAllowed;

            // Check if host/username/password works
            bool connectionOk = false;

            if (!Host.Equals("") && !UserName.Equals("") && !UserPass.Equals(""))
            {
                try
                {
                    LmiHandler lmiHandler = new LmiHandler(Host, "", UserName, UserPass, null, false, From, To);
                    lmiHandler.checkConnection();
                    connectionOk = true;
                }
                catch (Exception)
                {
                    // just ignored at this stage
                }
            }
            else if (isPromptingAllowed)
            {
                String[] credentials;
                bool     res = credentialsService.TryGetCredentials <String[]>("LMI::DEFAULT", out credentials);
                Host     = res == false ? "" : credentials[0];
                UserName = res == false ? "" : credentials[1];
                UserPass = res == false ? "" : credentials[2];
            }
            // Check if we need to prompt
            bool needsPrompting = !connectionOk;

            if (!isPromptingAllowed && needsPrompting)
            {
                // It is not allowed to show the prompt UI and there is not enough information
                // to retrieve data so an exception needs to be thrown and import will be aborted.
                throw new ImportException("User prompt needed but disallowed by prompt mode or application mode.");
            }

            // Generate an enumerator for the prompt models.
            IEnumerable <object> promptModels = new List <object>();

            // 2. Prompt for Uri if it is allowed to show UI
            if (isPromptingAllowed)
            {
                switch (promptMode)
                {
                case DataSourcePromptMode.All:

                    // Always prompt
                    promptModels = this.Prompt(credentialsService);
                    break;

                case DataSourcePromptMode.RequiredOnly:

                    // Prompt only if needed
                    if (needsPrompting)
                    {
                        promptModels = this.Prompt(credentialsService);
                    }
                    break;

                case DataSourcePromptMode.None:

                    // No prompting.
                    break;

                default:

                    // No prompting.
                    break;
                }
            }

            // 3. Create and return a connection
            return(new LmiDataSourceConnection(this, serviceProvider, promptMode, promptModels));
        }
        public LmiDataRowReader(LmiHandler lmiHandler)
        {
            this.lmiHandler = lmiHandler;
            initQuery();

            resultProperties = new ResultProperties();
            resultProperties.SetProperty("Host", lmiHandler.Host);
            resultProperties.SetProperty("UserName", lmiHandler.UserName);
            resultProperties.SetProperty("Query", lmiHandler.Query);
            if (lmiHandler.QueryId != null)
            {
                resultProperties.SetProperty("QueryID", lmiHandler.QueryId);
            }
            if (lmiHandler.IsCorrelation)
            {
                resultProperties.SetProperty("Correlation", "true");
            }
            else
            {
                resultProperties.SetProperty("Correlation", "false");
            }
            columns = new DataRowReaderColumn[queryDesc.columns.Length];
            cursors = new DataValueCursor[queryDesc.columns.Length];

            int i = 0;

            foreach (ColumnDesc column in queryDesc.columns)
            {
                switch (column.type)
                {
                case "TIMESTAMP":
                    cursors[i] = DataValueCursor.CreateMutableCursor(DataType.DateTime);
                    columns[i] = new DataRowReaderColumn(column.name, DataType.DateTime, cursors[i]);
                    break;

                case "INT":
                    cursors[i] = DataValueCursor.CreateMutableCursor(DataType.Integer);
                    columns[i] = new DataRowReaderColumn(column.name, DataType.Integer, cursors[i]);
                    break;

                case "LONG":
                    cursors[i] = DataValueCursor.CreateMutableCursor(DataType.LongInteger);
                    columns[i] = new DataRowReaderColumn(column.name, DataType.LongInteger, cursors[i]);
                    break;

                case "DOUBLE":
                    cursors[i] = DataValueCursor.CreateMutableCursor(DataType.Real);
                    columns[i] = new DataRowReaderColumn(column.name, DataType.Real, cursors[i]);
                    break;

                case "BOOLEAN":
                    cursors[i] = DataValueCursor.CreateMutableCursor(DataType.Boolean);
                    columns[i] = new DataRowReaderColumn(column.name, DataType.Boolean, cursors[i]);
                    break;

                //case "INET_ADDR":
                default:
                    cursors[i] = (MutableValueCursor <string>)DataValueCursor.CreateMutableCursor(DataType.String);
                    columns[i] = new DataRowReaderColumn(column.name, DataType.String, cursors[i]);
                    break;
                }
                i++;
            }
        }