Пример #1
1
        public Organisation(
            User createdByUser,
            string name,
            string description,
            string website,
            MediaResource avatar,
            MediaResource background,
            IEnumerable<string> categories,
            DateTime createdDateTime,
            Group parentGroup)
            : base(createdByUser,
            name,
            createdDateTime,
            parentGroup)
        {
            Check.RequireNotNull(categories != null, "categories");

            InitMembers();

            SetOrganisationDetails(
                description,
                website,
                avatar,
                background,
                categories);

            ApplyEvent(new DomainModelCreatedEvent<Organisation>(this, createdByUser, this));
        }
Пример #2
0
        public Observation(
            string key,
            User createdByUser,
            string title,
            DateTime createdOn,
            DateTime observedOn,
            string latitude,
            string longitude,
            string address,
            bool anonymiseLocation,
            string category,
            UserProject userProject,
            IEnumerable<Project> projects,
            IEnumerable<Tuple<MediaResource, string, string, bool>> media
            )
            : base(key,
            createdByUser,
            createdOn,
            observedOn,
            latitude,
            longitude,
            anonymiseLocation,
            category,
            userProject,
            projects)
        {
            InitMembers();

            SetObservationDetails(
                title,
                address,
                media);

            ApplyEvent(new SightingCreatedEvent(this, createdByUser, this, projects));
        }
        public object Make(Sighting sighting, SightingNote sightingNote, User user, User authenticatedUser)
        {
            dynamic viewModel = new ExpandoObject();

            viewModel.Id = sightingNote.Id;
            viewModel.SightingId = sighting.Id;
            viewModel.CreatedOn = sightingNote.CreatedOn;
            viewModel.NoteComments = sightingNote.Comments;
            viewModel.Descriptions = sightingNote.Descriptions;
            viewModel.Tags = sightingNote.Tags;
            viewModel.User = _userViewFactory.Make(user, authenticatedUser);
            viewModel.TagCount = sightingNote.Tags.Count();
            viewModel.DescriptionCount = sightingNote.Descriptions.Count();
            viewModel.AllTags = string.Join(", ", sightingNote.Tags);
            viewModel.CreatedOnDescription = sightingNote.CreatedOn.ToString("d MMMM yyyy");
            viewModel.TotalVoteScore = sightingNote.Votes.Sum(x => x.Score);

            // Current user-specific properties
            if (authenticatedUser != null)
            {
                var userId = authenticatedUser.Id;

                viewModel.UserVoteScore = sightingNote.Votes.Any(x => x.User.Id == userId) ? sightingNote.Votes.Single(x => x.User.Id == userId).Score : 0;
                viewModel.IsOwner = sightingNote.User.Id == authenticatedUser.Id;
            }

            return viewModel;
        }
Пример #4
0
        public object Make(Group group, User authenticatedUser, bool fullDetails = false, int sightingCount = 0, int userCount = 0, int postCount = 0, IEnumerable<Observation> sampleObservations = null)
        {
            Check.RequireNotNull(group, "group");

            dynamic viewModel = new ExpandoObject();

            viewModel.Id = group.Id;
            viewModel.Name = group.Name;
            viewModel.GroupType = group.GroupType;

            if (group is IPublicGroup)
            {
                viewModel.Avatar = MakeAvatar(((IPublicGroup)group).Avatar);
                viewModel.CreatedBy = group.User.Id;
            }

            if (fullDetails)
            {
                viewModel.Created = group.CreatedDateTime.ToString("d MMM yyyy");
                viewModel.CreatedDateTimeOrder = group.CreatedDateTime.ToString("yyyyMMddHHmmss");

                if (group is IPublicGroup)
                {
                    viewModel.Background = ((IPublicGroup)group).Background;
                    viewModel.Website = ((IPublicGroup)group).Website;
                    viewModel.Description = ((IPublicGroup)group).Description;
                    viewModel.UserCount = userCount;
                    viewModel.PostCount = postCount;
                }
                if (group is Project)
                {
                    viewModel.SightingCount = sightingCount;
                    viewModel.Categories = ((Project)group).Categories;
                    if (sampleObservations != null)
                    {
                        viewModel.SampleObservations = sampleObservations.Select(x =>
                                                                        new
                                                                            {
                                                                                x.Id,
                                                                                Media = MakePrimaryMedia(x.PrimaryMedia)
                                                                            });
                    }
                    else
                    {
                        viewModel.SampleObservations = new object[] {};
                    }
                }
                if (group is Organisation)
                {
                    viewModel.Categories = ((Organisation)group).Categories;
                }

                if (authenticatedUser != null)
                {
                    viewModel.IsMember = authenticatedUser.Memberships.Any(x => x.Group.Id == group.Id);
                }
            }

            return viewModel;
        }
 public UserJoinedChatEvent(
     User user,
     Chat chat,
     DomainModel sender)
     : base(user,
     sender)
 {
     Chat = chat;
 }
 public RequestPasswordUpdate(
     User user,
     DomainModel sender,
     bool sendEmail)
     : base(user,
     sender)
 {
     SendEmail = sendEmail;
 }
