Sunday, July 14, 2013

Generate Sequcen Diagram (Visual Studio)

Shout it kick it on DotNetKicks.com
Following post is about feature provided by MS Visual Studio to generate sequence diagram from already written code.

Before getting into details how the Visual Studio does the task of generated sequence diagram, Following is describe what is sequence diagram (Following description is from Wikipedia).

Sequence Diagram
A sequence diagram is a kind of interaction diagram that shows how processes operate with one another and in what order. It is a construct of a Message Sequence Chart. A sequence diagram shows object interactions arranged in time sequence. It depicts the objects and classes involved in the scenario and the sequence of messages exchanged between the objects needed to carry out the functionality of the scenario. Sequence diagrams are typically associated with use case realizations in the Logical View of the system under development.
Read more on this : http://en.wikipedia.org/wiki/Sequence_diagram

Now in the following way I designed my code and than I am going to show the sequence of this code.
View Layer

This layer of the code is View part that is going to display to the end user of the application i.e. the front end of the application.

Business Layer

This layer of the code provides business logic for the fort end part of application . This layer does all the complex activity and communicate with the datalyer.

Data Layer

This layer of the code communicate with the DataBase or DataStructure where the data is stored and bring that data out of it.

Now after doing all this For the new developer in team or to my manager I want to show the flow of code goes from front end of application and data get bring in and out of database or datastructure . Flow of the code need  to be cover following thing

  1. How the code flow from one layer to another layer
  2. Which classes are involved
  3. Which method of the classes are involved

So to achieve this Visual Studio provide feature to generate Sequence Diagram which gives answer to above questions.

Generate Sequence Diagram

To generate sequence diagram just right click on the method of the code and in context menu there is option Generate Sequence diagram as you see in image.

Generate Sequence Diagram Window
Once clicked on menu above dialog displayed to use which ask use to provide input for generating sequence diagram. Following are the some important parameter of it.
  • Maximum call depth - How much deep you want to go i.e. if there are more than one class involved in call and how much deep you want to go.   
  • Include calls in - as the options says include class and methods of project only or full solution  or full solution and external references.
  • Exclude calls to - exclude call made to property, system name space or any other namespaces. 
Generated Sequence Diagram

Now once clicked on the dialog generate sequence diagram as shown in above. Above sequence diagram shows the call made to GetCustomer detail to display on front end i.e. to the user of the application.
If you see the code above in images or recall the above image code is divided in three layer and three classes involved which are respectively part of each layer.
Following steps are performed to get data from the database layer displayed by sequence diagram above.
  • View layer of application i.e. Font ask for getting customer data form business layer by calling Getcustomer method, Which is static method of business class so there is no call to create object of business layer class.
  • Business layer of application receives the call to method called GetCustomer so to fill the customer details it gives call to datalayer. But before making call it crate instance of datalayer Customer class.
  • Database layer of application receives call to the method call and in turns it make call to database and retrieve data.
  • Now database layer returns this data back to business layer customer class.
  • Business layer does the process of row data return form the datalayer and return the customer object back to view layer.
  • View layer of fetch value from the object return by business layer and display it to end user
So by the mean of generating sequence diagram I will actually able to find out flow of my code between layer, classes and methods. Also this answer the all the above question.

Note :
I specified 10 in Maximum call textbox of dialog but over here only 3 level is displayed, because as discussed my layer of coding only involve three classes of three layer.

Goto code from Sequence Diagram


With the help of generated sequence diagram by visual studio I can also jump to specify method of code directly by double clicking on the message or method call.
For example I clicked on new Customer create message or method call i.e. on the method call which marked red in above image.

Code on double click from sequence diagram

So after double clicking on the method call it directly redirect me to the code part form the generated sequence diagram. 

Advantage of the Generating Sequence diagram
  • Biggest advantage of this is its helps to understand code build by some one else i.e. if you are involved in development of the project and code build by some other developer who is not part of your team and you want to find the flow of the code from start point to end point.
  • It also help you to explain code build by you and you want to explain to the other developer joining your team.
  • It displays the all classes and method called in code. 
Note :
This feature generates sequence diagram from the method you clicked till end, but it doesn't display the method called before the method you selected.
For example
If I clicked on the method of business layer of my project to generate sequence diagram and it generates sequence diagram from that method i.e. from the business layer and database layer. It doesn't display those method which given call to the method on which I clicked, that means I am not able to get information from which Font end method this method is get called.
So when generated sequence diagram by clicking on the business layer method of the code discussed above, it generate sequence diagram display above. As discussed it doesn't display method of view layer which called business layer method.  

Conclusion
So this cool feature of visual studio very helpful when you want to explain your own code or you want to understand code.

Thanks for reading and do post comment if you like it or something is missing or wrong.

Ref by : http://msdn.microsoft.com/en-us/library/vstudio/ee317485.aspx 

