Ejemplo n.º 1
0
        public static void Encrypt(String path)
        {
            if (Common.IsRunningOnMono() && Common.IsPlatformUnix())
            {
                SysFile.Encrypt(path);
                return;
            }
            String fullPath       = Path.GetFullPath(path);
            string normalizedPath = Path.NormalizeLongPath(fullPath);

            if (NativeMethods.EncryptFile(normalizedPath))
            {
                return;
            }
            int errorCode = Marshal.GetLastWin32Error();

            if (errorCode == NativeMethods.ERROR_ACCESS_DENIED)
            {
                var di = new DriveInfo(Path.GetPathRoot(normalizedPath));
                if (!String.Equals("NTFS", di.DriveFormat))
                {
                    throw new NotSupportedException("NTFS drive required for file encryption");
                }
            }
            Common.ThrowIOError(errorCode, fullPath);
        }
Ejemplo n.º 2
0
        public static string SaveImage(byte[] p_ImgData, string p_Exe)
        {
            string outstr = string.Empty;

            string filename = GetTempFileName("pic", p_Exe);//临时文件

            if (filename == "")
            {
                SysFile.WriteFrameworkLog("导出临时图片生成失败,请重新导出");
                return(outstr);
            }
            try
            {
                if (p_ImgData.Length != 0)//有图片内容
                {
                    System.IO.MemoryStream ms    = new System.IO.MemoryStream(p_ImgData);
                    System.Drawing.Image   image = System.Drawing.Image.FromStream(ms);
                    image.Save(filename);
                }
            }
            catch
            {
                return(outstr);
            }
            return(filename);
        }
Ejemplo n.º 3
0
        public async Task MoveAsync(Guid id, Guid?parentId)
        {
            var entity = await _sysFileRepository.GetAsync(id);

            if (entity.ParentId == parentId)
            {
                return;
            }

            var children = await FindChildrenAsync(id, true);

            var oldCode = entity.Code;

            //开始移动

            entity.Code = await GetNextChildCodeAsync(parentId);

            entity.ParentId = parentId;
            // await ValidateSysfileAsync(entity);

            foreach (var child in children)
            {
                child.Code = SysFile.AppendCode(entity.Code, SysFile.GetRelativeCode(child.Code, oldCode));
            }
        }
Ejemplo n.º 4
0
        public object Upload([FromForm] IFormCollection formData, [FromQuery] UploadType uploadType)
        {
            if (uploadType == UploadType.UserPicture)
            {
                if (formData.Files.Count != 1)
                {
                    return(new { });
                }
                var      file       = formData.Files[0];
                var      extName    = file.FileName.GetFileExtName();
                string   targetPath = "/uploads/" + Guid.NewGuid().ToString().Replace("-", "") + extName;
                FileInfo fileInfo   = new FileInfo(Env.WebRootPath + targetPath);
                using (FileStream fs = new FileStream(fileInfo.ToString(), FileMode.Create))
                {
                    file.CopyTo(fs);
                    fs.Flush();
                }
                var entity = new SysFile()
                {
                    Name = file.FileName, CreateTime = DateTime.Now, ExtName = fileInfo.Extension, Path = targetPath, UploadType = uploadType
                };
                SysFileService.Add(entity);
                return(new { fileId = entity.Id, url = UrlPrefix + targetPath });
            }

            return(new { });
        }
Ejemplo n.º 5
0
        private string GetFullPath(SysFile file)
        {
            var userId = file.CreatedUserId == null ? _user.Id : file.CreatedUserId;
            var path   = Path.Combine(_appConfig.FilePath, file.FileDate, userId.ToString());

            return(path);
        }
Ejemplo n.º 6
0
 public static FileStream Create(string path, int bufferSize, FileOptions options)
 {
     if (Common.IsRunningOnMono() && Common.IsPlatformUnix())
     {
         return(SysFile.Create(path, bufferSize, options));
     }
     return(Open(path, FileMode.Create, FileAccess.ReadWrite, FileShare.None, bufferSize, options));
 }
