Beispiel #1
0
        public ActionResult Upload(TorrentUploaderWidgetModel model)
        {
            try
            {
                this._torrentService.Upload(model);
            }
            catch (Exception e)
            {
                System.IO.File.AppendAllText(@"C:\temp\inset.txt", $"{Environment.NewLine}{e.Message}");
                return(View("Default", new TorrentUploaderWidgetModel()));
            }

            return(RedirectToAction(string.Empty));
        }
Beispiel #2
0
        public void Upload(TorrentUploaderWidgetModel torrent)
        {
            string torrentExtention = Path.GetExtension(torrent.TorrentFile.FileName);
            string torrentTitle     = Path.GetFileNameWithoutExtension(torrent.TorrentFile.FileName);
            Guid   torrentFileId    = this._documentService.UploadTorrentFile(torrentTitle, torrent.TorrentFile.InputStream, torrent.TorrentFile.FileName, torrentExtention, TORRENT_FILE_LIBRARY);

            string imageExtention = Path.GetExtension(torrent.CoverImage.FileName);
            string imageTitle     = Path.GetFileNameWithoutExtension(torrent.CoverImage.FileName);
            Guid   torrentImageId = this._imageService.Upload(imageTitle, torrent.CoverImage.InputStream, torrent.CoverImage.FileName, imageExtention, TORRENT_COVER_IMAGE_ALBUM);

            // Set the provider name for the DynamicModuleManager here. All available providers are listed in
            // Administration -> Settings -> Advanced -> DynamicModules -> Providers
            var providerName = String.Empty;

            // Set a transaction name and get the version manager
            var transactionName = "someTransactionName";
            var versionManager  = VersionManager.GetManager(null, transactionName);

            DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(providerName, transactionName);
            Type           torrentType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Torrents.Torrent");
            DynamicContent torrentItem = dynamicModuleManager.CreateDataItem(torrentType);

            // This is how values for the properties are set
            torrentItem.SetValue("Title", torrent.Title);
            torrentItem.SetValue("Description", torrent.Description);

            LibrariesManager torrentFileManager = LibrariesManager.GetManager();
            var torrentFileItem = torrentFileManager.GetDocuments().FirstOrDefault(i => i.Id == torrentFileId && i.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Master);

            if (torrentFileItem != null)
            {
                torrentItem.CreateRelation(torrentFileItem, "TorrentFile");
            }

            LibrariesManager imageManager = LibrariesManager.GetManager();
            var imageItem = imageManager.GetImages().FirstOrDefault(i => i.Id == torrentImageId && i.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Master);

            if (imageItem != null)
            {
                torrentItem.CreateRelation(imageItem, "Image");
            }

            torrentItem.SetString("UrlName", Guid.NewGuid().ToString());
            torrentItem.SetValue("Owner", SecurityManager.GetCurrentUserId());
            torrentItem.SetValue("PublicationDate", DateTime.UtcNow);

            // Create a version and commit the transaction in order changes to be persisted to data store
            torrentItem.SetWorkflowStatus(dynamicModuleManager.Provider.ApplicationName, "Draft");

            // Create a version and commit the transaction in order changes to be persisted to data store
            versionManager.CreateVersion(torrentItem, false);

            // We can now call the following to publish the item
            ILifecycleDataItem publishedTorrentItem = dynamicModuleManager.Lifecycle.Publish(torrentItem);

            // You need to set appropriate workflow status
            torrentItem.SetWorkflowStatus(dynamicModuleManager.Provider.ApplicationName, "Published");

            // Create a version and commit the transaction in order changes to be persisted to data store
            versionManager.CreateVersion(torrentItem, true);



            TransactionManager.CommitTransaction(transactionName);
        }