public void Add(IImageCommand command, string groupName)
		{
			if (InvokeRequired)
			{
				MethodInvoker action = () => Add(command, groupName);
				BeginInvoke(action);
				return;
			}

			if (command == null || _commands.Contains(command))
			{
				// Do nothing if the command has already been added.
				// Note that this prevents using the same command twice in different groups.
				return;
			}

			command.PropertyChanged += CommandPropertyChanged;

			ListViewItem item = new ListViewItem {Tag = command};
			Update(item);

			if (!string.IsNullOrEmpty(groupName))
			{
				ListViewGroup group = FindOrCreateGroup(groupName);
				item.Group = group;
			}
			listView.Items.Add(item);
		}
Beispiel #2
0
 public GroupFilesPipe(ILocalizationService localizationService, ILoggingService loggingService, IImageService imageService,
                       IImageCommand imageCommand, IImageRepository imageRepository)
 {
     _localizationService = localizationService ?? throw new ArgumentNullException(nameof(localizationService));
     _loggingService      = loggingService ?? throw new ArgumentNullException(nameof(loggingService));
     _imageService        = imageService ?? throw new ArgumentNullException(nameof(imageService));
     _imageCommand        = imageCommand ?? throw new ArgumentNullException(nameof(imageCommand));
     _imageRepository     = imageRepository ?? throw new ArgumentNullException(nameof(imageRepository));
 }
Beispiel #3
0
 public UserEditPipe(IMembershipService membershipService, ILocalizationService localizationService,
                     IActivityService activityService, ILoggingService loggingService, IImageService imageService,
                     IImageCommand imageCommand, IImageRepository imageRepository)
 {
     _membershipService   = membershipService;
     _localizationService = localizationService;
     _activityService     = activityService;
     _loggingService      = loggingService;
     _imageService        = imageService ?? throw new ArgumentNullException(nameof(imageService));
     _imageCommand        = imageCommand ?? throw new ArgumentNullException(nameof(imageCommand));
     _imageRepository     = imageRepository ?? throw new ArgumentNullException(nameof(imageRepository));
 }
Beispiel #4
0
        public async Task ExecuteAsync(CommandContext ctx, int argPos, IImageCommand command)
        {
            (bool success, string image) = await command.GetImageUrlAsync();

            if (!success)
            {
                throw new CommandExecutionException(command);
            }

            using (ctx.Channel.EnterTypingState())
            {
                var embed = new EmbedBuilder().WithImageUrl(image).Build();
                await ctx.Channel.SendMessageAsync(string.Empty, embed : embed);
            }
        }
		public void Remove(IImageCommand command)
		{
			if (InvokeRequired)
			{
				MethodInvoker action = () => Remove(command);
				BeginInvoke(action);
				return;
			}

			ListViewItem item = FindByCommand(command);
			if (item != null)
			{
				command.PropertyChanged -= CommandPropertyChanged;
				listView.Items.Remove(item);
			}
		}
Beispiel #6
0
 public UserCreatePipe(IMembershipService membershipService, ILoggingService loggingService,
                       ISettingsService settingsService, ILocalizationService localizationService, IEmailService emailService,
                       IActivityService activityService, IGroupInviteService groupInviteService, IGroupService groupService,
                       IImageService imageService, IImageCommand imageCommand, IImageRepository imageRepository)
 {
     _membershipService   = membershipService;
     _loggingService      = loggingService;
     _settingsService     = settingsService;
     _localizationService = localizationService;
     _emailService        = emailService;
     _activityService     = activityService;
     _groupInviteService  = groupInviteService;
     _groupService        = groupService;
     _imageService        = imageService ?? throw new ArgumentNullException(nameof(imageService));
     _imageCommand        = imageCommand ?? throw new ArgumentNullException(nameof(imageCommand));
     _imageRepository     = imageRepository ?? throw new ArgumentNullException(nameof(imageRepository));
 }
