Exemple #1
0
        public IEnumerable <Tag> GetNewTags(Guid subject, Folder <string> parentFolder, bool deepSearch)
        {
            var folderId = DaoSelector.ConvertId(parentFolder.ID);

            var fakeFolderId = parentFolder.ID.ToString();

            var entryIDs = FilesDbContext.ThirdpartyIdMapping
                           .Where(r => r.Id.StartsWith(fakeFolderId))
                           .Select(r => r.HashId)
                           .ToList();

            if (!entryIDs.Any())
            {
                return(new List <Tag>());
            }

            var q = FilesDbContext.Tag
                    .Join(FilesDbContext.TagLink.DefaultIfEmpty(),
                          r => new TagLink {
                TenantId = r.TenantId, Id = r.Id
            },
                          r => new TagLink {
                TenantId = r.TenantId, Id = r.TagId
            },
                          (tag, tagLink) => new { tag, tagLink },
                          new TagLinkComparer())
                    .Where(r => r.tag.TenantId == TenantID)
                    .Where(r => r.tag.Flag == TagType.New)
                    .Where(r => r.tagLink.TenantId == TenantID)
                    .Where(r => entryIDs.Any(a => a == r.tagLink.EntryId));

            if (subject != Guid.Empty)
            {
                q = q.Where(r => r.tag.Owner == subject);
            }

            var tags = q
                       .ToList()
                       .Select(r => new Tag
            {
                TagName   = r.tag.Name,
                TagType   = r.tag.Flag,
                Owner     = r.tag.Owner,
                EntryId   = MappingID(r.tagLink.EntryId),
                EntryType = r.tagLink.EntryType,
                Count     = r.tagLink.TagCount,
                Id        = r.tag.Id
            });

            if (deepSearch)
            {
                return(tags);
            }

            var folderFileIds = new[] { fakeFolderId }
            .Concat(GetFolderSubfolders(folderId).Select(x => MakeId(x)))
            .Concat(GetFolderFiles(folderId).Select(x => MakeId(x)));

            return(tags.Where(tag => folderFileIds.Contains(tag.EntryId.ToString())));
        }
Exemple #2
0
        public File <string> SaveFile(File <string> file, Stream fileStream)
        {
            if (fileStream == null)
            {
                throw new ArgumentNullException("fileStream");
            }

            if (file.ID != null)
            {
                var sharePointFile = ProviderInfo.CreateFile(file.ID, fileStream);

                var resultFile = ProviderInfo.ToFile(sharePointFile);
                if (!sharePointFile.Name.Equals(file.Title))
                {
                    var folder = ProviderInfo.GetFolderById(file.FolderID);
                    file.Title = GetAvailableTitle(file.Title, folder, IsExist);

                    var id = ProviderInfo.RenameFile(DaoSelector.ConvertId(resultFile.ID).ToString(), file.Title);
                    return(GetFile(DaoSelector.ConvertId(id)));
                }
                return(resultFile);
            }

            if (file.FolderID != null)
            {
                var folder = ProviderInfo.GetFolderById(file.FolderID);
                file.Title = GetAvailableTitle(file.Title, folder, IsExist);
                return(ProviderInfo.ToFile(ProviderInfo.CreateFile(folder.ServerRelativeUrl + "/" + file.Title, fileStream)));
            }

            return(null);
        }