Ejemplo n.º 7
0
 public static void SetAttributes(string path, FileAttributes fileAttributes)
 {
     if (Common.IsRunningOnMono() && Common.IsPlatformUnix())
     {
         SysFile.SetAttributes(path, fileAttributes);
     }
     Common.SetAttributes(path, fileAttributes);
 }
Ejemplo n.º 8
0
        public void AddSysFile(string pname, string desc)
        {
            var sysFile = new SysFile();

            sysFile.PathName    = pname;
            sysFile.Description = desc;
            SysFiles.Add(sysFile);
        }
Ejemplo n.º 9
0
 public static FileAttributes GetAttributes(string path)
 {
     if (Common.IsRunningOnMono() && Common.IsPlatformUnix())
     {
         return(SysFile.GetAttributes(path));
     }
     return(Common.GetFileAttributes(path));
 }
Ejemplo n.º 10
0
 public static FileStream OpenRead(String path)
 {
     if (Common.IsRunningOnMono() && Common.IsPlatformUnix())
     {
         SysFile.OpenRead(path);
     }
     return(Open(path, FileMode.Open, FileAccess.Read, FileShare.Read));
 }
Ejemplo n.º 11
0
        public JsonResult UploadFile(HttpPostedFileBase fileData, string sysId)
        {
            if (fileData != null)
            {
                if (sysId == null)
                {
                    sysId = Util.NewId();
                }
                try
                {
                    ControllerContext.HttpContext.Request.ContentEncoding  = Encoding.GetEncoding("UTF-8");
                    ControllerContext.HttpContext.Response.ContentEncoding = Encoding.GetEncoding("UTF-8");
                    ControllerContext.HttpContext.Response.Charset         = "UTF-8";

                    string filePath = fileData.FileName;
                    string fileName = filePath.Substring(filePath.LastIndexOf("\\") + 1);
                    byte[] mydata   = new byte[fileData.ContentLength + 1];
                    fileData.InputStream.Read(mydata, 0, (int)fileData.ContentLength);

                    SysFile sysFile = new SysFile()
                    {
                        RelID    = sysId,
                        FileName = fileName,
                        FileSize = mydata.Length / (1024 * 1024.0),
                        CreateDT = DateTime.Now,
                        ModifyDT = DateTime.Now,
                        FileData = mydata
                    };
//
                    //if (fileService.FileRepository.Add(sysFile) > 0)
                    //{
                    //    return Json("上传成功");
                    //}
                    //else
                    //{
                    //    return Json("上传失败");
                    //}
                    bool result = fileService.UploadFile(sysFile);

                    if (result)
                    {
                        return(Json("上传成功"));
                    }
                    else
                    {
                        return(Json("上传失败"));
                    }
                }
                catch (Exception ex)
                {
                    return(Json("上传失败," + ex.Message));
                }
            }
            else
            {
                return(Json("上传失败,文件为空"));
            }
        }
Ejemplo n.º 12
0
        public static FileStream OpenWrite(String path)
        {
            if (Common.IsRunningOnMono() && Common.IsPlatformUnix())
            {
                SysFile.OpenWrite(path);
            }

            return(Open(path, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None));
        }