Пример #7
0
        protected DomainEventBase(
            User user, 
            object sender)
        {
            Check.RequireNotNull(user, "user");
            Check.RequireNotNull(sender, "sender");

            User = user;
            Sender = sender;
        }
 public OnlineUserUpdatedEvent(
     User user,
     OnlineUser onlineUser,
     string connectionId,
     DomainModel sender)
     : base(user,
     sender)
 {
     OnlineUser = onlineUser;
     ConnectionId = connectionId;
 }
 public MediaResourceCreateFailedEvent(
     User user,
     string key,
     string reason,
     DomainModel sender)
     : base(user,
     sender)
 {
     Key = key;
     Reason = reason;
 }
Пример #10
0
        public SightingGroup(
            Group group,
            User createdByUser,
            DateTime createdDateTime)
            : base()
        {
            Check.RequireNotNull(group, "group");
            Check.RequireNotNull(createdByUser, "createdByUser");

            Group = group;
            User = createdByUser;
            CreatedDateTime = createdDateTime;
        }
Пример #11
0
        public ChatMessage(
            string id,
            User user,
            DateTime timestamp,
            string message)
        {
            Check.RequireNotNull(user, "user");

            Id = id;
            User = user;
            Timestamp = timestamp;
            Message = message;
        }
Пример #12
0
        public Vote(
            int id,
            User createdByUser,
            int score,
            DateTime createdOn)
            : base()
        {
            Check.RequireNotNull(createdByUser, "createdByUser");

            SequentialId = id;
            Id = id.ToString();
            User = createdByUser;
            CreatedOn = createdOn;
            Score = score;
        }
Пример #13
0
        public Member(
            User createdByUser,
            DateTime created,
            Group group,
            IEnumerable<Role> roles)
            : base()
        {
            Check.RequireNotNull(group, "group");
            Check.Require(roles != null && roles.ToList().Count > 0, "role collection must be not null and must contain at least one role items");

            InitMembers();

            Group = group;
            Roles = roles;
            Created = created;
        }
Пример #14
0
        public bool Save(MediaResourceCreateCommand command, User createdByUser, out string failureReason, out MediaResource mediaResource)
        {
            failureReason = string.Empty;
            mediaResource = null;

            if (!_documentSession.Load<AppRoot>(Constants.AppRootId).DocumentServiceStatus)
            {
                failureReason = "Word documents and PDF files cannot be uploaded at the moment. Please try again later.";
                return false;
            }

            bool returnValue;

            try
            {
                //var extension = Path.GetExtension(command.OriginalFileName) ?? string.Empty;

                //var acceptedFileTypes = new List<string>()
                //                      {
                //                          "doc",
                //                          "docx",
                //                          "pdf"
                //                      };

                //if (acceptedFileTypes.Any(x => x.Contains(extension)))
                //{
                //    MakeDocumentMediaResourceFiles(mediaResource, command);
                //}

                returnValue = true;
            }
            catch (Exception exception)
            {
                _logger.ErrorException("Error saving document", exception);

                failureReason = "The file is corrupted or not a valid Word or PDF document and could not be saved. Please check the file and try again.";
                returnValue = false;
            }

            return returnValue;
        }
