private void BuildDirNode(CloudBlobDirectory cloudDir, DirNode dirNode)
        {
            foreach (IListBlobItem item in cloudDir.ListBlobs(false, BlobListingDetails.Metadata, HelperConst.DefaultBlobOptions))
            {
                CloudBlob          cloudBlob   = item as CloudBlob;
                CloudBlobDirectory subCloudDir = item as CloudBlobDirectory;

                if (cloudBlob != null)
                {
                    if (CloudBlobHelper.MapStorageBlobTypeToBlobType(cloudBlob.BlobType) == this.BlobType)
                    {
                        FileNode fileNode = new FileNode(cloudBlob.GetShortName());
                        this.BuildFileNode(cloudBlob, fileNode);
                        dirNode.AddFileNode(fileNode);
                    }
                }
                else if (subCloudDir != null)
                {
                    var     subDirName = subCloudDir.GetShortName();
                    DirNode subDirNode = dirNode.GetDirNode(subDirName);

                    // A blob directory could be listed more than once if it's across table servers.
                    if (subDirNode == null)
                    {
                        subDirNode = new DirNode(subDirName);
                        this.BuildDirNode(subCloudDir, subDirNode);
                        dirNode.AddDirNode(subDirNode);
                    }
                }
            }
        }
예제 #2
0
        public static void AddTree(DirNode dirNode, string dirPrefix, string filePrefix, int width, int depth, int fileSizeInKB, FileAttributes?fa = null, DateTime?lmt = null)
        {
            for (int i = 0; i < width; ++i)
            {
                string   fileName = i == 0 ? filePrefix : filePrefix + "_" + i;
                FileNode fileNode = new FileNode(fileName)
                {
                    SizeInByte       = 1024L * fileSizeInKB,
                    FileAttr         = fa,
                    LastModifiedTime = lmt,
                };

                dirNode.AddFileNode(fileNode);
            }

            if (depth > 0)
            {
                for (int i = 0; i < width; ++i)
                {
                    string  dirName    = i == 0 ? dirPrefix : dirPrefix + "_" + i;
                    DirNode subDirNode = dirNode.GetDirNode(dirName);
                    if (subDirNode == null)
                    {
                        subDirNode = new DirNode(dirName);
                        dirNode.AddDirNode(subDirNode);
                    }

                    DMLibDataHelper.AddTree(subDirNode, dirPrefix, filePrefix, width, depth - 1, fileSizeInKB, fa, lmt: lmt);
                }
            }
        }
예제 #3
0
        public static FileNode GetFileNode(DirNode dirNode, params string[] tokens)
        {
            DirNode currentDirNode = dirNode;

            for (int i = 0; i < tokens.Length; ++i)
            {
                if (i == tokens.Length - 1)
                {
                    FileNode fileNode = currentDirNode.GetFileNode(tokens[i]);
                    if (fileNode == null)
                    {
                        Test.Error("FileNode {0} doesn't exist.", tokens[i]);
                        return(null);
                    }

                    return(fileNode);
                }
                else
                {
                    currentDirNode = currentDirNode.GetDirNode(tokens[i]);
                    if (currentDirNode == null)
                    {
                        Test.Error("DirNode {0} doesn't exist.", tokens[i]);
                        return(null);
                    }
                }
            }

            return(null);
        }
예제 #4
0
        public static void AddTree(
            DirNode dirNode,
            string dirPrefix,
            string filePrefix,
            int width,
            int depth,
            int fileSizeInKB,
            FileAttributes?fa         = null,
            DateTime?lmt              = null,
            string cacheControl       = null,
            string contentDisposition = null,
            string contentEncoding    = null,
            string contentLanguage    = null,
            string contentType        = null,
            string md5 = null,
            IDictionary <string, string> metadata = null)
        {
            for (int i = 0; i < width; ++i)
            {
                string   fileName = i == 0 ? filePrefix : filePrefix + "_" + i;
                FileNode fileNode = new FileNode(fileName)
                {
                    SizeInByte         = 1024L * fileSizeInKB,
                    FileAttr           = fa,
                    LastModifiedTime   = lmt,
                    CacheControl       = cacheControl,
                    ContentDisposition = contentDisposition,
                    ContentEncoding    = contentEncoding,
                    ContentLanguage    = contentLanguage,
                    ContentType        = contentType,
                    MD5      = md5,
                    Metadata = metadata
                };

                dirNode.AddFileNode(fileNode);
            }

            if (depth > 0)
            {
                for (int i = 0; i < width; ++i)
                {
                    string  dirName    = i == 0 ? dirPrefix : dirPrefix + "_" + i;
                    DirNode subDirNode = dirNode.GetDirNode(dirName);
                    if (subDirNode == null)
                    {
                        subDirNode = new DirNode(dirName);
                        dirNode.AddDirNode(subDirNode);
                    }

                    DMLibDataHelper.AddTree(subDirNode, dirPrefix, filePrefix, width, depth - 1, fileSizeInKB, fa, lmt: lmt);
                }
            }
        }
