Beispiel #1
0
        public void Reconfigure(IEnumerable <string> nextProposers)
        {
            var message = "Next Proposers " + string.Join(", ", nextProposers);

            Events.Add(Tuple.Create(DateTimeOffset.Now, message));
            Trace.WriteLine(message);
            var proposal = new ProposalConfiguration <string>(new Configuration <string>(nextProposers, nextProposers, _paxos.ConfigurationHint.Learners));
            var task     = this.WaitAsync(proposal, CancellationToken.None);
            var t        = this.ReplicateAsync(proposal, CancellationToken.None);

            task.ContinueWith(a =>
            {
                if (a.Status == TaskStatus.RanToCompletion)
                {
                    Events.Add(Tuple.Create(DateTimeOffset.Now, "Reconfiguration successful"));
                    Trace.WriteLine("Reconfigure Succeeded");
                }
                else
                {
                    Events.Add(Tuple.Create(DateTimeOffset.Now, "Reconfiguration failed"));
                    Trace.WriteLine(Tuple.Create(a.Status, a.Exception));
                }
            });
        }
        /// <summary>
        /// Obtains a Proxied URL from a given Image URL.
        /// </summary>
        /// <param name="ImageURL">The URL of the target image.</param>
        /// <param name="ImageName">The Name to give the image once downloaded.</param>
        /// <param name="DiscordSocketClient">A Discord Socket Client service to parse the storage channel.</param>
        /// <param name="ProposalConfiguration">Configuration holding the storage channel ID.</param>
        /// <returns>A <c>Task</c> object, which can be awaited until this method completes successfully.</returns>

        public static async Task <string> GetProxiedImage(this string ImageURL, string ImageName, DiscordSocketClient DiscordSocketClient, ProposalConfiguration ProposalConfiguration)
        {
            string ImageCacheDir = Path.Combine(Directory.GetCurrentDirectory(), "ImageCache");

            if (!Directory.Exists(ImageCacheDir))
            {
                Directory.CreateDirectory(ImageCacheDir);
            }

            string FilePath = Path.Combine(ImageCacheDir, $"{ImageName}{Path.GetExtension(ImageURL.Split("?")[0])}");

            using WebClient WebClient = new();

            await WebClient.DownloadFileTaskAsync(ImageURL, FilePath);

            ITextChannel Channel = DiscordSocketClient.GetChannel(ProposalConfiguration.StorageChannelID) as ITextChannel;

            IUserMessage AttachmentMSG = await Channel.SendFileAsync(FilePath);

            File.Delete(FilePath);

            return(AttachmentMSG.Attachments.FirstOrDefault().ProxyUrl);
        }