コード例 #1
0
        /// <summary>
        /// Look at the file and try and represent the file as a dataset without a definition
        /// </summary>
        /// <returns>A representation of the data</returns>
        public override DataItemDefinition Analyse(AnalyseRequest <Object> request)
        {
            // Create a blank result data table
            DataItemDefinition result = new DataItemDefinition()
            {
            };
            String rawData = ""; // The data which ultimately will be read from

            // Check to see what can of analysis is being requested
            if ((request.Connection?.ConnectionString ?? String.Empty) != String.Empty)
            {
                // Get the stream of data from the raw file
                rawData = File.ReadAllText(request.Connection.ConnectionStringProcessed);
            }
            else
            {
                // No connection was provided so use the raw data provided instead
                switch (request.Data.GetType().ToShortName())
                {
                case "string":

                    rawData = (String)request.Data;

                    break;

                default:

                    ((Stream)request.Data).Position = 0;     // Reset the stream position

                    // Read the data from the stream
                    StreamReader reader = new StreamReader((Stream)request.Data);
                    rawData = reader.ReadToEnd();

                    // Reset the position again so that it can be re-used
                    ((Stream)request.Data).Position = 0;

                    break;
                }
            }

            // Pass down to the analyse text core function
            AnalyseRequest <String> analyseTextRequest =
                new AnalyseRequest <String>()
            {
                Data       = rawData,
                Connection = request.Connection
            };

            result = DelimitedFileHelper.AnalyseText(analyseTextRequest);

            base.MarkLastAction(); // Tell the provider base class that it did something

            // Send the analysis data table back
            return(result);
        }
コード例 #2
0
        public void Analyse_Column_Numbers_From_String()
        {
            // Arrange
            TestHelper testHelper = new TestHelper();
            String     testData   = testHelper.GetResourceString(TestHelper.TestFile_Headers);

            // Act
            DataItemDefinition definition = DelimitedFileHelper.AnalyseText(
                new AnalyseRequest <String>()
            {
                Data       = testData,
                Connection = testHelper.TestConnection()
            }
                );

            // Assert
            Assert.Equal(definition.ItemProperties.Count, (int)3);
        }
コード例 #3
0
        public void Analyse_Column_DataType_From_String()
        {
            // Arrange
            TestHelper testHelper = new TestHelper();
            String     testData   = testHelper.GetResourceString(TestHelper.TestFile_DataTypes);

            // Act
            DataItemDefinition definition = DelimitedFileHelper.AnalyseText(
                new AnalyseRequest <string>()
            {
                Data       = testData,
                Connection = testHelper.TestConnection()
            });

            // Assert
            Assert.Equal(definition.ItemProperties.Count, (int)5);
            Assert.Equal(typeof(String), definition.ItemProperties[0].DataType);
            Assert.Equal(typeof(DateTime), definition.ItemProperties[1].DataType);
            Assert.Equal(typeof(int), definition.ItemProperties[2].DataType);
            Assert.Equal(typeof(String), definition.ItemProperties[3].DataType);
            Assert.Equal(typeof(int), definition.ItemProperties[4].DataType);
        }