Ejemplo n.º 13
0
        /// <summary>
        ///     Opens the specified file.
        /// </summary>
        /// <param name="path">
        ///     A <see cref="String"/> containing the path of the file to open.
        /// </param>
        /// <param name="access">
        ///     One of the <see cref="FileAccess"/> value that specifies the operations that can be
        ///     performed on the file.
        /// </param>
        /// <param name="mode">
        ///     One of the <see cref="FileMode"/> values that specifies whether a file is created
        ///     if one does not exist, and determines whether the contents of existing files are
        ///     retained or overwritten.
        /// </param>
        /// <param name="share">
        ///     One of the <see cref="FileShare"/> values specifying the type of access other threads
        ///     have to the file.
        /// </param>
        /// <returns>
        ///     A <see cref="FileStream"/> that provides access to the file specified in
        ///     <paramref name="path"/>.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="path"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="ArgumentException">
        ///     <paramref name="path"/> is an empty string (""), contains only white
        ///     space, or contains one or more invalid characters as defined in
        ///     <see cref="Path.GetInvalidPathChars()"/>.
        ///     <para>
        ///         -or-
        ///     </para>
        ///     <paramref name="path"/> contains one or more components that exceed
        ///     the drive-defined maximum length. For example, on Windows-based
        ///     platforms, components must not exceed 255 characters.
        /// </exception>
        /// <exception cref="PathTooLongException">
        ///     <paramref name="path"/> exceeds the system-defined maximum length.
        ///     For example, on Windows-based platforms, paths must not exceed
        ///     32,000 characters.
        /// </exception>
        /// <exception cref="DirectoryNotFoundException">
        ///     One or more directories in <paramref name="path"/> could not be found.
        /// </exception>
        /// <exception cref="UnauthorizedAccessException">
        ///     The caller does not have the required access permissions.
        ///     <para>
        ///         -or-
        ///     </para>
        ///     <paramref name="path"/> refers to a file that is read-only and <paramref name="access"/>
        ///     is not <see cref="FileAccess.Read"/>.
        ///     <para>
        ///         -or-
        ///     </para>
        ///     <paramref name="path"/> is a directory.
        /// </exception>
        /// <exception cref="IOException">
        ///     <paramref name="path"/> refers to a file that is in use.
        ///     <para>
        ///         -or-
        ///     </para>
        ///     <paramref name="path"/> specifies a device that is not ready.
        /// </exception>
        public static FileStream Open(string path, FileMode mode, FileAccess access, FileShare share)
        {
            if (Common.IsRunningOnMono() && Common.IsPlatformUnix())
            {
                return(SysFile.Open(path, mode, access, share));
            }

            return(Open(path, mode, access, share, 0, FileOptions.None));
        }
Ejemplo n.º 14
0
        public static FileStream Open(string path, FileMode mode)
        {
            if (Common.IsRunningOnMono() && Common.IsPlatformUnix())
            {
                return(SysFile.Open(path, mode));
            }

            return(File.Open(path, mode, (mode == FileMode.Append ? FileAccess.Write : FileAccess.ReadWrite), FileShare.None));
        }