Пример #15
0
        public UserProject(
            User createdByUser,
            string name,
            string description,
            string website,
            MediaResource avatar,
            MediaResource background,
            DateTime createdDateTime,
            Group parentGroup)
            : base(createdByUser,
            name,
            createdDateTime,
            parentGroup)
        {
            SetUserProjectDetails(
                description,
                website,
                avatar,
                background);

            ApplyEvent(new DomainModelCreatedEvent<UserProject>(this, createdByUser, this));
        }
        public object MakeUpdateSightingNote(Sighting sighting, User user, int sightingNoteId)
        {
            var sightingNote = sighting.Notes.Single(x => x.SequentialId == sightingNoteId);

            dynamic viewModel = new ExpandoObject();

            viewModel.Id = sightingNoteId;
            viewModel.SightingId = sighting.Id;
            viewModel.Descriptions = sightingNote.Descriptions.Select(x =>
                                                                      new
                                                                      {
                                                                          Key = x.Id,
                                                                          Value = x.Text,
                                                                          x.Description,
                                                                          x.Group,
                                                                          x.Label
                                                                      });
            viewModel.Tags = string.Join(", ", sightingNote.Tags);
            viewModel.NoteComments = sightingNote.Comments;

            return viewModel;
        }
        public MediaResource MakeBackgroundImage(
            string key,
            User createdByUser,
            DateTime createdOn,
            string originalFileName,
            ImageDimensions originalImageDimensions,
            string originalImageMimeType,
            List<ImageCreationTask> imageCreationTasks)
        {
            var mediaResource = new ImageMediaResource(Constants.MediaResourceTypes.Image, createdByUser, createdOn, key, null);
            _documentSession.Store(mediaResource);
            _documentSession.SaveChanges();

            mediaResource.Image.Original = MakeOriginalImageFile(originalImageMimeType, MakeUri(mediaResource, "Original", originalImageMimeType), originalImageDimensions.Width, originalImageDimensions.Height, null, originalFileName, null);
            mediaResource.Image.Small = MakeDerivedMediaResourceFile(MakeUri(mediaResource, "Small", Constants.ImageMimeTypes.Jpeg), ImageDimensions.MakeRectangle(512, 100).Width, ImageDimensions.MakeRectangle(512, 100).Height, imageCreationTasks, "Small", ImageResizeMode.Crop, Constants.ImageMimeTypes.Jpeg);
            mediaResource.Image.Large = MakeDerivedMediaResourceFile(MakeUri(mediaResource, "Large", Constants.ImageMimeTypes.Jpeg), ImageDimensions.MakeRectangle(1024, 200).Width, ImageDimensions.MakeRectangle(1024, 200).Height, imageCreationTasks, "Large", ImageResizeMode.Crop, Constants.ImageMimeTypes.Jpeg);

            _documentSession.Store(mediaResource);
            _documentSession.SaveChanges();

            return mediaResource;
        }
Пример #18
0
        public Species(
            string category,
            IEnumerable<string> commonGroupNames,
            IEnumerable<string> commonNames,
            string kingdomName,
            string phylumName,
            string className,
            string orderName,
            string familyName,
            string genusName,
            string speciesName,
            string subSpeciesName,
            string synonym,
            DateTime createdOn,
            User createdByUser)
            : base()
        {
            InitMembers();

            CreatedDateTime = createdOn;
            CreatedByUser = createdByUser;

            SetSpeciesDetails(
                category,
                commonGroupNames,
                commonNames,
                kingdomName,
                phylumName,
                className,
                orderName,
                familyName,
                genusName,
                speciesName,
                subSpeciesName,
                synonym);

            ApplyEvent(new DomainModelCreatedEvent<Species>(this, createdByUser, this));
        }
