示例#1
0
        public FileTemp InsertDocument(FileTemp Document, bool dbStore)
        {
            Document.MediaType = Document.MediaType.EmptyNull();
            Document.MediaType = Document.MediaType.Truncate(20);

            Document.FileName = Document.FileName.Truncate(100);

            //Document document = _documentRepository.Create();

            var docContent = new FileContent()
            {
                FileName = Document.FileName,
                Content  = Convert.ToBase64String(Document.FileBinary)
            };

            Document.FileContent = docContent.ToXml();
            //_documentRepository.Add(Document);
            _work.commit();

            if (!dbStore)
            {
                SaveDocumentInFile(Document.Id, Document.FileBinary, Document.MediaType);
            }

            return(Document);
        }
示例#2
0
        public FileTemp InsertAttachment(FileTemp attachment, bool dbStore)
        {
            attachment.MediaType = attachment.MediaType.EmptyNull();
            attachment.MediaType = attachment.MediaType.Truncate(20);

            attachment.FileName = attachment.FileName.Truncate(100);

            //Document document = _documentRepository.Create();

            var contentFile = new ContentFile()
            {
                FileName    = attachment.FileName,
                FileContent = Convert.ToBase64String(attachment.FileBinary)
            };

            attachment.FileContent = contentFile.ToXml();
            _tempFileRepository.Add(attachment);
            _work.commit();

            if (!dbStore)
            {
                SaveDocumentInFile(attachment.Id, attachment.FileBinary, attachment.MediaType);
            }

            return(attachment);
        }
示例#3
0
        public int SaveFileTemp(FileTemp ft)
        {
            var _context = _contextFactory();

            _context.FileTemp.Add(ft);
            _context.SaveChanges();
            return(ft.FileTempId);
        }
示例#4
0
        /// <summary>
        /// 保存评论的上传附件,返回关联文件
        /// </summary>
        /// <param name="repid"></param>
        /// <param name="filesid"></param>
        public List <FileTemp> ContentReplyFiles(long repid, string filesid)
        {
            //返回文件集合
            List <FileTemp> listFileTemp = new List <FileTemp>();

            var listFile = filesid.Split(',');

            //var reapFile = _contentReplyFileRepository.GetAll().Where(a => a.ContentReplyId==repid);

            //删除原来的评论上传文件
            //foreach (var item in reapFile)
            //{
            //    _contentReplyFileRepository.Delete(item);
            //}
            //新增上传文件
            if (listFile.Count() > 0)
            {
                foreach (var item in listFile)
                {
                    if (item != "" && item != "删除")
                    {
                        var fileId = item.ToInt32();
                        if (fileId != 0)
                        {
                            ContentReplyFile rfiles = new ContentReplyFile
                            {
                                ContentReplyId = repid,
                                FileId         = fileId
                            };
                            _contentReplyFileRepository.Insert(rfiles);
                            //根据文件ID查询出上传文件,并加入返回集合
                            var File_Id = _filesRepository.Get(fileId);
                            var filetp  = new FileTemp();
                            filetp.Id     = File_Id.Id;
                            filetp.Name   = File_Id.TrueName;
                            filetp.Length = File_Id.Length;
                            if (File_Id.Length > 1024 * 1024)
                            {
                                filetp.LengthKb = ((double)(File_Id.Length * 100 / (1024 * 1024)) / 100) + "MB";
                            }
                            else
                            {
                                filetp.LengthKb = ((double)(File_Id.Length * 100 / 1024) / 100) + "KB";
                            }
                            filetp.Uptime = File_Id.UploadTime;
                            filetp.Upurl  = File_Id.Url;

                            listFileTemp.Add(filetp);
                        }
                    }
                }
            }
            return(listFileTemp);
        }
示例#5
0
        public void Delete(int id)
        {
            var _context = _contextFactory();
            var ft       = new FileTemp {
                FileTempId = id
            };

            _context.FileTemp.Attach(ft);
            _context.FileTemp.Remove(ft);
            _context.SaveChanges();
        }
示例#6
0
 internal PostFile(FileTemp file) : this()
 {
     TimeFilename     = file.tim;
     OriginalFilename = file.filename;
     FileExtension    = file.ext;
     FileSize         = file.fsize;
     MD5             = file.md5;
     Width           = file.w;
     Height          = file.h;
     ThumbnailWidth  = file.tn_w;
     ThumbnailHeight = file.tn_h;
     IsDeleted       = file.filedeleted == 1;
     IsSpoiler       = file.spoiler == 1;
     CustomSpoiler   = file.custom_spoiler;
 }
