public StorageTreeNode getNextTreeNode()
            {
                StorageTreeNode oRes = null;

                if (m_nIndex < 0)
                {
                    m_nIndex = 0;
                }
                else
                {
                    m_nIndex++;
                }
                if (m_nIndex < m_nLength)
                {
                    while (true)
                    {
                        StorageTreeNode oCurItem = m_oStorageTreeNode.m_aSubNodes[m_nIndex];
                        if (false == oCurItem.m_bIsDirectory)
                        {
                            oRes = oCurItem;
                            break;
                        }
                        if (m_nIndex >= m_nLength)
                        {
                            break;
                        }
                        m_nIndex++;
                    }
                }
                return(oRes);
            }
        public StorageTreeNode GetTreeNode(string strPath)
        {
            StorageTreeNode oNode = null;

            try
            {
                using (Amazon.S3.AmazonS3 oS3Client = Amazon.AWSClientFactory.CreateAmazonS3Client(m_oRegion))
                {
                    string strPrefix = GetDirPath(strPath);
                    Amazon.S3.Model.ListObjectsRequest oRequest = new Amazon.S3.Model.ListObjectsRequest();
                    oRequest.WithBucketName(m_strBucketName).WithPrefix(strPrefix);

                    using (Amazon.S3.Model.ListObjectsResponse oResponse = oS3Client.ListObjects(oRequest))
                    {
                        oNode = new StorageTreeNode(strPrefix.Substring(0, strPrefix.Length - 1), true);
                        foreach (Amazon.S3.Model.S3Object entry in oResponse.S3Objects)
                        {
                            AddNodeRecursive(oNode, entry.Key.Substring(strPrefix.Length));
                        }
                    }
                }
            }
            catch
            {
            }

            return(oNode);
        }
        public StorageTreeNode GetTreeNodeEnd(IAsyncResult ar)
        {
            StorageTreeNode oStorageTreeNode = null;

            try
            {
                oStorageTreeNode = m_oGetTreeNodeDelegate.EndInvoke(ar);
            }
            catch
            {
            }
            return(oStorageTreeNode);
        }
        public StorageTreeNode GetTreeNode(string strPath)
        {
            StorageTreeNode oRoot = new StorageTreeNode("root", true);

            try
            {
                if (Directory.Exists(GetFilePath(strPath)))
                {
                    GetTreeNodeRecursion(oRoot, strPath);
                }
            }
            catch
            {
            }
            return(oRoot);
        }
        private void AddNodeRecursive(StorageTreeNode oNode, string strKey)
        {
            try
            {
                if ("" != strKey)
                {
                    int nFirstIndex = strKey.IndexOf("/");
                    if (-1 != nFirstIndex)
                    {
                        StorageTreeNode oDirNode  = null;
                        String          strSubDir = strKey.Substring(0, nFirstIndex);

                        foreach (StorageTreeNode oExistNode in oNode.m_aSubNodes)
                        {
                            if (oExistNode.m_bIsDirectory && oExistNode.m_sName == strSubDir)
                            {
                                oDirNode = oExistNode;
                                break;
                            }
                        }

                        if (null == oDirNode)
                        {
                            oNode.m_aSubNodes.Add(new StorageTreeNode(strSubDir, true));
                        }
                        else
                        {
                            AddNodeRecursive(oDirNode, strKey.Substring(nFirstIndex + 1));
                        }
                    }
                    else
                    {
                        oNode.m_aSubNodes.Add(new StorageTreeNode(strKey, false));
                    }
                }
                else
                {
                    oNode.m_bIsDirectory = true;
                }
            }
            catch
            { }
            return;
        }
        private void GetTreeNodeRecursion(StorageTreeNode oNode, string strPath)
        {
            string sPath = GetFilePath(strPath);

            string[] aFiles = Directory.GetFiles(sPath);
            for (int i = 0, length = aFiles.Length; i < length; ++i)
            {
                string sFile = aFiles[i];
                oNode.m_aSubNodes.Add(new StorageTreeNode(Path.GetFileName(sFile), false));
            }
            string[] aDirectories = Directory.GetDirectories(sPath);
            for (int i = 0, length = aDirectories.Length; i < length; ++i)
            {
                string          sDir    = aDirectories[i];
                StorageTreeNode oNewDir = new StorageTreeNode(Path.GetFileName(sDir), true);
                GetTreeNodeRecursion(oNewDir, Path.Combine(strPath, sDir));
                oNode.m_aSubNodes.Add(oNewDir);
            }
        }