Пример #19
0
        public UserProject UpdateDetails(User updatedByUser, string name, string description, string website, MediaResource avatar, MediaResource background)
        {
            Check.RequireNotNull(updatedByUser, "updatedByUser");
            Check.RequireNotNullOrWhitespace(name, "name");
            Check.RequireNotNullOrWhitespace(name, "avatar");
            Check.RequireNotNullOrWhitespace(name, "background");

            SetGroupDetails(name);

            SetUserProjectDetails(
                description,
                website,
                avatar,
                background);

            ApplyEvent(new DomainModelUpdatedEvent<Group>(this, updatedByUser, this));

            return this;
        }
Пример #20
0
        public bool Save(MediaResourceCreateCommand command, User createdByUser, out string failureReason, out MediaResource mediaResource)
        {
            failureReason = string.Empty;
            mediaResource = null;

            if (!_documentSession.Load<AppRoot>(Constants.AppRootId).YouTubeVideoServiceStatus)
            {
                failureReason = "Youtube video files cannot be imported at the moment. Please try again later.";
                return false;
            }

            bool returnValue;

            try
            {
                string apiUri = string.Format(_apiUriFormat, command.VideoId);

                JObject data = GetVideoDataFromApi(apiUri);

                // Get thumbnail URI
                var mediaThumbnails = data["entry"]["media$group"]["media$thumbnail"];
                var mediaThumbnail = mediaThumbnails.Single(x => (string)x["yt$name"] == "hqdefault");
                var thumbnailUri = (string)mediaThumbnail["url"];

                var imageCreationTasks = new List<ImageCreationTask>();

                using (var stream = new MemoryStream(new WebClient().DownloadData(thumbnailUri)))
                {
                    var image = ImageUtility.Load(stream);

                    mediaResource = _mediaResourceFactory.MakeContributionExternalVideo(
                        command.Key,
                        createdByUser,
                        command.UploadedOn,
                        string.Format(_uriFormat, command.VideoId),
                        "youtube",
                        data,
                        command.VideoId,
                        ImageDimensions.MakeRectangle(1024, 576), // As at 08/2012, Youtube states that videos are encoded in 16:9 ratio. 1024x576px is the max size we present in Bowerbird at that ratio
                        thumbnailUri,
                        image.GetDimensions(),
                        MediaTypeUtility.GetStandardMimeTypeForMimeType(image.GetMimeType()),
                        GetVideoMetadata(data, command.VideoId),
                        imageCreationTasks);

                    image.Save(mediaResource, imageCreationTasks, _mediaFilePathFactory);

                    image.Cleanup();
                }

                returnValue = true;
            }
            catch (Exception exception)
            {
                _logger.ErrorException("Error saving video", exception);

                failureReason = "The video cannot be retrieved from Youtube. Please check the video and try again.";
                returnValue = false;
            }

            return returnValue;
        }
Пример #21
0
        public Observation UpdateDetails(
            User updatedByUser,
            DateTime updatedOn,
            string title,
            DateTime observedOn,
            string latitude,
            string longitude,
            string address,
            bool anonymiseLocation,
            string category,
            IEnumerable<Project> projects,
            IEnumerable<Tuple<MediaResource, string, string, bool>> media)
        {
            Check.RequireNotNull(updatedByUser, "updatedByUser");

            SetSightingDetails(
                updatedByUser,
                updatedOn,
                observedOn,
                latitude,
                longitude,
                anonymiseLocation,
                category,
                projects);

            SetObservationDetails(
                title,
                address,
                media);

            ApplyEvent(new DomainModelUpdatedEvent<Observation>(this, updatedByUser, this));

            return this;
        }
Пример #22
0
        private MediaResource MakeContributionImage(User createdByUser, ImageUtility image, List<ImageCreationTask> imageCreationTasks, MediaResourceCreateCommand command)
        {
            IDictionary<string, object> exifData = image.GetExifData();
            ImageDimensions imageDimensions = image.GetDimensions();

            var metadata = new Dictionary<string, string>();

            if (exifData.Count > 0)
            {
                metadata = GetImageExifMetadata(exifData, createdByUser.Timezone);
            }

            return _mediaResourceFactory.MakeContributionImage(
                command.Key,
                createdByUser,
                command.UploadedOn,
                command.FileName,
                imageDimensions,
                command.FileStream.Length,
                exifData,
                image.GetMimeType(),
                metadata,
                imageCreationTasks);
        }
