Esempio n. 1
0
        /// <summary>
        /// <para>Preconditions: The associated <see cref="DiscordInterfacer"/> is in a Connected state</para>
        /// </summary>
        public async Task Execute(TagCommandParameters Command)
        {
            Log.Application_.LogVerbose(
                "Processing Tag command for {2} '{0}', Tagged to Taglist '{1}'",
                Command.ItemID, Command.TaglistName,
                Command.isItemAlbum ? "Album" : "Image"
                );
            Task <GalleryItem> TaggedItemTask;

            if (!Command.isItemAlbum)
            {
                TaggedItemTask = Imgur.ReadGalleryImage(Command.ItemID);
            }
            else
            {
                TaggedItemTask = Imgur.ReadGalleryAlbum(Command.ItemID);
            }
            Task <Taglist> LoadTaglistTask = RepositoryTaglists.Load(Command.TaglistName);
            Taglist        SpecifiedTaglist;

            try{
                SpecifiedTaglist = await LoadTaglistTask;
                //Any exceptions from TaggedItemTask will go unobserved if an exception is thrown in this try block
            }catch (EntityNotFoundException) {
                Log.Application_.LogWarning(
                    "The Taglist named '{0}' does not exist, which was specified by a Tag command on the Imgur Gallery Item with ID '{1}' (Comment ID {2:D})",
                    Command.TaglistName, Command.ItemID, Command.HostCommentID
                    );
                return;
            }catch (DataAccessException Error) {
                Log.Application_.LogError(
                    "Error loading Taglist '{1}' while processing Tag command on the Imgur Gallery Item with ID '{0}'; processing of command aborted: {2}",
                    Command.ItemID, Command.TaglistName, Error.Message
                    );
                return;
            }
            GalleryItem TaggedItem;

            try{
                TaggedItem = await TaggedItemTask;
                //Any exceptions from MentionUsersTask will go unobserved if an exception is thrown in this try block
            }catch (ImgurException Error) {
                Log.Application_.LogError("Error acquiring details for Tagged Imgur Gallery Item with ID '{0}'; unable to process Tag command for that item: {1}", Command.ItemID, Error.Message);
                return;
            }
            await Task.WhenAll(
                //Long-running operation, due to delay needed between Imgur Comments
                MentionInterestedUsers(Command, SpecifiedTaglist),
                ArchiveTaggedItem(Command, TaggedItem, SpecifiedTaglist)
                );

            Log.Application_.LogVerbose(
                "Completed processing of Tag command for {2} '{0}' to Taglist '{1}'",
                Command.ItemID, Command.TaglistName,
                Command.isItemAlbum ? "Album" : "Image"
                );
            await Imgur.LogRemainingBandwidth(TraceEventType.Verbose);
        }