Exemple #1
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);
            }
        }
Exemple #2
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);
        }
Exemple #3
0
        /// <summary>
        /// Checks the avatar state of the user. It also gives back the avatar creation timestamp and avatar path.
        /// </summary>
        /// <param name="avatarTimeStamp">An unsigned long integer containing the provided avatar timestamp.</param>
        /// <param name="fileCreationTimeStamp">An unsigned long integer gives back the avatar creation timestamp.Use "out" keyword with it.</param>
        /// <param name="filePath">An string gives back the avatar path.Use "out" keyword with it.</param>
        /// <returns>It returns the avatar state.</returns>
        public AvatarState GetAvatarState(ulong avatarTimeStamp, out ulong fileCreationTimeStamp, out NeeoFileInfo filePath)
        {
            fileCreationTimeStamp = 0;
            filePath = null;
            var file = FileManager.GetFile(_userID, FileCategory.Profile, MediaType.Image);

            if (file != null)
            {
                fileCreationTimeStamp = NeeoUtility.GetTimeStamp(file.Info.CreationTimeUtc);
                filePath = file.Info;

                if (fileCreationTimeStamp == avatarTimeStamp)
                {
                    return(AvatarState.NotModified);
                }
                return(AvatarState.Modified);
            }
            return(AvatarState.NotExist);
        }
Exemple #4
0
        /// <summary>
        /// Checks the avatar state of the user. It also gives back the avatar creation timestamp and avatar path.
        /// </summary>
        /// <param name="avatarTimeStamp">An unsigned long integer containing the provided avatar timestamp.</param>
        /// <param name="fileCreationTimeStamp">An unsigned long integer gives back the avatar creation timestamp.Use "out" keyword with it.</param>
        /// <param name="filePath">An string gives back the avatar path.Use "out" keyword with it.</param>
        /// <returns>It returns the avatar state.</returns>
        public AvatarState GetAvatarState(ulong avatarTimeStamp, bool thumbnail, out ulong fileCreationTimeStamp, out NeeoFileInfo filePath)
        {
            fileCreationTimeStamp = 0;
            filePath = null;
            // System.IO.File files;
            if (thumbnail == true)
            {
                var files = FileManager.GetFile(_userID, FileCategory.Thumbnail, MediaType.Image);
                if (files != null)
                {
                    fileCreationTimeStamp = NeeoUtility.GetTimeStamp(files.Info.CreationTimeUtc);
                    filePath = files.Info;

                    if (fileCreationTimeStamp == avatarTimeStamp)
                    {
                        return(AvatarState.NotModified);
                    }
                    return(AvatarState.Modified);
                }
                return(AvatarState.NotExist);
            }


            var file = FileManager.GetFile(_userID, FileCategory.Profile, MediaType.Image);

            if (file != null)
            {
                fileCreationTimeStamp = NeeoUtility.GetTimeStamp(file.Info.CreationTimeUtc);
                filePath = file.Info;

                if (fileCreationTimeStamp == avatarTimeStamp)
                {
                    return(AvatarState.NotModified);
                }
                return(AvatarState.Modified);
            }
            return(AvatarState.NotExist);
        }