Example #1
0
        public async Task<HttpResponseMessage> Post(string id, ProjectAvsxModel model)
        {
            // Get project entity
            await GetProjectAsync(id);

            // Add avsx
            var avsx = new DomainAvsx
            {
                ContentType = model.Avsx.ContentType,
                FileName = model.Avsx.Name,
                FileUri = model.Avsx.Uri,
                FileLength = model.Avsx.Length
            };

            avsx = await _projectAvsxService.AddAsync(id, avsx);

            var responseAvsx = new ProjectAvsx
            {
                Name = avsx.FileName,
                Uri = avsx.FileUri,
                Length = avsx.FileLength,
                ContentType = avsx.ContentType
            };

            HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, responseAvsx);

            response.SetLastModifiedDate(avsx.Modified);

            return response;
        }
        public async Task <DomainAvsx> 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.AvsxFileId))
            {
                throw new NotFoundException(string.Format("Project {0} does not have an avsx file", projectId));
            }

            StorageFile file = await _fileSystem.GetFilePropertiesAsync(new StorageFile { Id = project.AvsxFileId });

            if (file == null)
            {
                throw new NotFoundException(string.Format("Project's {0} avsx was not found", projectId));
            }

            DomainAvsx result = _mapper.Map <StorageFile, DomainAvsx>(file);

            result.FileUri = _uriProvider.CreateUri(result.FileId);

            return(result);
        }
Example #3
0
        // GET api/projects/{id}/avsx
        public async Task <HttpResponseMessage> Get(string id)
        {
            // Get project
            await GetProjectAsync(id);

            // Get avsx
            DomainAvsx avsx = await _projectAvsxService.GetAsync(id);

            if (avsx == null)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ResponseMessages.ResourceNotFound));
            }

            var responseAvsx = new ProjectAvsx
            {
                Name        = avsx.FileName,
                Uri         = avsx.FileUri,
                Length      = avsx.FileLength,
                ContentType = avsx.ContentType
            };

            HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, responseAvsx);

            response.SetLastModifiedDate(avsx.Modified);

            return(response);
        }
Example #4
0
        public async Task <HttpResponseMessage> Post(string id, ProjectAvsxModel model)
        {
            // Get project entity
            await GetProjectAsync(id);

            // Add avsx
            var avsx = new DomainAvsx
            {
                ContentType = model.Avsx.ContentType,
                FileName    = model.Avsx.Name,
                FileUri     = model.Avsx.Uri,
                FileLength  = model.Avsx.Length
            };

            avsx = await _projectAvsxService.AddAsync(id, avsx);

            var responseAvsx = new ProjectAvsx
            {
                Name        = avsx.FileName,
                Uri         = avsx.FileUri,
                Length      = avsx.FileLength,
                ContentType = avsx.ContentType
            };

            HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, responseAvsx);

            response.SetLastModifiedDate(avsx.Modified);

            return(response);
        }
        public async Task <DomainAvsx> AddAsync(string projectId, DomainAvsx 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 avsx
            if (!string.IsNullOrEmpty(project.AvsxFileId))
            {
                throw new ConflictException();
            }

            StorageFile storageFile;

            // uploading file
            using (FileStream stream = File.OpenRead(entity.FileUri))
            {
                storageFile = await _fileSystem.UploadFileFromStreamAsync(
                    new StorageFile(stream, AvsxContentType)
                {
                    UserId   = project.UserId,
                    FileName = entity.FileName,
                    Length   = entity.FileLength
                });
            }

            // updating project
            await _projectRepository.SetAvsxFileIdAsync(project.Id, storageFile.Id);

            DomainAvsx result = _mapper.Map <StorageFile, DomainAvsx>(storageFile);

            result.FileUri = _uriProvider.CreateUri(result.FileId);

            return(result);
        }
        public async Task<DomainAvsx> AddAsync(string projectId, DomainAvsx 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 avsx
            if (!string.IsNullOrEmpty(project.AvsxFileId))
            {
                throw new ConflictException();
            }

            StorageFile storageFile;

            // uploading file
            using (FileStream stream = File.OpenRead(entity.FileUri))
            {
                storageFile = await _fileSystem.UploadFileFromStreamAsync(
                    new StorageFile(stream, AvsxContentType)
                    {
                        UserId = project.UserId,
                        FileName = entity.FileName,
                        Length = entity.FileLength
                    });
            }

            // updating project
            await _projectRepository.SetAvsxFileIdAsync(project.Id, storageFile.Id);

            DomainAvsx result = _mapper.Map<StorageFile, DomainAvsx>(storageFile);
            result.FileUri = _uriProvider.CreateUri(result.FileId);

            return result;
        }
Example #7
0
        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;
        }