Ejemplo n.º 15
0
        public async Task <SysFile> CreateAsync(SysFile entity)
        {
            //获取实体的Code码
            entity.Code = await GetNextChildCodeAsync(entity.ParentId);
            await ValidateSysfileAsync(entity);

            entity.Id = await _sysFileRepository.InsertAndGetIdAsync(entity);

            return(entity);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// 项目文档上传的文件流
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        public async Task <SysFile> ProcessUploadedFileForProjectAsync(IFormFile file)
        {
            var rootFolder       = _appFolder.ProjectRootFolder;
            var dateDirctoryName = DateTime.Now.ToString("yyyy-MM-dd");
            var uniqueFileName   = SequentialGuidGenerator.Instance.Create().ToString() + Path.GetFileName(file.FileName);
            var dateDirctoryPath = Path.Combine(rootFolder, dateDirctoryName);

            if (!Directory.Exists(dateDirctoryPath))
            {
                Directory.CreateDirectory(dateDirctoryPath);
            }

            var saveRPath = Path.Combine(dateDirctoryName, uniqueFileName);//相对路径保存到数据库中  /

            saveRPath = saveRPath.Replace("\\", "/");
            var itempath = Path.Combine(rootFolder, saveRPath);

            var entity = new SysFile
            {
                ContentType      = file.ContentType,
                DateDirctoryName = dateDirctoryName,
                Path             = saveRPath,
                Dir           = false,
                FileExt       = Path.GetExtension(file.FileName),
                Name          = uniqueFileName,
                FileName      = file.FileName,
                Size          = file.Length,
                FormattedSize = GetAutoSizeString(file.Length)
            };

            //因为使用了非托管资源,所以需要手动进行释放
            using (var fileStream = new FileStream(itempath, FileMode.Create))
            {
                //使用IFormFile接口提供的CopyTo()方法将文件复制到文件夹
                await file.CopyToAsync(fileStream);
            }
            byte[] fileBytes;
            using (var stream = file.OpenReadStream())
            {
                fileBytes = stream.GetAllBytes();
            }

            if (file.ContentType.IsIn(MimeTypeNames.ImagePng, MimeTypeNames.ImageGif, MimeTypeNames.ImageJpeg, MimeTypeNames.ImagePjpeg, "image/bmp"))
            {
                using (var bmpImage = new Bitmap(new MemoryStream(fileBytes)))
                {   //图片 获取高度 宽度
                    // MimeTypeNames
                    entity.Width  = bmpImage.Width;
                    entity.Height = bmpImage.Height;
                    entity.IsImg  = true;
                }
            }

            return(entity);
        }
Ejemplo n.º 17
0
        private static StreamReader OpenText(string path, Encoding encoding)
        {
            if (Common.IsRunningOnMono() && Common.IsPlatformUnix())
            {
                return(SysFile.OpenText(path));
            }

            var stream = Open(path, FileMode.Open, FileAccess.Read, FileShare.Read, DefaultBufferSize, FileOptions.SequentialScan);

            return(new StreamReader(stream, encoding, true, 1024));
        }
Ejemplo n.º 18
0
        public static StreamReader OpenText(string path)
        {
            if (Common.IsRunningOnMono())
            {
                return(SysFile.OpenText(path));
            }

            var stream = Open(path, FileMode.Open, FileAccess.Read, FileShare.Read, DefaultBufferSize, FileOptions.SequentialScan);

            return(new StreamReader(stream, Encoding.UTF8, true, 1024));
        }
Ejemplo n.º 19
0
        public static StreamWriter CreateText(String path)
        {
            if (Common.IsRunningOnMono() && Common.IsPlatformUnix())
            {
                return(SysFile.CreateText(path));
            }

            var fileStream = Open(path, FileMode.Create, FileAccess.Write, FileShare.Read, DefaultBufferSize, FileOptions.SequentialScan);

            return(new StreamWriter(fileStream, UTF8NoBOM, DefaultBufferSize));
        }
Ejemplo n.º 20
0
        /// <summary>
        /// 完整文件路径
        /// </summary>
        /// <param name="input"></param>
        /// <param name="file"></param>
        /// <returns></returns>
        private string GetFileFullPath(FileInput input, SysFile file)
        {
            var dir  = Path.Combine(_appConfig.FilePath, file.FileDate, _user.Id.ToString());
            var path = Path.Combine(dir, input.Md5 + Path.GetExtension(input.FileName));

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }
            return(path);
        }
Ejemplo n.º 21
0
 /// <summary>
 /// 读取文件Word
 /// </summary>
 /// <param name="p_TecID">工艺单ID</param>
 /// <param name="o_FileID">返回文件ID</param>
 /// <param name="p_FileName">文件名称</param>
 public static void ReadFileWord(int p_TecID, int p_FileType, out int o_FileID, out string p_FileName)
 {
     byte[] o_File;
     p_FileName = string.Empty;;
     ReadFile(p_TecID, p_FileType, out o_FileID, out o_File);
     if (o_FileID != 0)
     {
         SysFile.CreateDDirectory(FileRouteRead);//没有找到则创建临时文件夹路径
         p_FileName = GetReadFileName(FileSaveNameWord, FileSaveNameWord);
         System.IO.File.WriteAllBytes(p_FileName, o_File);
     }
 }
