compcode

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
Last revision Both sides next revision
compcode [2007/06/12 15:34]
lavirotte créée
compcode [2011/01/05 16:33]
hourdin update again
Line 1: Line 1:
 +====== Sample of a Bean ======
 +
 +===== Source Code =====
 +
 +Here is a sample code of a component in C# (save this to a file called Your_CSharpBean_Name.cs) :
 +
 <code csharp> <code csharp>
-using WComp.Beans;​ // It contains ​the definition of the attribute [Bean]+using WComp.Beans; ​     // Contains ​the definition of the [Bean] ​attribute
 using System.Threading;​ // For the thread demo purposes using System.Threading;​ // For the thread demo purposes
 +
 namespace Your_Namespace_Name { namespace Your_Namespace_Name {
-[Bean] + 
-public class Your_CSharpBean_Name { +    ​[Bean] 
-public Your_CSharpBean_Name() { +    public class Your_CSharpBean_Name ​: IThreadCreator ​
-// Put here your init instructions +        ​private Thread t;      // Private attributes of the class 
-// Example of a loop that call the output +        private volatile bool run; 
-// every second. +        private volatile int eventValue;​ 
-new Thread(new ThreadStart(ThreadLoopMethod)).Start();​ + 
-+        ​public Your_CSharpBean_Name() { 
-// Loop sample +            // Put here your init instructions 
-public void ThreadLoopMethod() { +            t = new Thread(new ThreadStart(ThreadLoopMethod))
-while(Thread.CurrentThread.IsAlive) { +            run = false; 
-Thread.Sleep(1000);​ +            eventValue = 10; 
-double result; +        } 
-// Check if the output is connected + 
-if(Output_Sample != null) +        public void Start() {  // method starting the thread 
-// call the connected methods sequentially +            if (!run) { 
-result = Output_Sample(123); +                run = true; 
-// and so on... +                t.Start();  
-+            }  
-+        } 
-// --- Start: Input port sample --- +        public void Stop() {   // since version 2.4.0.856,​ 
-// an input port is a method (below) +            run = false; ​      // IThreadCreator defines the Stop() method 
-public ​int Input_Sample(string param_name) { +        }  
-string pn param_name; // You may use the parameters + 
-return ​0; // You may return anything +         // Loop sample 
-+         ​public void ThreadLoopMethod() { 
-// --- End: Input port sample --- +             ​while(run) { 
-// --- Start: Output port sample --- +                 ​Thread.Sleep(1000);​ 
-public delegate ​double ​Output_Sample_Signature(int ​param_name); +                 ​// Check if the output is connected 
-// This is the signature of the output method +                 ​if(Output_Sample != null) 
-public event Output_Sample_Signature Output_Sample;​ +                     ​// call the connected methods sequentially 
-// The output port is the event (before) +                     ​Output_Sample(eventValue); 
-// --- End: Output port sample --- +                // and so on... 
-}+             ​
 +        
 + 
 +        ​// --- Start: Input port sample --- 
 +        // an input port is a public ​method (like below) 
 +        public ​void Input_Sample(int intParam) { 
 +            ​eventValue ​intParam; 
 +            ​// No return ​value is expected in WComp: 
 +            ​// results are given using events 
 +        
 +        // --- End: Input port sample --- 
 + 
 +        ​// --- Start: Output port sample --- 
 +        public delegate ​void Output_Sample_Signature(int ​val); 
 +        // The delegate defines ​the signature of the output method 
 +        public event Output_Sample_Signature Output_Sample;​ 
 +        // The output port is the event, named here Output_Sample 
 +        // --- End: Output port sample --- 
 +    }
 } }
 </​code>​ </​code>​
 +
 +
 +
 +===== Compilation =====
 +
 +Here is a sample of the command line compilation:​
 +<​code>​
 +csc.exe /​target:​library /​r:​Beans.dll Sample_Component.cs
 +</​code>​
 +
 +You will find Beans.dll in the SharpWComp distrib.
  • compcode.txt
  • Last modified: 2011/06/06 10:48
  • by Stéphane Lavirotte