예제 #5
0
        public static bool Equals(DirNode dirNodeA, DirNode dirNodeB)
        {
            // The same node
            if (dirNodeA == dirNodeB)
            {
                return(true);
            }

            // Empty node equals to null
            if ((dirNodeA == null || dirNodeA.IsEmpty) &&
                (dirNodeB == null || dirNodeB.IsEmpty))
            {
                return(true);
            }

            // Compare two nodes
            if (null != dirNodeA && null != dirNodeB)
            {
                if (dirNodeA.FileNodeCount != dirNodeB.FileNodeCount ||
                    dirNodeA.NonEmptyDirNodeCount != dirNodeB.NonEmptyDirNodeCount)
                {
                    return(false);
                }

                foreach (FileNode fileNodeA in dirNodeA.FileNodes)
                {
                    FileNode fileNodeB = dirNodeB.GetFileNode(fileNodeA.Name);

                    if (!DMLibDataHelper.Equals(fileNodeA, fileNodeB))
                    {
                        return(false);
                    }
                }

                foreach (DirNode subDirNodeA in dirNodeA.DirNodes)
                {
                    DirNode subDirNodeB = dirNodeB.GetDirNode(subDirNodeA.Name);
                    if (!DMLibDataHelper.Equals(subDirNodeA, subDirNodeB))
                    {
                        return(false);
                    }
                }

                return(true);
            }

            return(false);
        }
예제 #6
0
        public static bool Equals(DirNode dirNodeA, DirNode dirNodeB)
        {
            // The same node
            if (dirNodeA == dirNodeB)
            {
                return(true);
            }

            // Empty node equals to null
            if ((dirNodeA == null || dirNodeA.IsEmpty) &&
                (dirNodeB == null || dirNodeB.IsEmpty))
            {
                return(true);
            }

            // Compare two nodes
            if (null != dirNodeA && null != dirNodeB)
            {
                if (dirNodeA.FileNodeCount != dirNodeB.FileNodeCount ||
                    dirNodeA.NonEmptyDirNodeCount != dirNodeB.NonEmptyDirNodeCount)
                {
                    return(false);
                }

                if ((null != dirNodeA.Metadata) && (dirNodeA.Metadata.Count > 0))
                {
                    if (null == dirNodeB.Metadata)
                    {
                        return(false);
                    }

                    if (dirNodeA.Metadata.Count != dirNodeB.Metadata.Count)
                    {
                        return(false);
                    }

                    foreach (var keyValue in dirNodeA.Metadata)
                    {
                        if (!string.Equals(dirNodeB.Metadata[keyValue.Key], keyValue.Value))
                        {
                            return(false);
                        }
                    }
                }
                else
                {
                    if ((null != dirNodeB.Metadata) && (dirNodeB.Metadata.Count > 0))
                    {
                        return(false);
                    }
                }

                foreach (FileNode fileNodeA in dirNodeA.FileNodes)
                {
                    FileNode fileNodeB = dirNodeB.GetFileNode(fileNodeA.Name);

                    FileNode fileNodeAA = fileNodeA;

                    if (null == fileNodeB)
                    {
                        fileNodeB = dirNodeB.GetFileNode(DMLibTestHelper.EscapeInvalidCharacters(fileNodeA.Name));

                        if (null != fileNodeB)
                        {
                            fileNodeAA = fileNodeA.Clone(DMLibTestHelper.EscapeInvalidCharacters(fileNodeA.Name));
                        }
                    }

                    if (!DMLibDataHelper.Equals(fileNodeAA, fileNodeB))
                    {
                        return(false);
                    }
                }

                foreach (DirNode subDirNodeA in dirNodeA.DirNodes)
                {
                    Test.Info("Verifying subfolder: {0} ", subDirNodeA.Name);
                    DirNode subDirNodeB = dirNodeB.GetDirNode(subDirNodeA.Name);

                    if (null == subDirNodeB)
                    {
                        subDirNodeB = dirNodeB.GetDirNode(DMLibTestHelper.EscapeInvalidCharacters(subDirNodeA.Name));
                    }

                    if (!DMLibDataHelper.Equals(subDirNodeA, subDirNodeB))
                    {
                        return(false);
                    }
                }

                return(true);
            }

            return(false);
        }