Tuesday, August 20, 2019

How to Convert JSON object into C# Object

In this post I'm going to show you how a JSON object is converted into C# object.

For this we need a JSON object to pass into our program. Following web site provides set of JSON objects in their site. Let's use one of them.

Follow the above link. Go to "Guide" tab. In the bottom of the page you can see multiple data sets. I'll use the below data set which has 5 data fields.

Copy Raw Data set to a text file and save it. We will be using the file path to access it.

In this article I will use .NET JavaScriptSerializer class. This is not the only method you can do this. I will explain other methods in another blog post.

You need to create a class to convert the JSON object into C# object. In that class, number of fields and the type of data fields should be equal to JSON object's data fields.  In our JSON object there are five data fields.

Data FieldData Type
postIdint
idint
namesting
emailsting
bodysting

We need to create a C# class according to this.
Then you need to create a JavaScriptSerializer object. To access this class add System.Web.Extensions reference to the solution.
By giving the JSON file you saved previously, deserialize the JSON object into C# object using JavaScriptSerializer.
You can test C# object's properties by printing them.

You're done.If you have any comments post here :)

Monday, October 24, 2016

How to Transfer Files Using Filezilla on Ubuntu

  • Go to Ubuntu Software Center and Install Filezilla
  • Go to Edit -> Preferences -> SFTP and give your key file(.ppk) and click on OK.
  •  Now you have a window like this 

  • Enter Host/Domain/IP address in the 'Host' field (If you tranfering files to AWS EC2 instance use public DNS here) 
  • Enter Username in the 'Username' field
  • Enter the password for the user entered in the 'Username' field
  • Enter 22 as 'Port' -  Since we used SFTP you need to use 22. If it is FTP use 21 instead of 22
  • Click 'QuickConnect'
  • If it is successfully connected you can see all the files are listed in the Remote site area

  • If you need to Upload a file from Local site to Remote site, just right click on it and click Upload. Make sure that you are in the correct folder in the Remote site.(Example - Figure 1, You are in the /home/gothami/Pictures/ in the Local Site and You are in the /home/ec2-user in the Remote site)
Figure 1
  •  If you need to download a file from Remote Site to Local Site, just right click on it and click Download.
  • After successful File Transfer you can see Status like this

Wednesday, September 28, 2016

Install Putty in Ubuntu

To connect to an AWS instance you need to use either a standalone SSH client or a java SSH client directly using your web browser. Here we are discussing about how to connect to your instance using a standalone SSH client.

Putty is a popular SSH client which supports flexible terminal setup.

Install Putty :
            sudo apt-get install putty

Access the Putty SSH Client :



Click on Putty SSH Client and You will get a window like below.



Give the public DNS of your instance as the Host Name.





In the category pane, expand Connection -> expand SSH -> Select Auth -> Click Browse under Private key file for authentication: -> Select the .ppk file that you generated for your key pair.




Click Open. You will get a Security Alert like this.


Click on Accept. Then it will ask for Username.









Wednesday, July 6, 2016

Install Intellij IDEA on Ubuntu 14.04

Here you can see how to install intellj IDEA on Ubuntu easily.

1.) Install java on your machines. Simply use following terminal commands to do that.

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer  

Use java -version command to check whether it has installed properly. Output will be like below.


2.) Download Intellij IDEA using below link.
https://www.jetbrains.com/idea/download/download-thanks.html?platform=linux

3.) Go to folder which you dowloaded the archive using terminal

4.) Extract downloaded archive to any folder using(Here i extract into Documents folder),

      tar xfz idea-IC-141.1532.4.tar.gz -C /home/gothami/Documents

4.) Go to bin directory inside idea-IC-141.1532.4 using terminal and run IDEA using,
        ./idea.sh 

5.) If you get a permission denied error set permissions using,
sudo chmod +x /home/gothami/Documents/idea-IC-141.1532.4/bin/idea.sh




Sunday, June 12, 2016

Simulation using NS2

Let's discuss how we can simulate TCP using NS2 (Network Simulator) in Ubuntu environment.

First you need to install NS2 and nam on your machine. Use following terminal commands to install them.

Install NS2
 sudo apt-get install ns2
Install nam
 sudo apt-get install nam

Sometimes installing nam using this method leads to segmentation fault (figure 1). You can use following command list instead of using apt-get.
                       
1. sudo apt-get purge nam
2. wget --user-agent="Mozilla/5.0 (Windows NT 5.2; rv:2.0.1) Gecko/20100101 Firefox/4.0.1" "http://technobytz.com/wp-content/uploads/2015/11/nam_1.14_amd64.zip"
3. unzip nam_1.14_amd64.zip
4. sudo dpkg -i nam_1.14_amd64.deb
5. sudo apt-mark hold nam


Figure 1
You can see the full code in Figure 2 below. Let's go through this .tcl code.

Create Node Structure

- Create ns object
- Give colors to 2 different data flows - This is for easiness of understanding data, flawing from different TCP nodes. Here I have given Red and Blue.
- Open nam trace file - set <File Name> [open <File to be created>.nam <read/write>]
- Create nodes - In this example I have created 6 nodes since I have used 2 as routers and 4 as nodes.
- Create links between nodes - $<ns object> <link type> <node> <node> <data rate> <latency> <data dropping type>
- Queue limit - Give a size to the queue
- Organize links - This gives locations to nodes in the graph.
- Create TCP object and attach it to node created in ns object
- Create sink object and attach it to node created in ns object
- Creating TCP object and attaching it to a node is not enough.Need to create a object which can send data(here i have used ftp). Then attach it to node attached with TCP.

Record Process

If we need to plot recorded data rate over time we can use a graph. For this I'm using "xgraph"
Install xgraph using following command.
        sudo apt-get install xgraph

Here we record all data received by sink1 and write them to f0 file with time. Then give that file to xgraph to plot. "record" function in below code do this.

Simulation

- Start process - Start ftp. Then they will start sending data - $<ns object> at <starting time> "ftp1 start"
- Finish process by executing nam <created namfile>
- finish function executes simulation as well as plotting the graph.

$ns at 0.0 "record" - start record function at 0.0ms time
$ns at 60.0 "finish" - start finish process st 60ms time
$ns run - run the code



figure