Exemple #7
0
        public ErrorTypes GenerateMediaXml(string sPath)
        {
            ErrorTypes eRes = ErrorTypes.NoError;
            Dictionary <string, string> aMediaXmlMapHash     = new Dictionary <string, string>();
            Dictionary <string, string> aMediaXmlMapFilename = new Dictionary <string, string>();

            Storage         oStorage         = new Storage();
            StorageTreeNode oStorageTreeNode = oStorage.GetTreeNode(Path.GetDirectoryName(sPath));

            if (null != oStorageTreeNode)
            {
                for (int i = 0, length = oStorageTreeNode.m_aSubNodes.Count; i < length; ++i)
                {
                    StorageTreeNode oSubNode = oStorageTreeNode.m_aSubNodes[i];
                    if (!oSubNode.m_bIsDirectory)
                    {
                        string sFilePath = Path.Combine(Path.GetDirectoryName(sPath), oSubNode.m_sName);
                        using (MemoryStream ms = new MemoryStream())
                        {
                            int        nReadWriteBytes;
                            ErrorTypes eReadError = oStorage.ReadFile(sFilePath, ms, out nReadWriteBytes);
                            if (ErrorTypes.NoError == eReadError && nReadWriteBytes > 0)
                            {
                                ms.Position = 0;
                                AddToMediaXmlBytes(aMediaXmlMapHash, aMediaXmlMapFilename, oSubNode.m_sName, ms);
                            }
                        }
                    }
                }
                byte[] aBuffer = GetMediaXmlBytes(aMediaXmlMapHash);
                using (MemoryStream ms = new MemoryStream(aBuffer))
                {
                    int nReadWriteBytes;
                    eRes = oStorage.WriteFile(sPath, ms, out nReadWriteBytes);
                }
            }
            else
            {
                eRes = ErrorTypes.Unknown;
            }
            return(eRes);
        }
        private void ReadNextMediaXmlCallback(IAsyncResult ar)
        {
            try
            {
                int        nReadWriteBytes;
                ErrorTypes eError = m_oGetMediaXml.m_oStorage.ReadFileEnd(ar, out nReadWriteBytes);
                if (ErrorTypes.NoError == eError)
                {
                    StorageTreeNode oCurNode = m_oGetMediaXml.m_oStorageTreeNode.m_aSubNodes[m_oGetMediaXml.m_nIndex];

                    m_oGetMediaXml.m_oMemoryStream.Position = 0;
                    string sHex = Utils.getMD5HexString(m_oGetMediaXml.m_oMemoryStream);
                    if (false == m_oGetMediaXml.m_aMediaXmlMapFilename.ContainsKey(oCurNode.m_sName))
                    {
                        m_oGetMediaXml.m_aMediaXmlMapFilename.Add(oCurNode.m_sName, sHex);
                    }
                    if (false == m_oGetMediaXml.m_aMediaXmlMapHash.ContainsKey(sHex))
                    {
                        m_oGetMediaXml.m_aMediaXmlMapHash.Add(sHex, oCurNode.m_sName);
                    }
                    oCurNode = m_oGetMediaXml.getNextTreeNode();
                    if (null == oCurNode)
                    {
                        m_oGetMediaXml.FireCallback();
                    }
                    else
                    {
                        m_oGetMediaXml.m_oMemoryStream = new MemoryStream();
                        m_oGetMediaXml.m_oStorage.ReadFileBegin(Path.Combine(Path.GetDirectoryName(m_oGetMediaXml.m_sPath), oCurNode.m_sName), m_oGetMediaXml.m_oMemoryStream, ReadNextMediaXmlCallback, null);
                    }
                }
                else
                {
                    m_oGetMediaXml.DisposeAndCallback();
                }
            }
            catch
            {
                m_oGetMediaXml.DisposeAndCallback();
            }
        }
        public StorageTreeNode GetTreeNodeEnd(IAsyncResult ar)
        {
            StorageTreeNode oNode = null;

            try
            {
                string strPrefix = m_oGetTreeNode.m_strPrefix;
                oNode = new StorageTreeNode(strPrefix.Substring(0, strPrefix.Length - 1), true);
                using (Amazon.S3.Model.ListObjectsResponse oResponse = m_oGetTreeNode.m_oS3Client.EndListObjects(ar))
                {
                    foreach (Amazon.S3.Model.S3Object oEntry in oResponse.S3Objects)
                    {
                        AddNodeRecursive(oNode, oEntry.Key.Substring(strPrefix.Length));
                    }
                }
            }
            catch
            {
            }
            return(oNode);
        }
 private void GetTreeNodeCallback(IAsyncResult ar)
 {
     try
     {
         m_oGetMediaXml.SetStorageTreeNode(m_oGetMediaXml.m_oStorage.GetTreeNodeEnd(ar));
         m_oGetMediaXml.m_ogetMD5HexStringDelegate = new Utils.getMD5HexStringDelegate(Utils.getMD5HexString);
         m_oGetMediaXml.m_oMemoryStream            = new MemoryStream();
         StorageTreeNode oFirstItem = m_oGetMediaXml.getNextTreeNode();
         if (null != oFirstItem)
         {
             m_oGetMediaXml.m_oStorage.ReadFileBegin(Path.Combine(Path.GetDirectoryName(m_oGetMediaXml.m_sPath), oFirstItem.m_sName), m_oGetMediaXml.m_oMemoryStream, ReadNextMediaXmlCallback, null);
         }
         else
         {
             m_oGetMediaXml.FireCallback();
         }
     }
     catch
     {
         m_oGetMediaXml.DisposeAndCallback();
     }
 }
 public StorageTreeNode GetTreeNodeEnd(IAsyncResult ar)
 {
     StorageTreeNode oNode = null;
     try
     {
         string strPrefix = m_oGetTreeNode.m_strPrefix;
         oNode = new StorageTreeNode(strPrefix.Substring(0, strPrefix.Length - 1), true);
         using (Amazon.S3.Model.ListObjectsResponse oResponse = m_oGetTreeNode.m_oS3Client.EndListObjects(ar))
         {
             foreach (Amazon.S3.Model.S3Object oEntry in oResponse.S3Objects)
             {
                 AddNodeRecursive(oNode, oEntry.Key.Substring(strPrefix.Length));
             }
         }
     }
     catch
     {
     }
     return oNode;
 }
        public StorageTreeNode GetTreeNode(string strPath)
        {
            StorageTreeNode oNode = null;
            try
            {
                using (Amazon.S3.AmazonS3 oS3Client = Amazon.AWSClientFactory.CreateAmazonS3Client(m_oRegion))
                {
                    string strPrefix = GetDirPath(strPath);
                    Amazon.S3.Model.ListObjectsRequest oRequest = new Amazon.S3.Model.ListObjectsRequest();
                    oRequest.WithBucketName(m_strBucketName).WithPrefix(strPrefix);

                    using (Amazon.S3.Model.ListObjectsResponse oResponse = oS3Client.ListObjects(oRequest))
                    {
                        oNode = new StorageTreeNode(strPrefix.Substring(0, strPrefix.Length - 1), true);
                        foreach (Amazon.S3.Model.S3Object entry in oResponse.S3Objects)
                        {
                            AddNodeRecursive(oNode, entry.Key.Substring(strPrefix.Length));
                        }
                    }
                }
            }
            catch
            {
            }

            return oNode;
        }
 private void GetTreeNodeRecursion(StorageTreeNode oNode, string strPath)
 {
     string sPath = GetFilePath(strPath);
     string[] aFiles = Directory.GetFiles(sPath);
     for (int i = 0, length = aFiles.Length; i < length; ++i)
     {
         string sFile = aFiles[i];
         oNode.m_aSubNodes.Add(new StorageTreeNode(Path.GetFileName(sFile), false));
     }
     string[] aDirectories = Directory.GetDirectories(sPath);
     for (int i = 0, length = aDirectories.Length; i < length; ++i)
     {
         string sDir = aDirectories[i];
         StorageTreeNode oNewDir = new StorageTreeNode(Path.GetFileName(sDir), true);
         GetTreeNodeRecursion(oNewDir, Path.Combine(strPath, sDir));
         oNode.m_aSubNodes.Add(oNewDir);
     }
 }
 public void SetStorageTreeNode(StorageTreeNode oStorageTreeNode)
 {
     m_oStorageTreeNode = oStorageTreeNode;
     m_nIndex = -1;
     m_nLength = oStorageTreeNode.m_aSubNodes.Count;
 }
        private void AddNodeRecursive(StorageTreeNode oNode, string strKey)
        {
            try
            {

                if ("" != strKey)
                {

                    int nFirstIndex = strKey.IndexOf("/");
                    if (-1 != nFirstIndex)
                    {
                        StorageTreeNode oDirNode = null;
                        String strSubDir = strKey.Substring(0, nFirstIndex);

                        foreach (StorageTreeNode oExistNode in oNode.m_aSubNodes)
                        {
                            if (oExistNode.m_bIsDirectory && oExistNode.m_sName == strSubDir)
                            {
                                oDirNode = oExistNode;
                                break;
                            }
                        }

                        if (null == oDirNode)
                        {

                            oNode.m_aSubNodes.Add(new StorageTreeNode(strSubDir, true));
                        }
                        else
                        {

                            AddNodeRecursive(oDirNode, strKey.Substring(nFirstIndex + 1));
                        }
                    }
                    else
                    {
                        oNode.m_aSubNodes.Add(new StorageTreeNode(strKey, false));
                    }
                }
                else
                {
                    oNode.m_bIsDirectory = true;
                }
            }
            catch
            { }
            return;
        }
 public StorageTreeNode GetTreeNode(string strPath)
 {
     StorageTreeNode oRoot = new StorageTreeNode("root", true);
     try
     {
     if (Directory.Exists(GetFilePath(strPath)))
         GetTreeNodeRecursion(oRoot, strPath);
     }
     catch
     {
     }
     return oRoot;
 }
 public void SetStorageTreeNode(StorageTreeNode oStorageTreeNode)
 {
     m_oStorageTreeNode = oStorageTreeNode;
     m_nIndex           = -1;
     m_nLength          = oStorageTreeNode.m_aSubNodes.Count;
 }