예제 #1
0
        /// <summary>
        /// Populates the FileDetail object's properties from the given Content object's properties.
        /// </summary>
        /// <param name="thisObject">Current FileDetail instance on which the extension method is called</param>
        /// <param name="content">Content model from which values to be read</param>
        public static DataDetail SetValuesFrom(this DataDetail thisObject, Content content)
        {
            if (content != null)
            {
                // Set Content Type.
                ContentTypes type = content.TypeID.ToEnum<int, ContentTypes>(ContentTypes.Generic);

                if (type == ContentTypes.Link)
                {
                    thisObject = new LinkDetail(content.ContentUrl, content.ContentID);
                }
                else
                {
                    var fileDetail = new FileDetail();
                    fileDetail.SetValuesFrom(content);
                    thisObject = fileDetail;
                }

                thisObject.Name = content.Filename;
                thisObject.ContentType = type;
            }

            return thisObject;
        }
예제 #2
0
        public async Task<JsonResult> AssociatedContent(HttpPostedFileBase associatedFile)
        {
            if (CurrentUserId == 0)
            {
                await TryAuthenticateFromHttpContext(_communityService, _notificationService);
            }
            if (associatedFile != null)
            {
                // Get File details.
                var fileDetail = new FileDetail();
                fileDetail.SetValuesFrom(associatedFile);

                var fileName = Path.GetFileNameWithoutExtension(associatedFile.FileName);
                var fileDetailString = string.Format(
                    CultureInfo.InvariantCulture,
                    "{0}~{1}~{2}~{3}~-1",
                    Path.GetExtension(associatedFile.FileName),
                    associatedFile.ContentLength,
                    fileDetail.AzureID,
                    associatedFile.ContentType);

                // 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);
                return new JsonResult { Data = new
                {
                    fileName,fileDetailString
                } };
            }

            return new JsonResult{Data="error: no file"};
        }
예제 #3
0
        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 FileDetail UpdateFileDetails(string filename, Stream fileContent)
        {
            var contentService = DependencyResolver.Current.GetService(typeof(IContentService)) as IContentService;

            var fileDetail = new FileDetail();
            fileDetail.SetValuesFrom(filename, fileContent);

            // TODO: Update mime type and size from the incoming request.
            fileDetail.MimeType = Path.GetExtension(filename).GetWwtMimeType(Request.ContentType);
            fileDetail.Size = Request.ContentLength;

            contentService.UploadTemporaryFile(fileDetail);

            return fileDetail;
        }
예제 #5
0
        public async Task<JsonResult> AddThumbnail(HttpPostedFileBase thumbnail, EntityType entity)
        {
            try
            {
                if (CurrentUserId == 0)
                {
                    await TryAuthenticateFromHttpContext(_communityService, _notificationService);
                }

                var thumbnailId = Guid.Empty;
                var thumnailUrl = Url.Content("~/content/images/" +
                                                 (entity == EntityType.User
                                                     ? "profile.png"
                                                     : entity == EntityType.Content
                                                         ? "defaultgenericthumbnail.png"
                                                         : "defaultcommunitythumbnail.png"));
                if (thumbnail != null)
                {
                    // Get File details.
                    var fileDetail = new FileDetail();
                    fileDetail.SetValuesFrom(thumbnail);

                    if (entity == EntityType.User)
                    {
                        // Update the size of the profile picture to 111 X 111 and upload it to temporary container in Azure.
                        fileDetail.DataStream =
                            thumbnail.InputStream.GenerateThumbnail(Constants.DefaultProfilePictureWidth,
                                Constants.DefaultProfilePictureHeight, Constants.DefaultThumbnailImageFormat);
                    }
                    else
                    {
                        // Update the size of the thumbnail to 160 X 96 and upload it to temporary container in Azure.
                        fileDetail.DataStream = thumbnail.InputStream.GenerateThumbnail(
                            Constants.DefaultThumbnailWidth, Constants.DefaultThumbnailHeight,
                            Constants.DefaultThumbnailImageFormat);
                    }

                    fileDetail.MimeType = Constants.DefaultThumbnailMimeType;

                    // 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.
                    _entityService.UploadTemporaryFile(fileDetail);

                    thumbnailId = fileDetail.AzureID;
                    thumnailUrl = "/file/thumbnail/" + thumbnailId;
                }

                var viewModel = new DefaultThumbnailViewModel(thumbnailId, entity, string.Empty,
                    ContentTypes.Generic);
                viewModel.ThumbnailLink = thumnailUrl;

                return new JsonResult {Data = viewModel};
            }
            catch
            {
                return new JsonResult {Data = "error: user not logged in"};
            }

        }