Ejemplo n.º 1
0
        public async Task CloudFileShareListFilesAndDirectoriesSegmentedAsync()
        {
            CloudFileShare share = GetRandomShareReference();

            try
            {
                await share.CreateAsync();

                List <string> fileNames = await CreateFilesAsync(share, 3);

                CloudFileDirectory rootDirectory = share.GetRootDirectoryReference();

                FileContinuationToken token = null;
                do
                {
                    FileResultSegment results = await rootDirectory.ListFilesAndDirectoriesSegmentedAsync(1, token, null, null);

                    int count = 0;
                    foreach (IListFileItem fileItem in results.Results)
                    {
                        Assert.IsInstanceOfType(fileItem, typeof(CloudFile));
                        Assert.IsTrue(fileNames.Remove(((CloudFile)fileItem).Name));
                        count++;
                    }
                    Assert.AreEqual(1, count);
                    token = results.ContinuationToken;
                }while (token != null);
                Assert.AreEqual(0, fileNames.Count);
            }
            finally
            {
                share.DeleteIfExistsAsync().Wait();
            }
        }
        public void CloudFileShareListFilesAndDirectoriesSegmentedOverload()
        {
            CloudFileShare share = GetRandomShareReference();

            try
            {
                share.Create();
                List <string>      fileNames     = CreateFiles(share, 3);
                CloudFileDirectory rootDirectory = share.GetRootDirectoryReference();

                FileContinuationToken token = null;
                do
                {
                    FileResultSegment results = rootDirectory.ListFilesAndDirectoriesSegmented(token);
                    int count = 0;
                    foreach (IListFileItem fileItem in results.Results)
                    {
                        Assert.IsInstanceOfType(fileItem, typeof(CloudFile));
                        Assert.IsTrue(fileNames.Remove(((CloudFile)fileItem).Name));
                        count++;
                    }
                    token = results.ContinuationToken;
                }while (token != null);
                Assert.AreEqual(0, fileNames.Count);
            }
            finally
            {
                share.DeleteIfExists();
            }
        }
        public void FileContinuationTokenVerifyXmlWithinXml()
        {
            CloudFileShare share = GetRandomShareReference();

            try
            {
                share.Create();
                List <string>      fileNames     = CreateFiles(share, 3);
                CloudFileDirectory rootDirectory = share.GetRootDirectoryReference();

                FileContinuationToken token = null;
                do
                {
                    FileResultSegment results = rootDirectory.ListFilesAndDirectoriesSegmented(1, token, null, null);
                    int count = 0;
                    foreach (IListFileItem fileItem in results.Results)
                    {
                        Assert.IsInstanceOfType(fileItem, typeof(CloudFile));
                        Assert.IsTrue(fileNames.Remove(((CloudFile)fileItem).Name));
                        count++;
                    }
                    Assert.IsTrue(count <= 1);
                    token = results.ContinuationToken;

                    if (token != null)
                    {
                        Assert.AreEqual(null, token.GetSchema());

                        XmlWriterSettings settings = new XmlWriterSettings();
                        settings.Indent = true;
                        StringBuilder sb = new StringBuilder();
                        using (XmlWriter writer = XmlWriter.Create(sb, settings))
                        {
                            writer.WriteStartElement("test1");
                            writer.WriteStartElement("test2");
                            token.WriteXml(writer);
                            writer.WriteEndElement();
                            writer.WriteEndElement();
                        }

                        using (XmlReader reader = XmlReader.Create(new StringReader(sb.ToString())))
                        {
                            token = new FileContinuationToken();
                            reader.ReadStartElement();
                            reader.ReadStartElement();
                            token.ReadXml(reader);
                            reader.ReadEndElement();
                            reader.ReadEndElement();
                        }
                    }
                }while (token != null);
                Assert.AreEqual(0, fileNames.Count);
            }
            finally
            {
                share.DeleteIfExists();
            }
        }
