示例#1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="fileCategory"></param>
        /// <returns></returns>
        public static bool IsExist(string fileName, FileCategory fileCategory, MediaType mediaType = MediaType.Image)
        {
            bool isExist = false;

            switch (fileCategory)
            {
            case FileCategory.Profile:
                isExist = File.Exists(Path.Combine(Profile.GetDirectoryPath(fileName), MediaUtility.AddFileExtension(fileName, mediaType)));
                break;

            case FileCategory.Shared:
                Network.Server server = new Network.Server()
                {
                    LocalIP = "127.0.0.1",
                    Name    = "Current Server"
                };
                isExist = File.Exists(Path.Combine(Shared.GetDirectoryPath(server.GetServerNetworkPath(), fileName, mediaType), MediaUtility.AddFileExtension(fileName, mediaType)));
                break;

            case FileCategory.Group:

                isExist = File.Exists(Path.Combine(Group.GetDirectoryPath(fileName), MediaUtility.AddFileExtension(fileName, mediaType)));
                break;
            }
            return(isExist);
        }
示例#2
0
        public new void DeleteDirectory(string name)
        {
            string path = Path.Combine(ProfileDirectoryPath, MediaUtility.GetHierarchicalPath(name, NeeoConstants.HierarchyLevelLimit), name, Profile);

            if (base.Exists(path))
            {
                base.DeleteDirectory(path);
            }
        }
        public new string CreateDirectory(string name)
        {
            string path = Path.Combine(GroupDirectoryPath, MediaUtility.GetHierarchicalPath(name, NeeoConstants.HierarchyLevelLimit));

            if (!base.Exists(path))
            {
                base.CreateDirectory(path);
            }
            return(path);
        }
示例#4
0
        public bool Exists(string name, out string path)
        {
            string dirPath = Path.Combine(ProfileDirectoryPath, MediaUtility.GetHierarchicalPath(name, NeeoConstants.HierarchyLevelLimit), name, Profile);

            if (base.Exists(dirPath))
            {
                path = dirPath;
                return(true);
            }
            path = "";
            return(false);
        }
示例#5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="fileCategory"></param>
        /// <returns></returns>
        public static bool Delete(string fileName, FileCategory fileCategory)
        {
            string path      = "";
            bool   isDeleted = false;

            switch (fileCategory)
            {
            case FileCategory.Profile:
                path = Path.Combine(Profile.GetDirectoryPath(fileName),
                                    MediaUtility.AddFileExtension(fileName, MediaType.Image));
                if (File.Exists(path))
                {
                    isDeleted = File.Delete(path);
                }
                else
                {
                    isDeleted = true;
                }

                break;

            case FileCategory.Shared:
                throw new NotImplementedException();
                break;

            case FileCategory.Group:

                path = Path.Combine(Group.GetDirectoryPath(fileName),
                                    MediaUtility.AddFileExtension(fileName, MediaType.Image));
                if (File.Exists(path))
                {
                    isDeleted = File.Delete(path);
                }
                else
                {
                    isDeleted = true;
                }
                break;
            }
            return(isDeleted);
        }
