예제 #1
0
        private static void PerformWriteFlushReadSeek(DataLakeFileSystemClient client)
        {
            string fileName = "/Test/dir1/testFilename1.txt";

            DataLakeFileClient file = client.GetFileClient(fileName);

            // Create the file
            Stream stream = BinaryData.FromString("This is the first line.\nThis is the second line.\n").ToStream();
            long   length = stream.Length;

            file.Upload(stream, true);

            // Append to the file
            stream = BinaryData.FromString("This is the third line.\nThis is the fourth line.\n").ToStream();
            file.Append(stream, length);
            file.Flush(length + stream.Length);

            // Read the file
            using (var readStream = file.OpenRead())
            {
                byte[] readData = new byte[1024];

                // Read 40 bytes at this offset
                int readBytes = readStream.Read(readData, 25, 40);
                Console.WriteLine("Read output of 40 bytes from offset 25: " + Encoding.UTF8.GetString(readData, 0, readBytes));
            }
        }
예제 #2
0
        public List <Project> GetProjects(
            ProjectReader reader)
        {
            List <string> fileNames = GetFileNames(MIPPEN_FILE_SEARCH_TERM);

            List <Project> projects = new List <Project>();

            DataLakeFileSystemClient fileSystemClient =
                serviceClient.GetFileSystemClient(fileSystemName);

            foreach (var fileName in fileNames)
            {
                // Get file contents
                DataLakeFileClient fileClient =
                    fileSystemClient.GetFileClient(fileName);

                // Try to get a project
                Project project;
                using (var stream = fileClient.OpenRead())
                {
                    project = reader.Read(stream);
                }

                if (project is not null)
                {
                    projects.Add(project);
                }
            }

            return(projects);
        }
예제 #3
0
        private static void TestTokenRefresh(DataLakeFileSystemClient client)
        {
            string             path = "/Test/TokenRefresh.txt";
            DataLakeFileClient file = client.GetFileClient(path);

            // Create file
            file.Upload(
                BinaryData.FromString("This is the first file.").ToStream(), overwrite: true);

            // Wait 1 mins
            Console.WriteLine("The token is refreshing...");
            Thread.Sleep(60 * 1000);

            // Read file - this still works, because token is internally refreshed
            using (var readStream = new StreamReader(file.OpenRead()))
            {
                string line;
                while ((line = readStream.ReadLine()) != null)
                {
                    Console.WriteLine(line);
                }
            }
        }