/// <summary> /// Move Home video from temp to correct container. /// </summary> /// <param name="fileDetails">Details of the video.</param> public OperationStatus MoveTempFile(FileDetail fileDetails) { OperationStatus operationStatus = null; this.CheckNotNull(() => new { fileDetails }); // Move Home video. if (fileDetails.AzureID != null) { // Move the video file from temporary container to file container. try { if (MoveAssetFile(fileDetails)) { operationStatus = OperationStatus.CreateSuccessStatus(); } else { operationStatus = OperationStatus.CreateFailureStatus(Resources.UnknownErrorMessage); } } catch (Exception) { operationStatus = OperationStatus.CreateFailureStatus(Resources.UnknownErrorMessage); } } return operationStatus; }
/// <summary> /// Populates the ContentDetails object's properties from the given Content's object's properties. /// </summary> /// <param name="thisObject">Current content details model on which the extension method is called</param> /// <param name="content">ContentsView model from which values to be read</param> public static void SetValuesFrom(this ContentDetails thisObject, Content content) { if (thisObject != null && content != null) { var start = DateTime.Now; // Populate the base values using the EntityViewModel's SetValuesFrom method. (thisObject as EntityDetails).SetValuesFrom(content); var contentData = new DataDetail(); thisObject.ContentData = contentData.SetValuesFrom(content); thisObject.Citation = content.Citation; thisObject.DownloadCount = content.DownloadCount ?? 0; // Get the distributed by user. thisObject.DistributedBy = content.DistributedBy; // Produced by is equivalent to created by. thisObject.ProducedBy = content.User.FirstName + " " + content.User.LastName; thisObject.TourLength = content.TourRunLength; // Set Thumbnail properties. var thumbnailDetail = new FileDetail {AzureID = content.ThumbnailID ?? Guid.Empty}; thisObject.Thumbnail = thumbnailDetail; // Set video properties. var video = content.ContentRelation.FirstOrDefault(cr => cr.ContentRelationshipTypeID == (int)AssociatedContentRelationshipType.Video); if (video != null) { var videoDetails = new DataDetail(); thisObject.Video = videoDetails.SetValuesFrom(video.Content1); } // Set associated file details. thisObject.AssociatedFiles = GetAssociatedFiles(content); } }
/// <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; }
/// <summary> /// Move temporary file to actual container in azure. /// </summary> /// <param name="fileDetails">Details of the file.</param> private bool MoveFile(FileDetail fileDetails) { var fileBlob = new BlobDetails() { BlobID = fileDetails.AzureID.ToString(), MimeType = fileDetails.MimeType }; return _blobDataRepository.MoveFile(fileBlob); }
/// <summary> /// Moves thumbnail from temporary storage to thumbnail storage in azure. /// </summary> /// <param name="fileDetails">Details of the thumbnail.</param> private Guid MoveThumbnail(FileDetail fileDetails) { var thumbnailId = Guid.Empty; if (fileDetails != null && fileDetails.AzureID != Guid.Empty) { var thumbnailBlob = new BlobDetails() { BlobID = fileDetails.AzureID.ToString() }; thumbnailId = _blobDataRepository.MoveThumbnail(thumbnailBlob) ? fileDetails.AzureID : Guid.Empty; } return thumbnailId; }
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"}; }
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 }); }
/// <summary> /// Populates the ContentViewModel object's properties from the given ContentsView object's properties. /// </summary> /// <param name="thisObject">Current content view model on which the extension method is called</param> /// <param name="content">ContentInputViewModel model from which values to be read</param> public static void SetValuesFrom(this ContentDetails thisObject, ContentInputViewModel content) { if (thisObject != null && content != null) { // Populate the base values using the EntityViewModel's SetValuesFrom method. (thisObject as EntityDetails).SetValuesFrom(content); thisObject.DistributedBy = content.DistributedBy; thisObject.Citation = content.Citation; // Set the access type for the content thisObject.AccessTypeID = content.AccessTypeID; thisObject.TourLength = content.TourLength; // Set content data properties. if (content.IsLink) { thisObject.ContentData = new LinkDetail(content.ContentUrl); } else { string[] fileDetails = content.ContentFileDetail.Split('~'); if (fileDetails.Count() == 5) { string mimeType = fileDetails[3]; // If the content file details does not have the following details // then do not process the file. DataDetail contentDetail = null; if (mimeType.ToUpperInvariant().Equals(Constants.LinkMimeType.ToUpperInvariant())) { contentDetail = new LinkDetail(content.FileName); } else { var fileDetail = new FileDetail(); // Get file name and Content type. fileDetail.Name = content.FileName; fileDetail.ContentType = fileDetails[0].GetContentTypes(); // Get File size. long fileSize; if (long.TryParse(fileDetails[1], out fileSize)) { fileDetail.Size = fileSize; } fileDetail.AzureID = content.ContentDataID; // Get content mime Type. fileDetail.MimeType = fileDetails[3]; contentDetail = fileDetail; } // Set Content ID if present. long contentID; if (long.TryParse(fileDetails[4], out contentID)) { contentDetail.ContentID = contentID; } thisObject.ContentData = contentDetail; } } // Set video properties. if (content.VideoID != Guid.Empty && content.VideoFileDetail != null) { var video = new FileDetail(); string[] videoDetails = content.VideoFileDetail.Split('~'); if (videoDetails.Count() == 5) { var fileDetail = new FileDetail(); // Get file name and Content type. fileDetail.Name = content.VideoName; fileDetail.ContentType = videoDetails[0].GetContentTypes(); // Get File size. long fileSize; if (long.TryParse(videoDetails[1], out fileSize)) { fileDetail.Size = fileSize; } fileDetail.AzureID = content.VideoID; // Get content mime Type. fileDetail.MimeType = videoDetails[3]; video = fileDetail; } thisObject.Video = video; } // Set associated file details. thisObject.AssociatedFiles = GetAssociatedFiles(content); } }
/// <summary> /// Creates the private community details for the given community. User id is used to check if the user is having any /// pending requests on the private community. /// </summary> /// <param name="community">Community for which private community details has to be created</param> /// <param name="userId">Current user id</param> /// <returns>Community details instance</returns> private CommunityDetails CreatePrivateCommunityDetails(Community community, long? userId) { CommunityDetails communityDetails = null; var permission = Permission.Visitor; // Check if already any pending approvals are there. if (userId.HasValue && _userRepository.PendingPermissionRequests(userId.Value, community.CommunityID)) { permission = Permission.PendingApproval; } communityDetails = new CommunityDetails(permission); communityDetails.ID = community.CommunityID; communityDetails.Name = community.Name; communityDetails.Description = community.Description; communityDetails.AccessTypeID = (int)AccessType.Private; communityDetails.CommunityType = (CommunityTypes)community.CommunityTypeID; // Set Thumbnail properties. var thumbnailDetail = new FileDetail(); thumbnailDetail.AzureID = community.ThumbnailID.HasValue ? community.ThumbnailID.Value : Guid.Empty; communityDetails.Thumbnail = thumbnailDetail; return communityDetails; }
/// <summary> /// Moves thumbnail from temporary storage to thumbnail storage in azure. /// </summary> /// <param name="thumbnail">Details of the thumbnail</param> private bool MoveThumbnail(FileDetail thumbnail) { var thumbnailBlob = new BlobDetails() { BlobID = thumbnail.AzureID.ToString() }; return _blobDataRepository.MoveThumbnail(thumbnailBlob); }
public static void RegisterServiceAutoMappers() { // Used by CommentService Mapper.CreateMap<CommentDetails, CommunityComments>() .ForMember(target => target.CommunityID, options => options.MapFrom(source => source.ParentID)) .ForMember(target => target.CommunityCommentsID, options => options.MapFrom(source => source.CommentID)); Mapper.CreateMap<CommentDetails, ContentComments>() .ForMember(target => target.ContentID, options => options.MapFrom(source => source.ParentID)) .ForMember(target => target.ContentCommentsID, options => options.MapFrom(source => source.CommentID)); Mapper.CreateMap<CommunityComments, CommentDetails>() .ForMember(target => target.ParentID, options => options.MapFrom(source => source.CommunityID)) .ForMember(target => target.CommentedBy, options => options.MapFrom(source => source.User.FirstName + " " + source.User.LastName)) .ForMember(target => target.CommentedByPictureID, options => options.MapFrom(source => source.User.PictureID)) .ForMember(target => target.CommentID, options => options.MapFrom(source => source.CommunityCommentsID)); Mapper.CreateMap<ContentComments, CommentDetails>() .ForMember(target => target.ParentID, options => options.MapFrom(source => source.ContentID)) .ForMember(target => target.CommentedDatetime, options => options.MapFrom(source => source.CommentDatetime)) .ForMember(target => target.CommentedBy, options => options.MapFrom(source => source.User.FirstName + " " + source.User.LastName)) .ForMember(target => target.CommentedByPictureID, options => options.MapFrom(source => source.User.PictureID)) .ForMember(target => target.CommentID, options => options.MapFrom(source => source.ContentCommentsID)); // Used by CommunityService Mapper.CreateMap<CommunityDetails, Community>() .ForMember(target => target.CommunityTypeID, options => options.MapFrom(source => (int)source.CommunityType)) .ForMember(target => target.CommunityType, options => options.Ignore()) .ForMember(target => target.ThumbnailID, options => options.Ignore()) .ForMember(target => target.CommunityID, options => options.Ignore()); // Used by ContentService Mapper.CreateMap<ContentDetails, Content>() .ForMember(target => target.Title, options => options.MapFrom(source => source.Name)); Mapper.CreateMap<Content, DownloadDetails>(); Mapper.CreateMap<StaticContent, StaticContentDetails>(); // Used by EntityService Mapper.CreateMap<TopCategoryEntities, ContentDetails>() .ForMember(target => target.Name, options => options.MapFrom(source => source.Title)) .ForMember(target => target.ID, options => options.MapFrom(source => source.ID)) .ForMember(target => target.ParentID, options => options.MapFrom(source => source.CommunityID)) .ForMember(target => target.ParentName, options => options.MapFrom(source => source.CommunityName)) .ForMember(target => target.Tags, options => options.Condition(source => !source.IsSourceValueNull)) .ForMember(target => target.ParentType, options => options.MapFrom(source => source.CommunityTypeID.ToEnum<int?, CommunityTypes>(CommunityTypes.None))); Mapper.CreateMap<TopCategoryEntities, EntityDetails>() .ForMember(target => target.Tags, options => options.Condition(source => !source.IsSourceValueNull)) .ForMember(target => target.ID, options => options.MapFrom(source => source.ID)) .ForMember(target => target.Name, options => options.MapFrom(source => source.Title)); Mapper.CreateMap<Community, CommunityDetails>() .ForMember(target => target.ID, options => options.MapFrom(source => source.CommunityID)) .ForMember(target => target.CategoryID, options => options.MapFrom(source => (int)source.Category.CategoryID)) .ForMember(target => target.AccessTypeID, options => options.MapFrom(source => (int)source.AccessType.AccessTypeID)) .ForMember(target => target.AccessTypeName, options => options.MapFrom(source => source.AccessType.Name)) .ForMember(target => target.CommunityType, options => options.MapFrom(source => source.CommunityTypeID)) .ForMember(target => target.LastUpdatedDatetime, options => options.MapFrom(source => source.ModifiedDatetime)); // Used by ProfileService Mapper.CreateMap<ProfileDetails, User>() .ForMember(target => target.LiveID, options => options.MapFrom(source => source.PUID)) .ForMember(target => target.UserID, options => options.MapFrom(source => source.ID)) .ForMember(target => target.Email, options => options.MapFrom(source => source.Email.FixEmailAddress())) .ForMember(target => target.UserTypeID, options => options.MapFrom(source => (int?)source.UserType)) .ForMember(target => target.UserType, options => options.Ignore()); Mapper.CreateMap<User, ProfileDetails>() .ForMember(target => target.PUID, options => options.MapFrom(source => source.LiveID)) .ForMember(target => target.ID, options => options.MapFrom(source => source.UserID)) .ForMember(target => target.Email, options => options.MapFrom(source => source.Email.FixEmailAddress())) .ForMember(target => target.UserType, options => options.MapFrom(source => source.UserTypeID.HasValue ? source.UserTypeID.Value.ToEnum<int, UserTypes>(UserTypes.Regular) : UserTypes.Regular)) .ForMember(target => target.TotalSize, options => options.MapFrom(source => source.UserType.MaxAllowedSize)); Mapper.CreateMap<User, AdminReportProfileDetails>() .ForMember(target => target.PUID, options => options.MapFrom(source => source.LiveID)) .ForMember(target => target.LastLoggedOn, options => options.MapFrom(source => source.LastLoginDatetime)) .ForMember(target => target.UserName, options => options.MapFrom(source => source.GetFullName())) .ForMember(target => target.Email, options => options.MapFrom(source => source.Email.FixEmailAddress())); Mapper.CreateMap<UserCommunities, PermissionItem>() .ForMember(target => target.Name, options => options.MapFrom(source => source.User.FirstName + " " + source.User.LastName)) .ForMember(target => target.Role, options => options.MapFrom(source => (UserRole)source.RoleID)) .ForMember(target => target.Date, options => options.MapFrom(source => source.CreatedDatetime)); Mapper.CreateMap<PermissionRequest, PermissionItem>() .ForMember(target => target.Name, options => options.MapFrom(source => source.User.FirstName + " " + source.User.LastName)) .ForMember(target => target.CommunityName, options => options.MapFrom(source => source.Community.Name)) .ForMember(target => target.Role, options => options.MapFrom(source => (UserRole)source.RoleID)) .ForMember(target => target.Date, options => options.MapFrom(source => source.RequestedDate)); Mapper.CreateMap<PermissionItem, PermissionRequest>() .ForMember(target => target.RoleID, options => options.MapFrom(source => (UserRole)source.Role)) .ForMember(target => target.Role, options => options.Ignore()); // Used by RatingService Mapper.CreateMap<RatingDetails, CommunityRatings>() .ForMember(target => target.CommunityID, options => options.MapFrom(source => source.ParentID)); Mapper.CreateMap<RatingDetails, ContentRatings>() .ForMember(target => target.RatingByID, options => options.MapFrom(source => source.RatedByID)) .ForMember(target => target.ContentID, options => options.MapFrom(source => source.ParentID)); // Used by ReportEntityService Mapper.CreateMap<ReportEntityDetails, OffensiveCommunities>() .ForMember(target => target.CommunityID, options => options.MapFrom(source => source.ParentID)) .ForMember(target => target.OffensiveTypeID, options => options.MapFrom(source => (int)source.ReportEntityType)) .ForMember(target => target.OffensiveStatusID, options => options.MapFrom(source => (int)source.Status)) .ForMember(target => target.Comments, options => options.MapFrom(source => source.Comment)); Mapper.CreateMap<ReportEntityDetails, OffensiveContent>() .ForMember(target => target.ContentID, options => options.MapFrom(source => source.ParentID)) .ForMember(target => target.OffensiveTypeID, options => options.MapFrom(source => (int)source.ReportEntityType)) .ForMember(target => target.OffensiveStatusID, options => options.MapFrom(source => (int)source.Status)) .ForMember(target => target.Comments, options => options.MapFrom(source => source.Comment)); Mapper.CreateMap<ContentsView, ContentDetails>() .ForMember(target => target.ID, options => options.MapFrom(source => source.ContentID)) .ForMember(target => target.Name, options => options.MapFrom(source => source.Title)) .ForMember(target => target.ParentType, options => options.MapFrom(source => source.CommunityTypeID)) .ForMember(target => target.ParentID, options => options.MapFrom(source => source.CommunityID)) .ForMember(target => target.ParentName, options => options.MapFrom(source => source.CommunityName)) .ForMember(target => target.Tags, options => options.MapFrom(source => (source.Tags ?? string.Empty))) .ForMember(target => target.SortOrder, options => options.Ignore()) .ForMember(target => target.TourLength, options => options.MapFrom(source => source.TourRunLength)) .ForMember( target => target.Thumbnail, options => options.MapFrom(source => new FileDetail() { AzureID = source.ThumbnailID ?? Guid.Empty })) .ForMember( target => target.ContentData, options => options.ResolveUsing(source => { ContentTypes type = source.TypeID.ToEnum<int, ContentTypes>(ContentTypes.Generic); DataDetail dataDetail; if (type == ContentTypes.Link) { dataDetail = new LinkDetail(source.ContentUrl, source.ContentID); } else { var fileDetail = new FileDetail(); fileDetail.ContentID = source.ContentID; fileDetail.AzureID = source.ContentAzureID; dataDetail = fileDetail; } dataDetail.Name = source.Filename; dataDetail.ContentType = type; return dataDetail; })); Mapper.CreateMap<AllContentsView, ContentDetails>() .ForMember(target => target.ID, options => options.MapFrom(source => source.ContentID)) .ForMember(target => target.Name, options => options.MapFrom(source => source.Title)) .ForMember(target => target.AccessTypeName, options => options.MapFrom(source => source.AccessType)) .ForMember(target => target.ParentType, options => options.MapFrom(source => source.CommunityTypeID)) .ForMember(target => target.ParentID, options => options.MapFrom(source => source.CommunityID)) .ForMember(target => target.ParentName, options => options.MapFrom(source => source.CommunityName)) .ForMember(target => target.Tags, options => options.MapFrom(source => (source.Tags ?? string.Empty))) .ForMember(target => target.SortOrder, options => options.Ignore()) .ForMember( target => target.Thumbnail, options => options.ResolveUsing(source => { var thumbnailDetail = new FileDetail(); thumbnailDetail.AzureID = source.ThumbnailID.HasValue ? source.ThumbnailID.Value : Guid.Empty; return thumbnailDetail; })) .ForMember( target => target.ContentData, options => options.ResolveUsing(source => { ContentTypes type = source.TypeID.ToEnum<int, ContentTypes>(ContentTypes.Generic); DataDetail dataDetail; if (type == ContentTypes.Link) { dataDetail = new LinkDetail(source.ContentUrl, source.ContentID); } else { var fileDetail = new FileDetail(); fileDetail.ContentID = source.ContentID; fileDetail.AzureID = source.ContentAzureID; dataDetail = fileDetail; } dataDetail.Name = source.Filename; dataDetail.ContentType = type; return dataDetail; })); Mapper.CreateMap<FeaturedContentsView, ContentDetails>() .ForMember(target => target.ID, options => options.MapFrom(source => source.ContentID)) .ForMember(target => target.Name, options => options.MapFrom(source => source.Title)) .ForMember(target => target.ParentType, options => options.MapFrom(source => source.CommunityTypeID)) .ForMember(target => target.ParentID, options => options.MapFrom(source => source.CommunityID)) .ForMember(target => target.ParentName, options => options.MapFrom(source => source.CommunityName)) .ForMember(target => target.Tags, options => options.MapFrom(source => (source.Tags == null ? string.Empty : source.Tags))) .ForMember( target => target.Thumbnail, options => options.ResolveUsing(source => { var thumbnailDetail = new FileDetail(); thumbnailDetail.AzureID = source.ThumbnailID.HasValue ? source.ThumbnailID.Value : Guid.Empty; return thumbnailDetail; })) .ForMember( target => target.ContentData, options => options.ResolveUsing(source => { ContentTypes type = source.TypeID.ToEnum<int, ContentTypes>(ContentTypes.Generic); DataDetail dataDetail; if (type == ContentTypes.Link) { dataDetail = new LinkDetail(source.ContentUrl, source.ContentID); } else { var fileDetail = new FileDetail(); fileDetail.ContentID = source.ContentID; fileDetail.AzureID = source.ContentAzureID; dataDetail = fileDetail; } dataDetail.Name = source.Filename; dataDetail.ContentType = type; return dataDetail; })); Mapper.CreateMap<CommunitiesView, CommunityDetails>() .ForMember(target => target.ID, options => options.MapFrom(source => source.CommunityID)) .ForMember(target => target.Name, options => options.MapFrom(source => source.CommunityName)) .ForMember(target => target.AccessTypeName, options => options.MapFrom(source => source.AccessType)) .ForMember(target => target.AccessTypeID, options => options.MapFrom(source => (int)source.AccessType.ToEnum<string, AccessType>(AccessType.Private))) .ForMember(target => target.CommunityType, options => options.MapFrom(source => source.CommunityTypeID.ToEnum<int, CommunityTypes>(CommunityTypes.None))) .ForMember(target => target.SortOrder, options => options.Ignore()) .ForMember( target => target.Thumbnail, options => options.ResolveUsing(source => { var thumbnailDetail = new FileDetail(); thumbnailDetail.AzureID = source.ThumbnailID.HasValue ? source.ThumbnailID.Value : Guid.Empty; return thumbnailDetail; })); Mapper.CreateMap<AllCommunitiesView, CommunityDetails>() .ForMember(target => target.ID, options => options.MapFrom(source => source.CommunityID)) .ForMember(target => target.Name, options => options.MapFrom(source => source.CommunityName)) .ForMember(target => target.AccessTypeName, options => options.MapFrom(source => source.AccessType)) .ForMember(target => target.AccessTypeID, options => options.MapFrom(source => (int)source.AccessType.ToEnum<string, AccessType>(AccessType.Private))) .ForMember(target => target.CommunityType, options => options.MapFrom(source => source.CommunityTypeID.ToEnum<int, CommunityTypes>(CommunityTypes.None))) .ForMember(target => target.SortOrder, options => options.Ignore()) .ForMember( target => target.Thumbnail, options => options.ResolveUsing(source => { var thumbnailDetail = new FileDetail(); thumbnailDetail.AzureID = source.ThumbnailID.HasValue ? source.ThumbnailID.Value : Guid.Empty; return thumbnailDetail; })); Mapper.CreateMap<FeaturedCommunitiesView, CommunityDetails>() .ForMember(target => target.ID, options => options.MapFrom(source => source.CommunityID)) .ForMember(target => target.Name, options => options.MapFrom(source => source.CommunityName)) .ForMember(target => target.AccessTypeName, options => options.MapFrom(source => source.AccessType)) .ForMember(target => target.AccessTypeID, options => options.MapFrom(source => (int)source.AccessType.ToEnum<string, AccessType>(AccessType.Private))) .ForMember(target => target.CommunityType, options => options.MapFrom(source => source.CommunityTypeID.ToEnum<int, CommunityTypes>(CommunityTypes.None))) .ForMember( target => target.Thumbnail, options => options.ResolveUsing(source => { var thumbnailDetail = new FileDetail(); thumbnailDetail.AzureID = source.ThumbnailID.HasValue ? source.ThumbnailID.Value : Guid.Empty; return thumbnailDetail; })); // Used by AdministrationService Mapper.CreateMap<OffensiveCommunities, OffensiveEntityDetails>() .ForMember(target => target.EntityID, options => options.MapFrom(source => source.CommunityID)) .ForMember(target => target.EntityName, options => options.MapFrom(source => source.Community.Name)) .ForMember(target => target.EntryID, options => options.MapFrom(source => source.OffensiveCommunitiesID)) .ForMember(target => target.ReportedByID, options => options.MapFrom(source => source.ReportedByID)) .ForMember(target => target.ReportedBy, options => options.MapFrom(source => source.User.FirstName + " " + source.User.LastName)) .ForMember(target => target.ReportedDatetime, options => options.MapFrom(source => source.ReportedDatetime)) .ForMember(target => target.Reason, options => options.MapFrom(source => Resources.ResourceManager.GetString(source.OffensiveTypeID.ToEnum<int, ReportEntityType>(ReportEntityType.None).ToString()))) .ForMember(target => target.Comment, options => options.MapFrom(source => source.Comments)); Mapper.CreateMap<OffensiveContent, OffensiveEntityDetails>() .ForMember(target => target.EntityID, options => options.MapFrom(source => source.ContentID)) .ForMember(target => target.EntityName, options => options.MapFrom(source => source.Content.Title)) .ForMember(target => target.EntryID, options => options.MapFrom(source => source.OffensiveContentID)) .ForMember(target => target.ReportedByID, options => options.MapFrom(source => source.ReportedByID)) .ForMember(target => target.ReportedBy, options => options.MapFrom(source => source.User.FirstName + " " + source.User.LastName)) .ForMember(target => target.ReportedDatetime, options => options.MapFrom(source => source.ReportedDatetime)) .ForMember(target => target.Reason, options => options.MapFrom(source => Resources.ResourceManager.GetString(source.OffensiveTypeID.ToEnum<int, ReportEntityType>(ReportEntityType.None).ToString()))) .ForMember(target => target.Comment, options => options.MapFrom(source => source.Comments)); Mapper.CreateMap<InviteRequestItem, InviteRequestContent>(); Mapper.CreateMap<InviteRequestItem, InviteRequestItem>() .ForMember(target => target.EmailIdList, options => options.Ignore()); Mapper.CreateMap<InviteRequestsView, InviteRequestItem>() .ForMember(target => target.EmailIdList, options => options.MapFrom(source => new Collection<string>() { source.EmailID })); Mapper.CreateMap<CommunityDetails, AdminEntityDetails>() .ForMember(target => target.EntityID, options => options.MapFrom(source => source.ID)) .ForMember(target => target.EntityName, options => options.MapFrom(source => source.Name)) .ForMember(target => target.Visibility, options => options.MapFrom(source => source.AccessTypeName)) .ForMember(target => target.ModifiedDatetime, options => options.MapFrom(source => source.LastUpdatedDatetime)) .ForMember(target => target.EntityType, options => options.UseValue(EntityType.Community)) .ForMember(target => target.Category, options => options.MapFrom(source => source.CategoryID.ToEnum<int, CategoryType>(CategoryType.All))) .ForMember(target => target.CreatedBy, options => options.MapFrom(source => source.ProducedBy)) .ForMember(target => target.CreatedByID, options => options.MapFrom(source => source.CreatedByID)) .ForMember(target => target.DistributedBy, options => options.MapFrom(source => HttpContext.Current.Server.HtmlDecode(source.DistributedBy).GetTextFromHtmlString())); Mapper.CreateMap<ContentDetails, AdminEntityDetails>() .ForMember(target => target.EntityID, options => options.MapFrom(source => source.ID)) .ForMember(target => target.EntityName, options => options.MapFrom(source => source.Name)) .ForMember(target => target.Visibility, options => options.MapFrom(source => source.AccessTypeName)) .ForMember(target => target.ModifiedDatetime, options => options.MapFrom(source => source.LastUpdatedDatetime)) .ForMember(target => target.EntityType, options => options.UseValue(EntityType.Content)) .ForMember(target => target.Category, options => options.MapFrom(source => source.CategoryID.ToEnum<int, CategoryType>(CategoryType.All))) .ForMember(target => target.CreatedBy, options => options.MapFrom(source => source.ProducedBy)) .ForMember(target => target.CreatedByID, options => options.MapFrom(source => source.CreatedByID)) .ForMember(target => target.DistributedBy, options => options.MapFrom(source => HttpContext.Current.Server.HtmlDecode(source.DistributedBy).GetTextFromHtmlString())); Mapper.CreateMap<ProfileDetails, AdminUserDetails>() .ForMember(target => target.UserID, options => options.MapFrom(source => source.ID)) .ForMember(target => target.UserName, options => options.MapFrom(source => source.FirstName + " " + source.LastName)) .ForMember(target => target.UserImageID, options => options.MapFrom(source => source.PictureID)) .ForMember(target => target.Email, options => options.MapFrom(source => source.Email)); Mapper.CreateMap<SearchView, EntityViewModel>() .ForMember(target => target.Tags, options => options.MapFrom(source => string.IsNullOrWhiteSpace(source.Tags) ? string.Empty : source.Tags)) .ForMember(target => target.ParentType, options => options.Condition(source => !source.IsSourceValueNull)); }
/// <summary> /// Uploads the associated file to temporary container. /// </summary> /// <param name="fileDetail">Details of the associated file.</param> /// <returns>True if content is uploaded; otherwise false.</returns> public OperationStatus UploadTemporaryFile(FileDetail fileDetail) { OperationStatus operationStatus = null; // Make sure file detail is not null this.CheckNotNull(() => new { fileDetail }); var fileBlob = new BlobDetails() { BlobID = fileDetail.AzureID.ToString(), Data = fileDetail.DataStream, MimeType = fileDetail.MimeType }; try { _blobDataRepository.UploadTemporaryFile(fileBlob); operationStatus = OperationStatus.CreateSuccessStatus(); } catch (Exception) { operationStatus = OperationStatus.CreateFailureStatus(Resources.UnknownErrorMessage); } return operationStatus; }
/// <summary> /// Uploads file to azure. /// </summary> /// <param name="fileDetails">Details of the file.</param> public OperationStatus UploadAsset(FileDetail fileDetails) { OperationStatus operationStatus = null; this.CheckNotNull(() => new { fileDetails }); var fileBlob = new BlobDetails() { BlobID = fileDetails.Name, Data = fileDetails.DataStream, MimeType = fileDetails.MimeType }; try { if (_blobDataRepository.UploadAsset(fileBlob)) { operationStatus = OperationStatus.CreateSuccessStatus(); } else { operationStatus = OperationStatus.CreateFailureStatus(Resources.UnknownErrorMessage); } } catch (Exception) { operationStatus = OperationStatus.CreateFailureStatus(Resources.UnknownErrorMessage); } return operationStatus; }
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; }
/// <summary> /// Deletes file from azure. /// </summary> /// <param name="fileDetail">Details of the file.</param> private void DeleteFile(FileDetail fileDetail) { var fileBlob = new BlobDetails() { BlobID = fileDetail.AzureID.ToString(), MimeType = fileDetail.MimeType }; // Delete file from azure. _blobDataRepository.DeleteFile(fileBlob); }
/// <summary> /// Gets the associated files from content input view model. /// </summary> /// <param name="content">Input view model.</param> /// <returns>Associated files.</returns> private static IEnumerable<DataDetail> GetAssociatedFiles(ContentInputViewModel content) { var associatedFiles = new List<DataDetail>(); if (content.PostedFileDetail != null) { for (int i = 0; i < content.PostedFileDetail.Count(); i++) { var file = content.PostedFileDetail.ElementAt(i); string[] fileDetails = file.Split('~'); if (fileDetails.Count() == 5) { string mimeType = fileDetails[3]; // If the posted file details does not have the following details // then do not process the file. DataDetail contentDetail = null; if (mimeType.ToUpperInvariant().Equals(Constants.LinkMimeType.ToUpperInvariant())) { contentDetail = new LinkDetail(content.PostedFileName.ElementAt(i)); } else { var fileDetail = new FileDetail(); // Get and set Content type. fileDetail.ContentType = fileDetails[0].GetContentTypes(); // Get file name and extension. fileDetail.Name = string.Format( System.Globalization.CultureInfo.InvariantCulture, "{0}{1}", content.PostedFileName.ElementAt(i), fileDetails[0]); // Get File size. long fileSize; if (long.TryParse(fileDetails[1], out fileSize)) { fileDetail.Size = fileSize; } // Get Azure ID Guid fileID; if (Guid.TryParse(fileDetails[2], out fileID)) { fileDetail.AzureID = fileID; } // Get content mime Type. fileDetail.MimeType = fileDetails[3]; contentDetail = fileDetail; } // Set Content ID if present. long contentID; if (long.TryParse(fileDetails[4], out contentID)) { contentDetail.ContentID = contentID; } associatedFiles.Add(contentDetail); } } } return associatedFiles; }
/// <summary> /// Uploads the associated file to temporary container. /// </summary> /// <param name="fileDetail">Details of the associated file.</param> /// <returns>True if content is uploaded; otherwise false.</returns> public bool UploadTemporaryFile(FileDetail fileDetail) { // Make sure file detail is not null this.CheckNotNull(() => new { fileDetail }); var fileBlob = new BlobDetails() { BlobID = fileDetail.AzureID.ToString(), Data = fileDetail.DataStream, MimeType = fileDetail.MimeType }; return _blobDataRepository.UploadTemporaryFile(fileBlob); }
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"}; } }