public BlobFile Get(string id)
        {
            BlobHelper blobHelper;
            BlobFile   blobFile;

            try
            {
                blobHelper = new BlobHelper(_loggerFactory, _config);

                blobFile = blobHelper.Get(id);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(blobFile);
        }
Beispiel #2
0
        /// <summary>
        /// Initializes the stream
        /// </summary>
        protected virtual void InitFileStream()
        {
            var blob = BlobHelper.Get(_path);

            if (_fileMode == FileMode.CreateNew && blob.Exists())
            {
                throw new Exception(string.Format("[FileStream.InitFileStream()]: Cannot create a new file '{0}', the file '{1}' already exists in BLOB storage.", Path, blob.Path));
            }

            if (_fileMode != FileMode.Create && blob.Exists())
            {
                var data = blob.Get();
                Write(data, 0, data.Length);
                Seek(0, SeekOrigin.Begin);

                if (_fileMode == FileMode.Append)
                {
                    Seek(data.Length, SeekOrigin.Begin);
                }
            }

            if ((_fileMode == FileMode.Open || _fileMode == FileMode.Append) && !blob.Exists())
            {
                // weird fallback from original implementation
                // if file does not exist, take local file instead
                // should be absolutely removed!!!

                if (!System.IO.File.Exists(_path))
                {
                    return;
                }

                var data = System.IO.File.ReadAllBytes(_path);
                Write(data, 0, data.Length);
                Seek(0, SeekOrigin.Begin);

                if (_fileMode == FileMode.Append)
                {
                    Seek(data.Length, SeekOrigin.Begin);
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Releases all resources.
        /// </summary>
        protected override void Dispose(bool disposing)
        {
            // handle closed streams
            if (!_stream.CanSeek)
            {
                // stream has been already disposed
                return;
            }

            Flush();

            if (_fileAccess == FileAccess.Write || _fileAccess == FileAccess.ReadWrite)
            {
                Seek(0, SeekOrigin.Begin);

                BlobHelper.Get(Path).Upload(_stream);

                CMS.IO.StorageHelper.LogUpdateFileTask(Path);
            }
        }