Ejemplo n.º 22
0
        //// custom codes

        public virtual async Task <string> GetNextChildCodeAsync(Guid?parentId)
        {
            var lastChild = await GetLastChildOrNullAsync(parentId);

            if (lastChild == null)
            {
                var parentCode = parentId != null ? await GetCodeAsync(parentId.Value) : null;

                return(SysFile.AppendCode(parentCode, SysFile.CreateCode(1)));
            }

            return(SysFile.CalculateNextCode(lastChild.Code));
        }
Ejemplo n.º 23
0
        /// <summary>
        ///     Copies the specified file to a specified new file, indicating whether to overwrite an existing file.
        /// </summary>
        /// <param name="sourcePath">
        ///     A <see cref="String"/> containing the path of the file to copy.
        /// </param>
        /// <param name="destinationPath">
        ///     A <see cref="String"/> containing the new path of the file.
        /// </param>
        /// <param name="overwrite">
        ///     <see langword="true"/> if <paramref name="destinationPath"/> should be overwritten
        ///     if it refers to an existing file, otherwise, <see langword="false"/>.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="sourcePath"/> and/or <paramref name="destinationPath"/> is
        ///     <see langword="null"/>.
        /// </exception>
        /// <exception cref="ArgumentException">
        ///     <paramref name="sourcePath"/> and/or <paramref name="destinationPath"/> is
        ///     an empty string (""), contains only white space, or contains one or more
        ///     invalid characters as defined in <see cref="Path.GetInvalidPathChars()"/>.
        ///     <para>
        ///         -or-
        ///     </para>
        ///     <paramref name="sourcePath"/> and/or <paramref name="destinationPath"/>
        ///     contains one or more components that exceed the drive-defined maximum length.
        ///     For example, on Windows-based platforms, components must not exceed 255 characters.
        /// </exception>
        /// <exception cref="PathTooLongException">
        ///     <paramref name="sourcePath"/> and/or <paramref name="destinationPath"/>
        ///     exceeds the system-defined maximum length. For example, on Windows-based platforms,
        ///     paths must not exceed 32,000 characters.
        /// </exception>
        /// <exception cref="FileNotFoundException">
        ///     <paramref name="sourcePath"/> could not be found.
        /// </exception>
        /// <exception cref="DirectoryNotFoundException">
        ///     One or more directories in <paramref name="sourcePath"/> and/or
        ///     <paramref name="destinationPath"/> could not be found.
        /// </exception>
        /// <exception cref="UnauthorizedAccessException">
        ///     The caller does not have the required access permissions.
        ///     <para>
        ///         -or-
        ///     </para>
        ///     <paramref name="overwrite"/> is true and <paramref name="destinationPath"/> refers to a
        ///     file that is read-only.
        /// </exception>
        /// <exception cref="IOException">
        ///     <paramref name="overwrite"/> is false and <paramref name="destinationPath"/> refers to
        ///     a file that already exists.
        ///     <para>
        ///         -or-
        ///     </para>
        ///     <paramref name="sourcePath"/> and/or <paramref name="destinationPath"/> is a
        ///     directory.
        ///     <para>
        ///         -or-
        ///     </para>
        ///     <paramref name="overwrite"/> is true and <paramref name="destinationPath"/> refers to
        ///     a file that already exists and is in use.
        ///     <para>
        ///         -or-
        ///     </para>
        ///     <paramref name="sourcePath"/> refers to a file that is in use.
        ///     <para>
        ///         -or-
        ///     </para>
        ///     <paramref name="sourcePath"/> and/or <paramref name="destinationPath"/> specifies
        ///     a device that is not ready.
        /// </exception>
        public static void Copy(string sourcePath, string destinationPath, bool overwrite)
        {
            if (Common.IsRunningOnMono() && Common.IsPlatformUnix())
            {
                SysFile.Copy(sourcePath, destinationPath, overwrite);
            }

            string normalizedSourcePath      = Path.NormalizeLongPath(sourcePath, "sourcePath");
            string normalizedDestinationPath = Path.NormalizeLongPath(destinationPath, "destinationPath");

            if (!NativeMethods.CopyFile(normalizedSourcePath, normalizedDestinationPath, !overwrite))
            {
                throw Common.GetExceptionFromLastWin32Error();
            }
        }
