Exemplo n.º 1
0
        /// <summary>
        /// Generates file version path segment suitable for usage in file name.
        /// This method is slow as it does byte file sig calculation
        /// </summary>
        public string GenerateContentFileVersionSegment(string filePath)
        {
            if (m_ContentFS == null)
            {
                return(null);
            }
            if (m_ContentFSConnect == null)
            {
                return(null);
            }
            if (filePath.IsNullOrWhiteSpace())
            {
                return(null);
            }

            using (var session = m_ContentFS.StartSession(m_ContentFSConnect))
            {
                var buf    = new byte[8 * 1024];
                var fName  = m_ContentFS.CombinePaths(m_ContentFSRootPath, filePath);
                var fsFile = session[fName] as FileSystemFile;
                if (fsFile == null)
                {
                    return(null);
                }
                long sz   = 0;
                var  csum = new NFX.IO.ErrorHandling.Adler32();
                using (var stream = fsFile.FileStream)
                    while (true)
                    {
                        var got = stream.Read(buf, 0, buf.Length);
                        if (got <= 0)
                        {
                            break;
                        }
                        sz += got;
                        csum.Add(buf, 0, got);
                    }

                var data = (ulong)sz << 32 | (ulong)csum.Value;
                return(data.ToString("X").ToLowerInvariant());
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Generates file version path segment suitable for usage in file name.
        /// This method is slow as it does byte file sig calculation
        /// </summary>
        public string GenerateContentFileVersionSegment(string filePath)
        {
            if (m_ContentFS==null) return null;
               if (m_ContentFSConnect==null) return null;
               if (filePath.IsNullOrWhiteSpace()) return null;

               using(var session = m_ContentFS.StartSession(m_ContentFSConnect))
               {
             var buf = new byte[8*1024];
             var fName = m_ContentFS.CombinePaths(m_ContentFSRootPath, filePath);
             var fsFile = session[fName] as FileSystemFile;
             if (fsFile==null) return null;
             long sz = 0;
             var csum = new NFX.IO.ErrorHandling.Adler32();
             using(var stream = fsFile.FileStream)
             while(true)
             {
               var got = stream.Read(buf, 0, buf.Length);
               if (got<=0) break;
               sz += got;
               csum.Add(buf, 0, got);
             }

             var data = (ulong)sz << 32 | (ulong)csum.Value;
             return data.ToString("X").ToLowerInvariant();
               }
        }