private void HandleMessage(string message, IModel channel) { Console.WriteLine(" [x] Received {0}", message); try { var bytes = _screenShotService.GetScreenBytesByUrl(message); var linkToScreen = _сaptureService.UploadScreenShot(bytes); _repository.Create(message, linkToScreen); Console.WriteLine("Screenshot done."); } catch (Exception ex) { _repository.Create(message, "", true); Console.WriteLine("Exeption is " + ex); } }
public bool ChangeProjectRights(Identity projectId, IEnumerable <ProjectRights> newProjectRights) { var project = _projectRepository.Read(projectId.ToMongoIdentity()); if (project == null) { throw new EntityNotFoundException { Id = projectId }; } var filter = Builders <MongoSecurityRights> .Filter.Eq(x => x.ProjectId, projectId.ToMongoIdentity()); var oldRights = _securityRightsRepository.Find(filter).ToArray(); _securityRightsRepository.Delete(filter); try { var mongoRights = newProjectRights.Select(x => new MongoSecurityRights { ProjectId = projectId.ToMongoIdentity(), UserId = x.UserId.ToMongoIdentity(), CanChangeProjectRights = x.CanChangeProjectRights, CanChangeRequirements = x.CanChangeRequirements, CanChangeUseCases = x.CanChangeUseCases, CanViewProject = x.CanViewProject, IsAdministrator = x.IsAdministrator, }); foreach (var mongoRight in mongoRights) { _securityRightsRepository.Create(mongoRight); } } catch (EntityNotFoundException) { foreach (var right in oldRights) { _securityRightsRepository.Create(right); } throw; } return(true); }
public void Create_Success() { var entity = new MongoTestEntity() { Bool = false, Number = 1, String = "String" }; entity = Repository.Create(entity); Assert.IsNotNull(entity.Id); Assert.IsTrue(entity.Created >= DateTime.UtcNow.AddSeconds(-5)); Assert.IsTrue(entity.Updated >= DateTime.UtcNow.AddSeconds(-5)); }