Sunday 6 January 2019

Debugging in Angular with Visual studio code



Setting up debug steps for Visual studio code  :





1. In the above screenshot , click on debug menu from the left panel

2. You need to setup the launch.json file  with the below code  changes  :

   "version": "0.2.0",
    "configurations": [
        {
            "type": "chrome",
            "request": "launch",
            "name": "Launch Chrome against localhost",
            "url": "http://localhost:4200",
            "webRoot": "${workspaceFolder}"
        }
    ]
3. Make sure for chrome you need to install the debug for chrome  extension .

4. Run the angular project , put the break point where ever required.

   

Tuesday 1 January 2019

C# code for HttpPost with Authorization Token


C# code for HttpPost with Authorization Token


Assembly :  System.Net.Http


using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
                var res = await client.PostAsync("URL",
                new  StringContent(JsonConvert.SerializeObject(yourObject),Encoding.UTF8, "application/json"));
                var resp =res.Content.ReadAsStringAsync().Result;
                var response = res;
            }

Upload file programmatically C# to Microsoft Azure Storage



c# code sample for uploading  file into Azure storage programmatically         


Nuget Package  :
          Install  "Microsoft.Azure.Storage.Blob" package
         

        private async Task<bool> UploadFile()
{

            CloudBlobContainer blobContainer = new CloudBlobContainer(new  Uri("URL"));
            CloudBlockBlob blob = blobContainer.GetBlockBlobReference("FolderName");
            await blob.UploadFromFileAsync("FolderPath");
            return true;
}

Monday 16 May 2016

Angular Environment Setup


Angular  Environment Setup:

Here are the simple steps to configure the angular environment.

Step 1 : Firstly you need to check if npm is installed in the system or not. Simply  use “npm -version ” in the command prompt , if this shows any version in the system your are good to proceed with second step else go to this link  https://nodejs.org/en/  to download and install the node then proceed with step2.

Step 2 : Secondly you need to check for “ng -version” for angular CLI , if you get  some version in the command prompt then you are good to go with the angular development ,else  run the command in the cmd prompt  “npm install -g @angular/cli”  to install the angular cli globally (-g in the command indicates globally)


Hey!!!! If you done with the above 2 steps then you are good for the development to start with.

Thursday 3 December 2015

ASP.NET MVC Action Filter


ASP.NET MVC Filters allow us to inject extra logic into MVC Framework request processing, this logic either before or after an action is executed. 

I will show you the different categories of filters that the MVC Framework supports, how to create and use filters, and how to control their execution. We can make your own custom filters or attributes either by implementing ASP.NET MVC filter interface or by inheriting and overriding methods of ASP.NET MVC filter attribute class if available.


Understanding the Four Basic Types of Filters

The ASP.NET MVC Framework supports four different types of filters. Each allows you to introduce logic at different points during request processing. The four filter types are described in Table.
All ASP.NET MVC filter are executed in an order. Following list shows the order in which ASP.NET MVC Filters are executing.
  1. Authentication filters
  2. Authorization filters
  3. Action filters
  4. Result filters



Thursday 19 November 2015

Json Deserilize Model Binding Async,Await

Json Deserilize Model Binding Async,Await

Sample Code is here :

  public async Task<List<Models.Emp>> DemoAsyn()
        {
var obj = await new WebClient().DownloadStringTaskAsync("http://api.androidhive.info/contacts/");
string str = obj.Split('[').GetValue(1).ToString().Split(']').GetValue(0).ToString();
List<Models.Emp> list = JsonConvert.DeserializeObject<List<Models.Emp>>("[" + str + "]");
return View(list);
        }


Monday 16 November 2015

SqlDependency


SqlDependency

In this fast moving world of technologies , there is need  to share data between instances, as in a chat program, or receive constant updates like scores, as in a stock broker application.

Sqldependency will fulfill this, as this provides the instant trigger if the event when ever there is a change in the database entries .

Among the many new features for SQL Server 2012 are Service Broker and Query Notifications. The Service Broker is a queued, reliable messaging mechanism that is built into SQL Server 2012 and provides a robust asynchronous programming model.

Query Notifications allow applications to receive a notice when the results of a query have been changed. This improves performance by not having to periodically query the database for changes. 

To use SqlDependecy, the database must support a Service Broker. If the database was not created with this option enabled, you will need to enable it.

  ALTER DATABASE database SET ENABLE_BROKER

SqlNotificationRequest can also be used to provide the same services, however, it requires a good deal of manual setup. SqlDependency sets up the plumbing for you. While it is simpler to implement, it obviously doesn't allow the degree of customization that may be necessary for some applications, andSqlNotificationRequest would be the best choice.

A dependency is created between the application and the database via a SqlCommand. Before that can be established, the SqlDependency must be started for this session.


Sample code to use sqldependency

  using (SqlCommand command = new SqlCommand(query, connection))
            {
                command.Notification = null;
                SqlDependency dependency = new SqlDependency(command);
                dependency.OnChange += new OnChangeEventHandler(dependency_OnChange);
                connection.Open();
                SqlDataReader reader = command.ExecuteReader();

                if (reader.HasRows)
                {
                    reader.Read();
                    message = reader[0].ToString();
                    stat = reader[1].ToString();
                }
            }


 private void dependency_OnChange(object sender, SqlNotificationEventArgs e)
        {
            
            if (e.Info == SqlNotificationInfo.Insert)
            {
               //function code
            }

            if (e.Info == SqlNotificationInfo.Update)
            {
               //function code
            }

        }