Ejemplo n.º 24
0
        /// <summary>
        ///     Deletes the specified file.
        /// </summary>
        /// <param name="path">
        ///      A <see cref="String"/> containing the path of the file to delete.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="path"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="ArgumentException">
        ///     <paramref name="path"/> is an empty string (""), contains only white
        ///     space, or contains one or more invalid characters as defined in
        ///     <see cref="Path.GetInvalidPathChars()"/>.
        ///     <para>
        ///         -or-
        ///     </para>
        ///     <paramref name="path"/> contains one or more components that exceed
        ///     the drive-defined maximum length. For example, on Windows-based
        ///     platforms, components must not exceed 255 characters.
        /// </exception>
        /// <exception cref="PathTooLongException">
        ///     <paramref name="path"/> exceeds the system-defined maximum length.
        ///     For example, on Windows-based platforms, paths must not exceed
        ///     32,000 characters.
        /// </exception>
        /// <exception cref="FileNotFoundException">
        ///     <paramref name="path"/> could not be found.
        /// </exception>
        /// <exception cref="DirectoryNotFoundException">
        ///     One or more directories in <paramref name="path"/> could not be found.
        /// </exception>
        /// <exception cref="UnauthorizedAccessException">
        ///     The caller does not have the required access permissions.
        ///     <para>
        ///         -or-
        ///     </para>
        ///     <paramref name="path"/> refers to a file that is read-only.
        ///     <para>
        ///         -or-
        ///     </para>
        ///     <paramref name="path"/> is a directory.
        /// </exception>
        /// <exception cref="IOException">
        ///     <paramref name="path"/> refers to a file that is in use.
        ///     <para>
        ///         -or-
        ///     </para>
        ///     <paramref name="path"/> specifies a device that is not ready.
        /// </exception>
        public static void Delete(string path)
        {
            if (Common.IsRunningOnMono() && Common.IsPlatformUnix())
            {
                SysFile.Delete(path);
                return;
            }

            string normalizedPath = Path.NormalizeLongPath(path);

            if (!NativeMethods.DeleteFile(normalizedPath))
            {
                throw Common.GetExceptionFromLastWin32Error();
            }
        }
Ejemplo n.º 25
0
        /// <summary>
        /// mvc下载文件
        /// </summary>
        /// <param name="sysId"></param>
        /// <returns></returns>
        public ActionResult DownloadFile(string sysId)
        {
            SysFile sysFile = fileService.GetFile(sysId);

            Response.Charset         = "UTF-8";
            Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
            Response.ContentType     = "application/octet-stream";
            //解决文件名乱码问题
            Response.AddHeader("Content-Disposition", "attachment;filename=" + Server.UrlEncode(sysFile.FileName));

            Response.BinaryWrite(sysFile.FileData);
            Response.Flush();
            Response.End();

            return(new EmptyResult());
        }