Ejemplo n.º 4
0
        public static async Task <IEnumerable <IListFileItem> > ListFilesAndDirectoriesAsync(CloudFileDirectory directory, string prefix, int?maxResults, FileRequestOptions options, OperationContext operationContext)
        {
            List <IListFileItem>  results = new List <IListFileItem>();
            FileContinuationToken token   = null;

            do
            {
                FileResultSegment resultSegment = await directory.ListFilesAndDirectoriesSegmentedAsync(prefix, maxResults, token, options, operationContext);

                results.AddRange(resultSegment.Results);
                token = resultSegment.ContinuationToken;
            }while (token != null);
            return(results);
        }
        public void CloudFileShareListFilesAndDirectoriesSegmentedAPM()
        {
            CloudFileShare share = GetRandomShareReference();

            try
            {
                share.Create();
                List <string>      fileNames     = CreateFiles(share, 3);
                CloudFileDirectory rootDirectory = share.GetRootDirectoryReference();

                using (AutoResetEvent waitHandle = new AutoResetEvent(false))
                {
                    FileContinuationToken token = null;
                    do
                    {
                        IAsyncResult result = rootDirectory.BeginListFilesAndDirectoriesSegmented(1, token, null, null,
                                                                                                  ar => waitHandle.Set(),
                                                                                                  null);
                        waitHandle.WaitOne();
                        FileResultSegment results = rootDirectory.EndListFilesAndDirectoriesSegmented(result);
                        int count = 0;
                        foreach (IListFileItem fileItem in results.Results)
                        {
                            Assert.IsInstanceOfType(fileItem, typeof(CloudFile));
                            Assert.IsTrue(fileNames.Remove(((CloudFile)fileItem).Name));
                            count++;
                        }
                        Assert.IsTrue(count <= 1);
                        token = results.ContinuationToken;
                    }while (token != null);
                    Assert.AreEqual(0, fileNames.Count);
                }
            }
            finally
            {
                share.DeleteIfExists();
            }
        }
Ejemplo n.º 6
0
        public void CloudFileDirectoryListFilesAndDirectoriesAPM()
        {
            CloudFileClient client = GenerateCloudFileClient();
            string          name   = GetRandomShareName();
            CloudFileShare  share  = client.GetShareReference(name);

            try
            {
                share.Create();
                if (CloudFileDirectorySetup(share))
                {
                    CloudFileDirectory topDir1 = share.GetRootDirectoryReference().GetDirectoryReference("TopDir1");
                    using (AutoResetEvent waitHandle = new AutoResetEvent(false))
                    {
                        FileContinuationToken token       = null;
                        List <IListFileItem>  simpleList1 = new List <IListFileItem>();
                        do
                        {
                            IAsyncResult result = topDir1.BeginListFilesAndDirectoriesSegmented(
                                null,
                                null,
                                null,
                                null,
                                ar => waitHandle.Set(),
                                null);
                            waitHandle.WaitOne();
                            FileResultSegment segment = topDir1.EndListFilesAndDirectoriesSegmented(result);
                            simpleList1.AddRange(segment.Results);
                            token = segment.ContinuationToken;
                        }while (token != null);

                        ////Check if for 3 because if there were more than 3, the previous assert would have failed.
                        ////So the only thing we need to make sure is that it is not less than 3.
                        Assert.IsTrue(simpleList1.Count == 3);

                        IListFileItem item11 = simpleList1.ElementAt(0);
                        Assert.IsTrue(item11.Uri.Equals(share.Uri + "/TopDir1/File1"));
                        Assert.AreEqual("File1", ((CloudFile)item11).Name);

                        IListFileItem item12 = simpleList1.ElementAt(1);
                        Assert.IsTrue(item12.Uri.Equals(share.Uri + "/TopDir1/MidDir1"));
                        Assert.AreEqual("MidDir1", ((CloudFileDirectory)item12).Name);

                        IListFileItem item13 = simpleList1.ElementAt(2);
                        Assert.IsTrue(item13.Uri.Equals(share.Uri + "/TopDir1/MidDir2"));
                        Assert.AreEqual("MidDir2", ((CloudFileDirectory)item13).Name);
                        CloudFileDirectory midDir2 = (CloudFileDirectory)item13;

                        List <IListFileItem> simpleList2 = new List <IListFileItem>();
                        do
                        {
                            IAsyncResult result = midDir2.BeginListFilesAndDirectoriesSegmented(
                                token,
                                ar => waitHandle.Set(),
                                null);
                            waitHandle.WaitOne();
                            FileResultSegment segment = midDir2.EndListFilesAndDirectoriesSegmented(result);
                            simpleList2.AddRange(segment.Results);
                            token = segment.ContinuationToken;
                        }while (token != null);
                        Assert.IsTrue(simpleList2.Count == 2);

                        IListFileItem item21 = simpleList2.ElementAt(0);
                        Assert.IsTrue(item21.Uri.Equals(share.Uri + "/TopDir1/MidDir2/EndDir1"));
                        Assert.AreEqual("EndDir1", ((CloudFileDirectory)item21).Name);

                        IListFileItem item22 = simpleList2.ElementAt(1);
                        Assert.IsTrue(item22.Uri.Equals(share.Uri + "/TopDir1/MidDir2/EndDir2"));
                        Assert.AreEqual("EndDir2", ((CloudFileDirectory)item22).Name);
                    }
                }
            }
            finally
            {
                share.DeleteIfExists();
            }
        }