Esempio n. 1
0
        /// <summary>
        /// Creates user's directories based on his/her phone number. It is a static method.
        /// </summary>
        /// <param name="phoneNumber">A string containing user's phone number.</param>
        public static void CreateUserDirectoryStructure(string phoneNumber)
        {
            string userDirectoryPath = Path.Combine(_rootPath, NeeoUtility.GetDirectoryHierarchy(phoneNumber));

            if (!Directory.Exists(userDirectoryPath))
            {
                DirectoryInfo dirInfo = Directory.CreateDirectory(userDirectoryPath);
                dirInfo.CreateSubdirectory(_dirProfile);
                dirInfo.CreateSubdirectory(_dirOffline);
                dirInfo.CreateSubdirectory(_dirAlbum);
            }
            else
            {
                if (!Directory.Exists(Path.Combine(userDirectoryPath, _dirProfile)))
                {
                    DirectoryInfo dirInfo = Directory.CreateDirectory(Path.Combine(userDirectoryPath, _dirProfile));
                }
                if (!Directory.Exists(Path.Combine(userDirectoryPath, _dirOffline)))
                {
                    DirectoryInfo dirInfo = Directory.CreateDirectory(Path.Combine(userDirectoryPath, _dirOffline));
                }
                if (!Directory.Exists(Path.Combine(userDirectoryPath, _dirAlbum)))
                {
                    DirectoryInfo dirInfo = Directory.CreateDirectory(Path.Combine(userDirectoryPath, _dirAlbum));
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="avatarTimeStamp"></param>
        /// <returns></returns>
        public AvatarState GetAvatarState(ulong avatarTimeStamp)
        {
            string userDirectoryPath = Path.Combine(_rootPath, NeeoUtility.GetDirectoryHierarchy(_userID), _dirProfile);

            if (Directory.Exists(userDirectoryPath))
            {
                DirectoryInfo dirInfo  = new DirectoryInfo(userDirectoryPath);
                FileInfo      fileInfo = dirInfo.GetFiles().SingleOrDefault(x => x.Name == NeeoUtility.ConvertToFileName(_userID));
                if (fileInfo != null)
                {
                    if (NeeoUtility.GetTimeStamp(fileInfo.CreationTimeUtc) == avatarTimeStamp)
                    {
                        return(AvatarState.NotModified);
                    }
                    else
                    {
                        return(AvatarState.Modified);
                    }
                }
                else
                {
                    return(AvatarState.NotExist);
                }
            }
            else
            {
                return(AvatarState.NotExist);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Deletes user's profile picture stored in the user profile directory. It is an instance method.
        /// </summary>
        /// <returns>true if user's profile picture is successfully deleted; otherwise false.</returns>
        public bool DeleteFile(FileClassfication fileClassfication, string fileName)
        {
            bool   result        = false;
            string directoryPath = null;

            switch (fileClassfication)
            {
            case FileClassfication.Profile:
                directoryPath = Path.Combine(_rootPath, NeeoUtility.GetDirectoryHierarchy(_userID), _dirProfile);
                break;

            case FileClassfication.Offline:
                directoryPath = Path.Combine(_rootPath, NeeoUtility.GetDirectoryHierarchy(_userID), _dirOffline);
                break;

            case FileClassfication.Album:
                directoryPath = Path.Combine(_rootPath, NeeoUtility.GetDirectoryHierarchy(_userID), _dirAlbum);
                break;
            }

            if (Directory.Exists(directoryPath))
            {
                result = File.DeleteFile(fileName, directoryPath);
            }
            else
            {
                throw new ApplicationException(CustomHttpStatusCode.InvalidUser.ToString("D"));
            }
            return(result);
        }
Esempio n. 4
0
        /// <summary>
        /// Updates user's profile picture stores in the user's profile directory.
        /// </summary>
        /// <param name="fileData">A string containing base64-encoded file data.</param>
        /// <param name="senderID">A string containing sender user id. It is required only while uploading offline file.</param>
        /// <returns>true if user's profile picture is successfully updated; otherwise false. </returns>
        public string UploadImageFile(string fileData, FileClassfication fileClassfication, string senderID)
        {
            string result        = null;
            string fileName      = null;
            string directoryPath = null;

            switch (fileClassfication)
            {
            case FileClassfication.Profile:
                fileName      = NeeoUtility.ConvertToFileName(_userID);
                directoryPath = Path.Combine(_rootPath, NeeoUtility.GetDirectoryHierarchy(_userID), _dirProfile);
                if (Directory.Exists(directoryPath))
                {
                    result = File.SaveFile(fileName, fileData, directoryPath).ToString();
                }
                else
                {
                    throw new ApplicationException(CustomHttpStatusCode.InvalidUser.ToString("D"));
                }
                break;

            case FileClassfication.Offline:
                string timeStamp = NeeoUtility.GetTimeStamp(DateTime.UtcNow).ToString();
                fileName      = NeeoUtility.GetFileNameInOfflineFileFormat(senderID, _userID, timeStamp);
                directoryPath = Path.Combine(_rootPath, NeeoUtility.GetDirectoryHierarchy(_userID), _dirOffline);
                if (Directory.Exists(directoryPath))
                {
                    if (File.SaveFile(fileName, fileData, directoryPath))
                    {
                        result = NeeoUtility.GenerateImageUrl(_userID, timeStamp, fileClassfication, 0, senderID);
                    }
                }
                else
                {
                    throw new ApplicationException(CustomHttpStatusCode.InvalidUser.ToString("D"));
                }
                break;

            case FileClassfication.Album:
                fileName      = NeeoUtility.GetTimeStamp(DateTime.UtcNow).ToString();
                directoryPath = Path.Combine(_rootPath, NeeoUtility.GetDirectoryHierarchy(_userID), _dirAlbum);
                if (Directory.Exists(directoryPath))
                {
                    result = File.SaveFile(NeeoUtility.ConvertToFileName(fileName), fileData, directoryPath).ToString();
                }
                else
                {
                    throw new ApplicationException(CustomHttpStatusCode.InvalidUser.ToString("D"));
                }
                break;
            }
            return(result);
        }
Esempio n. 5
0
        /// <summary>
        /// Gets the path of the user's profile picture if it exists.
        /// </summary>
        /// <returns>path of the file if it exists; otherwise empty string will be returned.</returns>
        public string GetAvatar()
        {
            string fileName          = NeeoUtility.ConvertToFileName(_userID);
            string userDirectoryPath = Path.Combine(_rootPath, NeeoUtility.GetDirectoryHierarchy(_userID), _dirProfile);

            if (Directory.Exists(userDirectoryPath))
            {
                return(File.GetFilePath(fileName, userDirectoryPath));
            }
            else
            {
                return("");
            }
        }
Esempio n. 6
0
 /// <summary>
 /// Deletes user's directories based on his/her phone number. It is an instance method.
 /// </summary>
 /// <param name="phoneNumber">A string containing user's phone number.</param>
 public void DeleteUserDirectoryStructure()
 {
     try
     {
         string userDirectoryPath = Path.Combine(_rootPath, NeeoUtility.GetDirectoryHierarchy(_userID));
         if (Directory.Exists(userDirectoryPath))
         {
             Directory.Delete(userDirectoryPath, true);
         }
     }
     catch (UnauthorizedAccessException unAuthExp)
     {
         LogManager.CurrentInstance.ErrorLogger.LogError(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, unAuthExp.Message, unAuthExp);
     }
 }
Esempio n. 7
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="fileName"></param>
 /// <param name="fileClassfication"></param>
 /// <returns></returns>
 public string GetFileState(string fileName, FileClassfication fileClassfication)
 {
     if (fileClassfication == FileClassfication.Offline)
     {
         string userDirectoryPath = Path.Combine(_rootPath, NeeoUtility.GetDirectoryHierarchy(_userID), _dirOffline);
         if (Directory.Exists(userDirectoryPath))
         {
             DirectoryInfo dirInfo  = new DirectoryInfo(userDirectoryPath);
             FileInfo      fileInfo = dirInfo.GetFiles().SingleOrDefault(x => x.Name == fileName);
             if (fileInfo != null)
             {
                 return(fileInfo.FullName);
             }
             else
             {
                 return(null);
             }
         }
         else
         {
             return(null);
         }
     }
     else if (fileClassfication == FileClassfication.Album)
     {
         string userDirectoryPath = Path.Combine(_rootPath, NeeoUtility.GetDirectoryHierarchy(_userID), _dirAlbum);
         if (Directory.Exists(userDirectoryPath))
         {
             DirectoryInfo dirInfo  = new DirectoryInfo(userDirectoryPath);
             FileInfo      fileInfo = dirInfo.GetFiles().SingleOrDefault(x => x.Name == fileName);
             if (fileInfo != null)
             {
                 return(fileInfo.FullName);
             }
             else
             {
                 return(null);
             }
         }
         else
         {
             return(null);
         }
     }
     return(null);
 }
Esempio n. 8
0
        /// <summary>
        /// Determines the existance of user's directories based on his/her phone number. It is a static method.
        /// </summary>
        /// <param name="phoneNumber">A string containing user's phone number.</param>
        /// <returns>true if user's directories exists; otherwise false.</returns>
        public static bool UserDirectoryStructureExists(string phoneNumber)
        {
            string userDirectoryPath = Path.Combine(_rootPath, NeeoUtility.GetDirectoryHierarchy(phoneNumber));

            return(Directory.Exists(userDirectoryPath));
        }