示例#7
0
        protected virtual void DeleteDocumentOnFileSystem(FileTemp document)
        {
            if (document == null)
            {
                throw new ArgumentNullException("document");
            }

            string lastPart = MimeTypes.MapMimeTypeToExtension(document.MediaType);
            string fileName = string.Format("{0}-0.{1}", document.Id.ToString("0000000"), lastPart);
            string filePath = GetDocumentLocalPath(fileName);

            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }
        }
示例#8
0
        private HttpResponseMessage DeprecatedActivityAttachment(MultipartFormDataStreamProvider provider)
        {
            FileTemp document = null;

            if (provider.FormData.AllKeys.Contains("serial"))
            {
                document = new FileTemp()
                {
                    Serial  = Guid.NewGuid().ToString(),
                    Name    = (provider.FormData.AllKeys.Contains("name")) ? provider.FormData.GetValues("name").FirstOrDefault() : string.Empty,
                    Comment = (provider.FormData.AllKeys.Contains("description")) ? provider.FormData.GetValues("description").FirstOrDefault() : string.Empty
                };
            }
            else
            {
                provider.DeleteLocalFiles();
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Not found document was matched."));
            }

            var fileTemporary = new FileTemp();

            foreach (var fileData in provider.FileData)
            {
                var documentAttachment = new FileTemp
                {
                    Serial             = document.Serial,
                    Comment            = document.Comment,
                    Name               = document.Name,
                    FileName           = fileData.Headers.ContentDisposition.FileName.ToUnquoted(),
                    MediaType          = fileData.Headers.ContentType.MediaType.ToUnquoted(),
                    ContentDisposition = fileData.Headers.ContentDisposition.Parameters,
                    FileBinary         = File.ReadAllBytes(fileData.LocalFileName)
                };

                if (documentAttachment.FileBinary != null && documentAttachment.FileBinary.Length > 0)
                {
                    fileTemporary = _attachmentService.Value.InsertAttachment(documentAttachment, true);
                }
            }

            var result = new { success = true, data = fileTemporary };

            provider.DeleteLocalFiles();

            return(Request.CreateResponse(HttpStatusCode.OK, result));
        }
示例#9
0
        /// <summary>
        /// 根据评论ID获取上传附件集合
        /// </summary>
        /// <param name="repid"></param>
        /// <returns></returns>
        public List <FileTemp> ReplyFilesList(long repid)
        {
            //返回文件集合
            List <FileTemp> listFileTemp = new List <FileTemp>();
            var             replyFile    = _contentReplyFileRepository.GetAll().Where(x => x.ContentReplyId == repid).ToList();
            List <long>     fileList     = new List <long>();

            if (replyFile.Count > 0)
            {
                for (int i = 0; i < replyFile.Count; i++)
                {
                    fileList.Add(replyFile[i].FileId);
                }
            }
            if (fileList.Count > 0)
            {
                foreach (var item in fileList)
                {
                    //根据文件ID查询出上传文件,并加入返回集合
                    var File_Id = _filesRepository.Get(item);
                    var filetp  = new FileTemp();
                    filetp.Id     = File_Id.Id;
                    filetp.Name   = File_Id.TrueName;
                    filetp.Length = File_Id.Length;
                    if (File_Id.Length > 1024 * 1024)
                    {
                        filetp.LengthKb = ((double)(File_Id.Length * 100 / (1024 * 1024)) / 100) + "MB";
                    }
                    else
                    {
                        filetp.LengthKb = ((double)(File_Id.Length * 100 / 1024) / 100) + "KB";
                    }
                    filetp.Uptime = File_Id.UploadTime;
                    filetp.Upurl  = File_Id.Url;

                    listFileTemp.Add(filetp);
                }
            }


            return(listFileTemp);
        }
示例#10
0
        /// <summary>
        /// 根据评论ID,查询关联上传附件
        /// </summary>
        /// <param name="repid"></param>
        public List <FileTemp> ContentReplyFileList(string repid)
        {
            //新建一列,把评论ID保存。
            //返回文件集合
            List <FileTemp> listFileTemp = new List <FileTemp>();

            var listRealy = repid.Split(',');


            if (listRealy.Count() > 0)
            {
                foreach (var item in listRealy)
                {
                    //根据评论ID查询该评论上传文件
                    var itemId     = item.ToInt32();
                    var ListFileId = _contentReplyFileRepository.GetAll().Where(x => x.ContentReplyId == itemId).ToList();
                    for (int i = 0; i < ListFileId.Count; i++)
                    {
                        //根据文件ID查询出上传文件,并加入返回集合
                        var File_Id = _filesRepository.Get(ListFileId[i].FileId);
                        var filetp  = new FileTemp();
                        filetp.Id     = File_Id.Id;
                        filetp.Name   = File_Id.TrueName;
                        filetp.Length = File_Id.Length;
                        if (File_Id.Length > 1024 * 1024)
                        {
                            filetp.LengthKb = ((double)(File_Id.Length * 100 / (1024 * 1024)) / 100) + "MB";
                        }
                        else
                        {
                            filetp.LengthKb = ((double)(File_Id.Length * 100 / 1024) / 100) + "KB";
                        }
                        filetp.Uptime  = File_Id.UploadTime;
                        filetp.Upurl   = File_Id.Url;
                        filetp.RealyId = itemId;
                        listFileTemp.Add(filetp);
                    }
                }
            }
            return(listFileTemp);
        }
