hdolder.com srl

  hdc Home | Contenido  | KO1  | Director | Direcciones | email
  BLOCKS - Ejemplo BO2

v112

 

 

 *** Documento en elaboración ***

Este ejemplo muestra una mini-aplicacion BLOCKS No-visual en la que la configuracion de la red de BLOCKS se hace puramente  mediante código sin utilizar XAML. El ejemplo utiliza el componente  BBLOCKSBoard para albergar y procesar una red de BLOCKS muy simple compueta por dos instancias del BLOCK BTest1.

El codigo de la aplicacion es:

using System;
using ...
using ob.core;

namespace ob.gc
{
static class Program
{
	// The main entry point for the application.
	[STAThread]
	static void Main()
	{
		BTest1 bt1;
		BTest1 bt2;

		BBLOCKSBoard host = new BBLOCKSBoard();

		bt1 = new BTest1();
		host.Attach(bt1);

		bt2 = new BTest1();
		host.Attach(bt2);

		// Bindings 
		Binding myBinding = new Binding();
		myBinding.Source = bt1;
		myBinding.Path = new PropertyPath("OutStr");
		myBinding.Mode = BindingMode.OneWay;
		bt2.SetBinding(BTest1.InStrProperty, myBinding);

		host.Start();

		bt1.InStr = "12345";
		String outS = bt2.OutStr;

		bt1.InStr = "MNBVC	XZ"; 
		outS = bt2.OutStr;

		bt1.InStr = "MNBVCXZ";
		outS = bt2.OutStr;

	}
}}

El codigo del  BLOCK BTest1 es (IMORTANTE: casi la totalidad del codigo fué creado mediante  las Development Tools):

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//  BTest1 BLOCKS Control
//  Copia String de Input al Output
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
using System;
using ...
using ob.core;

namespace ob.gc
{
    public class BTest1 : BLOCK
    {
        static int iii = 0;  // for debugging

        // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        // Connectors del BLOCK
        // (Dependency Properties)
        // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        // [**
 
    public String InStr 
    { 
      get { return (String)GetValue(InStrProperty); } 
      set {  
            SetValue(InStrProperty, value);  
          } 
    } 
    public static readonly DependencyProperty InStrProperty = 
        DependencyProperty.Register("InStr", typeof(String), typeof(BTest1), 
             new PropertyMetadata("", new PropertyChangedCallback(OnInStrChanged))); 
 
    private static void OnInStrChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) 
    { 
      ((BTest1)d).OnInStrChanged(e); 
    } 
 
    protected virtual void OnInStrChanged(DependencyPropertyChangedEventArgs e) 
    { 
            if (IsReady)
                OutStr  = (String)e.NewValue; 
    } 
 

    public String OutStr 
    { 
      get { return (String)GetValue(OutStrProperty); } 
      set {  
            SetValue(OutStrProperty, value);  
          } 
    } 
    public static readonly DependencyProperty OutStrProperty = 
        DependencyProperty.Register("OutStr", typeof(String), typeof(BTest1), 
             new PropertyMetadata("", new PropertyChangedCallback(OnOutStrChanged))); 
 
    private static void OnOutStrChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) 
    { 
      ((BTest1)d).OnOutStrChanged(e); 
    } 
 
    protected virtual void OnOutStrChanged(DependencyPropertyChangedEventArgs e) 
    { 
      // ....... 
    } 
 
        // **]

        // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        // Constructor 
        // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        public  BTest1():base()
        {
            iii = 0;
            // [**

            // **]
        }

    }
}

 

@to_do actualizar

 

  TBW The BLOCKS World

©2011 hdolder.com srl