private IMediaFile AddMediaFile(IMediaFile mediaFile) { ValidateMediaFileData(mediaFile); IMediaFileData fileData = DataFacade.BuildNew <IMediaFileData>(); fileData.Id = Guid.NewGuid(); CopyFileData(mediaFile, fileData); fileData.LastWriteTime = fileData.CreationTime = DateTime.Now; IMediaFile internalMediaFile; using (Stream readStream = mediaFile.GetReadStream()) { Verify.IsNotNull(readStream, "GetReadStream returned null for type '{0}'", mediaFile.GetType()); fileData.Length = (int)readStream.Length; string internalPath = Path.Combine(_workingDirectory, fileData.Id.ToString()); internalMediaFile = new MediaFile(fileData, Store.Id, _context.CreateDataSourceId( new MediaDataId { MediaType = MediaElementType.File, Id = fileData.Id }, typeof(IMediaFile)), internalPath); using (Stream writeStream = internalMediaFile.GetNewWriteStream()) { readStream.CopyTo(writeStream); } } TransactionFileSystemFileStreamManager.WriteFileToDisk(internalMediaFile); fileData = DataFacade.AddNew <IMediaFileData>(fileData); return(internalMediaFile); }