Changeset 206


Ignore:
Timestamp:
Jan 29, 2009, 10:16:07 PM (13 years ago)
Author:
Thomas Schmid
Message:
  • added output presentation format (text, hex, base64) to text output plugin
  • updated project samples with new plugin properties
Location:
trunk
Files:
28 edited

Legend:

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

    r184 r206  
    437437        {
    438438          fillValue = value.ToString();
     439          if (fillValue != null && fillValue.Length > settings.MaxLength)
     440          {
     441            fillValue = fillValue.Substring(0, settings.MaxLength);
     442          }
    439443        }
    440444
    441445        if (fillValue != null)
    442446        {
     447          // Presentation format conversion
     448          switch (settings.Presentation)
     449          {
     450            case TextOutputSettings.PresentationFormat.Text:
     451              // nothin to do here
     452              break;
     453            case TextOutputSettings.PresentationFormat.Hex:
     454              byte[] byteValues = Encoding.Default.GetBytes(fillValue.ToCharArray());
     455              fillValue = BitConverter.ToString(byteValues, 0, byteValues.Length).Replace("-", "");
     456              break;
     457            case TextOutputSettings.PresentationFormat.Base64:
     458              fillValue = Convert.ToBase64String(Encoding.Default.GetBytes(fillValue.ToCharArray()));
     459              break;
     460            default:
     461              break;
     462          }
     463
     464
    443465          Presentation.Dispatcher.Invoke(DispatcherPriority.Normal, (SendOrPostCallback)delegate
    444466          {
  • trunk/CrypPlugins/TextOutput/TextOutputSettings.cs

    r178 r206  
    216216    #region Private variables
    217217    private EncodingTypes encoding = EncodingTypes.Default;
     218    private PresentationFormat presentation = PresentationFormat.Text;
    218219    private int maxLength = 65536; //64kB
    219220    private bool hasChanges = false;
     
    225226    public enum EncodingTypes { Default = 0, Unicode = 1, UTF7 = 2, UTF8 = 3, UTF32 = 4, ASCII = 5, BigEndianUnicode = 6 };
    226227    public enum DynamicDataTypes { CryptoolStream, String, ByteArray, Boolean, Integer , Object};
     228    public enum PresentationFormat { Text, Hex, Base64 }
     229
    227230    public bool CanChangeProperty { get; set; }
    228231
     
    247250    }
    248251
     252    public PresentationFormat Presentation
     253    {
     254      get { return this.presentation; }
     255      set
     256      {
     257        if (this.presentation != value) hasChanges = true;
     258        this.presentation = value;
     259        OnPropertyChanged("Presentation");
     260      }
     261    }
     262
    249263    #region settings
    250264
     
    252266    /// Encoding property used in the Settings pane.
    253267    /// </summary>
    254     [ContextMenu("Stream encoding", "Choose the expected encoding of the input stream and byte array.", 1, DisplayLevel.Experienced, ContextMenuControlType.ComboBox, null, new string[] { "Default system encoding", "Unicode", "UTF-7", "UTF-8", "UTF-32", "ASCII", "Big endian unicode" })]
    255     [TaskPane("Stream encoding", "Choose the expected encoding of the input stream and byte array. (The stream/byte[] will be interpreted as set here, no matter what the bytes really mean)", null, 1, false, DisplayLevel.Experienced, ControlType.ComboBox, new string[] { "Default system encoding", "Unicode", "UTF-7", "UTF-8", "UTF-32", "ASCII", "Big endian unicode" })]
     268    [ContextMenu("Input encoding", "Choose the expected encoding of the input.", 1, DisplayLevel.Experienced, ContextMenuControlType.ComboBox, null, new string[] { "Default system encoding", "Unicode", "UTF-7", "UTF-8", "UTF-32", "ASCII", "Big endian unicode" })]
     269    [TaskPane("Input encoding", "Choose the expected encoding of the input. (The input will be interpreted as set here, no matter what the bytes really mean)", null, 1, false, DisplayLevel.Experienced, ControlType.ComboBox, new string[] { "Default system encoding", "Unicode", "UTF-7", "UTF-8", "UTF-32", "ASCII", "Big endian unicode" })]
    256270    public int EncodingSetting
    257271    {
     
    268282    }
    269283
     284
     285    /// <summary>
     286    /// Gets or sets the presentation format setting.
     287    /// </summary>
     288    /// <value>The presentation format setting.</value>
     289    [ContextMenu("Presentation format", "Choose the format that will be used te present the input data.", 2, DisplayLevel.Experienced, ContextMenuControlType.ComboBox, null, new string[] { "Text", "Hex", "Base64" })]
     290    [TaskPane("Presentation format", "Choose the format that will be used te present the input data.", null, 2, false, DisplayLevel.Experienced, ControlType.ComboBox, new string[] { "Text", "Hex", "Base64" })]
     291    public int PresentationFormatSetting
     292    {
     293      get
     294      {
     295        return (int)this.presentation;
     296      }
     297      set
     298      {
     299        if (this.presentation != (PresentationFormat)value) HasChanges = true;
     300        this.presentation = (PresentationFormat)value;
     301        OnPropertyChanged("PresentationFormatSetting");
     302      }
     303    }
     304
     305
    270306    /// <summary>
    271307    /// Maximum size property used in the settings pane.
    272308    /// </summary>
    273     [TaskPane("Maximum length", "Provide the maximum number of bytes to convert.", null, 2, false, DisplayLevel.Professional, ControlType.NumericUpDown, ValidationType.RangeInteger, 1, 65536)]
     309    [TaskPane("Maximum length", "Provide the maximum number of bytes to convert.", null, 3, false, DisplayLevel.Professional, ControlType.NumericUpDown, ValidationType.RangeInteger, 1, 65536)]
    274310    public int MaxLength
    275311    {
     
    287323
    288324    private bool append = false;
    289     [ContextMenu("Append text input", "With this checkbox enabled, incoming text will be appended to the current text.", 3, DisplayLevel.Experienced, ContextMenuControlType.CheckBox, null, new string[] { "Append text input" })]
    290     [TaskPane("Append text input", "With this checkbox enabled, incoming text will be appended to the current text.", "Append", 3, false, DisplayLevel.Beginner, ControlType.CheckBox, "", null)]
     325    [ContextMenu("Append text input", "With this checkbox enabled, incoming text will be appended to the current text.", 0, DisplayLevel.Experienced, ContextMenuControlType.CheckBox, null, new string[] { "Append text input" })]
     326    [TaskPane("Append text input", "With this checkbox enabled, incoming text will be appended to the current text.", "Append", 0, false, DisplayLevel.Beginner, ControlType.CheckBox, "", null)]
    291327    public bool Append
    292328    {
     
    303339
    304340    private int appendBreaks = 1;
    305     [TaskPane("Append n-breaks", "Defines how much new lines are added after new input. (Applies only if \"Append text input\" is active.)", "Append", 4, false, DisplayLevel.Experienced, ControlType.NumericUpDown, ValidationType.RangeInteger, 0, int.MaxValue)]
     341    [TaskPane("Append n-breaks", "Defines how much new lines are added after new input. (Applies only if \"Append text input\" is active.)", "Append", 0, false, DisplayLevel.Experienced, ControlType.NumericUpDown, ValidationType.RangeInteger, 0, int.MaxValue)]
    306342    public int AppendBreaks
    307343    {
     
    314350          OnPropertyChanged("AppendBreaks");
    315351          HasChanges = true;
    316         }
    317       }
    318     }
    319 
    320     private bool flushOnPreExecution = true;
    321     [ContextMenu("Flush text on PreExec", "Flush all text boxes on PreExecution call.", 5, DisplayLevel.Beginner, ContextMenuControlType.CheckBox, null, new string[] {"Flush text on PreExec"})]
    322     [TaskPane("Flush text on PreExec", "Flush all text boxes on PreExecution call.", null, 5, false, DisplayLevel.Beginner, ControlType.CheckBox, null)]
    323     public bool FlushOnPreExecution
    324     {
    325       get { return flushOnPreExecution; }
    326       set
    327       {
    328         if (value != flushOnPreExecution)
    329         {
    330           flushOnPreExecution = value;
    331           OnPropertyChanged("FlushOnPreExecution");
    332352        }
    333353      }
     
    358378    }
    359379
    360     [TaskPane("Type", "Select DataType of plugin.", "", 2, false, DisplayLevel.Beginner, ControlType.ComboBox, new string[] { "CryptoolStream", "string", "byte[]", "boolean", "int", "object"})]
     380    [TaskPane("Type", "Select DataType of plugin.", "", 4, false, DisplayLevel.Beginner, ControlType.ComboBox, new string[] { "CryptoolStream", "string", "byte[]", "boolean", "int", "object" })]
    361381    public int DataType
    362382    {
     
    374394    }
    375395
     396    private bool flushOnPreExecution = true;
     397    [ContextMenu("Flush text on PreExec", "Flush all text boxes on PreExecution call.", 5, DisplayLevel.Beginner, ContextMenuControlType.CheckBox, null, new string[] {"Flush text on PreExec"})]
     398    [TaskPane("Flush text on PreExec", "Flush all text boxes on PreExecution call.", null, 5, false, DisplayLevel.Beginner, ControlType.CheckBox, null)]
     399    public bool FlushOnPreExecution
     400    {
     401      get { return flushOnPreExecution; }
     402      set
     403      {
     404        if (value != flushOnPreExecution)
     405        {
     406          flushOnPreExecution = value;
     407          OnPropertyChanged("FlushOnPreExecution");
     408        }
     409      }
     410    }
    376411    # endregion settings
    377412
Note: See TracChangeset for help on using the changeset viewer.