public async Task<HttpResponseMessage> Post(string id, ProjectScreenshotModel model) { await GetProjectAsync(id); var screenshot = new DomainScreenshot { FileName = model.Screenshot.Name, FileUri = model.Screenshot.Uri, FileId = Guid.NewGuid().ToString(), FileLength = model.Screenshot.Length, ContentType = model.Screenshot.ContentType, Created = DateTime.UtcNow, Modified = DateTime.UtcNow }; screenshot = await _projectScreenshotService.AddAsync(id, screenshot); var projectScreenshot = new ProjectScreenshot { ContentType = screenshot.ContentType, Name = screenshot.FileName, Uri = screenshot.FileUri, Length = screenshot.FileLength }; HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, projectScreenshot); response.SetLastModifiedDate(screenshot.Modified); return response; }
public async Task <DomainScreenshot> GetAsync(string projectId) { ProjectEntity project = await _projectRepository.GetAsync(projectId); if (project == null) { throw new NotFoundException(string.Format("Project {0} was not found", projectId)); } if (string.IsNullOrEmpty(project.ScreenshotFileId)) { throw new NotFoundException(string.Format("Project {0} does not have a screenshot", projectId)); } StorageFile file = await _fileSystem.GetFilePropertiesAsync(new StorageFile { Id = project.ScreenshotFileId }); if (file == null) { throw new NotFoundException(string.Format("Project's {0} screenshot was not found", projectId)); } DomainScreenshot result = _mapper.Map <StorageFile, DomainScreenshot>(file); result.FileUri = _uriProvider.CreateUri(result.FileId); return(result); }
public async Task <HttpResponseMessage> Post(string id, ProjectScreenshotModel model) { await GetProjectAsync(id); var screenshot = new DomainScreenshot { FileName = model.Screenshot.Name, FileUri = model.Screenshot.Uri, FileId = Guid.NewGuid().ToString(), FileLength = model.Screenshot.Length, ContentType = model.Screenshot.ContentType, Created = DateTime.UtcNow, Modified = DateTime.UtcNow }; screenshot = await _projectScreenshotService.AddAsync(id, screenshot); var projectScreenshot = new ProjectScreenshot { ContentType = screenshot.ContentType, Name = screenshot.FileName, Uri = screenshot.FileUri, Length = screenshot.FileLength }; HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, projectScreenshot); response.SetLastModifiedDate(screenshot.Modified); return(response); }
// GET api/projects/{id}/screenshot public async Task <HttpResponseMessage> Get(string id) { await GetProjectAsync(id); DomainScreenshot screenshot = await _projectScreenshotService.GetAsync(id); var projectScreenshot = new ProjectScreenshot { Name = screenshot.FileName, Uri = screenshot.FileUri, Length = screenshot.FileLength, ContentType = screenshot.ContentType }; HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, projectScreenshot); response.SetLastModifiedDate(screenshot.Modified); return(response); }
/// <summary> /// Gets a video viewmodel. /// </summary> /// <param name="watch">Watch project model.</param> /// <param name="id">Project identifier.</param> /// <returns></returns> protected async Task <VideoModel> GetVideoModel(Watch watch, string id) { VideoModel video = CreateVideoModel(id); video.Video = watch; video.Name = watch.Name; video.Description = watch.Description; OverrideParams(video); // If screenshot was not overriden if (string.IsNullOrEmpty(video.Image)) { // Set default image video.Image = watch.Screenshots.Count == 0 ? string.Empty : watch.Screenshots[0].Uri; // Try to receive screenshot from the service if (String.IsNullOrEmpty(video.Image) || watch.Generator != (int)ProductType.TaggerIPhone) { try { DomainScreenshot screenshot = await _screenshotService.GetAsync(id); video.Image = screenshot.FileUri; } catch (NotFoundException) { } catch (Exception e) { Trace.TraceError("Failed to receive project {0} screenshot: {1}", id, e); } } } SetImage(video); return(video); }
public async Task <DomainScreenshot> AddAsync(string projectId, DomainScreenshot entity) { ProjectEntity project = await _projectRepository.GetAsync(projectId); if (project == null) { throw new NotFoundException(string.Format("Project {0} was not found", projectId)); } // Check whether project already contains screenshot if (!string.IsNullOrEmpty(project.ScreenshotFileId)) { throw new ConflictException(); } StorageFile storageFile; // uploading file using (FileStream stream = File.OpenRead(entity.FileUri)) { storageFile = await _fileSystem.UploadFileFromStreamAsync( new StorageFile(stream, entity.ContentType) { UserId = project.UserId, FileName = entity.FileName, Length = entity.FileLength }); } // updating project await _projectRepository.SetScreenshotFileIdAsync(project.Id, storageFile.Id); // building result DomainScreenshot result = _mapper.Map <StorageFile, DomainScreenshot>(storageFile); result.FileUri = _uriProvider.CreateUri(storageFile.Id); return(result); }
public async Task<DomainScreenshot> AddAsync(string projectId, DomainScreenshot entity) { ProjectEntity project = await _projectRepository.GetAsync(projectId); if (project == null) { throw new NotFoundException(string.Format("Project {0} was not found", projectId)); } // Check whether project already contains screenshot if (!string.IsNullOrEmpty(project.ScreenshotFileId)) { throw new ConflictException(); } StorageFile storageFile; // uploading file using (FileStream stream = File.OpenRead(entity.FileUri)) { storageFile = await _fileSystem.UploadFileFromStreamAsync( new StorageFile(stream, entity.ContentType) { UserId = project.UserId, FileName = entity.FileName, Length = entity.FileLength }); } // updating project await _projectRepository.SetScreenshotFileIdAsync(project.Id, storageFile.Id); // building result DomainScreenshot result = _mapper.Map<StorageFile, DomainScreenshot>(storageFile); result.FileUri = _uriProvider.CreateUri(storageFile.Id); return result; }
public async Task <HttpResponseMessage> Post(ExternalProjectModel model) { try { await CongratUserIfNeeded(); } catch (Exception e) { Trace.TraceError("Failed to notify user by email: {0}", e); } // Add project 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); // Add external video await _externalVideoService.AddAsync(project.Id, new DomainExternalVideo { ProductName = model.ProductName, VideoUri = model.VideoUri }); // Add avsx file if exists if (model.Avsx != null) { var avsx = new DomainAvsx { ContentType = model.Avsx.ContentType, FileName = model.Avsx.Name, FileUri = model.Avsx.Uri, FileLength = model.Avsx.Length }; await _projectAvsxService.AddAsync(project.Id, avsx); // For statistics Request.Properties.Add("isAvsx", true); } // Add screenshot file if exists if (model.Screenshot != null) { var screenshot = new DomainScreenshot { FileName = model.Screenshot.Name, FileUri = model.Screenshot.Uri, FileId = Guid.NewGuid().ToString(), FileLength = model.Screenshot.Length, ContentType = model.Screenshot.ContentType, Created = DateTime.UtcNow, Modified = DateTime.UtcNow }; await _projectScreenshotService.AddAsync(project.Id, screenshot); // For statistics Request.Properties.Add("isScreenshot", true); } 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<HttpResponseMessage> Post(ExternalProjectModel model) { try { await CongratUserIfNeeded(); } catch (Exception e) { Trace.TraceError("Failed to notify user by email: {0}", e); } // Add project 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); // Add external video await _externalVideoService.AddAsync(project.Id, new DomainExternalVideo { ProductName = model.ProductName, VideoUri = model.VideoUri }); // Add avsx file if exists if (model.Avsx != null) { var avsx = new DomainAvsx { ContentType = model.Avsx.ContentType, FileName = model.Avsx.Name, FileUri = model.Avsx.Uri, FileLength = model.Avsx.Length }; await _projectAvsxService.AddAsync(project.Id, avsx); // For statistics Request.Properties.Add("isAvsx", true); } // Add screenshot file if exists if (model.Screenshot != null) { var screenshot = new DomainScreenshot { FileName = model.Screenshot.Name, FileUri = model.Screenshot.Uri, FileId = Guid.NewGuid().ToString(), FileLength = model.Screenshot.Length, ContentType = model.Screenshot.ContentType, Created = DateTime.UtcNow, Modified = DateTime.UtcNow }; await _projectScreenshotService.AddAsync(project.Id, screenshot); // For statistics Request.Properties.Add("isScreenshot", true); } 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; }