Пример #23
0
        private MediaResource MakeBackgroundImage(User createdByUser, ImageUtility image, List<ImageCreationTask> imageCreationTasks, MediaResourceCreateCommand command)
        {
            ImageDimensions imageDimensions = image.GetDimensions();

            return _mediaResourceFactory.MakeBackgroundImage(
                command.Key,
                createdByUser,
                command.UploadedOn,
                command.FileName,
                imageDimensions,
                image.GetMimeType(),
                imageCreationTasks);
        }
Пример #24
0
        public void UpdateDetails(
            string category,
            IEnumerable<string> commonGroupNames,
            IEnumerable<string> commonNames,
            string kingdomName,
            string phylumName,
            string className,
            string orderName,
            string familyName,
            string genusName,
            string speciesName,
            string subSpeciesName,
            string synonym,
            User updatedByUser
            )
        {
            SetSpeciesDetails(
                category,
                commonGroupNames,
                commonNames,
                kingdomName,
                phylumName,
                className,
                orderName,
                familyName,
                genusName,
                speciesName,
                subSpeciesName,
                synonym);

            ApplyEvent(new DomainModelUpdatedEvent<Species>(this, updatedByUser, this));
        }
        public MediaResource MakeContributionExternalVideo(
            string key,
            User createdByUser,
            DateTime createdOn,
            string uri,
            string provider,
            object providerData,
            string videoId,
            ImageDimensions originalVideoDimensions,
            string originalThumbnailUri,
            ImageDimensions originalThumbnailDimensions,
            string originalThumbnailMimeType,
            Dictionary<string, string> metadata,
            List<ImageCreationTask> imageCreationTasks)
        {
            var mediaResource = new VideoMediaResource(Constants.MediaResourceTypes.Video, createdByUser, createdOn, key, metadata);
            _documentSession.Store(mediaResource);
            _documentSession.SaveChanges();

            var constrained240Dimensions = originalVideoDimensions.ResizeWithTargetDimensions(320, 240);
            var constrained480Dimensions = originalVideoDimensions.ResizeWithTargetDimensions(640, 480);
            var constrained600Dimensions = originalVideoDimensions.ResizeWithTargetDimensions(800, 600);
            var full640Dimensions = originalVideoDimensions.ResizeWithTargetDimensions(640, 640);
            var full800Dimensions = originalVideoDimensions.ResizeWithTargetDimensions(800, 800);
            var full1024Dimensions = originalVideoDimensions.ResizeWithTargetDimensions(1024, 1024);

            mediaResource.Video.Original = MakeOriginalVideoFile(provider, videoId, providerData, originalVideoDimensions.Width, originalVideoDimensions.Height, uri);
            mediaResource.Video.OriginalImage = MakeOriginalImageFile(originalThumbnailMimeType, originalThumbnailUri, originalThumbnailDimensions.Width, originalThumbnailDimensions.Height, null, null, null);
            mediaResource.Video.Square50 = MakeDerivedMediaResourceFile(MakeUri(mediaResource, "Square50", Constants.ImageMimeTypes.Jpeg), ImageDimensions.MakeSquare(100).Width, ImageDimensions.MakeSquare(100).Height, imageCreationTasks, "Square50", ImageResizeMode.Crop, Constants.ImageMimeTypes.Jpeg);
            mediaResource.Video.Square100 = MakeDerivedMediaResourceFile(MakeUri(mediaResource, "Square100", Constants.ImageMimeTypes.Jpeg), ImageDimensions.MakeSquare(200).Width, ImageDimensions.MakeSquare(200).Height, imageCreationTasks, "Square100", ImageResizeMode.Crop, Constants.ImageMimeTypes.Jpeg);
            mediaResource.Video.Square200 = MakeDerivedMediaResourceFile(MakeUri(mediaResource, "Square200", Constants.ImageMimeTypes.Jpeg), ImageDimensions.MakeSquare(400).Width, ImageDimensions.MakeSquare(400).Height, imageCreationTasks, "Square200", ImageResizeMode.Crop, Constants.ImageMimeTypes.Jpeg);
            mediaResource.Video.Constrained240 = MakeDerivedMediaResourceFile(uri, constrained240Dimensions.Width, constrained240Dimensions.Height, imageCreationTasks, "Constrained240", ImageResizeMode.Crop, Constants.ImageMimeTypes.Jpeg);
            mediaResource.Video.Constrained480 = MakeDerivedMediaResourceFile(uri, constrained480Dimensions.Width, constrained480Dimensions.Height, imageCreationTasks, "Constrained480", ImageResizeMode.Crop, Constants.ImageMimeTypes.Jpeg);
            mediaResource.Video.Constrained600 = MakeDerivedMediaResourceFile(uri, constrained600Dimensions.Width, constrained600Dimensions.Height, imageCreationTasks, "Constrained600", ImageResizeMode.Crop, Constants.ImageMimeTypes.Jpeg);
            mediaResource.Video.Full640 = MakeDerivedMediaResourceFile(uri, full640Dimensions.Width, full640Dimensions.Height, imageCreationTasks, "Full640", ImageResizeMode.Normal, Constants.ImageMimeTypes.Jpeg);
            mediaResource.Video.Full800 = MakeDerivedMediaResourceFile(uri, full800Dimensions.Width, full800Dimensions.Height, imageCreationTasks, "Full800", ImageResizeMode.Normal, Constants.ImageMimeTypes.Jpeg);
            mediaResource.Video.Full1024 = MakeDerivedMediaResourceFile(uri, full1024Dimensions.Width, full1024Dimensions.Height, imageCreationTasks, "Full1024", ImageResizeMode.Normal, Constants.ImageMimeTypes.Jpeg);

            _documentSession.Store(mediaResource);
            _documentSession.SaveChanges();

            return mediaResource;
        }
        public MediaResource MakeContributionAudio(
            string key,
            User createdByUser,
            DateTime createdOn,
            string originalFileName,
            object id3Data,
            string standardMimeType,
            Dictionary<string, string> metadata)
        {
            var mediaResource = new AudioMediaResource(Constants.MediaResourceTypes.Audio, createdByUser, createdOn, key, metadata);
            _documentSession.Store(mediaResource);
            _documentSession.SaveChanges();

            var avatarUri = @"/img/audio-avatar.png";
            var audioFileUri = _mediaFilePathFactory.MakeRelativeMediaFileUri(mediaResource.Id, "Original", MediaTypeUtility.GetStandardExtensionForMimeType(standardMimeType));

            mediaResource.Audio.Original = MakeOriginalAudioFile(standardMimeType);
            mediaResource.Audio.Square50 = MakeDerivedMediaResourceFile(avatarUri, ImageDimensions.MakeSquare(100).Width, ImageDimensions.MakeSquare(100).Height);
            mediaResource.Audio.Square100 = MakeDerivedMediaResourceFile(avatarUri, ImageDimensions.MakeSquare(200).Width, ImageDimensions.MakeSquare(200).Height);
            mediaResource.Audio.Square200 = MakeDerivedMediaResourceFile(avatarUri, ImageDimensions.MakeSquare(400).Width, ImageDimensions.MakeSquare(400).Height);
            mediaResource.Audio.Constrained240 = MakeDerivedMediaResourceFile(audioFileUri, 100, 100);
            mediaResource.Audio.Constrained480 = MakeDerivedMediaResourceFile(audioFileUri, 200, 200);
            mediaResource.Audio.Constrained600 = MakeDerivedMediaResourceFile(audioFileUri, 400, 400);
            mediaResource.Audio.Full640 = MakeDerivedMediaResourceFile(audioFileUri, 640, 480);
            mediaResource.Audio.Full800 = MakeDerivedMediaResourceFile(audioFileUri, 800, 600);
            mediaResource.Audio.Full1024 = MakeDerivedMediaResourceFile(audioFileUri, 1024, 768);

            return mediaResource;
        }
