Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
            }
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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);
        }