Ejemplo n.º 1
0
        /// <summary>
        /// Reads version from database.
        /// </summary>
        /// <param name="path">Version path.</param>
        /// <returns>Instance of <see cref="IVersionAsync"/>.</returns>
        private IVersion readVersion(string path)
        {
            int ind = path.IndexOf('&', path.IndexOf('?'));

            if (ind > 0)
            {
                path = path.Remove(ind);
            }
            string versionNum = path.Substring(path.LastIndexOf('=') + 1);
            string itemPath   = path.Remove(path.IndexOf('?'));

            DavFile item = (DavFile)GetHierarchyItem(itemPath);

            if (item == null)
            {
                return(null);
            }

            string command =
                @"SELECT ItemId, VersionId, VersionNumber, Name, CreatedOn, SerialNumber
                  FROM DMS_DocumentVersions
                  WHERE ItemId = @ItemId AND VersionNumber = @versionNum";

            return(ExecuteVersion(
                       itemPath,
                       command,
                       "@ItemId", item.ItemId,
                       "@versionNum", versionNum).FirstOrDefault());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Reads version content.
        /// </summary>
        /// <param name="output">Stream to write content to.</param>
        /// <param name="startIndex">First byte to read.</param>
        /// <param name="count">Number of bytes to read.</param>
        public void Read(Stream output, long startIndex, long count)
        {
            if (DavFile.ContainsDownloadParam(context.Request.RawUrl))
            {
                DavFile.AddContentDisposition(context, Name);
            }

            using (SqlDataReader reader = context.ExecuteReader(
                       CommandBehavior.SequentialAccess,
                       "SELECT FileContent FROM DMS_DocumentVersions WHERE VersionId = @VersionId",
                       "@VersionId", versionId))
            {
                reader.Read();

                long   bufSize = 1048576; // 1Mb
                byte[] buf     = new byte[bufSize];
                long   retval;

                while ((retval = reader.GetBytes(
                            reader.GetOrdinal("FileContent"),
                            startIndex,
                            buf,
                            0,
                            (int)(count > bufSize ? bufSize : count))) > 0)
                {
                    output.Write(buf, 0, (int)retval);
                    startIndex += retval;
                    count      -= retval;
                }
            }
        }