コード例 #1
0
        private static async Task ImportFileMetadataToScratchTable(string basePath)
        {
            using (var client = new ArribaClient(ArribaServerUrl))
            {
                if (!Directory.Exists(basePath))
                {
                    Trace.WriteLine(String.Format("Error: Can't import file metadata from '{0}' because '{0}' was not found.", basePath));
                    return;
                }

                // Create the table if it doesn't yet exist
                if (!client.Tables.Contains("Scratch"))
                {
                    await CreateScratchTable();
                }

                Trace.WriteLine(String.Format("Importing file metadata from '{0}' into Scratch table...", basePath));

                // Build a DataBlock with file details
                DirectoryInfo root  = new DirectoryInfo(basePath);
                FileInfo[]    files = root.GetFiles("*.*", SearchOption.AllDirectories);

                // Copy values into strongly typed arrays [performance; avoids boxing on insert]
                string[]   names            = new string[files.Length];
                DateTime[] createdDateUtcs  = new DateTime[files.Length];
                DateTime[] modifiedDateUtcs = new DateTime[files.Length];
                long[]     lengths          = new long[files.Length];

                for (int i = 0; i < files.Length; ++i)
                {
                    FileInfo file = files[i];
                    names[i]            = file.Name;
                    createdDateUtcs[i]  = file.CreationTimeUtc;
                    modifiedDateUtcs[i] = file.LastWriteTimeUtc;
                    lengths[i]          = file.Length;
                }

                // Put data into DataBlock, using existing arrays
                DataBlock block = new DataBlock(new string[] { "Name", "CreatedDateUTC", "ModifiedDateUTC", "LengthBytes" }, files.Length, new Array[] { names, createdDateUtcs, modifiedDateUtcs, lengths });

                // Import the new CSV
                ArribaTableClient table = client["Scratch"];
                await table.ImportDataBlock(block);

                await table.SaveAsync();

                Trace.WriteLine(String.Format("Done. {0:n0} items imported.", files.Length));
            }
        }
コード例 #2
0
        private static async Task ImportFileToScratchTable(string filePath)
        {
            using (var client = new ArribaClient(ArribaServerUrl))
            {
                // Create the table if it doesn't yet exist
                if (!client.Tables.Contains("Scratch"))
                {
                    await CreateScratchTable();
                }

                Trace.WriteLine(String.Format("Importing '{0}' into Scratch table...", filePath));

                ArribaTableClient table = client["Scratch"];

                // Import the new CSV
                await table.ImportFileAsync(filePath);

                await table.SaveAsync();

                Trace.WriteLine(String.Format("'{0}' imported into Scratch table.", filePath));
            }
        }