compcode

Differences

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

Link to this comparison view

Next revision
Previous revision
Next revision Both sides next revision
compcode [2007/06/12 15:34]
lavirotte créée
compcode [2011/01/05 16:26]
hourdin fixes in the code, update to new version
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 = false; 
-// every second. + 
-new Thread(new ThreadStart(ThreadLoopMethod)).Start();​ +        ​public Your_CSharpBean_Name() { 
-+            // Put here your init instructions 
-// Loop sample +            // Example of a loop that call the output 
-public void ThreadLoopMethod() { +            // every second. 
-while(Thread.CurrentThread.IsAlive) { +            t = new Thread(new ThreadStart(ThreadLoopMethod))
-Thread.Sleep(1000);​ +        } 
-double result; + 
-// Check if the output is connected +        public void Start() { 
-if(Output_Sample != null) +            if (!run) { 
-// call the connected methods sequentially +                run = true; 
-result = Output_Sample(123);​ +                t.Start();  
-// and so on... +            }  
-+        } 
-+        public void Stop() {   // since version 2.4.0.856,​ 
-// --- Start: Input port sample --- +            run = false; ​      // IThreadCreator defines the Stop() method 
-// an input port is a method (below) +        }  
-public ​int Input_Sample(string param_name) { + 
-string pn = param_name; // You may use the parameters +         // Loop sample 
-return 0; // You may return ​anything +         ​public void ThreadLoopMethod() { 
-+             ​while(run) { 
-// --- End: Input port sample --- +                 ​Thread.Sleep(1000);​ 
-// --- Start: Output port sample --- +                 ​double result; 
-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) +                     ​result = Output_Sample(123);​ 
-// --- End: Output port sample --- +                // and so on... 
-}+             ​
 +        
 + 
 +        ​// --- Start: Input port sample --- 
 +        // an input port is a method (below) 
 +        public ​void Input_Sample(string param_name) { 
 +            string pn = param_name; // You may use the parameters 
 +            // No return ​value is expected in WComp: 
 +            // results are given using events 
 +        
 +        // --- End: Input port sample --- 
 + 
 +        ​// --- Start: Output port sample --- 
 +        public delegate double Output_Sample_Signature(int param_name);​ 
 +        // 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