public dtoModuleUploadedItem(liteRepositoryItem item, liteRepositoryItemVersion version, ItemUploadError error)
 {
     Error        = error;
     ItemAdded    = item;
     VersionAdded = version;
 }
        public List <dtoModuleUploadedItem> FileAddToRepository(liteRepositorySettings settings, String istance, RepositoryIdentifier identifier, litePerson person, Boolean alwaysLastVersion, 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 = new List <String>();
                    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))
                    {
                        ItemUploadError       error   = ItemUploadError.None;
                        RepositoryItem        item    = null;
                        RepositoryItemVersion version = null;
                        if (ItemHasDuplicate(brothersFile, dto.Name, ItemType.File, dto.Extension))
                        {
                            dto.OriginalName = dto.DisplayName;
                            dto.Name         = ItemGetSuggestedName(brothersFile, dto.Name, ItemType.File, dto.Extension);
                        }
                        try
                        {
                            if (!isInTransaction)
                            {
                                Manager.BeginTransaction();
                            }
                            item           = RepositoryItem.CreateFile(dto, defaultDownload[dto.Type], defaultDisplayMode[dto.Type], person, date, UC.IpAddress, UC.ProxyIpAddress, identifier, obj, idObject, idObjectType, idModule, moduleCode, idModuleAjaxAction, idModuleAction);
                            item.Thumbnail = dto.ThumbnailFileName;
                            if (!String.IsNullOrWhiteSpace(dto.ThumbnailFileName))
                            {
                                item.AutoThumbnail = true;
                                item.DisplayMode   = DisplayMode.downloadOrPlayOrModal;
                            }
                            Manager.SaveOrUpdate(item);
                            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;
                            }
                            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();
                            }

                            brothersFile.Add(dto.Name);
                            dto.Id = item.Id;
                        }
                        catch (Exception ex)
                        {
                            if (!isInTransaction)
                            {
                                Manager.RollBack();
                            }
                            if (item != null && dto.Id == 0)
                            {
                                item    = null;
                                version = null;
                                error   = ItemUploadError.UnableToSaveFile;
                            }
                        }
                        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);
                    }
                }
            }
            catch (Exception ex)
            {
            }
            return(files);
        }
        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);
        }
示例#4
0
 public dtoCreatedItem()
 {
     Error = ItemUploadError.None;
 }