Пример #27
0
        public Organisation UpdateDetails(User updatedByUser, string name, string description, string website,
            MediaResource avatar, MediaResource background, IEnumerable<string> categories)
        {
            Check.RequireNotNull(updatedByUser, "updatedByUser");
            Check.RequireNotNullOrWhitespace(name, "name");
            Check.RequireNotNull(categories != null, "categories");

            SetGroupDetails(name);

            SetOrganisationDetails(
                description,
                website,
                avatar,
                background,
                categories);

            ApplyEvent(new DomainModelUpdatedEvent<Organisation>(this, updatedByUser, this));

            return this;
        }
Пример #28
0
        public bool Save(MediaResourceCreateCommand command, User createdByUser, out string failureReason, out MediaResource mediaResource)
        {
            failureReason = string.Empty;
            mediaResource = null;

            if (!_documentSession.Load<AppRoot>(Constants.AppRootId).ImageServiceStatus)
            {
                failureReason = "Image files cannot be uploaded at the moment. Please try again later.";
                return false;
            }

            ImageUtility image = null;
            bool returnValue;

            try
            {
                var imageCreationTasks = new List<ImageCreationTask>();

                image = ImageUtility.Load(command.FileStream);

                if (command.Usage == "contribution")
                {
                    mediaResource = MakeContributionImage(
                        createdByUser,
                        image,
                        imageCreationTasks,
                        command);
                }
                else if (command.Usage == "avatar")
                {
                    mediaResource = MakeAvatarImage(
                        createdByUser,
                        image,
                        imageCreationTasks,
                        command);
                }
                else if (command.Usage == "background")
                {
                    mediaResource = MakeBackgroundImage(
                        createdByUser,
                        image,
                        imageCreationTasks,
                        command);
                }
                else
                {
                    throw new ArgumentException("The specified usage '" + command.Usage + "' is not recognised.");
                }

                image.Save(mediaResource, imageCreationTasks, _mediaFilePathFactory);

                returnValue = true;
            }
            catch (Exception exception)
            {
                _logger.ErrorException("Error saving images", exception);

                failureReason = "The file is corrupted or not a valid JPEG and could not be saved. Please check the file and try again.";
                returnValue = false;
            }
            finally
            {
                if (image != null)
                {
                    image.Cleanup();
                }
            }

            return returnValue;
        }
