Esempio n. 1
0
        // subscribed to Begin event because a new form should be created+processed+closed on each iteration
        private static void wireUpEvents(IDecryptable decryptBook)
        {
            #region create form
            var decryptDialog = new DecryptForm();
            #endregion

            #region define how model actions will affect form behavior
            void decryptBegin(object _, string __) => decryptDialog.Show();

            void titleDiscovered(object _, string title) => decryptDialog.SetTitle(title);
            void authorsDiscovered(object _, string authors) => decryptDialog.SetAuthorNames(authors);
            void narratorsDiscovered(object _, string narrators) => decryptDialog.SetNarratorNames(narrators);
            void coverImageFilepathDiscovered(object _, byte[] coverBytes) => decryptDialog.SetCoverImage(coverBytes);
            void updateProgress(object _, int percentage) => decryptDialog.UpdateProgress(percentage);

            void decryptCompleted(object _, string __) => decryptDialog.Close();

            #endregion

            #region subscribe new form to model's events
            decryptBook.DecryptBegin += decryptBegin;

            decryptBook.TitleDiscovered              += titleDiscovered;
            decryptBook.AuthorsDiscovered            += authorsDiscovered;
            decryptBook.NarratorsDiscovered          += narratorsDiscovered;
            decryptBook.CoverImageFilepathDiscovered += coverImageFilepathDiscovered;
            decryptBook.UpdateProgress += updateProgress;

            decryptBook.DecryptCompleted += decryptCompleted;
            #endregion

            #region when form closes, unsubscribe from model's events
            // unsubscribe so disposed forms aren't still trying to receive notifications
            decryptDialog.FormClosing += (_, __) =>
            {
                decryptBook.DecryptBegin -= decryptBegin;

                decryptBook.TitleDiscovered              -= titleDiscovered;
                decryptBook.AuthorsDiscovered            -= authorsDiscovered;
                decryptBook.NarratorsDiscovered          -= narratorsDiscovered;
                decryptBook.CoverImageFilepathDiscovered -= coverImageFilepathDiscovered;
                decryptBook.UpdateProgress -= updateProgress;

                decryptBook.DecryptCompleted -= decryptCompleted;
            };
            #endregion
        }
 public string GetDecryptedString(IDecryptable decryptLogic)
 {
     return(decryptLogic.GetDecryptedString());
 }