Ignore:
Timestamp:
Dec 10, 2008, 11:11:24 PM (13 years ago)
Author:
Thomas Schmid
Message:
  • changed PersistenceManager to load WS without restoring all connections if plugin properties have changed
  • added byte counter TextInput/TextOutput
  • added QuickWatch to TextOutput
  • TextOutput now accepts different input type
  • ToDO: fix connections on workspaces using old TextOutput
Location:
trunk/CrypPlugins/TextOutput
Files:
3 edited

Legend:

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

    r136 r140  
    225225  public class TextOutput : DependencyObject, IOutput
    226226  {
    227     # region dps
    228     public static readonly DependencyProperty StringContentProperty =
    229       DependencyProperty.Register("StringContent", typeof(String), typeof(TextOutput),
    230       new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
    231 
    232     public static readonly DependencyProperty StreamContentProperty =
    233       DependencyProperty.Register("StreamContent", typeof(CryptoolStream), typeof(TextOutput),
    234       new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
    235 
    236     public static readonly DependencyProperty ByteArrayContentProperty =
    237       DependencyProperty.Register("ByteArrayContent", typeof(byte[]), typeof(TextOutput),
    238       new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
    239     # endregion
     227    private readonly string inputOne = "InputOne";
    240228
    241229    #region Private variables
     
    249237    /// </summary>
    250238    private Dictionary<string, NotificationLevel> dicWarningsAndErros = new Dictionary<string, NotificationLevel>();
     239    private bool canSendPropertiesChangedEvent = true;
     240    private int inputs = 0;
    251241    #endregion
     242
     243    #region events
     244    public event DynamicPropertiesChanged OnDynamicPropertiesChanged;
     245    public event GuiLogNotificationEventHandler OnGuiLogNotificationOccured;
     246    public event PropertyChangedEventHandler PropertyChanged;
     247    #pragma warning disable 67
     248    public event StatusChangedEventHandler OnPluginStatusChanged;
     249    #pragma warning restore
     250    #endregion events
    252251
    253252    # region constructor
     
    255254    {
    256255      Presentation = new TextOutputPresentation();
    257       settings = new TextOutputSettings();
     256      settings = new TextOutputSettings(this);
     257      settings.OnGuiLogNotificationOccured += settings_OnGuiLogNotificationOccured;
     258      CanChangeDynamicProperty = true;
     259      // No dynProp event in constructor - editor will read the property initial without the event.
     260      // event can cause problems when using save files and is processed after
     261      // connections have been restored.
     262      CreateInputOutput(false);
    258263    }
    259264    # endregion
     
    268273    }
    269274
    270     [PropertyInfo(Direction.Input, "Text", "Text can be viewed in a text box.", "", false, false, DisplayLevel.Beginner, QuickWatchFormat.Text, null)]
    271     public string StringInput
    272     {
    273       get
    274       {
    275         return (string)textOutputPresentation.Dispatcher.Invoke(DispatcherPriority.Normal, (DispatcherOperationCallback)delegate
    276         {
    277           return textOutputPresentation.textBoxString.Text;
    278         }, null);
    279       }
    280       set
    281       {
    282         try
    283         {
    284           if (value != null)
     275    public void CreateInputOutput(bool announcePropertyChange)
     276    {
     277      DicDynamicProperties.Clear();
     278      AddInput(inputOne, "Input value");
     279      if (announcePropertyChange) DynamicPropertiesChanged();
     280    }
     281
     282    private void DynamicPropertiesChanged()
     283    {
     284      if (OnDynamicPropertiesChanged != null) OnDynamicPropertiesChanged(this);
     285    }
     286
     287    private void settings_OnGuiLogNotificationOccured(IPlugin sender, GuiLogEventArgs args)
     288    {
     289      EventsHelper.GuiLogMessage(OnGuiLogNotificationOccured, this, new GuiLogEventArgs(args.Message, this, args.NotificationLevel));
     290    }
     291
     292    public Dictionary<string, DynamicProperty> dicDynamicProperties = new Dictionary<string, DynamicProperty>();
     293
     294    [DynamicPropertyInfo("methodGetValue", "methodSetValue", "CanChangeDynamicProperty", "OnDynamicPropertiesChanged", "CanSendPropertiesChangedEvent")]
     295    public Dictionary<string, DynamicProperty> DicDynamicProperties
     296    {
     297      get { return dicDynamicProperties; }
     298      set { dicDynamicProperties = value; }
     299    }
     300
     301    public bool CanChangeDynamicProperty
     302    {
     303      get { return settings.CanChangeProperty; }
     304      set { settings.CanChangeProperty = value; }
     305    }
     306
     307    public bool CanSendPropertiesChangedEvent
     308    {
     309      get { return canSendPropertiesChangedEvent; }
     310      set { canSendPropertiesChangedEvent = value; }
     311    }
     312
     313
     314    private Type getCurrentType()
     315    {
     316      switch (settings.CurrentDataType)
     317      {
     318        case TextOutputSettings.DynamicDataTypes.CryptoolStream:
     319          return typeof(CryptoolStream);
     320        case TextOutputSettings.DynamicDataTypes.String:
     321          return typeof(string);
     322        case TextOutputSettings.DynamicDataTypes.ByteArray:
     323          return typeof(byte[]);
     324        case TextOutputSettings.DynamicDataTypes.Boolean:
     325          return typeof(bool);
     326        case TextOutputSettings.DynamicDataTypes.Integer:
     327          return typeof(int);
     328        default:
     329          return null;
     330      }
     331    }
     332
     333    private QuickWatchFormat getQuickWatchFormat()
     334    {
     335      Type type = getCurrentType();
     336      if (type == typeof(CryptoolStream))
     337        return QuickWatchFormat.Hex;
     338      else if (type == typeof(string))
     339        return QuickWatchFormat.Text;
     340      else if (type == typeof(byte[]))
     341        return QuickWatchFormat.Hex;
     342      else if (type == typeof(bool))
     343        return QuickWatchFormat.Text;
     344      else if (type == typeof(int))
     345        return QuickWatchFormat.Text;
     346      else
     347        return QuickWatchFormat.None;
     348    }
     349
     350    private object getCurrentValue(string name)
     351    {
     352      if (DicDynamicProperties.ContainsKey(name))
     353      {
     354        switch (settings.CurrentDataType)
     355        {
     356          case TextOutputSettings.DynamicDataTypes.CryptoolStream:
     357            if ((CryptoolStream)DicDynamicProperties[name].Value != null)
     358            {
     359              CryptoolStream cryptoolStream = new CryptoolStream();
     360              listCryptoolStreamsOut.Add(cryptoolStream);
     361              cryptoolStream.OpenRead(((CryptoolStream)DicDynamicProperties[name].Value).FileName);
     362              return cryptoolStream;
     363            }
     364            else
     365              return null;
     366          case TextOutputSettings.DynamicDataTypes.String:
     367            return DicDynamicProperties[name].Value;
     368          case TextOutputSettings.DynamicDataTypes.ByteArray:
     369            return DicDynamicProperties[name].Value;
     370          case TextOutputSettings.DynamicDataTypes.Boolean:
     371            return DicDynamicProperties[name].Value;
     372          case TextOutputSettings.DynamicDataTypes.Integer:
     373            return DicDynamicProperties[name].Value;
     374          default:
     375            return null;
     376        }
     377      }
     378      return null;
     379    }
     380
     381    private void AddInput(string name, string toolTip)
     382    {
     383      inputs++;
     384      if (name == null || name == string.Empty) name = "Input " + inputs;
     385      DicDynamicProperties.Add(name,
     386        new DynamicProperty(name, getCurrentType(),
     387          new PropertyInfoAttribute(Direction.Input, name, toolTip, "", false, true, DisplayLevel.Beginner, getQuickWatchFormat(), null)));
     388    }
     389
     390    [MethodImpl(MethodImplOptions.Synchronized)]
     391    public void methodSetValue(string propertyKey, object value)
     392    {
     393      try
     394      {
     395        if (DicDynamicProperties.ContainsKey(propertyKey))
     396        {
     397          DicDynamicProperties[propertyKey].Value = value;
     398        }
     399
     400        string fillValue = null;
     401        if (value is String || value is string)
     402        {
     403          fillValue = value as string;
     404        }
     405        else if (value is int)
     406        {
     407          fillValue = ((int)value).ToString();
     408        }
     409        else if (value is bool)
     410        {
     411          fillValue = ((bool)value).ToString();
     412        }
     413        else if (value is CryptoolStream)
     414        {
     415          listCryptoolStreamsOut.Add((CryptoolStream)value);
     416          CryptoolStream stream = value as CryptoolStream;
     417          GuiLogMessage("Stream: Filling TextBoxes now...", NotificationLevel.Debug);
     418          if (stream.Length > settings.MaxLength)
     419            AddMessage("WARNING - Stream is too large (" + (stream.Length / 1024).ToString("0.00") + " kB), output will be truncated to " + (settings.MaxLength / 1024).ToString("0.00") + "kB", NotificationLevel.Warning);
     420          byte[] byteValues = new byte[Math.Min(settings.MaxLength, stream.Length)];
     421          int bytesRead;
     422          stream.Seek(0, SeekOrigin.Begin);
     423          bytesRead = stream.Read(byteValues, 0, byteValues.Length);
     424          fillValue = GetStringForSelectedEncoding(byteValues);
     425        }
     426        else if (value is byte[])
     427        {
     428          byte[] byteArray = value as byte[];
     429          GuiLogMessage("Byte array: Filling textbox now...", NotificationLevel.Debug);
     430          if (byteArray.Length > settings.MaxLength)
    285431          {
    286             textOutputPresentation.Dispatcher.Invoke(DispatcherPriority.Normal, (SendOrPostCallback)delegate
    287             {
    288               if (settings.Append)
    289               {
    290                 if (textOutputPresentation.textBoxString.Text.Length > settings.MaxLength)
    291                 {
    292                   GuiLogMessage("Text exceeds size limit. Deleting text...", NotificationLevel.Info);
    293                   textOutputPresentation.textBoxString.Text = string.Empty;
    294                 }
    295 
    296                 // append line breaks only if not first line
    297                 if (textOutputPresentation.textBoxString.Text != null && textOutputPresentation.textBoxString.Text.Length > 0)
    298                 {
    299                   for (int i = 0; i < settings.AppendBreaks; i++)
    300                   {
    301                     textOutputPresentation.textBoxString.AppendText("\n");
    302                   }
    303                 }
    304                 textOutputPresentation.textBoxString.AppendText(value);
    305                 textOutputPresentation.textBoxString.ScrollToEnd();
    306               }
    307               else textOutputPresentation.textBoxString.Text = value;
    308             }, value);
    309             OnPropertyChanged("StringInput");
     432            AddMessage("WARNING - byte array is too large (" + (byteArray.Length / 1024).ToString("0.00") + " kB), output will be truncated to " + (settings.MaxLength / 1024).ToString("0.00") + "kB", NotificationLevel.Warning);
    310433          }
    311           else
    312             AddMessage("Got null value for Text", NotificationLevel.Error);
    313         }
    314         catch (Exception exception)
    315         {
    316           GuiLogMessage(exception.Message, NotificationLevel.Error);
    317           GuiLogMessage(exception.StackTrace, NotificationLevel.Error);
    318         }
    319       }
    320     }
    321 
    322     [PropertyInfo(Direction.Input, "Stream", "Input stream will be converted to ASCII text and Hex string an and can be viewed in a text box.", "", false, false, DisplayLevel.Beginner, QuickWatchFormat.Text, null)]
    323     public CryptoolStream StreamInput
    324     {
    325       get
    326       {
    327         object stream = textOutputPresentation.Dispatcher.Invoke(DispatcherPriority.Normal, (DispatcherOperationCallback)delegate
    328         {
    329           if (textOutputPresentation.textBoxStream.Text != null && textOutputPresentation.textBoxStream.Text != string.Empty)
     434
     435          long size = byteArray.Length;
     436          if (size > settings.MaxLength)
    330437          {
    331             CryptoolStream cryptoolStream = new CryptoolStream();
    332             cryptoolStream.OpenRead(this.GetPluginInfoAttribute().Caption, Encoding.Default.GetBytes(textOutputPresentation.textBoxStream.Text));
    333             listCryptoolStreamsOut.Add(cryptoolStream);
    334             return cryptoolStream;
     438            size = settings.MaxLength;
    335439          }
    336           return null;
    337         }, null);
    338         return stream as CryptoolStream;
    339       }
    340       set
    341       {
    342         GuiLogMessage("Got stream.", NotificationLevel.Info);
    343         Dispatcher.Invoke(DispatcherPriority.Normal, (SendOrPostCallback)delegate
    344         {
    345           SetValue(StreamContentProperty, value);
    346         }, value);
    347 
    348         textOutputPresentation.Dispatcher.Invoke(DispatcherPriority.Normal, (SendOrPostCallback)delegate
    349         {
    350           if (settings.Append)
     440          byte[] sizedArray = new byte[size];
     441          for (int i = 0; i < size; i++)
    351442          {
    352             if (textOutputPresentation.textBoxStream.Text.Length > settings.MaxLength)
    353             {
    354               GuiLogMessage("Stream textBox exceeds size limit. Deleting text...", NotificationLevel.Info);
    355               textOutputPresentation.textBoxStream.Text = string.Empty;
    356               textOutputPresentation.textBoxByteArray.Text = string.Empty;
    357             }
    358 
    359             // append line breaks only if not first line
    360             if (textOutputPresentation.textBoxStream.Text != null && textOutputPresentation.textBoxStream.Text.Length > 0)
    361             {
    362               for (int i = 0; i < settings.AppendBreaks; i++)
    363               {
    364                 textOutputPresentation.textBoxStream.AppendText("\n");
    365               }
    366             }
     443            sizedArray[i] = byteArray[i];
    367444          }
    368         }, string.Empty);
    369 
    370         // process input
    371         if (value != null && value.Length > 0)
    372         {
    373           GuiLogMessage("Stream: Filling TextBoxes now...", NotificationLevel.Debug);
    374           if (value.Length > settings.MaxLength)
    375             AddMessage("WARNING - Stream is too large (" + (value.Length / 1024).ToString("0.00") + " kB), output will be truncated to " + (settings.MaxLength / 1024).ToString("0.00") + "kB", NotificationLevel.Warning);
    376           byte[] byteValues = new byte[Math.Min(settings.MaxLength, value.Length)];
    377           int bytesRead;
    378           value.Seek(0, SeekOrigin.Begin);
    379           bytesRead = value.Read(byteValues, 0, byteValues.Length);
    380 
    381           String strTxt = GetStringForSelectedEncoding(byteValues);
    382 
    383           StringBuilder strHex = new StringBuilder();
    384           for (int i = 0; i < bytesRead; i++)
    385           {
    386             strHex.Append(String.Format("{0:X2}", byteValues[i]));
    387           }
    388 
    389           textOutputPresentation.Dispatcher.Invoke(DispatcherPriority.Normal, (SendOrPostCallback)delegate
     445          fillValue = GetStringForSelectedEncoding(sizedArray);
     446        }
     447
     448        if (fillValue != null)
     449        {
     450          Presentation.Dispatcher.Invoke(DispatcherPriority.Normal, (SendOrPostCallback)delegate
    390451          {
    391452            if (settings.Append)
    392453            {
    393               textOutputPresentation.textBoxStream.AppendText(strTxt);
    394               textOutputPresentation.textBoxStream.ScrollToEnd();
    395             }
    396             else
    397               textOutputPresentation.textBoxStream.Text = strTxt;
    398           }, strTxt);
    399 
    400           // used to return correct value to quickWatch requests
    401           textOutputPresentation.Dispatcher.Invoke(DispatcherPriority.Normal, (SendOrPostCallback)delegate
    402           {
    403             if (settings.Append)
    404             {
    405               textOutputPresentation.textBoxStreamByte.AppendText(strHex.ToString());
    406               textOutputPresentation.textBoxStreamByte.ScrollToEnd();
    407             }
    408             else
    409               textOutputPresentation.textBoxStreamByte.Text = strHex.ToString();
    410           }, strHex);
    411           GuiLogMessage("TextBoxes filled.", NotificationLevel.Debug);
    412           OnPropertyChanged("StreamInput");
    413         }
    414         else
    415         {
    416           if (value == null)
    417             AddMessage("Stream: value is null.", NotificationLevel.Warning);
    418           else if (value.Length == 0)
    419             AddMessage("Stream length is 0.", NotificationLevel.Warning);
    420         }
    421 
    422       }
    423     }
    424 
    425 
    426     private byte[] byteArrayInput;
    427     [PropertyInfo(Direction.Input, "Byte array", "Byte array will be converted to hex-value.", "", false, false, DisplayLevel.Beginner, QuickWatchFormat.Text, null)]
    428     public byte[] ByteArrayInput
    429     {
    430       get
    431       {
    432         object value = textOutputPresentation.Dispatcher.Invoke(DispatcherPriority.Normal, (DispatcherOperationCallback)delegate
    433         {
    434           if (textOutputPresentation.textBoxByteArray.Text != null && textOutputPresentation.textBoxByteArray.Text != string.Empty)
    435             return Encoding.Default.GetBytes(textOutputPresentation.textBoxByteArray.Text);
    436           return null;
    437         }, null);
    438         return value as byte[];
    439       }
    440       set
    441       {
    442         GuiLogMessage("Got byte array.", NotificationLevel.Debug);
    443         if (value != null)
    444         {
    445           // Progress(50, 100);
    446           GuiLogMessage("Byte array: Filling textbox now...", NotificationLevel.Debug);
    447           if (value.Length > settings.MaxLength)
    448             AddMessage("WARNING - byte array is too large (" + (value.Length / 1024).ToString("0.00") + " kB), output will be truncated to " + (settings.MaxLength / 1024).ToString("0.00") + "kB", NotificationLevel.Warning);
    449 
    450           textOutputPresentation.Dispatcher.Invoke(DispatcherPriority.Normal, (SendOrPostCallback)delegate
    451           {
    452             if (settings.Append)
    453             {
    454               // set empty
    455               if (textOutputPresentation.textBoxByteArray.Text.Length > settings.MaxLength)
     454              if (textOutputPresentation.textBox.Text.Length > settings.MaxLength)
    456455              {
    457                 GuiLogMessage("byte array textbox exceeds size limit. Deleting text...", NotificationLevel.Info);
    458                 textOutputPresentation.textBoxByteArray.Text = string.Empty;
     456                GuiLogMessage("Text exceeds size limit. Deleting text...", NotificationLevel.Info);
     457                textOutputPresentation.textBox.Text = string.Empty;
    459458              }
     459
    460460              // append line breaks only if not first line
    461               if (textOutputPresentation.textBoxByteArray.Text != null && textOutputPresentation.textBoxByteArray.Text.Length > 0)
     461              if (textOutputPresentation.textBox.Text != null && textOutputPresentation.textBox.Text.Length > 0)
    462462              {
    463463                for (int i = 0; i < settings.AppendBreaks; i++)
    464464                {
    465                   textOutputPresentation.textBoxByteArray.AppendText("\n");
     465                  textOutputPresentation.textBox.AppendText("\n");
    466466                }
    467467              }
    468             }
    469           }, string.Empty);
    470 
    471           long size = value.Length; if (size > settings.MaxLength) size = settings.MaxLength;
    472           byte[] sizedArray = new byte[size];
    473           for (int i = 0; i < size; i++)
    474           {
    475             sizedArray[i] = value[i];
    476           }
    477 
    478           string converted = GetStringForSelectedEncoding(sizedArray);
    479 
    480           textOutputPresentation.Dispatcher.Invoke(DispatcherPriority.Normal, (SendOrPostCallback)delegate
    481           {
    482             if (settings.Append)
    483             {
    484               textOutputPresentation.textBoxByteArray.AppendText(converted);
    485               textOutputPresentation.textBoxByteArray.ScrollToEnd();
     468              textOutputPresentation.textBox.AppendText(fillValue);
     469              textOutputPresentation.textBox.ScrollToEnd();
    486470            }
    487471            else
    488               textOutputPresentation.textBoxByteArray.Text = converted;
    489           }, converted);
    490           GuiLogMessage("Byte array: Textbox filled.", NotificationLevel.Debug);
    491 
    492           byteArrayInput = Encoding.Default.GetBytes(converted.ToCharArray());
    493           OnPropertyChanged("ByteArrayInput");
    494         }
    495         else
    496         {
    497           if (value == null)
    498             AddMessage("Byte array: value is null.", NotificationLevel.Warning);
    499         }
    500       }
    501     }
    502 
     472            {
     473              textOutputPresentation.textBox.Text = fillValue;
     474            }
     475            textOutputPresentation.labelBytes.Content = string.Format("{0:0,0}", Encoding.Default.GetBytes(textOutputPresentation.textBox.Text.ToCharArray()).Length) + " Bytes";
     476          }, fillValue);
     477          OnPropertyChanged("StringInput");
     478        }
     479
     480        OnPropertyChanged(propertyKey);
     481      }
     482      catch (Exception ex)
     483      {
     484        GuiLogMessage(ex.Message, NotificationLevel.Error);
     485      }
     486    }
     487
     488    private List<string> listBuffer = new List<string>();
     489
     490    [MethodImpl(MethodImplOptions.Synchronized)]
     491    public object methodGetValue(string propertyKey)
     492    {
     493      return getCurrentValue(propertyKey); // QuickWatchDataCall to Input values
     494    }
    503495
    504496    #endregion
     
    552544
    553545    #region INotifyPropertyChanged Members
    554 
    555     public event PropertyChangedEventHandler PropertyChanged;
    556 
     546   
    557547    public void OnPropertyChanged(string name)
    558548    {
     
    573563    public UserControl QuickWatchPresentation
    574564    {
    575       get { return null; }
     565      get { return Presentation; }
    576566    }
    577567
     
    601591        textOutputPresentation.Dispatcher.Invoke(DispatcherPriority.Normal, (SendOrPostCallback)delegate
    602592        {
    603           textOutputPresentation.textBoxByteArray.Text = null;
    604           textOutputPresentation.textBoxStream.Text = null;
    605           textOutputPresentation.textBoxStreamByte.Text = null;
    606           textOutputPresentation.textBoxString.Text = null;
     593          textOutputPresentation.textBox.Text = null;
    607594        }, null);
    608595      }
     596      foreach (DynamicProperty item in dicDynamicProperties.Values)
     597      {
     598        if (item.Value is CryptoolStream)
     599        {
     600          item.Value = null;
     601        }
     602      }
    609603      Dispose();
    610604    }
     
    615609    }
    616610
    617 #pragma warning disable 67
    618                 public event StatusChangedEventHandler OnPluginStatusChanged;
    619 #pragma warning restore
    620 
    621     public event GuiLogNotificationEventHandler OnGuiLogNotificationOccured;
    622611    private void GuiLogMessage(string message, NotificationLevel logLevel)
    623612    {
  • trunk/CrypPlugins/TextOutput/TextOutputPresentation.xaml

    r4 r140  
    55    <Grid>
    66    <Grid.RowDefinitions>
    7       <RowDefinition Height="25*" />
    8       <RowDefinition Height="25*" />
    9       <RowDefinition Height="25*" />
    10       <RowDefinition Height="25*" />
     7      <RowDefinition Height="Auto" />
     8      <RowDefinition Height="*" />
     9      <RowDefinition Height="Auto" />
    1110    </Grid.RowDefinitions>
    12     <TextBox Name="textBoxString" Grid.Row="0" Margin="0,29,0,0" IsEnabled="True" TextWrapping="Wrap" VerticalScrollBarVisibility="Auto" IsReadOnly="True" />
    13     <Label Height="28" Name="labelString" VerticalAlignment="Top" Background="#DFDFDF">String</Label>
    14 
    15     <TextBox Name="textBoxStream" Grid.Row="1" Margin="0,29,0,0" IsEnabled="True" TextWrapping="Wrap" IsReadOnly="True" VerticalScrollBarVisibility="Auto" />
    16     <Label Grid.Row="1" Height="28" Name="labelStream" VerticalAlignment="Top" Background="#FF9B28">Stream displayed as string</Label>
    17 
    18     <TextBox Name="textBoxStreamByte" Grid.Row="2" Margin="0,29,0,0" IsEnabled="True" TextWrapping="Wrap" IsReadOnly="True" VerticalScrollBarVisibility="Auto" />
    19     <Label Grid.Row="2" Height="28" Name="labelStreamByte" VerticalAlignment="Top" Background="#FF9B28">Stream displayed as hex value</Label>
    20 
    21     <TextBox Name="textBoxByteArray" Grid.Row="3" Margin="0,29,0,0" IsEnabled="True" TextWrapping="Wrap" IsReadOnly="True" VerticalScrollBarVisibility="Auto" />
    22     <Label Grid.Row="3" Height="28" Name="labelByteArray" VerticalAlignment="Top" Background="Aqua">Byte Array</Label>
    23 
    24   </Grid>
     11    <Label Padding="0" Grid.Row="0" Name="labelString" VerticalAlignment="Top" Background="#DFDFDF">Input</Label>
     12    <TextBox Name="textBox" Grid.Row="1" Margin="0" IsEnabled="True" TextWrapping="Wrap" VerticalScrollBarVisibility="Auto" IsReadOnly="True" />   
     13    <Label Padding="0" Grid.Row="2" Name="labelBytes" VerticalAlignment="Top" Background="#DFDFDF">0 Bytes</Label>
     14    </Grid>
    2515</UserControl>
  • trunk/CrypPlugins/TextOutput/TextOutputSettings.cs

    r4 r140  
    208208using Cryptool.PluginBase;
    209209using System.ComponentModel;
     210using Cryptool.PluginBase.Miscellaneous;
    210211
    211212namespace TextOutput
     
    217218    private int maxLength = 65536; //64kB
    218219    private bool hasChanges = false;
     220    private TextOutput myTextOutput;
    219221    #endregion
    220222
    221     public enum EncodingTypes { Default = 0, Unicode = 2, UTF7 = 3, UTF8 = 4, UTF32 = 5, ASCII = 6, BigEndianUnicode = 7 };
     223    public event GuiLogNotificationEventHandler OnGuiLogNotificationOccured;
     224
     225    public enum EncodingTypes { Default = 0, Unicode = 1, UTF7 = 2, UTF8 = 3, UTF32 = 4, ASCII = 5, BigEndianUnicode = 6 };
     226    public enum DynamicDataTypes { CryptoolStream, String, ByteArray, Boolean, Integer };
     227    public bool CanChangeProperty { get; set; }
     228
     229    public TextOutputSettings(TextOutput textOutput)
     230    {
     231      if (textOutput == null) throw new ArgumentException("textOutput");
     232      myTextOutput = textOutput;
     233    }
    222234
    223235    /// <summary>
     
    234246      }
    235247    }
     248
     249    #region settings
    236250
    237251    /// <summary>
     
    320334    }
    321335
     336    private DynamicDataTypes currentDataType;
     337    public DynamicDataTypes CurrentDataType
     338    {
     339      get { return currentDataType; }
     340      set
     341      {
     342        if (currentDataType != value)
     343        {
     344          currentDataType = value;
     345
     346          // Changes must be applied synchronously, because onLoad of save file
     347          // the Properties have to be set correctly BEFORE init of restore connections starts.
     348          //
     349          // The flag CanSendPropertiesChangedEvent will be set to false while loading a save file
     350          // right after creating plugin instance. Next this Property will be set by the editor-loading-method.
     351          // Here we set the new type without sending an event, because the event could be processed after
     352          // the connections have been restored. That would result in an unuseable workspace or throw an exception
     353          // while executing the init method.
     354          myTextOutput.CreateInputOutput(myTextOutput.CanSendPropertiesChangedEvent);
     355          // OnPropertyChanged("CurrentDataType");
     356        }
     357      }
     358    }
     359
     360    [TaskPane("Type", "Select DataType of plugin.", "", 2, false, DisplayLevel.Beginner, ControlType.ComboBox, new string[] { "CryptoolStream", "string", "byte[]", "boolean", "int" })]
     361    public int DataType
     362    {
     363      get { return (int)CurrentDataType; }
     364      set
     365      {
     366        if (CanChangeProperty)
     367        {
     368          if (value != (int)CurrentDataType) HasChanges = true;
     369          CurrentDataType = (DynamicDataTypes)value;
     370        }
     371        else EventsHelper.GuiLogMessage(OnGuiLogNotificationOccured, null, new GuiLogEventArgs("Can't change type while plugin is connected.", null, NotificationLevel.Warning));
     372        OnPropertyChanged("DataType");
     373      }
     374    }
     375
     376    # endregion settings
     377
    322378    #region INotifyPropertyChanged Members
    323379
     
    328384      if (PropertyChanged != null)
    329385      {
    330         PropertyChanged(this, new PropertyChangedEventArgs(name));
     386        EventsHelper.PropertyChanged(PropertyChanged, this, new PropertyChangedEventArgs(name));
    331387      }
    332388    }
Note: See TracChangeset for help on using the changeset viewer.