示例#6
0
文件: File.cs 项目: HasanKalim19/new
        /// <summary>
        /// Save file to the mentioned directory.
        /// </summary>
        /// <param name="file">An object containing file information and its data.</param>
        /// <returns>true if file is successfully saved; otherwise, false.</returns>
        public static void Save(File file)
        {
            string filePath = null;

            FileStream fileStream = null;

            if (file.Info.FullName != null)
            {
                filePath = Path.Combine(file.Info.FullPath, file.Info.FullName);
            }
            else
            {
                filePath = Path.Combine(file.Info.FullPath, MediaUtility.AddFileExtension(file.Info.Name, file.Info.MediaType));
            }

            if (file.Data != null)
            {
                if (System.IO.File.Exists(filePath))
                {
                    LogManager.CurrentInstance.InfoLogger.LogInfo(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, "Deleted avatar while updating it.");
                    System.IO.File.Delete(filePath);
                }
                try
                {
                    byte[] fileDataBinary = null;
                    fileDataBinary = Convert.FromBase64String(file.Data);
                    //fileStream = System.IO.File.OpenWrite(filePath);
                    //fileStream.Write(fileDataBinary, 0, fileDataBinary.Length);
                    using (MemoryStream stream = new MemoryStream(fileDataBinary, 0, fileDataBinary.Length))
                    {
                        System.Drawing.Image.FromStream(stream, true).Save(filePath, ImageFormat.Jpeg);
                        var fileInfo = new FileInfo(filePath);
                        file.Info.CreationTimeUtc = fileInfo.CreationTimeUtc;
                        file.Info.Length          = fileInfo.Length;
                    }
                }
                catch (FormatException formatExp)
                {
                    LogManager.CurrentInstance.ErrorLogger.LogError(
                        System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, formatExp.Message, formatExp);
                    throw new ApplicationException(CustomHttpStatusCode.InvalidFileData.ToString("D"));
                }
                catch (System.Runtime.InteropServices.ExternalException extExp)
                {
                    LogManager.CurrentInstance.ErrorLogger.LogError(
                        System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, extExp.Message, extExp);
                    throw new ApplicationException(CustomHttpStatusCode.FileFormatMismatched.ToString("D"));
                }
                finally
                {
                    if (fileStream != null)
                    {
                        fileStream.Close();
                    }
                }
            }
            else if (file.FileStream != null)
            {
                if (System.IO.File.Exists(filePath))
                {
                    LogManager.CurrentInstance.InfoLogger.LogInfo(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, "Deleted avatar while updating it.");
                    System.IO.File.Delete(filePath);
                }
                try
                {
                    fileStream = System.IO.File.OpenWrite(filePath);
                    if (file.FileStream.Postion > 0)
                    {
                        if (file.FileStream.Postion > fileStream.Length)
                        {
                            fileStream.Position = file.FileStream.Postion - 1;
                        }
                        else
                        {
                            throw new IndexOutOfRangeException("File seek position is invalid.");
                        }
                    }
                    file.FileStream.Stream.CopyTo(fileStream);
                    var info = new FileInfo(filePath);
                    file.Info.CreationTimeUtc = info.CreationTimeUtc;
                }
                catch (Exception exception)
                {
                    LogManager.CurrentInstance.ErrorLogger.LogError(
                        System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, exception.Message, exception);
                    throw;
                }
                finally
                {
                    if (fileStream != null)
                    {
                        fileStream.Close();
                    }
                }
            }
        }
示例#7
0
        public new bool Exists(string name)
        {
            string path = Path.Combine(ProfileDirectoryPath, MediaUtility.GetHierarchicalPath(name, NeeoConstants.HierarchyLevelLimit), name, Profile);

            return(base.Exists(path));
        }
示例#8
0
        //public string GetDirectoryPath(string name)
        //{
        //    return Path.Combine(ProfileDirectoryPath, MediaUtility.GetHierarchicalPath(name, NeeoConstants.HierarchyLevelLimit), name, Profile);
        //}

        public string GetDirectoryPath(string name)
        {
            return(Path.Combine(ProfileDirectoryPath, MediaUtility.GetHierarchicalPath(name, NeeoConstants.HierarchyLevelLimit), name, Profile));
            //string path = ConfigurationManager.AppSettings["profileImageSavePath"];
            //return path;
        }
 public string GetDirectoryPath(string name)
 {
     return(Path.Combine(ProfileDirectoryPath, MediaUtility.GetHierarchicalPath(name, NeeoConstants.HierarchyLevelLimit), name, Profile));
 }
示例#10
0
 public string GetDirectoryPath(string serverNetworkPath, string name, MediaType mediaType)
 {
     return(Path.Combine(serverNetworkPath, Shared, mediaType.ToString("G"), MediaUtility.GetHierarchicalPath(name, NeeoConstants.HierarchyLevelLimit)));
 }