Ejemplo n.º 26
0
        /// <summary>
        ///     Moves the specified file to a new location.
        /// </summary>
        /// <param name="sourcePath">
        ///     A <see cref="String"/> containing the path of the file to move.
        /// </param>
        /// <param name="destinationPath">
        ///     A <see cref="String"/> containing the new path of the file.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="sourcePath"/> and/or <paramref name="destinationPath"/> is
        ///     <see langword="null"/>.
        /// </exception>
        /// <exception cref="ArgumentException">
        ///     <paramref name="sourcePath"/> and/or <paramref name="destinationPath"/> is
        ///     an empty string (""), contains only white space, or contains one or more
        ///     invalid characters as defined in <see cref="Path.GetInvalidPathChars()"/>.
        ///     <para>
        ///         -or-
        ///     </para>
        ///     <paramref name="sourcePath"/> and/or <paramref name="destinationPath"/>
        ///     contains one or more components that exceed the drive-defined maximum length.
        ///     For example, on Windows-based platforms, components must not exceed 255 characters.
        /// </exception>
        /// <exception cref="PathTooLongException">
        ///     <paramref name="sourcePath"/> and/or <paramref name="destinationPath"/>
        ///     exceeds the system-defined maximum length. For example, on Windows-based platforms,
        ///     paths must not exceed 32,000 characters.
        /// </exception>
        /// <exception cref="FileNotFoundException">
        ///     <paramref name="sourcePath"/> could not be found.
        /// </exception>
        /// <exception cref="DirectoryNotFoundException">
        ///     One or more directories in <paramref name="sourcePath"/> and/or
        ///     <paramref name="destinationPath"/> could not be found.
        /// </exception>
        /// <exception cref="UnauthorizedAccessException">
        ///     The caller does not have the required access permissions.
        /// </exception>
        /// <exception cref="IOException">
        ///     <paramref name="destinationPath"/> refers to a file that already exists.
        ///     <para>
        ///         -or-
        ///     </para>
        ///     <paramref name="sourcePath"/> and/or <paramref name="destinationPath"/> is a
        ///     directory.
        ///     <para>
        ///         -or-
        ///     </para>
        ///     <paramref name="sourcePath"/> refers to a file that is in use.
        ///     <para>
        ///         -or-
        ///     </para>
        ///     <paramref name="sourcePath"/> and/or <paramref name="destinationPath"/> specifies
        ///     a device that is not ready.
        /// </exception>
        public static void Move(string sourcePath, string destinationPath)
        {
            if (Common.IsRunningOnMono() && Common.IsPlatformUnix())
            {
                SysFile.Move(sourcePath, destinationPath);
                return;
            }

            string normalizedSourcePath      = Path.NormalizeLongPath(sourcePath, "sourcePath");
            string normalizedDestinationPath = Path.NormalizeLongPath(destinationPath, "destinationPath");

            if (!NativeMethods.MoveFile(normalizedSourcePath, normalizedDestinationPath))
            {
                throw Common.GetExceptionFromLastWin32Error();
            }
        }
Ejemplo n.º 27
0
        /// <summary>
        ///     Returns a value indicating whether the specified path refers to an existing file.
        /// </summary>
        /// <param name="path">
        ///     A <see cref="String"/> containing the path to check.
        /// </param>
        /// <returns>
        ///     <see langword="true"/> if <paramref name="path"/> refers to an existing file;
        ///     otherwise, <see langword="false"/>.
        /// </returns>
        /// <remarks>
        ///     Note that this method will return false if any error occurs while trying to determine
        ///     if the specified file exists. This includes situations that would normally result in
        ///     thrown exceptions including (but not limited to); passing in a file name with invalid
        ///     or too many characters, an I/O error such as a failing or missing disk, or if the caller
        ///     does not have Windows or Code Access Security (CAS) permissions to to read the file.
        /// </remarks>
        public static bool Exists(string path)
        {
            if (Common.IsRunningOnMono() && Common.IsPlatformUnix())
            {
                return(SysFile.Exists(path));
            }

            bool isDirectory;

            if (Common.Exists(path, out isDirectory))
            {
                return(!isDirectory);
            }

            return(false);
        }
