private VideoModel CreateVideoModel(string id) { string queryString = Request.QueryString.ToString(); if (queryString.Length > 0) { queryString = string.Format(@"?{0}", queryString); } // HTTP addresses var video = new VideoModel { VideoUrl = _projectUriProvider.GetUri(id) + queryString, EmbedUrl = Url.RouteUrl(RouteNames.Embed, new { id, autoplay = 1 }, "http") }; // HTTPS address var builder = new UriBuilder(video.VideoUrl) { Scheme = "https", Port = 443 }; video.VideoSecureUrl = builder.Uri.ToString(); builder = new UriBuilder(video.EmbedUrl) { Scheme = "https", Port = 443 }; video.EmbedSecureUrl = builder.Uri.ToString(); video.Robot = GetProvider(Request.UserAgent); return(video); }
public async Task <ActionResult> Sitemap(int page) { // Get projects List <DomainProject> projectsPage = await _projectService.GetSitemapPageAsync(page); // Build sitemap var sitemap = new SitemapModel(); foreach (DomainProject project in projectsPage) { sitemap.Urls.Add(new SitemapItem { Location = _projectUriProvider.GetUri(project.Id), ChangeFrequency = SitemapUrlChangeFrequency.Monthly, LastModified = project.Modified }); } // Serialize var serializer = new XmlSerializer(typeof(SitemapModel)); var xmlns = new XmlSerializerNamespaces(); xmlns.Add("", "http://www.sitemaps.org/schemas/sitemap/0.9"); var xmlStream = new MemoryStream(); serializer.Serialize(xmlStream, sitemap, xmlns); xmlStream.Seek(0, SeekOrigin.Begin); return(File(xmlStream, "text/xml")); }
public async Task <HttpResponseMessage> Post(ProjectModel model) { try { await CongratUserIfNeeded(); } catch (Exception e) { Trace.TraceError("Failed to notify user by email: {0}", e); } ProductType product = _productIdExtractor.Get(UserAgent); var project = new DomainProject { UserId = UserId, Name = model.Name, Description = model.Description, Access = model.Access, ProductType = product, ProjectType = model.ProjectType, ProjectSubtype = model.ProjectSubtype, EnableComments = model.EnableComments }; project = await _projectService.AddAsync(project); var responseProject = new Project { Id = project.Id, Description = project.Description, Access = project.Access, Name = project.Name, Created = project.Created, PublicUrl = _projectUriProvider.GetUri(project.Id), ProjectType = project.ProjectType, ProjectSubtype = project.ProjectSubtype, EnableComments = project.EnableComments }; HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, responseProject); response.SetLastModifiedDate(project.Modified); return(response); }
public async Task SendAbuseNotificationAsync(Watch project, DomainUser reporter) { if (project == null) { throw new ArgumentNullException("project"); } if (reporter == null) { throw new ArgumentNullException("reporter"); } if (!_settings.EmailNotifications) { return; } string projectUri = _projectUriProvider.GetUri(project.Id); var email = new SendEmailDomain { Address = _settings.EmailAddressAlerts, DisplayName = Emails.SenderDisplayName, Emails = new List <string> { _settings.EmailAddressAbuse }, Subject = string.Format(Emails.SubjectAbuseReport, projectUri), Body = string.Format( PortalResources.AbuseReported, reporter.Name, _userUriProvider.GetUri(reporter.Id), project.Name, projectUri) }; // Send email await _emailSenderService.SendEmailAsync(email); }
public async Task <UrlTrackingResult> TrackAsync(DomainTrackingUrl trackingUrl) { if (string.IsNullOrEmpty(trackingUrl.Id)) { trackingUrl.Id = _urlShortenerService.Decode(trackingUrl.Key).ToString(CultureInfo.InvariantCulture); } TrackingUrlEntity entity = _mappingEngine.Map <DomainTrackingUrl, TrackingUrlEntity>(trackingUrl); entity = await _trackingUrlRepository.GetAsync(entity); if (entity == null) { throw new NotFoundException(string.Format("Could not find tracking url with id {0} and key {1}", trackingUrl.Id, trackingUrl.Key)); } // Build portal url link string projectUrl = _projectUriProvider.GetUri(entity.ProjectId); // We should keep requested schema in redirect link var projectUri = new UriBuilder(projectUrl) { Scheme = trackingUrl.RequestUri.Scheme, Port = trackingUrl.RequestUri.Port }; // Default redirect to Portal var result = new UrlTrackingResult { ProjectId = entity.ProjectId, SubscriptionId = entity.SubscriptionId, IsAccountable = false, Redirect = projectUri.Uri }; DomainCompany company; CompanySubscription subscription; try { company = await _companyService.FindBySubscriptionAsync(entity.SubscriptionId); subscription = await _subscriptionService.GetAsync(entity.SubscriptionId); } catch (ForbiddenException) { // blocked company or subscription - portal redirect return(result); } catch (NotFoundException) { // deleted or unexisting company or subscription - portal redirect return(result); } // Checking custom subscription type if (subscription.Type == SubscriptionType.Pro || subscription.Type == SubscriptionType.Custom) { // always redirect to client site result.Redirect = new Uri(entity.RedirectUrl); result.IsAccountable = true; } else if (subscription.Type == SubscriptionType.Basic) { // checking company balance if (subscription.IsManuallyEnabled || subscription.HasTrialClicks || (await _balanceService.GetBalanceAsync(company.Id)) > 0) { result.Redirect = new Uri(entity.RedirectUrl); result.IsAccountable = true; } } return(result); }
private Watch AggregateProject(ProjectEntity projectEntity, string userId, Dictionary <string, UserEntity> users, Dictionary <string, int> commentsCounts, Dictionary <string, List <CommentEntity> > comments) { DomainProject project = _mapper.Map <ProjectEntity, DomainProject>(projectEntity); // 1. Aggregate Data UserEntity projectUser = users.ContainsKey(project.UserId) ? users[project.UserId] : null; int commentsCount = commentsCounts.ContainsKey(project.Id) ? commentsCounts[project.Id] : 0; List <CommentEntity> projectComments = comments.ContainsKey(project.Id) ? comments[project.Id] : new List <CommentEntity>(); // Processed Videos var watchVideos = new List <WatchVideo>(); watchVideos.AddRange( from @group in project.EncodedVideos.GroupBy(q => q.Width) select @group.ToList() into processedVideos where processedVideos.Count == 2 from v in processedVideos select new WatchVideo { ContentType = v.ContentType, Width = v.Width, Height = v.Height, Uri = _uriProvider.CreateUri(v.FileId) }); // Processed Screenshots List <WatchScreenshot> watchScreenshots = project.EncodedScreenshots.Select( s => new WatchScreenshot { ContentType = s.ContentType, Uri = _uriProvider.CreateUri(s.FileId) }).ToList(); // External Video ExternalVideo externalVideo = !string.IsNullOrEmpty(project.VideoSource) ? new ExternalVideo { ProductName = project.VideoSourceProductName, VideoUri = project.VideoSource, AcsNamespace = _settings.AcsNamespace } : null; // 2. Calculate Video State WatchState state; if (string.IsNullOrEmpty(project.AvsxFileId) || (string.IsNullOrEmpty(project.OriginalVideoFileId) && externalVideo == null)) { state = WatchState.Uploading; } else if (externalVideo == null && watchVideos.Count == 0) { state = WatchState.Encoding; } else { state = WatchState.Ready; } // 3. Map comments var watchComments = new List <Comment>(); foreach (CommentEntity projectComment in projectComments) { UserEntity commentAuthor = users.ContainsKey(projectComment.UserId) ? users[projectComment.UserId] : null; DomainComment domainComment = _mapper.Map <Tuple <CommentEntity, UserEntity>, DomainComment>(new Tuple <CommentEntity, UserEntity>(projectComment, commentAuthor)); Comment comment = _mapper.Map <DomainComment, Comment>(domainComment); if (commentAuthor != null) { comment.AvatarUrl = _userAvatarProvider.GetAvatar(commentAuthor.Email); } watchComments.Add(comment); } watchComments.Reverse(); // Result return(new Watch { Name = project.Name, UserId = project.UserId, UserName = projectUser != null ? projectUser.Name : null, UserAvatarUrl = projectUser != null?_userAvatarProvider.GetAvatar(new DomainUser { Email = projectUser.Email }) : null, Description = project.Description, Created = project.Created, Avsx = !string.IsNullOrEmpty(project.AvsxFileId) ? _uriProvider.CreateUri(project.AvsxFileId) : null, Screenshots = watchScreenshots, Videos = watchVideos, PublicUrl = _projectUriProvider.GetUri(project.Id), Id = project.Id, Access = project.Access, IsEditable = project.UserId == userId, HitsCount = project.HitsCount, External = externalVideo, ScreenshotUrl = !string.IsNullOrEmpty(project.ScreenshotFileId) ? _uriProvider.CreateUri(project.ScreenshotFileId) : null, State = state, Generator = (int)project.ProductType, ProjectType = project.ProjectType, ProjectSubtype = project.ProjectSubtype, EnableComments = project.EnableComments, CommentsCount = commentsCount, LikesCount = project.LikesCount, DislikesCount = project.DislikesCount, Comments = watchComments }); }