tag:blogger.com,1999:blog-58593231024213886642024-01-05T23:19:02.298-08:00Developer's Thoughts"My software never has bugs. It just develops random features."Fady Sedrakhttp://www.blogger.com/profile/14890884941665741827noreply@blogger.comBlogger10125tag:blogger.com,1999:blog-5859323102421388664.post-26595950961535743022009-12-26T05:45:00.000-08:002009-12-26T07:25:45.483-08:00Workflow Without Windows WorkflowHello, it has been a while since I wrote my last blog. Anyway, I am back again. I have a nice blog today, I have been working for a while with a team which his main target is to use everything Microsoft has released. It is a good thing sometimes and a very bad thing the other times. They read a "workflow" word in the requirements document, the first came to their mind was WF (Windows Workflow Foundation). The problem was so simple using WF would be over engineering. So, I decided to think of a more simple solution. As I am a Spring.NET Freak and I think we can't build an application without using it, I thought of using it :).<br />
<br />
First, Let us create a <b>State</b> class first:<br />
<br />
<div style="background: white; color: black; font-family: Courier New; font-size: 10pt;"><div style="margin: 0px;"> <span style="color: blue;">public</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">State</span><br />
</div><div style="margin: 0px;"> {<br />
</div><div style="margin: 0px;"> <span style="color: blue;">private</span> <span style="color: blue;">string</span> _id;<br />
</div><div style="margin: 0px;"> <span style="color: blue;">private</span> <span style="color: blue;">string</span> _name;<br />
</div><div style="margin: 0px;"> <span style="color: blue;">private</span> <span style="color: #2b91af;">List</span><link> _links;<br />
</div><div style="margin: 0px;"><br />
</div><div style="margin: 0px;"> <span style="color: blue;">public</span> <span style="color: #2b91af;">List</span><state> NextStates</state><br />
</div><div style="margin: 0px;"> {<br />
</div><div style="margin: 0px;"> <span style="color: blue;">get</span><br />
</div><div style="margin: 0px;"> {<br />
</div><div style="margin: 0px;"> <span style="color: blue;">return</span> Links.Select(l => l.State).ToList();<br />
</div><div style="margin: 0px;"> }<br />
</div><div style="margin: 0px;"> }<br />
</div><div style="margin: 0px;"><br />
</div><div style="margin: 0px;"> <span style="color: blue;">public</span> <span style="color: blue;">string</span> Id<br />
</div><div style="margin: 0px;"> {<br />
</div><div style="margin: 0px;"> <span style="color: blue;">get</span> { <span style="color: blue;">return</span> _id; }<br />
</div><div style="margin: 0px;"> <span style="color: blue;">set</span> { _id = <span style="color: blue;">value</span>; }<br />
</div><div style="margin: 0px;"> }<br />
</div><div style="margin: 0px;"><br />
</div><div style="margin: 0px;"> <span style="color: blue;">public</span> <span style="color: #2b91af;">List</span><link> Links<br />
</div><div style="margin: 0px;"> {<br />
</div><div style="margin: 0px;"> <span style="color: blue;">get</span> { <span style="color: blue;">return</span> _links; }<br />
</div><div style="margin: 0px;"> <span style="color: blue;">set</span> { _links = <span style="color: blue;">value</span>; }<br />
</div><div style="margin: 0px;"> }<br />
</div><div style="margin: 0px;"><br />
</div><div style="margin: 0px;"> <span style="color: blue;">public</span> <span style="color: blue;">string</span> Name<br />
</div><div style="margin: 0px;"> {<br />
</div><div style="margin: 0px;"> <span style="color: blue;">get</span> { <span style="color: blue;">return</span> _name; }<br />
</div><div style="margin: 0px;"> <span style="color: blue;">set</span> { _name = <span style="color: blue;">value</span>; }<br />
</div><div style="margin: 0px;"> }<br />
</div><div style="margin: 0px;"><br />
</div><div style="margin: 0px;"> <span style="color: blue;">public</span> <span style="color: blue;">bool</span> IsEndState<br />
</div><div style="margin: 0px;"> {<br />
</div><div style="margin: 0px;"> <span style="color: blue;">get</span><br />
</div><div style="margin: 0px;"> {<br />
</div><div style="margin: 0px;"> <span style="color: blue;">return</span> Links.Count == 0;<br />
</div><div style="margin: 0px;"> }<br />
</div><div style="margin: 0px;"> }<br />
</div><div style="margin: 0px;"> }<br />
</div></div><br />
And a <b>Link</b> class:<br />
<br />
<div style="background: white; color: black; font-family: Courier New; font-size: 10pt;"><div style="margin: 0px;"> <span style="color: blue;">public</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">Link</span><br />
</div><div style="margin: 0px;"> {<br />
</div><div style="margin: 0px;"> <span style="color: green;">//this condition will written used SPEL (Spring Expression Langauge)</span><br />
</div><div style="margin: 0px;"> <span style="color: blue;">public</span> <span style="color: blue;">string</span> Condition { <span style="color: blue;">get</span>; <span style="color: blue;">internal</span> <span style="color: blue;">set</span>; }<br />
</div><div style="margin: 0px;"> <span style="color: blue;">public</span> State State { <span style="color: blue;">get</span>; <span style="color: blue;">internal</span> <span style="color: blue;">set</span>; }<br />
</div><div style="margin: 0px;"> }<br />
</div></div><br />
Then create the interface for the state machine:<br />
<br />
<div style="background: white; color: black; font-family: Courier New; font-size: 10pt;"><div style="margin: 0px;"> <span style="color: blue;">public</span> <span style="color: blue;">interface</span> <span style="color: #2b91af;">IStateMachine</span><br />
</div><div style="margin: 0px;"> {<br />
</div><div style="margin: 0px;"> State InitialState { <span style="color: blue;">get</span>; }<br />
</div><div style="margin: 0px;"> State CurrentState { <span style="color: blue;">get</span>; }<br />
</div><div style="margin: 0px;"> <span style="color: blue;">void</span> SetCurrentState(<span style="color: blue;">string</span> id);<br />
</div><div style="margin: 0px;"> <span style="color: blue;">bool</span> Advance();<br />
</div><div style="margin: 0px;"> <span style="color: #2b91af;">List</span><state> NextStates { <span style="color: blue;">get</span>; }</state><br />
</div><div style="margin: 0px;"> }<br />
</div></div>Then comes spring to the rescue, Spring here will used for 2 main tasks:<br />
<ol><li>Configuration File for our Workflow (State Machine): Keeps the state information and the transitions between states.</li>
<li>Spring Expression will be used to define the transition rules between different states.</li>
</ol>I decided to implement a simple interview process as an illustration for my small framework:<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgLSGfEwzglsvoQ37B7GJiW1YIkv5nAm94GPnVRvb67kUDgNv853Zhy-GZ09i-8EdhlWOE5G2yhKkSWh890-JEPt45JjSJT83yTFTQRzKXIGhX2XAnLEmmZXSXRRVu5ujLO0HL11QYRF2A/s1600-h/Wokflow.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgLSGfEwzglsvoQ37B7GJiW1YIkv5nAm94GPnVRvb67kUDgNv853Zhy-GZ09i-8EdhlWOE5G2yhKkSWh890-JEPt45JjSJT83yTFTQRzKXIGhX2XAnLEmmZXSXRRVu5ujLO0HL11QYRF2A/s640/Wokflow.png" /></a><br />
</div>The spring configuration file for the mentioned process will be as follows:<br />
<br />
<div style="background: white; color: black; font-family: Courier New; font-size: 10pt;"><div style="margin: 0px;"><span style="color: blue;"><span style="color: #a31515;"><span style="color: blue;"><</span>xml</span><span style="color: blue;"> </span><span style="color: red;">version</span><span style="color: blue;">=</span>"<span style="color: blue;">1.0</span>"<span style="color: blue;"> </span><span style="color: red;">encoding</span><span style="color: blue;">=</span>"<span style="color: blue;">utf-8</span>"<span style="color: blue;"> ?></span></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"><</span><span style="color: #a31515;">objects</span><span style="color: blue;"> </span><span style="color: red;">xmlns</span><span style="color: blue;">=</span>"<span style="color: blue;">http://www.springframework.net</span>"<span style="color: blue;">></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> </span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <</span><span style="color: #a31515;">object</span><span style="color: blue;"> </span><span style="color: red;">id</span><span style="color: blue;">=</span>"<span style="color: blue;">ExamToFirstInterview</span>"<span style="color: blue;"> </span><span style="color: red;">type</span><span style="color: blue;">=</span>"<span style="color: blue;">SimpleStateMachine.Link, SimpleStateMachine</span>"<span style="color: blue;">></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <</span><span style="color: #a31515;">property</span><span style="color: blue;"> </span><span style="color: red;">name</span><span style="color: blue;">=</span>"<span style="color: blue;">Condition</span>"<span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">ExamScore >= 25</span>"<span style="color: blue;">/></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <</span><span style="color: #a31515;">property</span><span style="color: blue;"> </span><span style="color: red;">name</span><span style="color: blue;">=</span>"<span style="color: blue;">State</span>"<span style="color: blue;"> </span><span style="color: red;">ref</span><span style="color: blue;">=</span>"<span style="color: blue;">FirstInterview</span>"<span style="color: blue;"> /></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <<span style="color: black;"><span style="color: #a31515;">object</span><span style="color: blue;">></span></span></span><br />
</div><div style="margin: 0px;"><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <</span><span style="color: #a31515;">object</span><span style="color: blue;"> </span><span style="color: red;">id</span><span style="color: blue;">=</span>"<span style="color: blue;">ExamToRejected</span>"<span style="color: blue;"> </span><span style="color: red;">type</span><span style="color: blue;">=</span>"<span style="color: blue;">SimpleStateMachine.Link, SimpleStateMachine</span>"<span style="color: blue;">></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <</span><span style="color: #a31515;">property</span><span style="color: blue;"> </span><span style="color: red;">name</span><span style="color: blue;">=</span>"<span style="color: blue;">Condition</span>"<span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">ExamScore </span><span style="color: red;"><</span><span style="color: blue;"> 25</span>"<span style="color: blue;">/></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <</span><span style="color: #a31515;">property</span><span style="color: blue;"> </span><span style="color: red;">name</span><span style="color: blue;">=</span>"<span style="color: blue;">State</span>"<span style="color: blue;"> </span><span style="color: red;">ref</span><span style="color: blue;">=</span>"<span style="color: blue;">Rejected</span>"<span style="color: blue;"> /></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <<span style="color: black;"><span style="color: #a31515;">object</span><span style="color: blue;">></span></span></span><br />
</div><div style="margin: 0px;"><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <</span><span style="color: #a31515;">object</span><span style="color: blue;"> </span><span style="color: red;">id</span><span style="color: blue;">=</span>"<span style="color: blue;">FirstInterviewToSecondInterview</span>"<span style="color: blue;"> </span><span style="color: red;">type</span><span style="color: blue;">=</span>"<span style="color: blue;">SimpleStateMachine.Link, SimpleStateMachine</span>"<span style="color: blue;">></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <</span><span style="color: #a31515;">property</span><span style="color: blue;"> </span><span style="color: red;">name</span><span style="color: blue;">=</span>"<span style="color: blue;">Condition</span>"<span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">FirstInterviewAccepted</span>"<span style="color: blue;">/></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <</span><span style="color: #a31515;">property</span><span style="color: blue;"> </span><span style="color: red;">name</span><span style="color: blue;">=</span>"<span style="color: blue;">State</span>"<span style="color: blue;"> </span><span style="color: red;">ref</span><span style="color: blue;">=</span>"<span style="color: blue;">SecondInterview</span>"<span style="color: blue;"> /></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <<span style="color: black;"><span style="color: #a31515;">object</span><span style="color: blue;">></span></span></span><br />
<br />
</div><div style="margin: 0px;"><span style="color: blue;"> <</span><span style="color: #a31515;">object</span><span style="color: blue;"> </span><span style="color: red;">id</span><span style="color: blue;">=</span>"<span style="color: blue;">FirstInterviewToRejected</span>"<span style="color: blue;"> </span><span style="color: red;">type</span><span style="color: blue;">=</span>"<span style="color: blue;">SimpleStateMachine.Link, SimpleStateMachine</span>"<span style="color: blue;">></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <</span><span style="color: #a31515;">property</span><span style="color: blue;"> </span><span style="color: red;">name</span><span style="color: blue;">=</span>"<span style="color: blue;">Condition</span>"<span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">!FirstInterviewAccepted</span>"<span style="color: blue;">/></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <</span><span style="color: #a31515;">property</span><span style="color: blue;"> </span><span style="color: red;">name</span><span style="color: blue;">=</span>"<span style="color: blue;">State</span>"<span style="color: blue;"> </span><span style="color: red;">ref</span><span style="color: blue;">=</span>"<span style="color: blue;">Rejected</span>"<span style="color: blue;"> /></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <<span style="color: black;"><span style="color: #a31515;">object</span><span style="color: blue;">></span></span></span><br />
<br />
</div><div style="margin: 0px;"><span style="color: blue;"> <</span><span style="color: #a31515;">object</span><span style="color: blue;"> </span><span style="color: red;">id</span><span style="color: blue;">=</span>"<span style="color: blue;">SecondInterviewToAccepted</span>"<span style="color: blue;"> </span><span style="color: red;">type</span><span style="color: blue;">=</span>"<span style="color: blue;">SimpleStateMachine.Link, SimpleStateMachine</span>"<span style="color: blue;">></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <</span><span style="color: #a31515;">property</span><span style="color: blue;"> </span><span style="color: red;">name</span><span style="color: blue;">=</span>"<span style="color: blue;">Condition</span>"<span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">SecondInterviewAccepted</span>"<span style="color: blue;">/></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <</span><span style="color: #a31515;">property</span><span style="color: blue;"> </span><span style="color: red;">name</span><span style="color: blue;">=</span>"<span style="color: blue;">State</span>"<span style="color: blue;"> </span><span style="color: red;">ref</span><span style="color: blue;">=</span>"<span style="color: blue;">Accepted</span>"<span style="color: blue;"> /></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <<span style="color: black;"><span style="color: #a31515;">object</span><span style="color: blue;">></span></span></span><br />
<br />
</div><div style="margin: 0px;"><span style="color: blue;"> <</span><span style="color: #a31515;">object</span><span style="color: blue;"> </span><span style="color: red;">id</span><span style="color: blue;">=</span>"<span style="color: blue;">SecondInterviewToRejected</span>"<span style="color: blue;"> </span><span style="color: red;">type</span><span style="color: blue;">=</span>"<span style="color: blue;">SimpleStateMachine.Link, SimpleStateMachine</span>"<span style="color: blue;">></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <</span><span style="color: #a31515;">property</span><span style="color: blue;"> </span><span style="color: red;">name</span><span style="color: blue;">=</span>"<span style="color: blue;">Condition</span>"<span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">!SecondInterviewAccepted</span>"<span style="color: blue;">/></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <</span><span style="color: #a31515;">property</span><span style="color: blue;"> </span><span style="color: red;">name</span><span style="color: blue;">=</span>"<span style="color: blue;">State</span>"<span style="color: blue;"> </span><span style="color: red;">ref</span><span style="color: blue;">=</span>"<span style="color: blue;">Rejected</span>"<span style="color: blue;"> /></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <<span style="color: black;"><span style="color: #a31515;">object</span><span style="color: blue;">></span></span></span><br />
<br />
</div><div style="margin: 0px;"><span style="color: blue;"> <</span><span style="color: #a31515;">object</span><span style="color: blue;"> </span><span style="color: red;">id</span><span style="color: blue;">=</span>"<span style="color: blue;">Exam</span>"<span style="color: blue;"> </span><span style="color: red;">type</span><span style="color: blue;">=</span>"<span style="color: blue;">SimpleStateMachine.State, SimpleStateMachine</span>"<span style="color: blue;">></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <</span><span style="color: #a31515;">property</span><span style="color: blue;"> </span><span style="color: red;">name</span><span style="color: blue;">=</span>"<span style="color: blue;">Id</span>"<span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">exam</span>"<span style="color: blue;">/></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <</span><span style="color: #a31515;">property</span><span style="color: blue;"> </span><span style="color: red;">name</span><span style="color: blue;">=</span>"<span style="color: blue;">Name</span>"<span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">Exam</span>"<span style="color: blue;">/></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <</span><span style="color: #a31515;">property</span><span style="color: blue;"> </span><span style="color: red;">name</span><span style="color: blue;">=</span>"<span style="color: blue;">Links</span>"<span style="color: blue;">></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <</span><span style="color: #a31515;">list</span><span style="color: blue;"> </span><span style="color: red;">element-type</span><span style="color: blue;">=</span>"<span style="color: blue;">SimpleStateMachine.Link, SimpleStateMachine</span>"<span style="color: blue;">></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <</span><span style="color: #a31515;">ref</span><span style="color: blue;"> </span><span style="color: red;">object</span><span style="color: blue;">=</span>"<span style="color: blue;">ExamToFirstInterview</span>"<span style="color: blue;">/></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <</span><span style="color: #a31515;">ref</span><span style="color: blue;"> </span><span style="color: red;">object</span><span style="color: blue;">=</span>"<span style="color: blue;">ExamToRejected</span>"<span style="color: blue;">/></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <<span style="color: black;"><span style="color: #a31515;">list</span><span style="color: blue;">></span></span></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <<span style="color: black;"><span style="color: #a31515;">property</span><span style="color: blue;">></span></span></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <<span style="color: black;"><span style="color: #a31515;">object</span><span style="color: blue;">></span></span></span><br />
</div><div style="margin: 0px;"><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <</span><span style="color: #a31515;">object</span><span style="color: blue;"> </span><span style="color: red;">id</span><span style="color: blue;">=</span>"<span style="color: blue;">FirstInterview</span>"<span style="color: blue;"> </span><span style="color: red;">type</span><span style="color: blue;">=</span>"<span style="color: blue;">SimpleStateMachine.State, SimpleStateMachine</span>"<span style="color: blue;">></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <</span><span style="color: #a31515;">property</span><span style="color: blue;"> </span><span style="color: red;">name</span><span style="color: blue;">=</span>"<span style="color: blue;">Id</span>"<span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">first_interview</span>"<span style="color: blue;">/></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <</span><span style="color: #a31515;">property</span><span style="color: blue;"> </span><span style="color: red;">name</span><span style="color: blue;">=</span>"<span style="color: blue;">Name</span>"<span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">First Interview</span>"<span style="color: blue;">/></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <</span><span style="color: #a31515;">property</span><span style="color: blue;"> </span><span style="color: red;">name</span><span style="color: blue;">=</span>"<span style="color: blue;">Links</span>"<span style="color: blue;">></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <</span><span style="color: #a31515;">list</span><span style="color: blue;"> </span><span style="color: red;">element-type</span><span style="color: blue;">=</span>"<span style="color: blue;">SimpleStateMachine.Link, SimpleStateMachine</span>"<span style="color: blue;">></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <</span><span style="color: #a31515;">ref</span><span style="color: blue;"> </span><span style="color: red;">object</span><span style="color: blue;">=</span>"<span style="color: blue;">FirstInterviewToSecondInterview</span>"<span style="color: blue;">/></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <</span><span style="color: #a31515;">ref</span><span style="color: blue;"> </span><span style="color: red;">object</span><span style="color: blue;">=</span>"<span style="color: blue;">FirstInterviewToRejected</span>"<span style="color: blue;">/></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <<span style="color: black;"><span style="color: #a31515;">list</span><span style="color: blue;">></span></span></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <<span style="color: black;"><span style="color: #a31515;">property</span><span style="color: blue;">></span></span></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <<span style="color: black;"><span style="color: #a31515;">object</span><span style="color: blue;">></span></span></span><br />
</div><div style="margin: 0px;"><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <</span><span style="color: #a31515;">object</span><span style="color: blue;"> </span><span style="color: red;">id</span><span style="color: blue;">=</span>"<span style="color: blue;">SecondInterview</span>"<span style="color: blue;"> </span><span style="color: red;">type</span><span style="color: blue;">=</span>"<span style="color: blue;">SimpleStateMachine.State, SimpleStateMachine</span>"<span style="color: blue;">></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <</span><span style="color: #a31515;">property</span><span style="color: blue;"> </span><span style="color: red;">name</span><span style="color: blue;">=</span>"<span style="color: blue;">Id</span>"<span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">second_interview</span>"<span style="color: blue;">/></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <</span><span style="color: #a31515;">property</span><span style="color: blue;"> </span><span style="color: red;">name</span><span style="color: blue;">=</span>"<span style="color: blue;">Name</span>"<span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">Second Interview</span>"<span style="color: blue;">/></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <</span><span style="color: #a31515;">property</span><span style="color: blue;"> </span><span style="color: red;">name</span><span style="color: blue;">=</span>"<span style="color: blue;">Links</span>"<span style="color: blue;">></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <</span><span style="color: #a31515;">list</span><span style="color: blue;"> </span><span style="color: red;">element-type</span><span style="color: blue;">=</span>"<span style="color: blue;">SimpleStateMachine.Link, SimpleStateMachine</span>"<span style="color: blue;">></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <</span><span style="color: #a31515;">ref</span><span style="color: blue;"> </span><span style="color: red;">object</span><span style="color: blue;">=</span>"<span style="color: blue;">SecondInterviewToAccepted</span>"<span style="color: blue;">/></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <</span><span style="color: #a31515;">ref</span><span style="color: blue;"> </span><span style="color: red;">object</span><span style="color: blue;">=</span>"<span style="color: blue;">SecondInterviewToRejected</span>"<span style="color: blue;">/></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <<span style="color: black;"><span style="color: #a31515;">list</span><span style="color: blue;">></span></span></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <<span style="color: black;"><span style="color: #a31515;">property</span><span style="color: blue;">></span></span></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <<span style="color: black;"><span style="color: #a31515;">object</span><span style="color: blue;">></span></span></span><br />
</div><div style="margin: 0px;"><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <</span><span style="color: #a31515;">object</span><span style="color: blue;"> </span><span style="color: red;">id</span><span style="color: blue;">=</span>"<span style="color: blue;">Accepted</span>"<span style="color: blue;"> </span><span style="color: red;">type</span><span style="color: blue;">=</span>"<span style="color: blue;">SimpleStateMachine.State, SimpleStateMachine</span>"<span style="color: blue;">></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <</span><span style="color: #a31515;">property</span><span style="color: blue;"> </span><span style="color: red;">name</span><span style="color: blue;">=</span>"<span style="color: blue;">Id</span>"<span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">accepted</span>"<span style="color: blue;">/></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <</span><span style="color: #a31515;">property</span><span style="color: blue;"> </span><span style="color: red;">name</span><span style="color: blue;">=</span>"<span style="color: blue;">Name</span>"<span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">Accepted</span>"<span style="color: blue;">/></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <</span><span style="color: #a31515;">property</span><span style="color: blue;"> </span><span style="color: red;">name</span><span style="color: blue;">=</span>"<span style="color: blue;">Links</span>"<span style="color: blue;">></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <</span><span style="color: #a31515;">list</span><span style="color: blue;"> </span><span style="color: red;">element-type</span><span style="color: blue;">=</span>"<span style="color: blue;">SimpleStateMachine.Link, SimpleStateMachine</span>"<span style="color: blue;">></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <<span style="color: black;"><span style="color: #a31515;">list</span><span style="color: blue;">></span></span></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <<span style="color: black;"><span style="color: #a31515;">property</span><span style="color: blue;">></span></span></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <<span style="color: black;"><span style="color: #a31515;">object</span><span style="color: blue;">></span></span></span><br />
</div><div style="margin: 0px;"><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <</span><span style="color: #a31515;">object</span><span style="color: blue;"> </span><span style="color: red;">id</span><span style="color: blue;">=</span>"<span style="color: blue;">Rejected</span>"<span style="color: blue;"> </span><span style="color: red;">type</span><span style="color: blue;">=</span>"<span style="color: blue;">SimpleStateMachine.State, SimpleStateMachine</span>"<span style="color: blue;">></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <</span><span style="color: #a31515;">property</span><span style="color: blue;"> </span><span style="color: red;">name</span><span style="color: blue;">=</span>"<span style="color: blue;">Id</span>"<span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">rejected</span>"<span style="color: blue;">/></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <</span><span style="color: #a31515;">property</span><span style="color: blue;"> </span><span style="color: red;">name</span><span style="color: blue;">=</span>"<span style="color: blue;">Name</span>"<span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">Rejected</span>"<span style="color: blue;">/></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <</span><span style="color: #a31515;">property</span><span style="color: blue;"> </span><span style="color: red;">name</span><span style="color: blue;">=</span>"<span style="color: blue;">Links</span>"<span style="color: blue;">></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <</span><span style="color: #a31515;">list</span><span style="color: blue;"> </span><span style="color: red;">element-type</span><span style="color: blue;">=</span>"<span style="color: blue;">SimpleStateMachine.Link, SimpleStateMachine</span>"<span style="color: blue;">></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <<span style="color: black;"><span style="color: #a31515;">list</span><span style="color: blue;">></span></span></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <<span style="color: black;"><span style="color: #a31515;">property</span><span style="color: blue;">></span></span></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <<span style="color: black;"><span style="color: #a31515;">object</span><span style="color: blue;">></span></span></span><br />
<span style="color: blue;"><span style="color: black;"><br />
</span></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <</span><span style="color: #a31515;">object</span><span style="color: blue;"> </span><span style="color: red;">id</span><span style="color: blue;">=</span>"<span style="color: blue;">InterviewProcess.InterviewStateMachine</span>"<span style="color: blue;"> </span><span style="color: red;">type</span><span style="color: blue;">=</span>"<span style="color: blue;">InterviewProcess.InterviewStateMachine, InterviewProcess</span>"<span style="color: blue;">></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <</span><span style="color: #a31515;">property</span><span style="color: blue;"> </span><span style="color: red;">name</span><span style="color: blue;">=</span>"<span style="color: blue;">AllStates</span>"<span style="color: blue;">></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <</span><span style="color: #a31515;">list</span><span style="color: blue;"> </span><span style="color: red;">element-type</span><span style="color: blue;">=</span>"<span style="color: blue;">SimpleStateMachine.State, SimpleStateMachine</span>"<span style="color: blue;">></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <</span><span style="color: #a31515;">ref</span><span style="color: blue;"> </span><span style="color: red;">object</span><span style="color: blue;">=</span>"<span style="color: blue;">Exam</span>"<span style="color: blue;">/></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <</span><span style="color: #a31515;">ref</span><span style="color: blue;"> </span><span style="color: red;">object</span><span style="color: blue;">=</span>"<span style="color: blue;">FirstInterview</span>"<span style="color: blue;">/></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <</span><span style="color: #a31515;">ref</span><span style="color: blue;"> </span><span style="color: red;">object</span><span style="color: blue;">=</span>"<span style="color: blue;">SecondInterview</span>"<span style="color: blue;">/></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <</span><span style="color: #a31515;">ref</span><span style="color: blue;"> </span><span style="color: red;">object</span><span style="color: blue;">=</span>"<span style="color: blue;">Accepted</span>"<span style="color: blue;">/></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <</span><span style="color: #a31515;">ref</span><span style="color: blue;"> </span><span style="color: red;">object</span><span style="color: blue;">=</span>"<span style="color: blue;">Rejected</span>"<span style="color: blue;">/></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <<span style="color: black;"><span style="color: #a31515;">list</span><span style="color: blue;">></span></span></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <<span style="color: black;"><span style="color: #a31515;">property</span><span style="color: blue;">></span></span></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <</span><span style="color: #a31515;">property</span><span style="color: blue;"> </span><span style="color: red;">name</span><span style="color: blue;">=</span>"<span style="color: blue;">InitialState</span>"<span style="color: blue;"> </span><span style="color: red;">ref</span><span style="color: blue;">=</span>"<span style="color: blue;">Exam</span>"<span style="color: blue;">/></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <<span style="color: black;"><span style="color: #a31515;">object</span><span style="color: blue;">></span></span></span><br />
</div><div style="margin: 0px;"><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <</span><span style="color: #a31515;">object</span><span style="color: blue;"> </span><span style="color: red;">id</span><span style="color: blue;">=</span>"<span style="color: blue;">SimpleStateMachine.IStateMachineManager</span>"<span style="color: blue;"> </span><span style="color: red;">type</span><span style="color: blue;">=</span>"<span style="color: blue;">SimpleStateMachine.StateMachineManager, SimpleStateMachine</span>"<span style="color: blue;">></span><br />
</div><div style="margin: 0px;"><span style="color: blue;"> <<span style="color: black;"><span style="color: #a31515;">object</span><span style="color: blue;">></span></span></span><br />
<br />
</div><div style="margin: 0px;"><span style="color: blue;"></span><span style="color: #a31515;"><span style="color: blue;"><</span>objects</span><span style="color: blue;">></span><br />
<span style="color: blue;"><br />
</span><br />
</div></div>Quite Simple? I think so :) Let us try it.<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgcHVN_nXieePJF1r50BNyvrHSUj4qOcKQoC0FwPZ8-Leir1Bf0EAelzKs7G3EcVnpxsSMu40H0XjJX_4vyYiLKrV8eBxk8vc_RMDJvSmdMeR072mPxa7Be88heNlk8uv-qC5dKchc6wO8/s1600-h/Console.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgcHVN_nXieePJF1r50BNyvrHSUj4qOcKQoC0FwPZ8-Leir1Bf0EAelzKs7G3EcVnpxsSMu40H0XjJX_4vyYiLKrV8eBxk8vc_RMDJvSmdMeR072mPxa7Be88heNlk8uv-qC5dKchc6wO8/s640/Console.png" /></a><br />
</div><br />
At the end I am not saying that this a replacement for windows workflow foundation is a very powerful framework but I am only pushing people to think outside of the box.<br />
<br />
You can refer to the full source code <a href="http://fadykamal.googlepages.com/StateMachineNoWF.rar">here</a> and don't forgot that I used Visual Studio 2010 Beta 2. Good Luck!<br />
<br />
The initials of my blog are WWWW, isn't this cool? :D ... maybe this will be the next WWW ;).Fady Sedrakhttp://www.blogger.com/profile/14890884941665741827noreply@blogger.com2tag:blogger.com,1999:blog-5859323102421388664.post-71239601560643296722009-05-08T12:31:00.000-07:002009-05-14T22:03:14.350-07:00Using WCF and Spring.NET to Scale Your Architecture<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi-pBFzGgO_hxHa3w6jyymanJ9M1xu8GhSKOzuY_l1Ln4EqUmrYiekMv5mfXLk_LN7jsQ2eJWxUHfCof92jxtNNu-5ksPHLQjoE5wX_2fiPfeuO8xdmXNxLoF7OveFMZm0FohsFW4sKadw/s1600-h/1server.JPG"></a>Windows Communication Foundation (WCF) is more than just web services. Most of the .NET developers think of it as a replacement for old ASMX web services. Today I am going to show you how I am going use it in a different way. I am going to use it to distribute different components of a system to be run separately on different machines without re-compilation of your code. You can do this based on your needs and the hardware available.<br /><p>First, Let us define the problem we are trying to solve. Assume that you are working on an application that part of its logic is to compute a complex operation. This operation can not be simplified and it consumes most of the application time. Your default deployment will be as following:</p><p><span class="Apple-style-span" style="color: rgb(0, 0, 238); "><br /><img src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi-pBFzGgO_hxHa3w6jyymanJ9M1xu8GhSKOzuY_l1Ln4EqUmrYiekMv5mfXLk_LN7jsQ2eJWxUHfCof92jxtNNu-5ksPHLQjoE5wX_2fiPfeuO8xdmXNxLoF7OveFMZm0FohsFW4sKadw/s320/1server.JPG" border="0" alt="" id="BLOGGER_PHOTO_ID_5335910529748705618" style="display: block; margin-top: 0px; margin-right: auto; margin-bottom: 10px; margin-left: auto; text-align: center; cursor: pointer; width: 320px; height: 179px; " /><div style="text-align: left;"><span class="Apple-style-span" style="color: rgb(0, 0, 0); ">This deployment model will introduce a bottleneck to your application. What I have in mind is to deploy the application on a server and the complex component on another one. This way you can distribute the processing across your servers. Then the deployment will be as following:</span><br /></div></span></p><p><span class="Apple-style-span" style="color: rgb(0, 0, 238);"><br /><img src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiBy2vqd5Du0Kg1XzAeIVegONXZZsIhyhpSokekyQ0N8q0NxmSzbtSZHWpCzfdmJmsCZiWHZDmWxI6qtu5ZEBgpvGU0waEAC0DU5ZdnszxjjdZE1SoFGXwdm3J8z7IQf3Pv1frMuTDzeIY/s400/2servers.JPG" border="0" alt="" id="BLOGGER_PHOTO_ID_5335910378434072226" style="display: block; margin-top: 0px; margin-right: auto; margin-bottom: 10px; margin-left: auto; text-align: center; cursor: pointer; width: 400px; height: 105px; " /></span></p><p>Let us see a simple example for the implementation of the following components. This our service contract:</p><p>[<span style="color:#2b91af;">ServiceContract</span>]</p><div style=" background: white; font-family:courier new;font-size:10pt;color:black;"><p style="margin: 0px"><span style="color:blue;">public</span> <span style="color:blue;">interface</span> <span style="color:#2b91af;">ICalcEngine</span></p><p style="margin: 0px">{</p><p style="margin: 0px"> [<span style="color:#2b91af;">OperationContract</span>]</p><br /><p style="margin: 0px"> <span style="color:#2b91af;">Operation</span> CalculateOperation(<span style="color:#2b91af;">Operation</span> operation);</p><p style="margin: 0px">}</p></div><p>We will use spring to load your component hosted in memory as mentioned in the first deployment model.</p><div style=" background: white; font-family:courier new;font-size:10pt;color:black;"><p style="margin: 0px"><span style="color:blue;"> <</span><span style="color:#a31515;">object</span><span style="color:blue;"> </span><span style="color:red;">name</span><span style="color:blue;">=</span>"<span style="color:blue;">CalcEngineWCF.ICalcEngine</span>"<span style="color:blue;"> </span></p><p style="margin: 0px"><span style="color:blue;"> </span><span style="color:red;">type</span><span style="color:blue;">=</span>"<span style="color:blue;">CalcEngineWCF.CalcEngine, CalcEngineWCF</span>"<span style="color:blue;">/></span></p></div><p>My proposed solution will allow you change the deployment model without changing a line of code in your application as mentioned in the second deployment model. You will deploy your complex component as a service on a remote host. In this case spring configuration in the client side (the main application server) will be as following:</p><div style=" background: white; font-family:courier new;font-size:10pt;color:black;"><p style="margin: 0px"><span style="color:blue;"> <</span><span style="color:#a31515;">object</span><span style="color:blue;"> </span><span style="color:red;">name</span><span style="color:blue;">=</span>"<span style="color:blue;">CalcEngineWCF.CalcEngineFactory</span>"</p><p style="margin: 0px"><span style="color:blue;"> </span><span style="color:red;">type</span><span style="color:blue;">=</span>"<span style="color:blue;">CalcEngineWCF.CalcEngineFactory, CalcEngineWCF</span>"<span style="color:blue;">></span></p><p style="margin: 0px"><span style="color:blue;"> <</span><span style="color:#a31515;">property</span><span style="color:blue;"> </span><span style="color:red;">name</span><span style="color:blue;">=</span>"<span style="color:blue;">Address</span>"<span style="color:blue;"> </span><span style="color:red;">value</span><span style="color:blue;">=</span>"<span style="color:blue;"><a href="http://remote-server:8000/CalcEngine/Service%22/">http://remote-server:8000/CalcEngine/Service</a>"<span style="color:blue;">/</span>></span></p><p style="margin: 0px"><span style="color:blue;"> </</span><span style="color:#a31515;">object</span><span style="color:blue;">></span></p><p style="margin: 0px"><span class="Apple-style-span" style="color: rgb(0, 0, 255);"><br /></span></p><p style="margin: 0px"><span style="color:blue;"> <</span><span style="color:#a31515;">object</span><span style="color:blue;"> </span><span style="color:red;">name</span><span style="color:blue;">=</span>"<span style="color:blue;">CalcEngineWCF.ICalcEngine</span>"</p><p style="margin: 0px"><span style="color:blue;"> </span><span style="color:red;">type</span><span style="color:blue;">=</span>"<span style="color:blue;">CalcEngineWCF.CalcEngine, CalcEngineWCF</span>"</p><p style="margin: 0px"><span style="color:blue;"> </span><span style="color:red;">factory-method</span><span style="color:blue;">=</span>"<span style="color:blue;">CreateWCFInstance</span>"</p><p style="margin: 0px"><span style="color:blue;"> </span><span style="color:red;">factory-object</span><span style="color:blue;">=</span>"<span style="color:blue;">CalcEngineWCF.CalcEngineFactory</span>"<span style="color:blue;">/></span></p></div><p>I hope this will be clear enough for you to be able to apply this model in your applications.</p><p>You can also refer to a working example <a href="http://fadykamal.googlepages.com/CalcEngineWCF.zip">here</a>. The mentioned solution contains 3 projects:</p><ol><li>CalcEngineWCF: Our complex component that needs to be distributed. </li><li>WCFHost: Remote application that will host CalcEngineWCF. </li><li>WCFClient: The main application server. Its name might be confusing because it acts as a client to the remote host. </li><br /></ol>Fady Sedrakhttp://www.blogger.com/profile/14890884941665741827noreply@blogger.com2tag:blogger.com,1999:blog-5859323102421388664.post-6060659764412807852008-04-04T16:49:00.000-07:002008-12-08T14:03:29.752-08:00Steganography in C#<span style="font-family:verdana;">It has been a while since I wrote my last blog, but anyway I am back again. I am going to talk today about Steganography using C#. </span><br /><br /><span style="font-family:verdana;">Well let us define Steganography first. According to Wikipedia:<br />“</span><a href="http://en.wikipedia.org/wiki/Steganography"><span style="font-family:verdana;">Steganography</span></a><span style="font-family:verdana;"> is the art and science of writing hidden messages in such a way that no one apart from the sender and intended recipient even realizes there is a hidden message. By contrast, cryptography obscures the meaning of a message, but it does not conceal the fact that there is a message.”</span><br /><span style="font-family:Verdana;"></span><br /><span style="font-family:verdana;">So it is all about information hiding, today I will not get into the different techniques of steganography . I will just talk about one of my project that I used steganography in it.</span><br /><span style="font-family:verdana;">It was required to implement an application that will be able to sign files digital using the RSA Algorithm.</span><br /><br /><br /><p><span style="font-family:verdana;">The application provides some features and they are listed as follows:</span></p><p><span style="font-family:verdana;">1. Signing Files: Files can be signed and store the signature inside it or in another separate file<br />2. Signing Wave Files: The application signs wave files by signing the header of the file and then store and hide this information inside the wave file</span></p><p><span style="font-family:verdana;">The operation of the file signing is divided into three states:<br /><strong>1. Hashing:</strong><br />In this operation we read the data that is going to be hashed. Depending on the hash function provided by the framework, you can hash the data in order to be ready for the next step.<br /></p></span><span style="font-family:verdana;"><p></span></p><span style="font-family:verdana;"><img id="BLOGGER_PHOTO_ID_5191783393331720130" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjLVq48B6G2KRxx-bO9DAsvEAhopx91Wrei90V8l-FPH3A7flg4VB_lP7T8BGNSKgLJ1jENHVO7QycEqGedWNyDgWcnnAT_sMhIw82xUgdna6-cj8uGy6xROY7chOs4BVADsZAYIOJFgF0/s400/Hash.JPG" border="0" /> <strong>2. Signing:<br /></strong>In this operation we are going to sign the data received from the previous step. All we have to do is to encrypt the provided data using the private key of the user.<br /><img id="BLOGGER_PHOTO_ID_5191785175743148018" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjL6EZlkBq0jqVgXn3H9leHm5xwmNzd9yjTAjRy0nWv4hN4GNilTG2DdSgJwfYNNANJKftdIKTxT7rgHa1eHKCIYYm2IsY9ePPMjvNYFhRX_Lcn38151R_WkRH9QZIHwDORDybsGPh0QgI/s400/Sign.JPG" border="0" /></span><p><span style="font-family:verdana;">Here is the method I used to sign the data:<br /><br /><span style="font-family:courier new;">public <span style="color:#3366ff;">byte[]</span> SignData(<span style="color:#3366ff;">string</span> data, HashType hashType)<br />{<br />HashWrapper hasher = <span style="color:#3366ff;">new</span> HashWrapper(hashType);<br /><span style="color:#3366ff;">byte[]</span> bytesArraySignedValue = rsa.SignData(HelperFunctions.ConvertStringToByteArray(data), hasher.GetHasher());</span></span></p><p><span style="font-family:courier new;">SignedValue = HelperFunctions.ConvertByteArrayToHexString(bytesArraySignedValue);</span></p><p><span style="font-family:courier new;"><span style="color:#3366ff;">return</span> bytesArraySignedValue;<br />}</span></p><p><span style="font-family:verdana;"><strong>3. Verification:<br /></strong>In this step we are going to verify the signature. In order to do that we have to hash data and keep the digest, then decrypt the signature using the public key. Both should match in order to be a valid signature. </span></p><p><span style="font-family:verdana;">Here is the method I used to verify the signed data:</span></p><p><span style="font-family:courier new;">public <span style="color:#3366ff;">bool</span> VerifySignedData(<span style="color:#3366ff;">string</span> data, HashType hashType, byte[] signature)<br />{<br />HashWrapper hasher = <span style="color:#3366ff;">new</span> HashWrapper(hashType);<br /><span style="color:#3366ff;">return</span> rsa.VerifyData(HelperFunctions.ConvertStringToByteArray(data), hasher.GetHasher(), signature);<br />}</span></p><p><span style="font-family:verdana;">It seems that Microsoft has done all the work for you ;)</span></p><p><span style="font-family:Verdana;"></span> </p><p><span style="font-family:verdana;">I will give you a breif about reading wave files in C#, For more information regarding reading wave files format please refer to the following <a href="http://ccrma.stanford.edu/courses/422/projects/WaveFormat">link</a>. The WAVE file format is a subset of Microsoft's RIFF specification for the storage of multimedia files. A RIFF file starts out with a file header followed by a sequence of data chunks. A WAVE file is often just a RIFF file with a single "WAVE" chunk which consists of two sub-chunks -- a "fmt " chunk specifying the data format and a "data" chunk containing the actual sample data.<br /></span><img id="BLOGGER_PHOTO_ID_5191786683276668930" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEijq6Kosg3VClo2-s_1rbEgsLos8laTUbEThZ-J6Dlz-9Ia7Jg7-otM7uSNRj9_sgf5vuQTRbVyk18_dgxZ1BjduBtmgH_MR0yQ01F84db4Ei5YTFWHhgNvUYFK9TccUiqLpoqLGCyfk6A/s400/WAVE.JPG" border="0" /><span style="font-family:verdana;"><strong>Signing Wave Files:</strong><br />I used a new idea by signing wave files. Signing wav files operations is similar to signing a normal file. First, we have to calculate the signature of the input file but instead of calculating the digest for the whole file. We will calculate the digest for the header only. Then encrypt this hash using the private key. The only difference is the storing operation. We will store the signature bits, by changing the least significant bit in all the wave samples according to the signature bits. This bit won’t make a difference in the sound of the file and we will have the digitally signed.<br /><br /><strong>Application Logical Design: </strong></span><br /></p><br /><p><span style="font-family:verdana;"><strong><img id="BLOGGER_PHOTO_ID_5191788594537115666" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEihsgnJHQkiXrL284qnv9vcCXOgSM95onY8tNlehCHicJHhXMvMHfPHngSHMTk3miK3y75j-ujKz6pb-ROIreJAWiXOStjHHGDEhZRs1-iWHUAx3gnBrLFFU5vX4UcEGh6NpaMfChOIedw/s400/Design.JPG" border="0" /><br /></strong></span><span style="font-family:verdana;"><em>*Logging Module:</em> This module is responsible for the logging functionality across all the application<br /><em>*Helper Classes:</em> This module includes some common functionalities like handling the bit manipulation using the c# language<br /><em>*Wave File Module:</em> This module is responsible for handling the wave operations: Reading wave binary data, writing a new wave file and signing the wave files<br /><em>*RSA Wrapper:</em> This module wraps the functionality of the RSA algorithm. It facilitates the using of encryption depending on the application logic<br /><em>*Hash Wrapper:</em> This module is responsible for wrapping the hash algorithm. It uses the hash service providers available through the dot net framework<br /><em>*Presentation Layer:</em> This module is responsible for handling the UI functionalities across all the application</span></p><p><span style="font-family:verdana;"><br /></p></span><p><span style="font-family:verdana;">I used Visual C# 2005 to implement this application. I am sharing the source code, I hope it could be helpful. You can find it <a href="http://fadykamal.googlepages.com/DigitalSigner.zip">here</a>. Pleas let me know your feedback.</span> </p><p><br /> </p><img id="BLOGGER_PHOTO_ID_5191807913300013090" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg1UO3anhwFxQ4UVKA-IKeNXeBLovWxFFkUlcfWnjFz3NuLs-5d1Tcc6tqqKi8ES9BDi8Qi2Go_RPxcJnSrqZWkk-XMLECga75kyK97sBBYzX7IpXKuxtNf7sFMYKQg-se3Eu1v-kAugy4/s400/DigSign.JPG" border="0" /><br /><span style="font-family:verdana;">Download: <a href="http://fadykamal.googlepages.com/DigitalSigner.zip">DigitalSigner.zip</a></span>Fady Sedrakhttp://www.blogger.com/profile/14890884941665741827noreply@blogger.com9tag:blogger.com,1999:blog-5859323102421388664.post-57753782168927249052007-10-07T08:58:00.000-07:002008-12-08T14:03:30.139-08:00Microformats: One step towards semantic web (Part 2)<div style="text-align: justify;"><span style="font-family:verdana;">Microformats isn’t a new technology at all. It has been around for a while now. It is being adopted by many organizations. The future versions of the Firefox browser version 3 and version 8 of Internet Explorer are expected to include native support for microformats. </span><br /><br /><span style="font-family:verdana;"><span style="font-size:130%;">Why are microformats a good idea to represents semantics in web page?</span> </span> </div><ul style="font-family: verdana; text-align: left;"><li>It is a standard method to markup website content.</li><li>It is not a new language. It is just a combination of XHTML and CSS.</li><li>It is embedded in the web page. i.e. hidden from humans, readable by machines.</li><li>It facilitate the interoperability between different applications like integrating the Outlook calendar with the events of a certain website.</li></ul><div style="text-align: justify;"><span style="font-family:verdana;">It is designed on the 3R principle (reduce, recycle and reuse). First, Reduce: It uses the KISS principle (Keep it simple and straight forward). Second, Recycle: It encourages the modularity. Third, Reuse: It favors best practices.</span><br /><br /><span style=";font-family:verdana;font-size:130%;" >How can I create a microformats?</span><span style="font-family:verdana;"> </span><br /><span style="font-family:verdana;">The Microformats community has developed a number of creators for hCard, hCalendar, and hReview. It helps people to create their first microformats. You enter the required data and it creates the equivalent XHTML code. These provide a simple way to start publishing microformatted content.</span><span style="font-family:verdana;"> </span><span style="font-family:verdana;">Here is a list of some microformats creator:</span> </div><ul style="font-family: verdana; text-align: left;"><li>hCard Creator: <a href="http://microformats.org/code/hcard/creator">http://microformats.org/code/hcard/creator</a><br /></li><li>hCalendar Creator: <a href="http://microformats.org/code/hcalendar/creator">http://microformats.org/code/hcalendar/creator</a> </li><li>hReview Creator: <a href="http://microformats.org/code/hreview/creator">http://microformats.org/code/hreview/creator</a></li></ul><div style="text-align: justify;"><span style="font-family:verdana;">People will think that it will take some time to be widely used on the web. Here is a tip for you the page you are reading right now uses microformats to markup contacts.</span> <a style="font-family: verdana;" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhenpeEC2_wqYuKJZuLy0gK4jGzoMO_33WUE9KPpNb-P5FSfrjx69P3Ll0J_qMq0NObFNoWXlI_3-v8hvpe2NeFMaX_zGmXzRJ_Q6kvz29z42OH289JrMbdHEaldY4xkZN94Sz2kocZl3o/s1600-h/fady_log_operator.bmp"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhenpeEC2_wqYuKJZuLy0gK4jGzoMO_33WUE9KPpNb-P5FSfrjx69P3Ll0J_qMq0NObFNoWXlI_3-v8hvpe2NeFMaX_zGmXzRJ_Q6kvz29z42OH289JrMbdHEaldY4xkZN94Sz2kocZl3o/s400/fady_log_operator.bmp" alt="" id="BLOGGER_PHOTO_ID_5118627132437205762" border="0" /></a><span style="font-family:verdana;">Let us see some microformats in action, now you are asking me isn’t the semantics embedded in a webpage for machines to understand. So I think we need a special tools to extract this information. I will review 2 tools you can use to discover microformats in embedded web pages.</span><br /><br /><a style="font-family: verdana; font-weight: bold;" href="https://addons.mozilla.org/en-US/firefox/addon/4106">Operator</a><br /><span style="font-family:verdana;">Operator lets you combine pieces of information on Web sites with applications in ways that are useful. For instance, Flickr + Google Maps, Upcoming + Google Calendar, Yahoo! Local + your address book, and many more possibilities and permutations. All of these scenarios are possible due to Microformats, an emerging standard for injecting semantics into HTML. The following screen shot shows Operator in action while opening </span><a style="font-family: verdana;" href="http://11870.com/">http://11870.com/</a><span style="font-family:verdana;"> which is a social network which implements hReview for user's reviews about places, services and business:</span> <a style="font-family: verdana;" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgL0cVW10mV6id7-xk5TZpK0n-40mXCRNdU-bxibbSkw4YOc_Fmar6IY5mw926Y3BPwCGq9TbPMmb4-2biIDxmceTmIvEORp1WDiG775mTOZkcOli3ayDXIGfaaaLYyTwq2nkCWutHDEBo/s1600-h/11870_operator.bmp"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgL0cVW10mV6id7-xk5TZpK0n-40mXCRNdU-bxibbSkw4YOc_Fmar6IY5mw926Y3BPwCGq9TbPMmb4-2biIDxmceTmIvEORp1WDiG775mTOZkcOli3ayDXIGfaaaLYyTwq2nkCWutHDEBo/s400/11870_operator.bmp" alt="" id="BLOGGER_PHOTO_ID_5118628755934843666" border="0" /></a><br /><a style="font-family: verdana; font-weight: bold;" href="https://addons.mozilla.org/en-US/firefox/addon/2240">Tails Export</a><br /><span style="font-family:verdana;">An extension for Showing and Exporting Microformats. Currently it supports the following formats ( hCard, hCalendar, hReview, xFolk and Rel-license). The following screen shot shows Tails export in action while opening </span><a style="font-family: verdana;" href="http://11870.com/">http://11870.com/</a><span style="font-family:verdana;"> :</span><br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhF7hpfnd7js3dgeVxktX_21jxDHLRJ-m9svtnz4FhM5MW6_Aft8ebMlqn72cvQDlpuSEQSwcF4K4Wb5q8RwdF2p6YPlUiyoqoKPm_PtPoLGEJr4nkZZrLxkDPpf9OWBzN9ifX__OM9Fe8/s1600-h/11870_tails.bmp"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhF7hpfnd7js3dgeVxktX_21jxDHLRJ-m9svtnz4FhM5MW6_Aft8ebMlqn72cvQDlpuSEQSwcF4K4Wb5q8RwdF2p6YPlUiyoqoKPm_PtPoLGEJr4nkZZrLxkDPpf9OWBzN9ifX__OM9Fe8/s400/11870_tails.bmp" alt="" id="BLOGGER_PHOTO_ID_5118633785341547314" border="0" /></a><br /><span style="font-family:verdana;">Finally, Microformats is a good step towards semantic web. Now, your browser can understand some of the semantics in a web page like the contacts, addresses, reviews ... etc. For example, Microformats can help you integrate addresses with google maps and so on...</span><br /><span style="font-family:verdana;">It is now clear that the dreams of </span><a style="font-family: verdana;" href="http://www.w3.org/People/Berners-Lee/">Tim Burners Lee</a><span style="font-family:verdana;"> are going to be true "a single web of meaning about everything and for everyone".</span></div>Fady Sedrakhttp://www.blogger.com/profile/14890884941665741827noreply@blogger.com0tag:blogger.com,1999:blog-5859323102421388664.post-85640879401043365972007-09-29T03:00:00.000-07:002008-12-08T14:03:30.327-08:00Microformats: One Step towards Semantic Web (Part 1)<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjAcZs1eoqHW5b0F4HNGl3aPyJ78sOWrnct6j9Cc7srNGHhk83cGTR2fYKcEZgUtzsZL3vKw9B2BuT89F3_caIHBm3HWmLzfC0ZWF9Jpt7BJMFM5_gmjs3Fp9b4voc8205SRXIxuUCtUGo/s1600-h/Microformat-logo.png"><img style="margin: 0pt 0pt 10px 10px; float: right; cursor: pointer;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjAcZs1eoqHW5b0F4HNGl3aPyJ78sOWrnct6j9Cc7srNGHhk83cGTR2fYKcEZgUtzsZL3vKw9B2BuT89F3_caIHBm3HWmLzfC0ZWF9Jpt7BJMFM5_gmjs3Fp9b4voc8205SRXIxuUCtUGo/s400/Microformat-logo.png" alt="" id="BLOGGER_PHOTO_ID_5115576408576922354" border="0" /></a><span style="font-family: verdana;">So what is really Semantic Web? Well, Semantic Web is an extension of the World Wide Web in which content can be expressed in a format that can be read and used by software not only by humans, to facilitate the searching, sharing and integration of information. In simple words it is a way to standardize the data and information representation over the world wide web, so that software would be able to understand its semantics without the need of complicated intelligent software. There have been several technologies that drive the road to semantic web like Resource Description Framework (</span><a style="font-family: verdana;" href="http://www.w3.org/rdf/">RDF</a><span style="font-family: verdana;">) and Web Ontology Language (</span><a style="font-family: verdana;" href="http://www.w3.org/2004/owl/">OWL</a><span style="font-family: verdana;">).</span><br /><br /><span style="font-family: verdana;">Semantic Web is one of the theories that </span><a style="font-family: verdana;" href="http://www.w3.org/People/Berners-Lee/">Tim Burners Lee</a><span style="font-family: verdana;"> the father of the World Wide Web has been dreaming about since he launched the first website in the history in 1991. He had a vision towards this giant network that it shouldn't be a human-human communication only, machines should have a role too. His exact words were </span><span style="font-style: italic; font-family: verdana;">"a single Web of meaning, about everything and for everyone."</span><span style="font-family: verdana;">. He made his idea available freely with no patent, so they can be easily adopted by anyone.</span><br /><br /><span style="font-family: verdana;">During the keynote at Microsoft MIX06, Bill Gates said, “We need microformats and to get people to agree on them. It is going to bootstrap exchanging data on the Web . . . we need them for things like contact cards, events, directions.”</span><br /><br /><div style="text-align: center;"><object style="font-family: verdana;" height="353" width="425"><param name="movie" value="http://www.youtube.com/v/Z9X-vHJ_Z-I&rel=1"><param name="wmode" value="transparent"><embed src="http://www.youtube.com/v/Z9X-vHJ_Z-I&rel=1" type="application/x-shockwave-flash" wmode="transparent" height="353" width="425"></embed></object><br /></div><br /><span style="font-family: verdana;font-size:130%;" >What are Microformats?</span><br /><br /><span style="font-family: verdana;">Microformats are, according to the definition of </span><a style="font-family: verdana;" href="http://microformats.org/about/">microformats.org</a><span style="font-family: verdana;">,</span><br /><br /><span style="font-style: italic; font-family: verdana;">“Designed for humans first and machines second, microformats are a set of simple, open data formats built upon existing and widely adopted standards. Instead of throwing away what works today, microformats intend to solve simpler problems first by adapting to current behaviors and usage patterns (e.g., XHTML, blogging).”</span><br /><br /><span style="font-family: verdana;">In another words, it is a web-based data formatting methodology that re-use existing content as metadata, using only XHTML and HTML classes and attributes. So that human still be able to understand it as they used to and software agents can process it easily to extract the information they want.</span><br /><br /><span style="font-family: verdana;">Microformats might catch up with the web development community faster than the RDF or OWL. As it is build on the existing skills of web developers. It doesn’t require developers to learn whole new technologies, throw away their existing code bases, or wait years for browser developers to catch up and actually implement support for the technology. Microformats simply use features of HTML that have been around for years and are familiar to most web developers,</span><br /><br /><span style="font-family: verdana;">Current microformats allow the encoding and extraction of events, contact information, social relationships, and so on. More are being developed.</span><br /><br /><span style="font-family: verdana;">Microformats uses XHTML and HTML standards allow for semantics to be embedded within the attributes of markup tags. Microformats indicates the presence of metadata using the following attributes class, rel and rev.</span><br /><br /><span style="font-family: verdana;">Let us see an example of microformats to understand how it works, the following example is how to use microformats to describe contact information:</span><br /><br /><p class="MsoNormal"><span style=";font-family:'Courier New';font-size:10;color:blue;" ><</span><span style="color: rgb(163, 21, 21);font-family:'Courier New';font-size:10;" >div</span><span style=";font-family:'Courier New';font-size:10;" > <span style="color:red;">class</span><span style="color:blue;">="vcard"></span><br /><span style=""> </span><span style="color:blue;"><</span><span style="color: rgb(163, 21, 21);">div</span> <span style="color:red;">class</span><span style="color:blue;">="fn"></span>Fady Younan<span style="color:blue;"></</span><span style="color: rgb(163, 21, 21);">div</span><span style="color:blue;">></span><br /><span style=""> </span><span style="color:blue;"><</span><span style="color: rgb(163, 21, 21);">div</span> <span style="color:red;">class</span><span style="color:blue;">="org"></span>ITWorx<span style="color:blue;"></</span><span style="color: rgb(163, 21, 21);">div</span><span style="color:blue;">></span><br /><span style=""> </span><span style="color:blue;"><</span><span style="color: rgb(163, 21, 21);">div</span> <span style="color:red;">class</span><span style="color:blue;">="tel"></span>000-555-1234<span style="color:blue;"></</span><span style="color: rgb(163, 21, 21);">div</span><span style="color:blue;">></span><br /><span style=""> </span><span style="color:blue;"><</span><span style="color: rgb(163, 21, 21);">a</span> <span style="color:red;">class</span><span style="color:blue;">="url"</span> <span style="color:red;">href</span><span style="color:blue;">="http://www.fady-younan.com"></span>http://www.fady-younan.com<span style="color:blue;"></</span><span style="color: rgb(163, 21, 21);">a</span><span style="color:blue;">></span></span><br /><span style="line-height: 115%;font-family:'Courier New';font-size:10;" ><span style=""> </span><span style="color:blue;"></</span><span style="color: rgb(163, 21, 21);">div</span><span style="color:blue;">></span></span></p><br /><span style="font-family: verdana;">Another example of how describe geographic information:</span><br /><br /><p class="MsoNormal"><span style=";font-family:'Courier New';font-size:10;" ><span style=""> </span><span style="color:blue;"><</span><span style="color: rgb(163, 21, 21);">span</span> <span style="color:red;">class</span><span style="color:blue;">="geo"></span><br /><span style=""> </span><span style="color:blue;"><</span><span style="color: rgb(163, 21, 21);">span</span> <span style="color:red;">class</span><span style="color:blue;">="latitude"></span>28.47<span style="color:blue;"></</span><span style="color: rgb(163, 21, 21);">span</span><span style="color:blue;">></span>,<br /><span style=""> </span><span style="color:blue;"><</span><span style="color: rgb(163, 21, 21);">span</span> <span style="color:red;">class</span><span style="color:blue;">="longitude"></span>19.89<span style="color:blue;"></</span><span style="color: rgb(163, 21, 21);">span</span><span style="color:blue;">></span></span><br /><span style="line-height: 115%;font-family:'Courier New';font-size:10;" ><span style=""> </span><span style="color:blue;"></</span><span style="color: rgb(163, 21, 21);">span</span><span style="color:blue;">></span></span></p><p class="MsoNormal"><br /></p><p style="font-family: verdana;" class="MsoNormal">If you haven't notice it uses the same XHTML and CSS to embed semantics in the web page, it uses the class "geo" to describe that is a geographic information, latitude and longitude to describe the co-ordination and so on ...<br /></p><p style="font-family: verdana;" class="MsoNormal"> </p><span style="font-family: verdana;">Here is list of some of the available microformats and there are others under development:</span><br /><ul style="font-family: verdana;"><li><span style="font-weight: bold;"><a href="http://microformats.org/wiki/hcard">hCard</a>: </span>describes the contact information for people or organizations</li><li><span style="font-weight: bold;"><a href="http://microformats.org/wiki/hcalendar">hCalendar</a>:</span> describes information about events such as conferences,meetings and parties</li><li><span style="font-weight: bold;"><a href="http://gmpg.org/xfn/">XFN</a>:</span> describes the relationships between people.</li><li><span style="font-weight: bold;"><a href="http://microformats.org/wiki/hreview">hReview</a>: </span>describes the reviews for movies, books .. etc.</li></ul><span style="font-family: verdana;">To be continued ...</span>Fady Sedrakhttp://www.blogger.com/profile/14890884941665741827noreply@blogger.com0tag:blogger.com,1999:blog-5859323102421388664.post-16435517612300891862007-09-01T09:01:00.001-07:002008-12-08T14:03:30.740-08:00Erlang: Web Development (Part 4)<span style="font-size:100%;"><span style="font-family:verdana;">Erlang was mainly developed targeting the telecom application. It had to satisfy some of requirements of the telecom applications which are being distributed, massively concurrent, real-time and high availability. These requirements are similar to those put upon Internet based applications, making Erlang a good candidate for development of web based services. So is Erlang ready to be an enterprise web development framework?</span><br /><br /></span> <p style="text-align: left;font-family:verdana;" class="MsoNormal"><span style="font-size:100%;">The first tries of Erlang to conquer the web development community was back at 1997, when Ericsson developed its first web server. This server was called <a href="http://www.erlang.org/doc/apps/inets/index.html">INETS</a>. It is still a part of the Open Telecom Platform (OTP). Back there it was written with 10,000 lines of code (Don’t forget it is a functional language) and achieved 80% of the Apache server functionality which at that time consisted of about 100,000 lines of code.</span></p><p style="text-align: left;font-family:verdana;" class="MsoNormal"><span style="font-size:100%;"><br /></span></p><span style="font-size:100%;"><a style="font-family: verdana;" href="http://yaws.hyber.org/">Yaws</a><span style="font-family:verdana;"> (Yet Another Web Server) is another HTTP high performance web server particularly well suited for dynamic-content web applications. It is entirely written in Erlang. It was released as an open source in 2002. It is a multithreaded web server where a light weight process is used to handle each client request. The performance of Yaws comes from the underlying Erlang system and its ability to handle concurrent processes in an efficient way. It was a revolutionary web server considering the performance.</span><br /><br /></span><p style="text-align: left;font-family:verdana;" class="MsoNormal"><span style="font-size:100%;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLFzxNlGIYI3uuKc4yQ3EvNqkmDgFoMp-kj5Fh7t51ZXABEvW0NCWR305P-pYCxQsSpSb-xcCN5g6Eleg3GLiqMxyGfSs_0kQYfaSVV-AnllQNewFrRXv_LWl2NGQAcpSnz2T9oo9qyBs/s1600-h/yaws_vs_apache.bmp"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLFzxNlGIYI3uuKc4yQ3EvNqkmDgFoMp-kj5Fh7t51ZXABEvW0NCWR305P-pYCxQsSpSb-xcCN5g6Eleg3GLiqMxyGfSs_0kQYfaSVV-AnllQNewFrRXv_LWl2NGQAcpSnz2T9oo9qyBs/s400/yaws_vs_apache.bmp" alt="" id="BLOGGER_PHOTO_ID_5109848435785017554" border="0" /></a></span></p> <p style="text-align: left;font-family:verdana;" class="MsoNormal"><span style="font-size:100%;">Let us not forget the famous <a href="http://www.sics.se/%7Ejoe/apachevsyaws.html">comparison</a> between Yaws and Apache. In a denial of service attack, the number of parallel connections needed to crash the Erlang web server was about 20 times as many as an Apache web server running on the same hardware. Apache (blue and green) dies when subject to a load of concurrent 4,000 parallel requests. Yaws (red) works till 80,000 concurrent requests.</span></p><p style="text-align: left;font-family:verdana;" class="MsoNormal"><span style="font-size:100%;"><br /></span></p><span style="font-size:100%;">I will try to give you a simple example about how to create a simple dynamic web page with Yaws.<br /><br />This a simple Hello world to Yaws.<br /><erl><br /><span style="color: rgb(51, 51, 255);"><</span><span style="font-size:100%;"><span style="color: rgb(51, 102, 255);">html</span><span style="color: rgb(51, 51, 255);">></span></span><span style="font-size:100%;"><span style="color: rgb(51, 51, 255);"><br /></span></span><span style="font-size:100%;"><span style="color: rgb(51, 51, 255);"><</span></span><span style="font-size:100%;"><span style="color: rgb(51, 51, 255);">h1</span></span><span style="font-size:100%;"><span style="color: rgb(51, 51, 255);">> </span></span><span style="font-size:100%;"><span style="color: rgb(51, 51, 255);">Title</span></span><span style="font-size:100%;"><span style="color: rgb(51, 51, 255);"><</span></span><span style="font-size:100%;"><span style="color: rgb(51, 51, 255);">/h1</span></span><span style="font-size:100%;"><span style="color: rgb(51, 51, 255);">></span></span><span style="font-size:100%;"><span style="color: rgb(51, 51, 255);"><br /></span></span><span style="color: rgb(255, 0, 0);font-size:100%;" ><</span><span style="font-size:100%;"><span style="color: rgb(255, 0, 0);">erl</span></span><span style="color: rgb(255, 0, 0);font-size:100%;" >></span><span style="font-size:100%;"><span style="color: rgb(255, 0, 0);"><br /></span><span style="color: rgb(51, 204, 0);"> out(Arg) -> {html, “Hello World"}.<br /></span></span><span style="color: rgb(255, 0, 0);font-size:100%;" ><</span><span style="font-size:100%;"><span style="color: rgb(255, 0, 0);">/erl</span></span><span style="color: rgb(255, 0, 0);font-size:100%;" >></span><span style="font-size:100%;"><span style="color: rgb(255, 0, 0);"><br /></span></span><span style="font-size:100%;"><span style="color: rgb(51, 51, 255);"><</span></span><span style="font-size:100%;"><span style="color: rgb(51, 51, 255);">h1</span></span><span style="font-size:100%;"><span style="color: rgb(51, 51, 255);">></span></span><span style="font-size:100%;"><span style="color: rgb(51, 51, 255);"> Something</span></span><span style="font-size:100%;"><span style="color: rgb(51, 51, 255);"><</span></span><span style="font-size:100%;"><span style="color: rgb(51, 51, 255);">/h1</span></span><span style="font-size:100%;"><span style="color: rgb(51, 51, 255);">></span></span><span style="font-size:100%;"><span style="color: rgb(51, 51, 255);"><br /></span></span><span style="font-size:100%;"><span style="color: rgb(51, 51, 255);"><</span></span><span style="font-size:100%;"><span style="color: rgb(51, 51, 255);">/html</span></span><span style="font-size:100%;"><span style="color: rgb(51, 51, 255);">></span></span><span style="font-size:100%;"><span style="color: rgb(51, 51, 255);"> </span><br /><br /></span></erl></span><p style="text-align: left;font-family:verdana;" class="MsoNormal"><span style="font-size:100%;">Thanks to <a href="http://yarivsblog.com/">Yariv Sadan</a>’s effort to involve Erlang in the web development community using <a href="http://erlyweb.org/">ErlyWeb</a> </span><span style="font-size:100%;"> </span><span style="font-size:100%;">which is a web framework that helps you easily build database-driven applications using the MVC architecture. It's similar to Ruby on Rails, except that it's written in Erlang. There is also <a href="http://code.google.com/p/erlydb/">ErlyDB</a> a database abstraction layer generator. ErlyDB taps into Erlang’s runtime metaprogramming powers to generate an abstraction layer for your database on the fly.</span></p><p style="text-align: left;font-family:verdana;" class="MsoNormal"><span style="font-size:100%;"><br /></span></p><div style="font-family: verdana; text-align: left;"> </div><p style="text-align: left;font-family:verdana;" class="MsoNormal"><span style="font-size:100%;">I am going to propose an architecture for web development using Erlang. It will consists of five layers:</span></p><div face="verdana"> </div><ul style="text-align: justify;font-family:verdana;"><li><!--[if !supportLists]--><span style="font-weight: bold;font-size:100%;" >Hardware/ Operating System: </span><span style="font-size:100%;">This layer represents the physical layer of the system. It can be a Linux system running on a network file system(NFS) to make use of the concurrency and distribution features in Erlang.</span></li><li><!--[if !supportLists]--><span style="font-weight: bold;font-size:100%;" >DBMS:</span><span style="font-size:100%;"> This layer represents the persistence layer of the system. It can be either Mnesia or MySQL.</span></li><li style="font-weight: bold;"><!--[if !supportLists]--><span style="font-size:100%;">Data Base Abstraction Layer.</span></li><li><!--[if !supportLists]--><!--[endif]--><span style="font-weight: bold;font-size:100%;" >Erlang/Open Telecom Platform:</span><span style="font-size:100%;"> It is the standard libraries of the Erlang language.</span></li><li><!--[if !supportLists]--><span style="font-weight: bold;font-size:100%;" >Presentation Layer:</span><span style="font-size:100%;"> This layer consists of two components. Yaws as a web server and ErlyWeb as rapid development framework.</span></li></ul><div style="text-align: justify;font-family:verdana;"><span style="font-size:100%;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj1LgKfLpTdMue71JD4ti0KmKwWOdLepDlOh7GFQkVB7hMmOxTbpPZXbzlipCgmOWx4Aw4sfiQ0gAmyxz0g3HP9E9cC3Zhq6qRmWv2dhK3gkXIesyBZOjX-K5Kzu3KvNMru-8r0muwH7hU/s1600-h/arch_web.bmp"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj1LgKfLpTdMue71JD4ti0KmKwWOdLepDlOh7GFQkVB7hMmOxTbpPZXbzlipCgmOWx4Aw4sfiQ0gAmyxz0g3HP9E9cC3Zhq6qRmWv2dhK3gkXIesyBZOjX-K5Kzu3KvNMru-8r0muwH7hU/s400/arch_web.bmp" alt="" id="BLOGGER_PHOTO_ID_5109852687802640610" border="0" /></a><br /></span> <span style="line-height: 115%;font-family:verdana;font-size:100%;" >Now, I can see that Erlang is starting to involve itself in the web development community. The problem is that the Erlang community isn't big enough to support this involvement. Is this going to change?</span></div><p style="text-align: justify;font-family:verdana;" class="MsoNormal"><span style="font-size:100%;"><br /></span></p><p class="MsoNormal"><br /></p>Fady Sedrakhttp://www.blogger.com/profile/14890884941665741827noreply@blogger.com60tag:blogger.com,1999:blog-5859323102421388664.post-51837459970325966292007-09-01T08:59:00.000-07:002008-12-08T14:03:30.847-08:00Erlang: Open Telecom Platform (Part 3)<span style="font-family:verdana;">Is Erlang really a new language? Do we have to write our old libraries and applications again from scratch? Actually Erlang is an old language may be older than Java and dot NET. It was developed in the late 80's. I will talk today about one the strengths of Erlang which is the Open Telecom Platform (OTP). The OTP is a development platform for building telecommunications applications based on Erlang. It was released as open source in 1998.</span><br /><br /><span style="font-family:verdana;">The OTP is a development system platform for building, and a control system platform for running, telecommunications applications. It is not a monolithic platform, but is made up of sets of tools and building blocks. Most of it is written in Erlang, there are some components that are written in C++. The OTP architecture consists of three layers as shown in the figure.<br /><br /></span><a style="font-family: verdana;" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg0jyFLwNP8mWbXpSrt3c-gKeFgGCv3NNTz5Zowg933Ike4z-mpYr5fSNvb9hVAZOvPx_XW6V5jPBjTUMS-sqwe5WCLprD8jwQYFum8AYBzbGNL3eiKRer9i5dE4ca8MiuN1ix-Ayq30M8/s1600-h/OTP_Arch.bmp"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg0jyFLwNP8mWbXpSrt3c-gKeFgGCv3NNTz5Zowg933Ike4z-mpYr5fSNvb9hVAZOvPx_XW6V5jPBjTUMS-sqwe5WCLprD8jwQYFum8AYBzbGNL3eiKRer9i5dE4ca8MiuN1ix-Ayq30M8/s400/OTP_Arch.bmp" alt="" id="BLOGGER_PHOTO_ID_5105320325009841938" border="0" /></a><br /><span style="font-weight: bold;font-family:verdana;" >The Bottom layer: </span><span style="font-family:verdana;">The system hardware in this layer. This is merely an architectural view; in real systems, the bottom layer contains many computers which may be of different types.</span><br /><br /><span style="font-weight: bold;font-family:verdana;" >The Middle layer:</span><span style="font-family:verdana;"> Support for telecommunications requirements is provided by a robust real-time components. Its main modules are:</span><br /><ul style="font-family:verdana;"><li><span style="font-weight: bold;">Erlang run-time system:</span> The basic system that supports the execution of Erlang programs.</li><li><span style="font-weight: bold;">Web server:</span> A Web server that serves HTTP requests via executing server side applications written in Erlang.</li><li><span style="font-weight: bold;">Mnesia:</span> A real-time fault-tolerant distributed DBMS that supports fast transactions for the telecommunications application, and a query language, called Mnemosyne, for handling complex queries.</li><li><span style="font-weight: bold;">SASL:</span> The systems architecture support libraries (SASL) contain basic software that supports system start/restart, live system software updates, and process management.<br /></li><li><span style="font-weight: bold;">SNMP support:</span> SNMP provides run-time support through an extensible agent.</li></ul> <span style="font-weight: bold;font-family:verdana;" >The Top layer:</span><span style="font-family:verdana;"> All applications have access to Mnesia and SASL. The SNMP agent and the Web server may also invoke functions that are provided by the applications in this layer.</span><br /><br /><span style="font-family:verdana;">Using this platform, libraries and utilities you will be able to write robust, real-time systems. You won't be able to realize how powerful is Erlang. I will talk next time about existing systems that uses Erlang.</span><br /><br /><span style="font-family:verdana;">To be continued ...</span>Fady Sedrakhttp://www.blogger.com/profile/14890884941665741827noreply@blogger.com0tag:blogger.com,1999:blog-5859323102421388664.post-54249208288132191002007-08-24T12:07:00.000-07:002008-12-08T14:03:31.401-08:00Erlang: Concurrency and Distribution (Part 2)<span style=";font-family:verdana;font-size:100%;" >One of the main strengths for Erlang is support for concurrency and distribution. It has a small set of primitives to create processes and communicate between them. Erlang processes are not operating system processes or threads, but they are lightweight threads similar to Java's "<a href="http://en.wikipedia.org/wiki/Green_threads">green threads</a>".<br /><br /></span><div style="text-align: left;"><span style="font-size:100%;"><span style="font-family:verdana;">Erlang is designed to be run in a distributed multi-node environment. Every computation in Erlang is performed within a process. Processes have no shared memory and communicate by asynchronous message passing. This is the philosophy of Erlang, the Concurrency Oriented Programming (COP). You have to think of your design from this prospective. Your application consists of a set of processes may be distributed on different machines.</span> <span style="font-family:verdana;"><br /><br />Here is a simple application to illustrate the feautres I was talking about. A process sends a message to another process using the send construct: Pid ! Message. Even if the Pid doesn’t exist, the send will succeed. A process can block to receive a message by using the receive construct. The receive construct may also take an optional timeout value in millseconds, after which the “after” clause of the receive construct is executed.</span><br /></span><br /><div style="border: 2px solid black;"><span style="font-size:85%;"><span style="color:black;">-</span><span style="color: rgb(0, 0, 131);">module</span><span style="color:black;">(IPCExample).<o:p></o:p></span></span> <p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;font-family:courier new;"><span style="font-size:85%;"><span style="color:black;">-</span><span style="color: rgb(0, 0, 131);">export</span><span style="color:black;">([main/</span><span style="color: rgb(41, 41, 255);">0</span><span style="color:black;">, thread/</span><span style="color: rgb(41, 41, 255);">0</span><span style="color:black;">]).<o:p></o:p></span></span></p> <p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;font-family:courier new;"><span style="font-size:85%;"><span style="color: rgb(84, 84, 84);"><o:p> </o:p></span></span></p> <p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;font-family:courier new;"><span style="font-size:85%;"><span style="color: rgb(0, 0, 131);">main</span><span style="color:black;">() -></span></span></p><p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;font-family:courier new;"><span style="font-size:85%;"><span style="color:black;"> Pid = </span><span style="color: rgb(131, 0, 0);">spawn</span><span style="color:black;">(receive1, thread, []),<o:p></o:p></span></span></p> <p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;font-family:courier new;"><span style="font-size:85%;"><span style="color:black;"> io:</span><span style="color: rgb(0, 0, 131);">fwrite</span><span style="color:black;">(</span><span style="color:red;">"Spawned new process _w_n"</span><span style="color:black;">, [Pid]),<o:p></o:p></span></span></p> <p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;font-family:courier new;"><span style="font-size:85%;"><span style="color:black;"> Pid ! hello.<o:p></o:p></span></span></p> <p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;font-family:courier new;"><span style="font-size:85%;"><span style="color: rgb(84, 84, 84);"><o:p> </o:p></span></span></p> <p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;font-family:courier new;"><span style="font-size:85%;"><span style="color: rgb(0, 0, 131);">thread</span><span style="color:black;">() -><o:p></o:p></span></span></p> <p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;font-family:courier new;"><span style="font-size:85%;"><span style="color:black;"> io:</span><span style="color: rgb(0, 0, 131);">fwrite</span><span style="color:black;">(</span><span style="color:red;">"This is a thread._n"</span><span style="color:black;">, []),<o:p></o:p></span></span></p> <p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;font-family:courier new;"><span style="font-size:85%;"><span style="color: rgb(0, 0, 131);"> process_messages</span><span style="color:black;">().<o:p></o:p></span></span></p> <p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;font-family:courier new;"><span style="font-size:85%;"><span style="color: rgb(84, 84, 84);"><o:p> </o:p></span></span></p> <p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;font-family:courier new;"><span style="font-size:85%;"><span style="color: rgb(0, 0, 131);">process_messages</span><span style="color:black;">() -><o:p></o:p></span></span></p> <p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;font-family:courier new;"><span style="font-size:85%;"><b><span style="color:black;"> receive<o:p></o:p></span></b></span></p> <p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;font-family:courier new;"><span style="font-size:85%;"><span style="color:black;"> hello -><o:p></o:p></span></span></p> <p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;font-family:courier new;"><span style="font-size:85%;"><span style="color:black;"> io:</span><span style="color: rgb(0, 0, 131);">fwrite</span><span style="color:black;">(</span><span style="color:red;">"Received hello_n"</span><span style="color:black;">),<o:p></o:p></span></span></p> <p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;font-family:courier new;"><span style="font-size:85%;"><span style="color: rgb(0, 0, 131);"> process_messages</span><span style="color:black;">()<o:p></o:p></span></span></p> <p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;font-family:courier new;"><span style="font-size:85%;"><span style="color:black;"> after </span><span style="color: rgb(41, 41, 255);">2000 </span><span style="color:black;">-><o:p></o:p></span></span></p> <p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;font-family:courier new;"><span style="font-size:85%;"><span style="color:black;"> io:</span><span style="color: rgb(0, 0, 131);">fwrite</span><span style="color:black;">(</span><span style="color:red;">"Timeout._n"</span><span style="color:black;">)<o:p></o:p></span></span></p> <p class="MsoNormal"><span style="font-size:85%;"><b style="font-family:courier new;"><span style="line-height: 115%;color:black;" > end.</span></b></span><span style=""><o:p></o:p></span></p></div><span style="font-size:100%;"><br /><span style="font-family:verdana;">Process IDs do not have to refer processes running on the same machine as the processes can be distributed an remote machines. So you can spawn a process using the node name and use the returned process ID to send messages just as if it were a process on the local machine.<br /></span> </span><br /><div style="border: 2px solid black;"><br /><span style="font-size:85%;"><span style="font-family:courier new;">Pid = <span style="color: rgb(102, 102, 204);">spawn</span>(<span style="color: rgb(255, 102, 102);">remote_node</span>,process1, thread, [])</span> <span style="font-family:courier new;">Pid ! a_message</span></span><br /><span style="font-size:85%;"><span style="font-family:courier new;">Pid <span style="color: rgb(0, 153, 0);">!</span> a_message</span></span><br /><br /></div><br /><span style="font-size:100%;"><span style="font-family:verdana;">Erlang handles the creation of the processes very efficiently. Here is a simple graph comparing Java, C#, Erlang comparing the time taken to create processes and asynchronous message passing.</span> </span><div style="text-align: center;font-family:verdana;"><span style="font-size:100%;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhVrtXr9Xcq_xpQfxY1bVq-I7x4YY1dD007bsKbF_cEMXL1tTIeUzuRfs_wcYuLRguOuCvcnUuYN1hE_OSANzuXSHJwxOFJUmlvcYSQT2ZZVRGHD-3KBceNTWQaTeWuOqUoNRufcv5GIBY/s1600-h/pcreation.bmp"><img style="cursor: pointer;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhVrtXr9Xcq_xpQfxY1bVq-I7x4YY1dD007bsKbF_cEMXL1tTIeUzuRfs_wcYuLRguOuCvcnUuYN1hE_OSANzuXSHJwxOFJUmlvcYSQT2ZZVRGHD-3KBceNTWQaTeWuOqUoNRufcv5GIBY/s400/pcreation.bmp" alt="" id="BLOGGER_PHOTO_ID_5105242032051003106" border="0" /></a><br /></span></div><div style="text-align: center;font-family:verdana;"><span style="font-size:100%;"><br /></span></div><span style="font-size:100%;"><span style="font-family:verdana;">This figure compares the time of creation of processes in Erlang versus Java and C#. We observe that the time taken to create an Erlang process is a constant 1 micro second up to 2,500 processes; and then it increases to about 3 micro second for up to 30,000 processes. As for </span></span><span style="font-size:100%;"><span style="font-family:verdana;">Java and C# </span></span><span style="font-size:100%;"><span style="font-family:verdana;">a small number of processes takes about 300 micro second to create a process. Creating more than two thousand processes is impossible.</span> </span><div style="text-align: center; font-family: verdana;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-nEcGie-XhNtza0jCYlm_8QGEc3OfrVFLxhN2bSJMzG8DOneDYILrcgaX6uSE_LK7JdNnEPflqFwvuKtmHpzf-Li2yKqRLMq1Mj2hBOMD18yY-Q3id3E7o4Z0zgSRIFFWRKleYRaklxs/s1600-h/mpassing.bmp"><img style="cursor: pointer;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-nEcGie-XhNtza0jCYlm_8QGEc3OfrVFLxhN2bSJMzG8DOneDYILrcgaX6uSE_LK7JdNnEPflqFwvuKtmHpzf-Li2yKqRLMq1Mj2hBOMD18yY-Q3id3E7o4Z0zgSRIFFWRKleYRaklxs/s400/mpassing.bmp" alt="" id="BLOGGER_PHOTO_ID_5105269571381305090" border="0" /></a></div><span style="font-size:100%;"><span style="font-family:verdana;">This figure compares the time of message passing between different processes in Erlang versus Java and C#. The time to send a simple message between two concurrent processes running on the same machine as a function of the total number of processes. We see that for up to 30,000 processes the time to send a message between two Erlang processes is about 0.8 micro second. For C# it takes about 50 micro second. per message, up to the maximum number of processes (which was about 1800 processes). Java was even worse, for up to 100 process it took about 50 micro second per message thereafter it increased rapidly to 10ms per message when there were about 1000 Java processes.</span><br /><br /><span style="font-family:verdana;">It is quite clear that Java and C# can't compete with Erlang in this features. We have to realize that the world is going towards parallel processing even we don't accept Erlang as a language I think it will take place in the next decade.</span> <span style="font-family:verdana;"><br /><br />To be continued ...</span></span><br /></div>Fady Sedrakhttp://www.blogger.com/profile/14890884941665741827noreply@blogger.com4tag:blogger.com,1999:blog-5859323102421388664.post-24786173059123381682007-08-24T06:38:00.000-07:002007-09-13T17:58:41.523-07:00Ruby vs Java, PHP, dot NET ... Hilarious :D<span style="font-family:verdana;"><span style="font-size:85%;"><span style="font-family:verdana;">I have never imagined that comparing web development frameworks would be that funny ... Ruby Rulez :D.</span></span><span style="color: rgb(102, 51, 255);font-size:180%;" ><br /></span></span><div style="text-align: center;"><span style="font-family:verdana;"><span style="color: rgb(102, 51, 255);font-size:180%;" ><span style="font-weight: bold; color: rgb(0, 0, 0);">Ruby vs Java</span></span></span><br /><span style="font-family:verdana;font-size:85%;"><span style="color: rgb(102, 51, 255);"><span style="color: rgb(0, 0, 0);">Comparing Jars of Java to Ruby.</span></span></span><span style="font-size:78%;"><br /><object align="middle" height="350" width="425"><param name="movie" value="http://www.youtube.com/v/PQbuyKUaKFo"><param name="wmode" value="transparent"><embed src="http://www.youtube.com/v/PQbuyKUaKFo" type="application/x-shockwave-flash" wmode="transparent" height="350" width="425"></embed></object><br /></span><br /><br /><span style="font-family:verdana;"><span style="font-size:180%;"><span style="font-weight: bold; color: rgb(0, 0, 0);">Ruby vs dot NET</span></span></span><br /><span style="font-family:verdana;font-size:85%;"><span style="font-family:verdana;"><span style="color: rgb(0, 0, 0);">Or we can say dot NOT :D.</span></span></span><span style="font-size:85%;"><br /></span><br /><span style="font-family:verdana;"><span style="font-size:180%;"><span style="font-family:verdana;"><span style="color: rgb(0, 0, 0);"><object style="color: rgb(0, 0, 0);" height="353" width="425"><param name="movie" value="http://www.youtube.com/v/528BCJiRkks"><param name="wmode" value="transparent"><embed src="http://www.youtube.com/v/528BCJiRkks" type="application/x-shockwave-flash" wmode="transparent" height="353" width="425"></embed></object></span></span></span></span><br /><span style="font-family:verdana;"><span style="font-size:180%;"><span style="font-family:verdana;"><span style="color: rgb(0, 0, 0);"><br /></span></span></span></span><br /><span style="font-family:verdana;"><span style="font-weight: bold; color: rgb(0, 0, 0);font-size:180%;" >Ruby vs PHP</span></span><br /><span style="font-family:verdana;font-size:85%;"><span style="color: rgb(0, 0, 0);">I didn't know that php is this sticky.</span></span><br /><span style="font-family:verdana;"><span style="font-weight: bold; color: rgb(0, 0, 0);font-size:130%;" >Round 1</span></span><br /><span style="font-family:verdana;"> <object style="color: rgb(0, 0, 0);" height="353" width="425"><param name="movie" value="http://www.youtube.com/v/n1NVfDlU6yQ"><param name="wmode" value="transparent"><embed src="http://www.youtube.com/v/n1NVfDlU6yQ" type="application/x-shockwave-flash" wmode="transparent" height="353" width="425"></embed></object></span><br /><span style="font-family:verdana;"><span style="font-weight: bold; color: rgb(0, 0, 0);font-size:130%;" >Round 2</span></span><br /><span style="font-family:verdana;"><span style="font-weight: bold; color: rgb(0, 0, 0);font-size:130%;" ><object height="353" width="425"><param name="movie" value="http://www.youtube.com/v/p5EIrSM8dCA"><param name="wmode" value="transparent"><embed src="http://www.youtube.com/v/p5EIrSM8dCA" type="application/x-shockwave-flash" wmode="transparent" height="353" width="425"></embed></object></span></span><br /><span style="font-family:verdana;"><span style="font-weight: bold; color: rgb(0, 0, 0);font-size:130%;" >Round 3</span></span><br /><br /><span style="font-family:verdana;"><span style="font-weight: bold; color: rgb(0, 0, 0);font-size:130%;" ><object height="353" width="425"><param name="movie" value="http://www.youtube.com/v/Ld919lziKgE"><param name="wmode" value="transparent"><embed src="http://www.youtube.com/v/Ld919lziKgE" type="application/x-shockwave-flash" wmode="transparent" height="353" width="425"></embed></object></span></span><br /><span style="font-family:verdana;"><span style="font-weight: bold; color: rgb(0, 0, 0);font-size:130%;" >Round 4</span></span><br /><br /><span style="font-family:verdana;"><object style="color: rgb(0, 0, 0);" height="353" width="425"><param name="movie" value="http://www.youtube.com/v/GQXqWkWqnSw"><param name="wmode" value="transparent"><embed src="http://www.youtube.com/v/GQXqWkWqnSw" type="application/x-shockwave-flash" wmode="transparent" height="353" width="425"></embed></object></span><br /><span style="font-family:verdana;"><span style="font-size:180%;"><span style="font-weight: bold; color: rgb(0, 0, 0);"><br /></span></span></span></div><span style="font-family:verdana;"><span style="font-size:180%;"><span style="font-family:verdana;"><span style="color: rgb(0, 0, 0);"><br /></span></span><span style="font-weight: bold;"></span></span></span>Fady Sedrakhttp://www.blogger.com/profile/14890884941665741827noreply@blogger.com0tag:blogger.com,1999:blog-5859323102421388664.post-44667688598720215512007-08-19T07:05:00.000-07:002007-08-24T03:00:06.648-07:00Erlang: The Introduction (Part 1)<p class="MsoNormal" face="verdana">Is Erlang really going to be the next Java according to <a href="http://www.cincomsmalltalk.com/userblogs/ralph/blogView?showComments=true&entry=3364027251">Ralph's Blog</a>? Erlang is really a powerful programming language, but thinking of it as a replacement for Java is not realistic. Developers are using Java over a decade now, they already have their applications, frameworks, libraries, ... etc. all written in Java. I don't see a clear reason to leave all this and start again from a scratch using another programming language. I am not completely against Erlang, although I am not completely with Java but I will try to predict the answer for the question I asked at the beginning. I will talk a bit about Erlang before I start comparing it to Java.<br /></p><p class="MsoNormal" style="font-family: verdana;"><span style="font-size:130%;">Introduction</span><br /></p><p class="MsoNormal" style="font-family: verdana;">Erlang is a general-purpose concurrent programming language and runtime system. It was designed by Ericsson to support distributed, real time, fault tolerant and non-stop application.</p> <p class="MsoNormal" style="font-family:verdana;">It was developed in the late 1980's by Ericsson to program the next generation of telecom applications. First it was used to program ATM Switches. It was released as open source in 1998 with the Open Telecom Platform (Erlang language, libraries and a real-time distributed database (<i>Mnesia</i>)) which I am going talk about it in details later.</p> <p class="MsoNormal" style="font-family:verdana;">Erlang is named after A. K. Erlang (Agner Krarup Erlang was a Danish mathematician, statistician and engineer, who invented the fields of traffic engineering and queuing theory). It is sometimes thought that its name is an abbreviation of <b style="color: rgb(51, 51, 255);">Er</b>icsson <b style="color: rgb(51, 102, 255);">Lang</b>uage. </p> <p class="MsoNormal" style="font-family:verdana;">Erlang as a framework has a lot features:</p> <p class="MsoNormal" style="margin-left: 0.5in; text-indent: -0.25in;font-family:verdana;"><!--[if !supportLists]--><span style=""><span style="">•<span style="font-size:7;"> </span></span></span><!--[endif]--><span dir="ltr"></span><b>Concurrent: </b>has a process-based model of concurrency with asynchronous message passing</p> <p class="MsoNormal" style="margin-left: 0.5in; text-indent: -0.25in;font-family:verdana;"><!--[if !supportLists]--><span style=""><span style="">•<span style="font-size:7;"> </span></span></span><!--[endif]--><span dir="ltr"></span><b>Real-time: </b>intended for programming real-time systems where response times in the order of milliseconds are required</p> <p class="MsoNormal" style="margin-left: 0.5in; text-indent: -0.25in;font-family:verdana;"><!--[if !supportLists]--><span style=""><span style="">•<span style="font-size:7;"> </span></span></span><!--[endif]--><span dir="ltr"></span><b>Continuous operation: </b>has primitives which allow code to be replaced in a running system and allow old and new versions of code to execute at the same time</p> <p class="MsoNormal" style="margin-left: 0.5in; text-indent: -0.25in;font-family:verdana;"><!--[if !supportLists]--><span style=""><span style="">•<span style="font-size:7;"> </span></span></span><!--[endif]--><span dir="ltr"></span><b>Robust: </b>Safety is a crucial requirement in systems such as the above. There are three constructs in the language for detecting run-time errors.</p> <p class="MsoNormal" style="margin-left: 0.5in; text-indent: -0.25in;font-family:verdana;"><!--[if !supportLists]--><span style=""><span style="">•<span style="font-size:7;"> </span></span></span><!--[endif]--><span dir="ltr"></span><b>Memory management: </b>a symbolic programming language with a real-time garbage collector</p> <p class="MsoNormal" style="margin-left: 0.5in; text-indent: -0.25in;font-family:verdana;"><!--[if !supportLists]--><span style=""><span style="">•<span style="font-size:7;"> </span></span></span><!--[endif]--><span dir="ltr"></span><b>Distribution: </b>has no shared memory. All interaction between processes is by asynchronous message passing </p> <p class="MsoNormal" style="font-family:verdana;">Erlang is a functional programming language. It is different from C++, C#, and Java, which are Procedural Programming Languages.</p> <p class="MsoNormal" style="margin-left: 0.5in; text-indent: -0.25in;font-family:verdana;"><!--[if !supportLists]--><span style=""><span style="">•<span style="font-size:7;"> </span></span></span><!--[endif]--><b>Procedural languages:</b> stress on the organization of data, and sequences of instructions which operate on some global state</p> <p class="MsoNormal" style="margin-left: 0.5in; text-indent: -0.25in;font-family:verdana;"><!--[if !supportLists]--><span style=""><span style="">•<span style="font-size:7;"> </span></span></span><!--[endif]--><b>Functional languages:</b> treat programs as evaluations of functions without a global state</p><span style="font-family:verdana;">To have a good idea about the language I added simple examples to check:</span><br /><ul><li><span style=""> </span><span style="font-size:130%;">Example 1: Hello World</span></li></ul> <p class="MsoNormal" style="font-family:verdana;"> This is the usual hello world program that displays "Hello World!" to the screen.<br /></p><p face="verdana" class="MsoNormal"> -<span style="color: rgb(51, 204, 0);">module</span>(hello).</p> <p face="verdana" class="MsoNormal"> -<span style="color: rgb(51, 204, 0);">export</span>([hello/0]).</p> <p face="verdana" class="MsoNormal"> hello() -><span style="color: rgb(102, 51, 255);">io:fwrite</span>(<span style="color: rgb(204, 0, 0);">"Hello, World!~n"</span>, []).</p> <ul><li><span style="font-size:130%;">Example 2: Factorial</span></li></ul> <p face="verdana" class="MsoNormal"><o:p> </o:p></p> <p face="verdana" class="MsoNormal"> This a simple factorial example.<br /></p><p face="verdana" class="MsoNormal"> -<span style="color: rgb(51, 204, 0);">module</span>(fact). </p> <p face="verdana" class="MsoNormal"> -<span style="color: rgb(51, 204, 0);">export</span>([fac/1]). </p> <p style="font-family: verdana;" class="MsoNormal"> fac(0) -> <span style="color: rgb(51, 102, 255);">1</span>; </p> <p style="font-family: verdana;" class="MsoNormal"> fac(N) <span style="color: rgb(51, 102, 255);">when</span> N > <span style="color: rgb(51, 102, 255);">0</span> -> N * fac(N-<span style="color: rgb(51, 102, 255);">1</span>).</p><br /><p style="font-family: verdana;" class="MsoNormal">To be continued ...<br /></p>Fady Sedrakhttp://www.blogger.com/profile/14890884941665741827noreply@blogger.com0