Ejemplo n.º 28
0
        /// <summary>
        /// The process of registering the file information in the database
        /// </summary>
        /// <param name="entityList"></param>
        /// <param name="userId"></param>
        /// <param name="isCommit"></param>
        /// <returns></returns>
        public async Task Add(IList <FileDto> modelList, Guid userId, bool isCommit = true)
        {
            foreach (var model in modelList)
            {
                SysFile entity = Mapper.Map <Domain.SysFile>(model);
                entity.Id       = Guid.NewGuid();
                entity.CreateBy = userId;
                entity.CreateDT = DateTime.Now;

                _uow.Repository <SysFile>().Add(entity);
            }

            if (isCommit)
            {
                await _uow.SaveChangesAsync();
            }
        }
Ejemplo n.º 29
0
        /// <summary>
        /// 验证文件是否符合
        /// </summary>
        /// <param name="entity"> </param>
        /// <returns> </returns>
        public async Task ValidateSysfileAsync(SysFile entity)
        {
            await Task.Yield();

            //var siblings = (await FindChildrenAsync(entity.ParentId))
            //     .Where(ou => ou.Id != entity.Id)
            //     .ToList();

            var result = QuerySysFiles().Any(a => a.Name == entity.Name);

            if (result)
            {
                throw new UserFriendlyException(L("SysfileDuplicateDisplayNameWarning", entity.FileName));
            }

            //对文件进行验证//todo:
        }
Ejemplo n.º 30
0
        private void ClearScanISN()
        {
            //if (DialogResult.Yes != this.ShowConfirmMessage("清除为不可恢复操作,确定清除"))
            //{
            //    return;
            //}

            ReadINIFile read        = new ReadINIFile("ParamSet.ini");
            string      defaultPath = "";// new ParamSetRule().RShowStr((int)ParamSet.扫描条码文件的默认路径);

            if (defaultPath == string.Empty)
            {
                defaultPath = @"D:\DATA.TXT";
            }
            string ScanPath = read.ReadString("ScanBarCode", "ScanPath", defaultPath); //默认路径

            SysFile.DeleteFile(defaultPath);
        }
Ejemplo n.º 31
0
 /// <summary>
 /// 上传文件至oracle数据库
 /// </summary>
 /// <param name="filePath"></param>
 /// <returns></returns>
 public JsonResult Upload(SysFile sysFile)
 {
     bool result = fileService.UploadFile(sysFile);
     return Json(result);
 }
Ejemplo n.º 32
0
        public JsonResult UploadFile(HttpPostedFileBase fileData, string sysId)
        {
            if (fileData != null)
            {
                if (sysId == null)
                {
                    sysId = Util.NewId();
                }
                try
                {
                    ControllerContext.HttpContext.Request.ContentEncoding = Encoding.GetEncoding("UTF-8");
                    ControllerContext.HttpContext.Response.ContentEncoding = Encoding.GetEncoding("UTF-8");
                    ControllerContext.HttpContext.Response.Charset = "UTF-8";

                    string filePath = fileData.FileName;
                    string fileName = filePath.Substring(filePath.LastIndexOf("\\") + 1);
                    byte[] mydata = new byte[fileData.ContentLength + 1];
                    fileData.InputStream.Read(mydata, 0, (int)fileData.ContentLength);

                    SysFile sysFile = new SysFile()
                        {
                            RelID = sysId,
                            FileName = fileName,
                            FileSize = mydata.Length / (1024 * 1024.0),
                            CreateDT = DateTime.Now,
                            ModifyDT = DateTime.Now,
                            FileData = mydata
                        };
            //
                    //if (fileService.FileRepository.Add(sysFile) > 0)
                    //{
                    //    return Json("上传成功");
                    //}
                    //else
                    //{
                    //    return Json("上传失败");
                    //}
                    bool result = fileService.UploadFile(sysFile);

                    if (result)
                    {
                        return Json("上传成功");
                    }
                    else
                    {
                        return Json("上传失败");
                    }

                }
                catch (Exception ex)
                {
                    return Json("上传失败," + ex.Message);
                }

            }
            else
            {
                return Json("上传失败,文件为空");
            }
        }