Exemplo n.º 1
0
        public List <FileEntry> GetSharesForMe()
        {
            using (var folderDao = daoFactory.GetFolderDao())
                using (var fileDao = daoFactory.GetFileDao())
                    using (var securityDao = daoFactory.GetSecurityDao())
                    {
                        var subjects = GetUserSubjects(SecurityContext.CurrentAccount.ID);

                        var records = securityDao.GetShares(subjects);

                        var fileIds   = new Dictionary <object, FileShare>();
                        var folderIds = new Dictionary <object, FileShare>();

                        foreach (var record in records)
                        {
                            var firstRecord = records.Where(x => Equals(record.EntryId, x.EntryId) && record.EntryType == x.EntryType)
                                              .OrderBy(r => subjects.IndexOf(r.Subject))
                                              .First();

                            if (firstRecord.Share == FileShare.Restrict)
                            {
                                continue;
                            }

                            if (firstRecord.EntryType == FileEntryType.Folder)
                            {
                                if (!folderIds.ContainsKey(firstRecord.EntryId))
                                {
                                    folderIds.Add(firstRecord.EntryId, firstRecord.Share);
                                }
                            }
                            else
                            {
                                if (!fileIds.ContainsKey(firstRecord.EntryId))
                                {
                                    fileIds.Add(firstRecord.EntryId, firstRecord.Share);
                                }
                            }
                        }

                        var files = fileDao.GetFiles(fileIds.Keys.ToArray());

                        files.ForEach(x => x.Access = fileIds[x.ID]);

                        var folders = folderDao.GetFolders(folderIds.Keys.ToArray());

                        folders.ForEach(x => x.Access = folderIds[x.ID]);

                        return(files.Cast <FileEntry>()
                               .Concat(folders.Cast <FileEntry>()).ToList());
                    }
        }
Exemplo n.º 2
0
 public FilesModule(
     TenantManager tenantManager,
     UserManager userManager,
     WebItemSecurity webItemSecurity,
     FilesLinkUtility filesLinkUtility,
     FileSecurity fileSecurity,
     IDaoFactory daoFactory)
     : base(tenantManager, webItemSecurity)
 {
     FileDao          = daoFactory.GetFileDao <int>();
     FolderDao        = daoFactory.GetFolderDao <int>();
     UserManager      = userManager;
     FilesLinkUtility = filesLinkUtility;
     FileSecurity     = fileSecurity;
 }
Exemplo n.º 3
0
        public override void IndexAll()
        {
            var fileDao = DaoFactory.GetFileDao <int>() as FileDao;

            (int, int, int) getCount(DateTime lastIndexed)
            {
                var q = fileDao.FilesDbContext.Files
                        .Where(r => r.ModifiedOn >= lastIndexed)
                        .Where(r => r.CurrentVersion)
                        .Join(fileDao.FilesDbContext.Tenants, r => r.TenantId, r => r.Id, (f, t) => new { f, t })
                        .Where(r => r.t.Status == ASC.Core.Tenants.TenantStatus.Active);

                var count = q.GroupBy(a => a.f.Id).Count();
                var min   = count > 0 ? q.Min(r => r.f.Id) : 0;
                var max   = count > 0 ? q.Max(r => r.f.Id) : 0;

                return(count, max, min);
            }

            List <DbFile> getData(long i, long step, DateTime lastIndexed) =>
            fileDao.FilesDbContext.Files
            .Where(r => r.ModifiedOn >= lastIndexed)
            .Where(r => r.CurrentVersion)
            .Where(r => r.Id >= i && r.Id <= i + step)
            .Join(fileDao.FilesDbContext.Tenants, r => r.TenantId, r => r.Id, (f, t) => new { f, t })
            .Where(r => r.t.Status == ASC.Core.Tenants.TenantStatus.Active)
            .Select(r => r.f)
            .ToList();

            try
            {
                foreach (var data in Indexer.IndexAll(getCount, getData))
                {
                    data.ForEach(r =>
                    {
                        TenantManager.SetCurrentTenant(r.TenantId);
                        fileDao.InitDocument(r);
                        TenantManager.CurrentTenant = null;
                    });
                    Index(data);
                }
            }
            catch (Exception e)
            {
                Logger.Error(e);
                throw;
            }
        }