示例#11
0
 public void UpdateAttachment(FileTemp document)
 {
     _tempFileRepository.Update(document);
     _work.commit();
 }
示例#12
0
 public FileTemp Get(FileTemp t)
 {
     throw new NotImplementedException();
 }
示例#13
0
        /// <summary>
        /// Copy the source directory contents to the destination directory.
        /// </summary>
        /// <param name="overwriteFlag">Flag determining whether or not files/folders will be overridden at destination if they already exist.</param>
        private bool CopyToSaveLocation(bool overwriteFlag)
        {
            //string TopFolderName = GetFileName(Source)
            //string UpperDestination = Destination
            // Destination = Destination + "\\" + TopFolderName
            if (QuickSaveButtonFlag)
            {
                Games.CurrentSettings.LastQuickSavePath = Destination; // set new last quick save path
            }
            bool success = true;

            if (overwriteFlag)
            {
                if (Directory.Exists(Destination))   // case 1
                {
                    if (Properties.Settings.Default.SimpleSaveOverwriting)
                    {
                        try {
                            if (Properties.Settings.Default.SimpleSaveOverwritingPermaDelete == false)
                            {
                                new Computer().FileSystem.DeleteDirectory(Destination, Microsoft.VisualBasic.FileIO.UIOption.OnlyErrorDialogs, Microsoft.VisualBasic.FileIO.RecycleOption.SendToRecycleBin, Microsoft.VisualBasic.FileIO.UICancelOption.DoNothing);
                            }
                            else
                            {
                                Directory.Delete(Destination, true);
                            }
                            new Computer().FileSystem.CopyDirectory(Source, Destination, overwriteFlag);
                        } catch {
                            AutosaveIOFailure(); // Autosave failure
                        }
                    }
                    else
                    {
                        try {
                            new Computer().FileSystem.CopyDirectory(Source, Destination, overwriteFlag);
                        } catch {
                            AutosaveIOFailure(); // Autosave failure
                        }
                    }
                }
                else     // case 2
                {
                    try {
                        Directory.CreateDirectory(Destination);
                        new Computer().FileSystem.CopyDirectory(Source, Destination, overwriteFlag);
                    } catch {
                        try {
                            Directory.Delete(Destination);
                        } catch { }
                        AutosaveIOFailure(); // Autosave failure
                        success = false;
                    }
                }
            }
            else                                    // Don't overwrite anything
            {
                if (!Directory.Exists(Destination)) // case 3
                {
                    try {
                        Directory.CreateDirectory(Destination);
                        new Computer().FileSystem.CopyDirectory(Source, Destination, overwriteFlag);
                    } catch {
                        AutosaveIOFailure(); // Autosave failure
                        return(false);
                    }
                }
                else     // case 4

                // Initialization.
                {
                    if (voidFiles != null)
                    {
                        voidFiles.Clear();
                    }
                    else
                    {
                        voidFiles = new List <string>();
                    }
                    if (voidDirectories != null)
                    {
                        voidDirectories.Clear();
                    }
                    else
                    {
                        voidDirectories = new List <string>();
                    }

                    // Preliminary populating.
                    string[] list = Directory.GetFiles(Source);
                    foreach (string FilePath in list)
                    {
                        voidFiles.Add(FilePath);
                    }

                    // Perform file/directory adding on all subfolders found as well.
                    GenerateWhatToSaveList(ref list, ref Source);

                    // Create all the directories first.
                    foreach (string DirectoryTemp in voidDirectories)
                    {
                        if (!Directory.Exists(Destination + DirectoryTemp))
                        {
                            try {
                                new Computer().FileSystem.CopyDirectory(Source + DirectoryTemp, Destination + DirectoryTemp);
                            } catch {
                                AutosaveIOFailure(); // Autosave failure
                            }
                        }
                    }

                    // Create all the files
                    foreach (string FileTemp in voidFiles)
                    {
                        string[] tmp2 = FileTemp.Split(new[] { Source }, StringSplitOptions.None);
                        try {
                            if (!File.Exists(Destination + tmp2[1]))
                            {
                                new Computer().FileSystem.CopyFile(FileTemp, Destination + tmp2[1]);
                            }
                        } catch {
                            AutosaveIOFailure(); // Autosave failure
                        }
                    }

                    voidFiles.Clear();
                    voidDirectories.Clear();
                }
            }
            return(success);
        }