private string GetTourAttr(XmlDocument tourDoc, string attr) { if (tourDoc != null) { return tourDoc.GetAttributeValue("Tour", attr); } return null; }
private long CreateCollection(string filename, Stream fileContent, ProfileDetails profileDetails, CommunityDetails parentCommunity) { // Get name/ tags/ category from Tour. var collectionDoc = new XmlDocument(); ContentDetails content = null; // NetworkStream is not Seek able. Need to load into memory stream so that it can be sought using (Stream writablefileContent = new MemoryStream()) { fileContent.CopyTo(writablefileContent); writablefileContent.Position = 0; content = GetContentDetail(filename, writablefileContent, profileDetails, parentCommunity); writablefileContent.Seek(0, SeekOrigin.Begin); collectionDoc = collectionDoc.SetXmlFromWtml(writablefileContent); } if (collectionDoc != null) { content.Name = collectionDoc.GetAttributeValue("Folder", "Name"); } var contentService = DependencyResolver.Current.GetService(typeof(IContentService)) as IContentService; var contentId = content.ID = contentService.CreateContent(content); if (contentId > 0) { var notificationService = DependencyResolver.Current.GetService(typeof(INotificationService)) as INotificationService; notificationService.NotifyNewEntityRequest(content, BaseUri() + "/"); } return contentId; }
public async Task<JsonResult> AddContent(HttpPostedFileBase contentFile, string id, bool extended) { if (CurrentUserId == 0) { await TryAuthenticateFromHttpContext(_communityService, _notificationService); } var contentDataViewModel = new ContentDataViewModel(); XmlDocument tourDoc = null; if (contentFile != null) { // Get File details. var fileDetail = new FileDetail(); fileDetail.SetValuesFrom(contentFile); contentDataViewModel.ContentDataID = fileDetail.AzureID; contentDataViewModel.ContentFileName = Path.GetFileName(contentFile.FileName); contentDataViewModel.ContentFileDetail = string.Format( CultureInfo.InvariantCulture, "{0}~{1}~{2}~{3}~-1", Path.GetExtension(contentFile.FileName), contentFile.ContentLength, fileDetail.AzureID, contentFile.ContentType); contentDataViewModel.ThumbnailLink = Url.Content("~/content/images/default" + Path.GetExtension(contentDataViewModel.ContentFileName).GetContentTypes().ToString().ToLower() + "thumbnail.png"); // Upload associated file in the temporary container. Once the user publishes the content // then we will move the file from temporary container to the actual container. // TODO: Need to have clean up task which will delete all unused file from temporary container. _contentService.UploadTemporaryFile(fileDetail); // Only for tour files, properties of the tour like title, description, author and thumbnail should be taken. if (Constants.TourFileExtension.Equals(Path.GetExtension(contentFile.FileName), StringComparison.OrdinalIgnoreCase)) { tourDoc = new XmlDocument(); contentFile.InputStream.Seek(0, SeekOrigin.Begin); tourDoc = tourDoc.SetXmlFromTour(contentFile.InputStream); if (tourDoc != null) { // Note that the spelling of Description is wrong because that's how WWT generates the WTT file. contentDataViewModel.TourTitle = tourDoc.GetAttributeValue("Tour", "Title"); contentDataViewModel.TourThumbnail = tourDoc.GetAttributeValue("Tour", "ThumbnailUrl"); contentDataViewModel.TourDescription = tourDoc.GetAttributeValue("Tour", "Descirption"); contentDataViewModel.TourDistributedBy = tourDoc.GetAttributeValue("Tour", "Author"); contentDataViewModel.TourLength = tourDoc.GetAttributeValue("Tour", "RunTime"); } } else if (Constants.CollectionFileExtension.Equals(Path.GetExtension(contentFile.FileName), StringComparison.OrdinalIgnoreCase)) { //// Only for WTML files, properties of the collection like title, thumbnail should be taken. tourDoc = new XmlDocument(); contentFile.InputStream.Seek(0, SeekOrigin.Begin); tourDoc = tourDoc.SetXmlFromWtml(contentFile.InputStream); if (tourDoc != null) { contentDataViewModel.TourTitle = tourDoc.GetAttributeValue("Folder", "Name"); } } } return Json(new { contentData=contentDataViewModel, extendedData = extended ? new { tags=GetTourAttr(tourDoc,"Keywords"), taxonomy = GetTourAttr(tourDoc, "Taxonomy"), tourGuid = GetTourAttr(tourDoc, "ID"), userLevel = GetTourAttr(tourDoc, "UserLevel"), author = GetTourAttr(tourDoc, "Author"), authorEmail = GetTourAttr(tourDoc, "AuthorEmail"), authorUrl = GetTourAttr(tourDoc, "AuthorUrl"), organization = GetTourAttr(tourDoc, "OrganizationName"), organizationUrl = GetTourAttr(tourDoc, "OrganizationUrl"), classification = GetTourAttr(tourDoc, "Classification"), ithList = GetTourAttr(tourDoc, "ITHList") } : null }); }
private long CreateTour(string filename, Stream fileContent, ProfileDetails profileDetails, CommunityDetails parentCommunity) { var tourDoc = new XmlDocument(); ContentDetails content = null; // NetworkStream is not Seek able. Need to load into memory stream so that it can be sought using (Stream writablefileContent = new MemoryStream()) { fileContent.CopyTo(writablefileContent); writablefileContent.Position = 0; content = GetContentDetail(filename, writablefileContent, profileDetails, parentCommunity); writablefileContent.Position = 0; tourDoc = tourDoc.SetXmlFromTour(writablefileContent); } if (tourDoc != null) { // Note that the spelling of Description is wrong because that's how WWT generates the WTT file. content.Name = tourDoc.GetAttributeValue("Tour", "Title"); content.Description = tourDoc.GetAttributeValue("Tour", "Descirption"); content.DistributedBy = tourDoc.GetAttributeValue("Tour", "Author"); content.TourLength = tourDoc.GetAttributeValue("Tour", "RunTime"); } var contentService = DependencyResolver.Current.GetService(typeof(IContentService)) as IContentService; var contentId = content.ID = contentService.CreateContent(content); if (contentId > 0) { var notificationService = DependencyResolver.Current.GetService(typeof(INotificationService)) as INotificationService; notificationService.NotifyNewEntityRequest(content, BaseUri() + "/"); } return contentId; }