Beispiel #7
0
 /// <summary>
 ///     Constructor
 /// </summary>
 /// <param name="context"></param>
 /// <param name="roleService"> </param>
 /// <param name="notificationService"> </param>
 /// <param name="GroupPermissionForRoleService"></param>
 /// <param name="cacheService"></param>
 public GroupService(IMvcForumContext context, IRoleService roleService,
                     INotificationService notificationService, IGroupPermissionForRoleService GroupPermissionForRoleService,
                     ICacheService cacheService, IGroupRepository groupRepository, ILocalizationService localizationService,
                     IGroupCommand groupCommand, IImageService imageService, IImageCommand imageCommand,
                     IImageRepository imageRepository)
 {
     _context                       = context ?? throw new ArgumentNullException(nameof(context));
     _roleService                   = roleService ?? throw new ArgumentNullException(nameof(roleService));
     _notificationService           = notificationService ?? throw new ArgumentNullException(nameof(notificationService));
     _groupPermissionForRoleService = GroupPermissionForRoleService ?? throw new ArgumentNullException(nameof(GroupPermissionForRoleService));
     _cacheService                  = cacheService ?? throw new ArgumentNullException(nameof(context));
     _groupRepository               = groupRepository ?? throw new ArgumentNullException(nameof(groupRepository));
     _localizationService           = localizationService ?? throw new ArgumentNullException(nameof(localizationService));
     _groupCommand                  = groupCommand ?? throw new ArgumentNullException(nameof(groupCommand));
     _imageService                  = imageService ?? throw new ArgumentNullException(nameof(imageService));
     _imageCommand                  = imageCommand ?? throw new ArgumentNullException(nameof(imageCommand));
     _imageRepository               = imageRepository ?? throw new ArgumentNullException(nameof(imageRepository));
 }
 /// <summary>
 ///     Constructor
 /// </summary>
 /// <param name="loggingService"> </param>
 /// <param name="membershipService"></param>
 /// <param name="localizationService"></param>
 /// <param name="roleService"></param>
 /// <param name="GroupService"></param>
 /// <param name="settingsService"> </param>
 /// <param name="topicService"> </param>
 /// <param name="cacheService"></param>
 /// <param name="postService"></param>
 /// <param name="pollService"></param>
 /// <param name="voteService"></param>
 /// <param name="favouriteService"></param>
 /// <param name="context"></param>
 /// <param name="notificationService"></param>
 public GroupController(ILoggingService loggingService, IMembershipService membershipService,
                        ILocalizationService localizationService, IRoleService roleService, IGroupService GroupService,
                        ISettingsService settingsService, ITopicService topicService,
                        ICacheService cacheService,
                        IPostService postService,
                        IPollService pollService, IVoteService voteService, IFavouriteService favouriteService,
                        IMvcForumContext context, INotificationService notificationService, IFeatureManager featureManager,
                        IImageCommand imageCommand)
     : base(loggingService, membershipService, localizationService, roleService,
            settingsService, cacheService, context)
 {
     _groupService        = GroupService;
     _topicService        = topicService;
     _pollAnswerService   = pollService;
     _voteService         = voteService;
     _favouriteService    = favouriteService;
     _notificationService = notificationService;
     _postService         = postService;
     _roleService         = roleService;
     _featureManager      = featureManager;
     _localizationService = localizationService;
     LoggedOnReadOnlyUser = membershipService.GetUser(System.Web.HttpContext.Current.User.Identity.Name, true);
     _imageCommand        = imageCommand ?? throw new ArgumentNullException(nameof(imageCommand));
 }
        /// <summary>
        ///     Uploads a file from a posted file
        /// </summary>
        /// <param name="file"></param>
        /// <param name="uploadFolderPath"></param>
        /// <param name="localizationService"></param>
        /// <param name="onlyImages"></param>
        /// <returns></returns>
        public static UploadFileResult UploadFile(this HttpPostedFileBase file, string uploadFolderPath,
                                                  ILocalizationService localizationService, IImageCommand imageCommand = null, IImageRepository imageRepository = null, IImageService imageService = null,
                                                  bool isAvatar = false, Guid imageSaveId = default(Guid))
        {
            var extension = Path.GetExtension(file.FileName);
            var fileName  = $"{Guid.NewGuid()}{extension}";
            var upResult  = new UploadFileResult {
                UploadSuccessful = true
            };
            var storageProvider = StorageProvider.Current;

            var fileOkResult = file.CanBeUploaded(localizationService);

            if (fileOkResult.IsOk)
            {
                if (!Directory.Exists(uploadFolderPath))
                {
                    Directory.CreateDirectory(uploadFolderPath);
                }

                var fileExtension = fileOkResult.FileExtension;

                // Store these here as we may change the values within the image manipulation
                string newFileName = string.Empty;

                // See if this is an image, if so then do some extra checks
                if (fileOkResult.IsImage)
                {
                    var sourceimage = file.ToImage();

                    if (!(imageService is null) && !(imageRepository is null))
                    {
                        var newFileId = imageSaveId != default(Guid) ? imageSaveId : Guid.NewGuid();
                        newFileName = $"{newFileId}.webp";

                        var transformedImage = isAvatar ? imageService.TransformImageForAvatar(new Bitmap(sourceimage)) :
                                               imageService.TransformImageForGroupHeader(new Bitmap(sourceimage));

                        var imageStream = new MemoryStream();
                        imageStream.Write(transformedImage.Bytes, 0, transformedImage.Bytes.Length);
                        upResult.UploadedFileUrl = storageProvider.SaveAs(uploadFolderPath, newFileName, imageStream);

                        var imageVM = new ImageViewModel(upResult.UploadedFileName, "user avatar")
                        {
                            FileName      = newFileName,
                            FileSizeBytes = Convert.ToInt32(file.ContentLength),
                            Height        = transformedImage.Height,
                            Width         = transformedImage.Width,
                            MediaType     = transformedImage.MediaType
                        };

                        if (isAvatar)
                        {
                            var membershipUserImageId = imageRepository.GetMembershipUserImageId(imageSaveId);
                            if (!(membershipUserImageId is null))
                            {
                                imageVM.Id = (Guid)membershipUserImageId;
                                _          = imageCommand.Update(imageVM);
                            }
                            else
                            {
                                var imageId = imageCommand.Create(imageVM);
                                _ = imageCommand.UpdateMembershipUserImageId(imageSaveId, imageId, newFileName);
                            }
                        }
                        else
                        {
                            var groupImageId = imageRepository.GetGroupImageId(imageSaveId);
                            if (!(groupImageId is null))
                            {
                                imageVM.Id = (Guid)groupImageId;
                                _          = imageCommand.Update(imageVM);
                            }
                            else
                            {
                                var imageId = imageCommand.Create(imageVM);
                                _ = imageCommand.UpdateGroupImageId(imageSaveId, imageId, newFileName);
                            }
                        }
		private ListViewItem FindByCommand(IImageCommand command)
		{
			foreach (ListViewItem item in listView.Items)
			{
				IImageCommand itemCommand = item.Tag as IImageCommand;
				if (itemCommand == command)
				{
					return item;
				}
			}

			return null;
		}
Beispiel #11
0
 public ImageService(IImageCommand imageCommand, ILogger <ImageService> logger)
 {
     _imageCommand = imageCommand;
     _logger       = logger;
 }