29 comments:

  1. Thanks this info was really helpful! I used a website called Lucidchart to create my own object diagram and it was really easy to understand. If you use diagrams often you should check it out!

    ReplyDelete
  2. Thanks for sharing such informative guide on .Net technology. This post gives me detailed information about the .net technology. I am working as trainer in leading IT training academy offering Dot Net Training in Chennai and i use your guide to educate my students.

    ReplyDelete
  3. There are lots of information about latest technology and how to get trained in them, like Best Hadoop Training In Chennai in Chennai have spread around the web, but this is a unique one according to me. The strategy you have updated here will make me to get trained in future technologies Hadoop Training in Chennai By the way you are running a great blog. Thanks for sharing this blogs..

    ReplyDelete
  4. I found some useful information in your blog, it was awesome to read, thanks for sharing this great content to my vision, keep sharing..
    SalesForce Training in Chennai

    ReplyDelete
  5. Pretty article! I found some useful information in your blog, it was awesome to read,thanks for sharing this great content to my vision, keep sharing..
    Unix Training In Chennai

    ReplyDelete
  6. This information is impressive..I am inspired with your post writing style & how continuously you describe this topic. After reading your post,thanks for taking the time to discuss this, I feel happy about it and I love learning more about this topic
    Android Training In Chennai In Chennai

    ReplyDelete
  7. SAP Training in Chennai
    This post is really nice and informative. The explanation given is really comprehensive and informative..

    ReplyDelete
  8. Oracle Training in chennai
    Thanks for sharing such a great information..Its really nice and informative..

    ReplyDelete
  9. Selenium Training in Chennai
    Wonderful blog.. Thanks for sharing informative blog.. its very useful to me..

    ReplyDelete
  10. Data warehousing Training in Chennai
    I am reading your post from the beginning, it was so interesting to read & I feel thanks to you for posting such a good blog, keep updates regularly..

    ReplyDelete
  11. Whatever we gathered information from the blogs, we should implement that in practically then only we can understand that exact thing clearly, but it’s no need to do it, because you have explained the concepts very well. It was crystal clear, keep sharing..
    Websphere Training in Chennai

    ReplyDelete
  12. Oracle DBA Training in Chennai
    Thanks for sharing this informative blog. I did Oracle DBA Certification in Greens Technology at Adyar. This is really useful for me to make a bright career..

    ReplyDelete
  13. This is really an awesome article. Thank you for sharing this.It is worth reading for everyone. Visit us:Oracle Training in Chennai

    ReplyDelete
  14. very nice blogs!!! i have to learning for lot of information for this sites...Sharing for wonderful information.Thanks for sharing this valuable information to our vision. You have posted a trust worthy blog keep sharing.Oracle DBA Training in Chennai

    ReplyDelete
  15. great article!!!!!This is very importent information for us.I like all content and information.I have read it.You know more about this please visit again.
    Oracle RAC Training in Chennai

    ReplyDelete
  16. Wonderful tips, very helpful well explained. Your post is definitely incredible. I will refer this to my friend.SalesForce Training in Chennai

    ReplyDelete
  17. I am reading your post from the beginning, it was so interesting to read & I feel thanks to you for posting such a good blog, keep updates regularly.
    Java Training in Chennai

    ReplyDelete
  18. Really awesome blog. Your blog is really useful for me. Thanks for sharing this informative blog. Keep update your blog.
    PHP Training in Chennai

    ReplyDelete
  19. Thanks for sharing this valuable information to our vision. You have posted a trust worthy blog keep sharing.Nice article i was really impressed by seeing this article, it was very interesting and it is very useful for me.. Android Training in Chennai

    ReplyDelete
  20. Really awesome blog. Your blog is really useful for me. Thanks for sharing this informative blog. Keep update your blog.SAP Training in Chennai

    ReplyDelete
  21. Excellent information with unique content and it is very useful to know about the information based on blogs. Hadoop Training in Chennai

    ReplyDelete
  22. Really awesome blog. Your blog is really useful for me.
    Thanks for sharing this informative blog. Keep update your blog.
    Oracle Training In Chennai

    ReplyDelete
  23. Best Java Training Institute In ChennaiThis information is impressive; I am inspired with your post writing style & how continuously you describe this topic. After reading your post, thanks for taking the time to discuss this, I feel happy about it and I love learning more about this topic..

    ReplyDelete
  24. Great post....Thank you for posting the great content……I found it quiet interesting, hopefully you will keep posting such blogs…
    If you Want more seo course in chennai

    ReplyDelete
  25. Such a great articles in my carrier, It's wonderful commands like easiest understand words of knowledge in information's.
    SQL Server Training in Chennai

    ReplyDelete
  26. Thanks for sharing informative article… Know about How to Change BSNL WiFi Password from techfizy.

    ReplyDelete
  27. Thanks for sharing the useful article , interesting to read , keep more update magento 2 training

    ReplyDelete