private dtoNodeFolderItem CreateItemNode(dtoNodeFolderItem father, dtoFolderTreeItem folder, long sizeToMove, List <long> idAvailable, Boolean forUpload) { dtoNodeFolderItem node = new dtoNodeFolderItem() { Type = NodeType.Item, IsCurrent = folder.IsCurrent }; node.Id = folder.Id; node.Name = folder.Name; node.IsHome = folder.IsHome; node.Selected = folder.IsCurrent; node.Selectable = (sizeToMove == 0 || folder.ValidateSpace(sizeToMove, forUpload)); return(node); }
public List <dtoModuleUploadedItem> FileAddToRepository(liteRepositorySettings settings, String istance, RepositoryIdentifier identifier, litePerson person, Boolean alwaysLastVersion, long idFolder, dtoFolderTreeItem folderQuota, IEnumerable <RepositoryItem> rpItems, List <dtoUploadedItem> itemsToAdd, Object obj, long idObject, Int32 idObjectType, String moduleCode, Int32 idModuleAjaxAction, Int32 idModuleAction = 0) { List <dtoModuleUploadedItem> files = null; Boolean isInTransaction = Manager.IsInTransaction(); try { if (person != null) { DateTime date = DateTime.Now; files = new List <dtoModuleUploadedItem>(); List <String> brothersFile = rpItems.Where(i => i.IdFolder == idFolder && i.Type != ItemType.Link && i.Type != ItemType.Folder && i.Deleted == BaseStatusDeleted.None).Select(f => f.DisplayName).ToList(); RepositoryItem father = rpItems.FirstOrDefault(i => i.Id == idFolder); List <RepositoryItem> fathers = (idFolder == 0) ? new List <RepositoryItem>() : GetFullReverseFathers(idFolder, rpItems); files.AddRange(itemsToAdd.Where(i => !i.IsValid).Select(i => new dtoModuleUploadedItem() { UploadedFile = i, Error = ItemUploadError.UnableToSaveFile }).ToList()); Int32 idModule = Manager.GetModuleID(moduleCode); Dictionary <ItemType, Boolean> defaultDownload = settings.GetDefaultAllowDownload(); Dictionary <ItemType, DisplayMode> defaultDisplayMode = settings.GetDefaultDisplayMode(); List <litePlayerSettings> players = (itemsToAdd.Any(i => i.IsValid && (i.Type == ItemType.Multimedia || i.Type == ItemType.ScormPackage || i.Type == ItemType.VideoStreaming)) ? PlayerGetSettings() : null); foreach (dtoUploadedItem dto in itemsToAdd.Where(i => i.IsValid)) { Boolean allowedByQuota = false; ItemUploadError error = ItemUploadError.None; RepositoryItem item = null; RepositoryItemVersion version = null; allowedByQuota = folderQuota.ValidateSpace(dto.Size, true); if (allowedByQuota) { if (idFolder == 0 || father != null) { long displayOrder = GetCurrentDisplayOrder(idFolder, rpItems); if (ItemHasDuplicate(brothersFile, dto.Name, ItemType.File, dto.Extension)) { dto.OriginalName = dto.DisplayName; dto.Name = ItemGetSuggestedName(brothersFile, dto.Name, ItemType.File, dto.Extension); } try { var queryAssignments = GetQueryAssignments(identifier).Where(a => a.Deleted == BaseStatusDeleted.None && a.Inherited); if (!isInTransaction) { Manager.BeginTransaction(); } item = RepositoryItem.CreateFile(idFolder, dto, defaultDownload[dto.Type], defaultDisplayMode[dto.Type], person, date, UC.IpAddress, UC.ProxyIpAddress, identifier); item.DisplayOrder = displayOrder; item.Thumbnail = dto.ThumbnailFileName; if (!String.IsNullOrWhiteSpace(dto.ThumbnailFileName)) { item.AutoThumbnail = true; item.DisplayMode = DisplayMode.downloadOrPlayOrModal; } switch (item.Type) { case ItemType.VideoStreaming: case ItemType.ScormPackage: case ItemType.Multimedia: item.IdPlayer = (players != null ? players.Where(p => p.Type == item.Type && p.EnableForUse && p.EnableForPlay).OrderByDescending(p => p.Id).Select(p => p.Id).FirstOrDefault() : 0); break; } Manager.SaveOrUpdate(item); version = item.CreateFirstVersion(); Manager.SaveOrUpdate(version); item.IdVersion = version.Id; Manager.SaveOrUpdate(item); switch (item.Type) { case ItemType.VideoStreaming: case ItemType.ScormPackage: case ItemType.Multimedia: FileTransferAdd(item, dto, person, date); break; } if (!isInTransaction) { Manager.Commit(); } if (!isInTransaction) { brothersFile.Add(dto.Name); dto.Id = item.Id; } folderQuota.Size += item.Size; if (fathers != null && fathers.Any()) { isInTransaction = isInTransaction || isInTransaction; if (!isInTransaction) { Manager.BeginTransaction(); } RecalculateFatherSize(fathers, item.Size, item.VersionsSize, person.Id, date); if (!isInTransaction) { Manager.Commit(); } } long permissions = (long)ModuleRepository.Base2Permission.DownloadOrPlay; ItemAssignments assignment = AssignmentAddCommunity(item.Id, item.Repository, item.IdCommunity, false, false, permissions, person, date); if (idFolder == 0) { assignment = AssignmentAddCommunity(item.Id, item.Repository, item.IdCommunity, false, true, permissions, person, date); } else { ApplyInheritedAssignment(item, GetQuery <ItemAssignments>().Where(a => a.Deleted == BaseStatusDeleted.None && a.Inherited), permissions, person, date); } if (isInTransaction) { brothersFile.Add(dto.Name); dto.Id = item.Id; } } catch (Exception ex) { if (!isInTransaction) { Manager.RollBack(); } if (item != null && dto.Id == 0) { item = null; } } } else { error = ItemUploadError.UnableToAddFileToUnknownFolder; } } else if (folderQuota.ValidateUploadSize(dto.Size)) { error = ItemUploadError.UnavailableRepositorySpace; } else { error = ItemUploadError.InvalidFileSize; } if (item != null) { files.Add(new dtoModuleUploadedItem() { Link = CreateModuleAction((Int32)ModuleRepository.Base2Permission.DownloadOrPlay, alwaysLastVersion, Manager.Get <liteRepositoryItem>(item.Id), idModule), ItemAdded = Manager.Get <liteRepositoryItem>(item.Id), VersionAdded = (version != null ? Manager.Get <liteRepositoryItemVersion>(version.Id) : null), UploadedFile = dto, Error = error }); } else { files.Add(new dtoModuleUploadedItem() { UploadedFile = dto, Error = error }); } } if (files.Any(i => i.IsValid && i.IsAdded && (i.ItemAdded.Type == ItemType.Multimedia || i.ItemAdded.Type == ItemType.VideoStreaming || i.ItemAdded.Type == ItemType.ScormPackage))) { FileTransferNotifyToTransferService(istance); } if (files.Any(i => i.IsAdded)) { lm.Comol.Core.DomainModel.Helpers.CacheHelper.PurgeCacheItems(CacheKeys.Repository(identifier)); lm.Comol.Core.DomainModel.Helpers.CacheHelper.PurgeCacheItems(CacheKeys.UsersViewOfRepository(identifier)); lm.Comol.Core.DomainModel.Helpers.CacheHelper.PurgeCacheItems(CacheKeys.UsersSizeViewOfRepository(identifier)); } } } catch (Exception ex) { } return(files); }