Changeset 626


Ignore:
Timestamp:
Oct 2, 2009, 11:48:49 AM (12 years ago)
Author:
Matthäus Wander
Message:

Caesar:

  • changeable settings during execution, closes #88
Location:
trunk/CrypPlugins/Caesar
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/CrypPlugins/Caesar/Caesar.cs

    r575 r626  
    1515*/
    1616
    17 using System;
    1817using System.Collections.Generic;
    19 using System.Linq;
    2018using System.Text;
    2119using Cryptool.PluginBase;
    2220using Cryptool.PluginBase.Cryptography;
    2321
    24 using System.IO;
    2522using System.ComponentModel;
    2623using Cryptool.PluginBase.IO;
    2724using System.Windows.Controls;
    28 using System.Runtime.CompilerServices;
    2925using Cryptool.PluginBase.Miscellaneous;
    30 using Cryptool.PluginBase.Control;
    3126
    3227namespace Cryptool.Caesar
     
    4641        private enum CaesarMode { encrypt, decrypt };
    4742        private List<CryptoolStream> listCryptoolStreamsOut = new List<CryptoolStream>();
     43        private bool isPlayMode = false;
    4844        #endregion
    4945       
     
    5652        {
    5753            this.settings = new CaesarSettings();
    58             ((CaesarSettings)(this.settings)).LogMessage += Caesar_LogMessage;
     54            this.settings.LogMessage += Caesar_LogMessage;
     55            this.settings.ReExecute += Caesar_ReExecute;
    5956        }
    6057 
     
    7875                    CryptoolStream cs = new CryptoolStream();
    7976                    listCryptoolStreamsOut.Add(cs);
    80                     cs.OpenRead(this.GetPluginInfoAttribute().Caption, Encoding.Default.GetBytes(outputString.ToCharArray()));
     77                    cs.OpenRead(Encoding.Default.GetBytes(outputString.ToCharArray()));
    8178                    return cs;
    8279                }
     
    214211        public void PostExecution()
    215212        {
     213            isPlayMode = false;
    216214            Dispose();
    217215        }
     
    347345        }
    348346
     347        /// <summary>
     348        /// Handles re-execution events from settings class
     349        /// </summary>
     350        private void Caesar_ReExecute()
     351        {
     352            if (isPlayMode)
     353                Execute();
     354        }
     355
    349356        #endregion
    350357
     
    355362#pragma warning restore
    356363
    357                         public void Execute()
    358         {
     364                public void Execute()
     365        {
     366            isPlayMode = true;
     367
    359368            switch (settings.Action)
    360369            {
    361370                case 0:
     371                    Caesar_LogMessage("encrypting", NotificationLevel.Debug);
    362372                    Encrypt();
    363373                    break;
  • trunk/CrypPlugins/Caesar/CaesarSettings.cs

    r575 r626  
    1919using System.Windows;
    2020using Cryptool.PluginBase;
    21 using System.Windows.Media;
    2221using System.Windows.Controls;
    2322
     
    2928       
    3029        /// <summary>
    31         /// We use this delegat to send log messages from the settings class to the Caesar plugin
     30        /// We use this delegate to send log messages from the settings class to the Caesar plugin
    3231        /// </summary>
    3332        public delegate void CaesarLogMessage(string msg, NotificationLevel loglevel);
     
    4342        /// </summary>
    4443        public event CaesarLogMessage LogMessage;
     44
     45        public delegate void CaesarReExecute();
     46
     47        public event CaesarReExecute ReExecute;
    4548
    4649        /// <summary>
     
    5154        {
    5255            get { return shiftValue; }
    53             set { setKeyByValue(value); }
     56            set
     57            {
     58                setKeyByValue(value);
     59            }
    5460        }
    5561
     
    185191        [PropertySaveOrder(4)]
    186192        [ContextMenu("Action", "Select the Algorithm action", 1, DisplayLevel.Beginner, ContextMenuControlType.ComboBox, new int[] { 1, 2 }, "Encrypt", "Decrypt")]
    187         [TaskPane("Action", "setAlgorithmActionDescription", null, 1, false, DisplayLevel.Beginner, ControlType.ComboBox, new string[] { "Encrypt", "Decrypt" })]
     193        [TaskPane("Action", "setAlgorithmActionDescription", null, 1, true, DisplayLevel.Beginner, ControlType.ComboBox, new string[] { "Encrypt", "Decrypt" })]
    188194        public int Action
    189195        {
     
    197203                this.selectedAction = value;
    198204                OnPropertyChanged("Action");
     205
     206                if (ReExecute != null) ReExecute();
    199207            }
    200208        }
    201209       
    202210        [PropertySaveOrder(5)]
    203         [TaskPane("Key as integer", "Enter the number of letters to shift. For instance a value of 1 means that the plaintext character a gets mapped to the ciphertext character B, b to C and so on.", null, 2, false, DisplayLevel.Beginner, ControlType.NumericUpDown, ValidationType.RangeInteger, 0, 100)]       
     211        [TaskPane("Key as integer", "Enter the number of letters to shift. For instance a value of 1 means that the plaintext character a gets mapped to the ciphertext character B, b to C and so on.", null, 2, true, DisplayLevel.Beginner, ControlType.NumericUpDown, ValidationType.RangeInteger, 0, 100)]       
    204212        public int ShiftValue
    205213        {
    206214            get { return shiftValue; }
    207             set { setKeyByValue(value); }
     215            set
     216            {
     217                setKeyByValue(value);
     218                if (ReExecute != null) ReExecute();
     219            }
    208220        }
    209221
    210222
    211223        [PropertySaveOrder(6)]
    212         [TaskPaneAttribute("Key as single letter", "Enter a single letter as the key. This letter is mapped to an integer stating the position in the alphabet. The values for \"Key as integer\" and \"Key as single letter” are always synchronized.", null, 3, false, DisplayLevel.Beginner, ControlType.TextBox, ValidationType.RegEx, "^([A-Z]|[a-z]){1,1}$")]
     224        [TaskPaneAttribute("Key as single letter", "Enter a single letter as the key. This letter is mapped to an integer stating the position in the alphabet. The values for \"Key as integer\" and \"Key as single letter” are always synchronized.", null, 3, true, DisplayLevel.Beginner, ControlType.TextBox, ValidationType.RegEx, "^([A-Z]|[a-z]){1,1}$")]
    213225        public string ShiftChar
    214226        {
    215227            get { return this.shiftChar.ToString(); }
    216             set { setKeyByCharacter(value); }
     228            set
     229            {
     230                setKeyByCharacter(value);
     231                if (ReExecute != null) ReExecute();
     232            }
    217233        }
    218234
    219235        [PropertySaveOrder(7)]
    220236        [ContextMenu("Unknown symbol handling", "What should be done with encountered characters at the input which are not in the alphabet?", 4, DisplayLevel.Expert, ContextMenuControlType.ComboBox, null, new string[] { "Ignore (leave unmodified)", "Remove", "Replace with \'?\'" })]
    221         [TaskPane("Unknown symbol handling", "What should be done with encountered characters at the input which are not in the alphabet?", null, 4, false, DisplayLevel.Expert, ControlType.ComboBox, new string[] { "Ignore (leave unmodified)", "Remove", "Replace with \'?\'" })]
     237        [TaskPane("Unknown symbol handling", "What should be done with encountered characters at the input which are not in the alphabet?", null, 4, true, DisplayLevel.Expert, ControlType.ComboBox, new string[] { "Ignore (leave unmodified)", "Remove", "Replace with \'?\'" })]
    222238        public int UnknownSymbolHandling
    223239        {
     
    228244                this.unknownSymbolHandling = (UnknownSymbolHandlingMode)value;
    229245                OnPropertyChanged("UnknownSymbolHandling");
     246
     247                if (ReExecute != null) ReExecute();
    230248            }
    231249        }
     
    233251        [SettingsFormat(0, "Normal", "Normal", "Black", "White", Orientation.Vertical)]
    234252        [PropertySaveOrder(9)]
    235         [TaskPane("Alphabet", "This is the used alphabet.", null, 6, false, DisplayLevel.Expert, ControlType.TextBox, "")]
     253        [TaskPane("Alphabet", "This is the used alphabet.", null, 6, true, DisplayLevel.Expert, ControlType.TextBox, "")]
    236254        public string AlphabetSymbols
    237255        {
     
    251269              LogMessage("Accepted new alphabet from user: \"" + alphabet + "\" (" + alphabet.Length.ToString() + " Symbols)", NotificationLevel.Info);
    252270              OnPropertyChanged("AlphabetSymbols");
     271
     272              if (ReExecute != null) ReExecute();
    253273            }
    254274          }
     
    261281        [PropertySaveOrder(8)]
    262282        [ContextMenu("Alphabet case sensitivity", "Should upper and lower case be treated differently? (Should a == A)", 7, DisplayLevel.Expert, ContextMenuControlType.ComboBox, null, new string[] { "Case insensitive", "Case sensitive" })]
    263         [TaskPane("Alphabet case sensitivity", "Should upper and lower case be treated differently? (Should a == A)", null, 7, false, DisplayLevel.Expert, ControlType.ComboBox, new string[] { "Case insensitive", "Case sensitive" })]
     283        [TaskPane("Alphabet case sensitivity", "Should upper and lower case be treated differently? (Should a == A)", null, 7, true, DisplayLevel.Expert, ControlType.ComboBox, new string[] { "Case insensitive", "Case sensitive" })]
    264284        public int AlphabetCase
    265285        {
     
    301321
    302322                OnPropertyChanged("AlphabetCase");
     323                if (ReExecute != null) ReExecute();
    303324            }
    304325        }
Note: See TracChangeset for help on using the changeset viewer.