Exemple #1
0
        private S3DownloadedFile DownloadFileFromS3(string providerName, string libraryName, string fileName)
        {
            LibrariesManager librariesManager = LibrariesManager.GetManager(providerName);
            var docLibs = librariesManager.GetDocumentLibraries();

            MediaContent document   = null;
            Stream       tempStream = null;
            MemoryStream fileStream = new MemoryStream();

            foreach (var lib in docLibs)
            {
                if (lib.Title.ToLower() == libraryName)
                {
                    document   = lib.Items().Where(item => item.Title == fileName).FirstOrDefault();
                    tempStream = librariesManager.Download(document);
                }
            }

            if (tempStream != null)
            {
                tempStream.CopyTo(fileStream);
                fileStream.Position = 0;
            }

            return(new S3DownloadedFile {
                Document = document, FileStream = fileStream
            });
        }
Exemple #2
0
        public static DocumentLibrary GetDocumentLibrary(Guid documentLibraryId)
        {
            LibrariesManager librariesManager = LibrariesManager.GetManager();
            DocumentLibrary  library          = librariesManager.GetDocumentLibraries().Where(l => l.Id == documentLibraryId).FirstOrDefault();

            return(library);
        }
Exemple #3
0
        public Guid UploadTorrentFile(string torrentTitle, Stream torrentFileStream, string torrentFileName, string torrentExtention, string torrentLibrary)
        {
            CultureInfo culture = CultureInfo.InvariantCulture;

            LibrariesManager librariesManager = LibrariesManager.GetManager(LibrariesManager.GetDefaultProviderName());
            DocumentLibrary  documentLibrary  = librariesManager.GetDocumentLibraries().Where(l => l.Title.Equals(torrentLibrary)).SingleOrDefault();

            Document document = librariesManager.CreateDocument();

            document.Parent           = documentLibrary;
            document.Title            = torrentTitle;
            document.DateCreated      = DateTime.UtcNow;
            document.PublicationDate  = DateTime.UtcNow;
            document.LastModified     = DateTime.UtcNow;
            document.UrlName          = Regex.Replace(torrentTitle.ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-");
            document.MediaFileUrlName = Regex.Replace(torrentFileName.ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-");

            librariesManager.Upload(document, torrentFileStream, torrentExtention);
            librariesManager.RecompileAndValidateUrls(document);

            document.ApprovalWorkflowState.Value = "Published";

            librariesManager.Lifecycle.Publish(document, culture);
            librariesManager.SaveChanges();

            return(document.Id);
        }
Exemple #4
0
        public void TearDown(Guid testLibraryId)
        {
            LibrariesManager librariesManager = LibrariesManager.GetManager();

            var library = librariesManager.GetDocumentLibraries().SingleOrDefault(l => l.Id == testLibraryId);

            if (library != null)
            {
                librariesManager.DeleteDocumentLibrary(library);
                librariesManager.SaveChanges();
            }
        }
Exemple #5
0
        public static void DeleteDocumentLibrary(Guid documentLibraryId)
        {
            LibrariesManager manager = LibrariesManager.GetManager();

            DocumentLibrary library = manager.GetDocumentLibraries().Where(b => b.Id == documentLibraryId).SingleOrDefault();

            if (library != null)
            {
                //Mark the library to be deleted.
                manager.DeleteDocumentLibrary(library);

                //Save the changes.
                manager.SaveChanges();
            }
        }
Exemple #6
0
        private bool UploadFileToS3(Guid masterDocumentId, string providerName, string libraryName, string fileName, MemoryStream fileStream)
        {
            LibrariesManager librariesManager = LibrariesManager.GetManager(providerName);
            Document         document         = librariesManager.GetDocuments().Where(i => i.Id == masterDocumentId).FirstOrDefault();

            if (document == null)
            {
                //The document is created as master. The masterDocumentId is assigned to the master version.
                document = librariesManager.CreateDocument(masterDocumentId);

                //Set the parent document library.
                DocumentLibrary documentLibrary = librariesManager.GetDocumentLibraries().Where(d => d.Title == libraryName).SingleOrDefault();
                document.Parent = documentLibrary;

                //Set the properties of the document.
                string documentTitle = masterDocumentId.ToString() + "_" + fileName;
                document.Title                 = documentTitle;
                document.DateCreated           = DateTime.UtcNow;
                document.PublicationDate       = DateTime.UtcNow;
                document.LastModified          = DateTime.UtcNow;
                document.UrlName               = Regex.Replace(documentTitle.ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-");
                document.MediaFileUrlName      = Regex.Replace(documentTitle.ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-");
                document.ApprovalWorkflowState = "Published";

                //Upload the document file.
                string fileExtension = fileName.Split(new string[] { "." }, StringSplitOptions.RemoveEmptyEntries).Last();
                librariesManager.Upload(document, fileStream, fileExtension ?? string.Empty);

                //Recompiles and validates the url of the document.
                librariesManager.RecompileAndValidateUrls(document);

                //Save the changes.
                librariesManager.SaveChanges();

                //Publish the DocumentLibraries item. The live version acquires new ID.
                var bag = new Dictionary <string, string>();
                bag.Add("ContentType", typeof(Document).FullName);
                WorkflowManager.MessageWorkflow(masterDocumentId, typeof(Document), null, "Publish", false, bag);

                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #7
0
        public static void ModifyDocumentLibrary(Guid documentLibraryId, string newTitle)
        {
            LibrariesManager librariesManager = LibrariesManager.GetManager();

            //Get the library.
            DocumentLibrary library = librariesManager.GetDocumentLibraries().Where(b => b.Id == documentLibraryId).FirstOrDefault();

            if (library != null)
            {
                //Modify the library.
                library.Title        = newTitle;
                library.LastModified = DateTime.UtcNow;
                library.Urls.Clear();
                library.UrlName = FormatUrlName(newTitle);

                //Save the changes.
                librariesManager.SaveChanges();
            }
        }
Exemple #8
0
        public static void CreateDocumentLibrary(Guid documentLibraryId, string documentLibraryTitle)
        {
            LibrariesManager librariesManager = LibrariesManager.GetManager();
            DocumentLibrary  library          = librariesManager.GetDocumentLibraries().Where(b => b.Id == documentLibraryId).FirstOrDefault();

            if (library == null)
            {
                //Create the library.
                library = librariesManager.CreateDocumentLibrary(documentLibraryId);

                //Set the properties of the library.
                library.Title        = documentLibraryTitle;
                library.DateCreated  = DateTime.UtcNow;
                library.LastModified = DateTime.UtcNow;
                library.UrlName      = FormatUrlName(documentLibraryTitle);

                //Save the changes.
                librariesManager.SaveChanges();
            }
        }
Exemple #9
0
        public static string FetchFromAmazonS3(string providerName, JobApplicationAttachmentType attachmentType, string itemTitle)
        {
            var libName = FileUploadLibraryGet(attachmentType);

            LibrariesManager librariesManager = LibrariesManager.GetManager(providerName);
            var docLibs = librariesManager.GetDocumentLibraries();

            foreach (var lib in docLibs)
            {
                if (lib.Title.ToLower() == libName)
                {
                    var items    = lib.Items();
                    var document = lib.Items().Where(item => item.Title.Contains(itemTitle)).FirstOrDefault();

                    if (document != null && document.Status != ContentLifecycleStatus.Deleted)
                    {
                        return(document.Url);
                    }
                }
            }

            return(null);
        }
Exemple #10
0
        public Document CreateDocumentNativeAPI(CreateDocumentDto createDocumentDto)
        {
            //The document is created as master. The masterDocumentId is assigned to the master version.
            LibrariesManager librariesManager = LibrariesManager.GetManager();
            Guid             documentId       = Guid.NewGuid();
            Document         document         = document = librariesManager.CreateDocument(documentId);

            //Set the parent document library.
            DocumentLibrary documentLibrary = librariesManager.GetDocumentLibraries().SingleOrDefault();

            document.Parent = documentLibrary;

            //Set the properties of the document.
            document.Title            = createDocumentDto.Title;
            document.DateCreated      = DateTime.UtcNow;
            document.PublicationDate  = DateTime.UtcNow;
            document.LastModified     = DateTime.UtcNow;
            document.UrlName          = Regex.Replace($"{createDocumentDto.Title}-{documentId}".ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-");
            document.MediaFileUrlName = Regex.Replace(createDocumentDto.FileName.ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-");

            //Upload the document file.
            librariesManager.Upload(document, createDocumentDto.Stream, createDocumentDto.FileExtension);

            //Recompiles and validates the url of the document.
            librariesManager.RecompileAndValidateUrls(document);

            //Save the changes.
            librariesManager.SaveChanges();

            //Publish the DocumentLibraries item. The live version acquires new ID.
            var bag = new Dictionary <string, string>();

            bag.Add("ContentType", typeof(Document).FullName);
            WorkflowManager.MessageWorkflow(documentId, typeof(Document), null, "Publish", false, bag);

            return(document);
        }
Exemple #11
0
        public static List <DocumentLibrary> GetAllDocumentLibraries()
        {
            LibrariesManager librariesManager = LibrariesManager.GetManager();

            return(librariesManager.GetDocumentLibraries().ToList());
        }
 public override IQueryable <Library> GetLibraries(LibrariesManager libMgr)
 {
     return(libMgr.GetDocumentLibraries());
 }
Exemple #13
0
        public static Guid CreateDocumentNativeAPI(Stream documentStream, string fileExtension)
        {
            LibrariesManager librariesManager = LibrariesManager.GetManager();

            librariesManager.Provider.SuppressSecurityChecks = true;
            WorkflowManager.GetManager().Provider.SuppressSecurityChecks = true;

            Guid documentId = Guid.Empty;

            try
            {
                var documentLibrary = librariesManager.GetDocumentLibraries().Where(x => x.Title == "Image requests uploaded").FirstOrDefault();

                #region create document library
                //create document library if it doesnt exist
                if (documentLibrary == null)
                {
                    documentLibrary = librariesManager.CreateDocumentLibrary();

                    documentLibrary.Title        = "Image requests uploaded";
                    documentLibrary.DateCreated  = DateTime.UtcNow;
                    documentLibrary.LastModified = DateTime.UtcNow;
                    documentLibrary.UrlName      = Regex.Replace(documentLibrary.Title.ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-");

                    //Recompiles and validates the url of the library.
                    librariesManager.RecompileAndValidateUrls(documentLibrary);

                    //Save the changes.
                    librariesManager.SaveChanges();
                }
                #endregion

                documentId = Guid.NewGuid();
                var document = librariesManager.CreateDocument(documentId);

                document.Parent = documentLibrary;

                document.Title            = "Resume-" + documentId.ToString();
                document.DateCreated      = DateTime.UtcNow;
                document.PublicationDate  = DateTime.UtcNow;
                document.LastModified     = DateTime.UtcNow;
                document.UrlName          = Regex.Replace(document.Title.ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-");
                document.MediaFileUrlName = Regex.Replace((document.Title + fileExtension).ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-");

                //Upload the document file.
                librariesManager.Upload(document, documentStream, fileExtension);
                //Recompiles and validates the url of the document.
                librariesManager.RecompileAndValidateUrls(document);
                librariesManager.Lifecycle.Publish(document);
                //Save the changes.
                librariesManager.SaveChanges();


                //Publish the DocumentLibraries item. The live version acquires new ID.
                var bag = new Dictionary <string, string>();
                bag.Add("ContentType", typeof(Document).FullName);
                WorkflowManager.MessageWorkflow(documentId, typeof(Document), null, "Publish", false, bag);
            }
            catch (Exception ex)
            {
                Log.Write(ex, System.Diagnostics.TraceEventType.Error);
                return(documentId);
            }
            finally
            {
                librariesManager.Provider.SuppressSecurityChecks = false;
                WorkflowManager.GetManager().Provider.SuppressSecurityChecks = false;
            }
            return(documentId);
        }