Ejemplo n.º 1
0
        public void Sample01a_HelloWorld_Errors()
        {
            // Get a reference to a share named "sample-share" and then create it
            string      shareName = Randomize("sample-share");
            ShareClient share     = new ShareClient(ConnectionString, shareName);

            try
            {
                share.Create();
                Sample01a_HelloWorld.Errors(ConnectionString, shareName);
            }
            finally
            {
                share.Delete();
            }
        }
Ejemplo n.º 2
0
        public void Sample01a_HelloWorld_Upload()
        {
            // Create a temporary Lorem Ipsum file on disk that we can upload
            string localFilePath = CreateTempFile(SampleFileContent);

            string      shareName = Randomize("sample-share");
            ShareClient share     = new ShareClient(ConnectionString, shareName);

            try
            {
                Sample01a_HelloWorld.Upload(ConnectionString, shareName, localFilePath);
            }
            finally
            {
                share.Delete();
                File.Delete(localFilePath);
            }
        }
Ejemplo n.º 3
0
        public void Sample01a_HelloWorld_Traverse()
        {
            // Create a temporary Lorem Ipsum file on disk that we can upload
            string originalPath = CreateTempFile(SampleFileContent);

            // Get a reference to a share named "sample-share" and then create it
            string      shareName = Randomize("sample-share");
            ShareClient share     = new ShareClient(ConnectionString, shareName);

            share.Create();
            try
            {
                // Create a bunch of directories
                ShareDirectoryClient first = share.CreateDirectory("first");
                first.CreateSubdirectory("a");
                first.CreateSubdirectory("b");
                ShareDirectoryClient second = share.CreateDirectory("second");
                second.CreateSubdirectory("c");
                second.CreateSubdirectory("d");
                share.CreateDirectory("third");
                ShareDirectoryClient fourth  = share.CreateDirectory("fourth");
                ShareDirectoryClient deepest = fourth.CreateSubdirectory("e");

                // Upload a file named "file"
                ShareFileClient file = deepest.GetFileClient("file");
                using (FileStream stream = File.OpenRead(originalPath))
                {
                    file.Create(stream.Length);
                    file.UploadRange(
                        ShareFileRangeWriteType.Update,
                        new HttpRange(0, stream.Length),
                        stream);
                }

                Sample01a_HelloWorld.Traverse(ConnectionString, shareName);
            }
            finally
            {
                share.Delete();
            }
        }
Ejemplo n.º 4
0
        public void Sample01a_HelloWorld_Download()
        {
            string      originalPath  = CreateTempFile(SampleFileContent);
            string      localFilePath = CreateTempPath();
            string      shareName     = Randomize("sample-share");
            ShareClient share         = new ShareClient(ConnectionString, shareName);

            try
            {
                share.Create();

                // Get a reference to a directory named "sample-dir" and then create it
                ShareDirectoryClient directory = share.GetDirectoryClient("sample-dir");
                directory.Create();

                // Get a reference to a file named "sample-file" in directory "sample-dir"
                ShareFileClient file = directory.GetFileClient("sample-file");

                // Upload the file
                using (FileStream stream = File.OpenRead(originalPath))
                {
                    file.Create(stream.Length);
                    file.UploadRange(
                        ShareFileRangeWriteType.Update,
                        new HttpRange(0, stream.Length),
                        stream);
                }

                Sample01a_HelloWorld.Download(ConnectionString, shareName, localFilePath);

                // Verify the contents
                Assert.AreEqual(SampleFileContent, File.ReadAllText(localFilePath));
            }
            finally
            {
                share.Delete();
                File.Delete(originalPath);
                File.Delete(localFilePath);
            }
        }