Thursday 24 March 2016

c# nested dictionary foreach key value pair

 Dictionary<string, Dictionary<string, string>> objData = new Dictionary<string, Dictionary<string, string>>();

//Assign data to  nested dictionary
                        objData.Add("A1", new Dictionary<string, string>() { { "motor1", "A1" } });
                        objData["A1"].Add("motor2", "A2");
                        objData["A1"].Add("motor3", "A3");

                        objData.Add("B1", new Dictionary<string, string>() { { "motorb1", "B1" } });
                        objData["B1"].Add("motorb2", "B2");
                        objData["B1"].Add("motorb3", "B3");


//Read data from  nested dictionary
                        foreach (var outerDict in objData)
                        {
                            var innerDict = outerDict.Value;

                            foreach (var innerDictValue in innerDict)
                            {
                                Console.WriteLine(outerDict.Key + " " + innerDictValue.Key + " " + innerDictValue.Value);
                            }
                        }

Sunday 20 March 2016

C# .Net execute from command line



Open CMD.
c:\users\test\Documents>
Open Notepad. Ex:
c:\users\test\Documents>notepad hello.cs

Write sample code.
Ex:

using System;
class Program
{
static void Main()
{
Console.WriteLine("Hello");
}
}

Save hello.cs
c:\users\test\Documents>

Now in the CMD execute .net exe.

Ex: C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe

now call hello.exe
c:\users\test\Documents> hello.exe

You will get the output Hello



Tuesday 8 March 2016

I have 300K records in SQL, out of that 1k records are having wrong data in one column. How you are going to fix it.



Try this...You may have better approach, but this is one approach.

1.Get right data from Source System to flat file with primary key value and column value.
EX: Employee Location is wrong, in this scenario, prepare a flat file with Epmid and EmpLocation.
2.Import above data in to same DB where your 300k records table is there
3.Now you are having 2 tables (One is actual and another one is imported table)
4.Now compare the 2 tables to find are there any data difference.
5.If you find data difference, now update actual table (300k) with imported table
6.Now compare the 2 tables to find are there any data difference, it should give 0 differences..

Monday 7 March 2016

Using HTTP Methods (GET, POST, PUT, etc.) in Web API

http://www.exceptionnotfound.net/using-http-methods-correctly-in-asp-net-web-api/

HTTP Overview


The Hypertext Transfer Protocol (HTTP) is an application-level protocol for distributed, collaborative, hypermedia information systems. This is the foundation for data communication for the World Wide Web (i.e. internet) since 1990. HTTP is a generic and stateless protocol which can be used for other purposes as well using extensions of its request methods, error codes, and headers.
Basically, HTTP is a TCP/IP based communication protocol, that is used to deliver data (HTML files, image files, query results, etc.) on the World Wide Web. The default port is TCP 80, but other ports can be used as well. It provides a standardized way for computers to communicate with each other. HTTP specification specifies how clients' request data will be constructed and sent to the server, and how the servers respond to these requests.

Basic Features

There are three basic features that make HTTP a simple but powerful protocol:
  • HTTP is connectionless: The HTTP client, i.e., a browser initiates an HTTP request and after a request is made, the client disconnects from the server and waits for a response. The server processes the request and re-establishes the connection with the client to send a response back.
  • HTTP is media independent: It means, any type of data can be sent by HTTP as long as both the client and the server know how to handle the data content. It is required for the client as well as the server to specify the content type using appropriate MIME-type.
  • HTTP is stateless: As mentioned above, HTTP is connectionless and it is a direct result of HTTP being a stateless protocol. The server and client are aware of each other only during a current request. Afterwards, both of them forget about each other. Due to this nature of the protocol, neither the client nor the browser can retain information between different requests across the web pages.
HTTP/1.0 uses a new connection for each request/response exchange, where as HTTP/1.1 connection may be used for one or more request/response exchanges.

Basic Architecture

The following diagram shows a very basic architecture of a web application and depicts where HTTP sits:
HTTP Architecture
The HTTP protocol is a request/response protocol based on the client/server based architecture where web browsers, robots and search engines, etc. act like HTTP clients, and the Web server acts as a server.

Client

The HTTP client sends a request to the server in the form of a request method, URI, and protocol version, followed by a MIME-like message containing request modifiers, client information, and possible body content over a TCP/IP connection.

Server

The HTTP server responds with a status line, including the message's protocol version and a success or error code, followed by a MIME-like message containing server information, entity meta information, and possible entity-body content.

Ref: http://www.tutorialspoint.com/http/http_overview.htm

Sunday 6 March 2016

Web API

http://www.c-sharpcorner.com/UploadFile/4d9083/how-to-create-web-api-in-Asp-Net-mvc/
http://www.c-sharpcorner.com/UploadFile/2b481f/testing-of-Asp-Net-web-api-method/

Friday 4 March 2016

Aras ApplySQL

Open AML Studio
Connect any Aras instance
Select "ApplySQL"
Use below sample query to run SQL statements
<sql>
  update MANUFACTURER_PART with (rowlock) set MODIFIED_ON = '2009-03-27 11:05:00.000' where id = '12345#######'
</sql>

Tuesday 1 March 2016

Aras Item update using AML

Step 1 lock: It will lock all revs of documents
<Item type="Document" action="lock" where="[Document].item_number='ABC'"></Item>

Step 2 Find user locked_by_id:
<Item action="get" type="Document"" where="[Document"].item_number='ABC'" select="locked_by_id">
</Item>

Now- you will get the result as below:

<locked_by_id keyed_name="test User" type="User">USERID456</locked_by_id>

Note down this Id, you will use in step 4

Step 3 update document with different owned_by_id:

<Item type="Document" action="update" version="0" where="[Document].item_number='ABC' and [Document].generation='1'"><owned_by_id>GUID123</owned_by_id></Item>

Note: Use: version="0", so that it will not generate new rev.

Step 4 unlock the item: It will unlock all revs
<Item type="document" action="unlock" where="[document].locked_by_id='USERID456'"></Item>