Exemple #1
0
        public async Task Execute(IJobExecutionContext context)
        {
            FilesDAL filesDAL = new FilesDAL();
            UsersDAL usersDAL = new UsersDAL();

            Trace.TraceInformation("Running the New Files Job.");
            List <Users> subscribers = usersDAL.GetSubscribers(subFiles);

            foreach (var user in subscribers)
            {
                try
                {
                    var    files   = filesDAL.GetRecentFiles(context.PreviousFireTimeUtc);
                    string subject = "ATHENA : Recent File Uploads";
                    string body    = $"<p>Attached is a spreadsheet with recent files [{files.Count}] uploaded since the last email.</p>";

                    if (files.Count > 0)
                    {
                        await SendEmailWithCSV(user.Email,
                                               subject,
                                               body,
                                               "NewFiles.csv",
                                               files.ToCsv());
                    }
                }catch (Exception e)
                {
                    Trace.TraceError($"Exception during new files job. {e.Message}");
                }
            }

            if (subscribers.Count == 0)
            {
                Trace.TraceWarning("No new files subscribers");
            }
        }
        public static bool DeleteFile(int fileId)
        {
            var file = FilesDAL.GetFile(fileId);

            if (file == null)
            {
                return(false);
            }
            System.IO.File.Delete(file.FullPath);
            return(FilesDAL.DeleteFile(fileId));
        }
Exemple #3
0
 public static FilesDTO GetFileByFileIdAndUserId(int FileId, int UserId)
 {
     return(FilesDAL.GetFileByFileIdAndUserId(FileId, UserId));
 }
Exemple #4
0
 public static bool DeleteFileByFileIdAndUserId(int FileId, int UserId)
 {
     return(FilesDAL.DeleteFileByFileIdAndUserId(FileId, UserId));
 }
Exemple #5
0
 public static int CreateFile(FilesDTO filesDTO)
 {
     return(FilesDAL.CreateFile(filesDTO));
 }
Exemple #6
0
 public static List <FilesDTO> GetFilesByParentFolderIdAndUserId(int ParentFolderId, int UserId)
 {
     return(FilesDAL.GetFilesByParentFolderIdAndUserId(ParentFolderId, UserId));
 }
        public string UploadFiles(int respondentId)
        {
            var result = "";

            if (Request == null || Request.Files == null || Request.Files.Count == 0)
            {
                return("Не выбрано ни одного файла");
            }

            if (SM.CurrentUserIsNull)
            {
                return("Для загрузки файлов необходимо авторизоваться на сайте");
            }

            var files  = new List <UserFile>();
            var userId = SM.CurrentUserId;

            var message = new Message
            {
                SenderId    = userId,
                RecipientId = respondentId,
                Text        = "Прикрепленные файлы:",
                Files       = new List <UserFile>()
            };
            var messageId = UserHelper.AddMessage(message);

            message.Id = messageId;

            foreach (string upload in Request.Files)
            {
                var uploadFile = Request.Files[upload];
                if (uploadFile == null || uploadFile.ContentLength == 0)
                {
                    continue;
                }

                var byteCount = uploadFile.ContentLength;
                if (byteCount > 50 * 1024 * 1024)
                {
                    result += "error,0,0";
                    continue;
                }

                string filename  = uploadFile.FileName;
                var    extension = Path.GetExtension(filename);
                if (extension != null)
                {
                    extension = extension.Replace(".", "");
                    filename  = filename.Substring(0, filename.IndexOf(extension) - 1);
                }

                var deniedExtensions = new List <string>()
                {
                    "exe", "js"
                };
                if (deniedExtensions.Contains(extension))
                {
                    return("Запрещено загружать файлы с расширением " + extension);
                }

                //var isImage = new List<string>() { "jpg", "jpeg", "png" }.Contains(extension);

                var file = new UserFile()
                {
                    UserId         = userId,
                    MessageId      = 0,
                    Name           = filename,
                    Extension      = extension,
                    ModerateResult = ModerateResults.NotChecked,
                    Added          = DateTime.Now.ToUniversalTime(),
                    Changed        = DateTime.Now.ToUniversalTime()
                };
                message.Files.Add(file);
                file.MessageId = messageId;

                try
                {
                    var folder = GetFileDirectoryForFiles(file);
                    if (!Directory.Exists(folder))
                    {
                        Directory.CreateDirectory(folder);
                    }
                    uploadFile.SaveAs(file.FullPath);
                    files.Add(file);
                    result += $"ok,{file.NameWithExtension},{file.Url}|";
                }
                catch (Exception ex)
                {
                    result = "error";
                    LogsDAL.AddError("in UserController.UploadFile(): userId = " + file.UserId + ", exception: " + ex);
                    return(result);
                }
            }

            SM.AddMessageToCurrentDialogs(message);

            FilesDAL.AddFiles(files);

            return(result);
        }