Пример #29
0
        public User UpdateMembership(User modifiedByUser, Group group, IEnumerable<Role> roles)
        {
            Check.RequireNotNull(group, "group");
            Check.RequireNotNull(roles, "roles");

            // FInd if user is a member yet
            var member = _memberships.FirstOrDefault(x => x.Group.Id == group.Id);

            if (member != null)
            {
                member.UpdateRoles(roles);

                ApplyEvent(new MemberUpdatedEvent(member, modifiedByUser, this, group));
            }
            else
            {
                member = new Member(modifiedByUser, DateTime.UtcNow, group, roles);
                _memberships.Add(member);

                ApplyEvent(new MemberCreatedEvent(member, modifiedByUser, this, group));
            }

            return this;
        }
        public MediaResource MakeContributionImage(
            string key,
            User createdByUser,
            DateTime createdOn,
            string originalFileName,
            ImageDimensions originalImageDimensions,
            long originalSize,
            IDictionary<string, object> originalExifData,
            string originalImageMimeType,
            Dictionary<string, string> metadata,
            List<ImageCreationTask> imageCreationTasks)
        {
            var mediaResource = new ImageMediaResource(Constants.MediaResourceTypes.Image, createdByUser, createdOn, key, metadata);
            _documentSession.Store(mediaResource);
            _documentSession.SaveChanges();

            mediaResource.Image.Original = MakeOriginalImageFile(originalImageMimeType, MakeUri(mediaResource, "Original", originalImageMimeType), originalImageDimensions.Width, originalImageDimensions.Height, originalExifData, originalFileName, originalSize);
            mediaResource.Image.Square50 = MakeDerivedMediaResourceFile(MakeUri(mediaResource, "Square50", Constants.ImageMimeTypes.Jpeg), ImageDimensions.MakeSquare(100).Width, ImageDimensions.MakeSquare(100).Height, imageCreationTasks, "Square50", ImageResizeMode.Crop, Constants.ImageMimeTypes.Jpeg);
            mediaResource.Image.Square100 = MakeDerivedMediaResourceFile(MakeUri(mediaResource, "Square100", Constants.ImageMimeTypes.Jpeg), ImageDimensions.MakeSquare(200).Width, ImageDimensions.MakeSquare(200).Height, imageCreationTasks, "Square100", ImageResizeMode.Crop, Constants.ImageMimeTypes.Jpeg);
            mediaResource.Image.Square200 = MakeDerivedMediaResourceFile(MakeUri(mediaResource, "Square200", Constants.ImageMimeTypes.Jpeg), ImageDimensions.MakeSquare(400).Width, ImageDimensions.MakeSquare(400).Height, imageCreationTasks, "Square200", ImageResizeMode.Crop, Constants.ImageMimeTypes.Jpeg);
            mediaResource.Image.Constrained240 = MakeDerivedMediaResourceFile(MakeUri(mediaResource, "Constrained240", Constants.ImageMimeTypes.Jpeg), ImageDimensions.MakeRectangle(320, 240).Width, ImageDimensions.MakeRectangle(320, 240).Height, imageCreationTasks, "Constrained240", ImageResizeMode.Crop, Constants.ImageMimeTypes.Jpeg);
            mediaResource.Image.Constrained480 = MakeDerivedMediaResourceFile(MakeUri(mediaResource, "Constrained480", Constants.ImageMimeTypes.Jpeg), ImageDimensions.MakeRectangle(640, 480).Width, ImageDimensions.MakeRectangle(640, 480).Height, imageCreationTasks, "Constrained480", ImageResizeMode.Crop, Constants.ImageMimeTypes.Jpeg);
            mediaResource.Image.Constrained600 = MakeDerivedMediaResourceFile(MakeUri(mediaResource, "Constrained600", Constants.ImageMimeTypes.Jpeg), ImageDimensions.MakeRectangle(800, 600).Width, ImageDimensions.MakeRectangle(800, 600).Height, imageCreationTasks, "Constrained600", ImageResizeMode.Crop, Constants.ImageMimeTypes.Jpeg);
            mediaResource.Image.Full640 = MakeDerivedMediaResourceFile(MakeUri(mediaResource, "Full640", Constants.ImageMimeTypes.Jpeg), originalImageDimensions.ResizeWithTargetDimensions(640, 640).Width, originalImageDimensions.ResizeWithTargetDimensions(640, 640).Height, imageCreationTasks, "Full640", ImageResizeMode.Normal, Constants.ImageMimeTypes.Jpeg);
            mediaResource.Image.Full800 = MakeDerivedMediaResourceFile(MakeUri(mediaResource, "Full800", Constants.ImageMimeTypes.Jpeg), originalImageDimensions.ResizeWithTargetDimensions(800, 800).Width, originalImageDimensions.ResizeWithTargetDimensions(800, 800).Height, imageCreationTasks, "Full800", ImageResizeMode.Normal, Constants.ImageMimeTypes.Jpeg);
            mediaResource.Image.Full1024 = MakeDerivedMediaResourceFile(MakeUri(mediaResource, "Full1024", Constants.ImageMimeTypes.Jpeg), originalImageDimensions.ResizeWithTargetDimensions(1024, 1024).Width, originalImageDimensions.ResizeWithTargetDimensions(1024, 1024).Height, imageCreationTasks, "Full1024", ImageResizeMode.Normal, Constants.ImageMimeTypes.Jpeg);

            _documentSession.Store(mediaResource);
            _documentSession.SaveChanges();

            return mediaResource;
        }