Skip to main content

Posts

Showing posts from August, 2016

First Angular Application

First Angular application 1. Open NetBeans or any other editor of your choice and Select File > New Project (Ctrl + Shift + N) 2. Select HTML 5  > HTML 5 Application. Click Next. 3. Enter Project Name: AngularDemo1 and click Finish. 4. Go to AngularJS.org  and download Angular JS 1. This will download will consist of a single file angular.min.js 5. Copy the file into the Site Root folder. 6. Drag the angular.min.js file into the index.html file as shown to generate a script tag that points to angular.min.js file. 7. Now add ng-app directive to body tag. Then to test if all works as expected lets add the following code     <body ng-app>         <div>The constant pi is equal to {{22/7}}.</div>     </body> 8. Right click AngularDemo1 project and select Run . 9. The output should look as shown below.

WCF Review Exercise 2

1. Download and open the WCF application  here . 2. Enable message logging in the host application 3. In the client application, handle CommunicationException, TimeOutException, and FaultException in the correct order.  4.  Use finally block to check if the client channel has entered a faulted state if it has then the abort the client and create a new instance of the client if the client is required again. 5. Enable reliable session by changing the app.config of the service host project.  6.  In the service host project, create a custom service host class called NewProdSrvHost. 7.   Override OnOpening() method to add an endpoint with basicHttpBinding and to enable metadata so that M etadata is always enabled with one endpoint. 8. Update the service host project to use the custom host class created above. 9. Update client reference and test the whole application.  10 Save and submit as a single zip file. 

CUMIPMT and CUMPRINC function

CUMIPMT Cumulative interest payment function allows you to calculate the interest paid for a loan or from an investment from period A to period B. When getting a loan, CUMIPMT function can be used to calculate the total amount of interest paid in the first five months or from period 12 to period 20. A period can be a month, a week or two week. Loan Amount : 350,000.00 APR: 4.5% Down payment: 0.00 Years: 25 Payment per year: 12 From the above data, we can calculate the following: No of Period: 25 × 12 = 300 Periodic Rate: 4.5/12 = 0.375% Here is how you will substitute these values into the function. = CUMIPMT (periodic rate, No of period, vehicle price, start period, end period,  ) = CUMIPMT (0.375, 300, 350000, 1, 5, 0) In an excel worksheet, we use cell address instead of actual values as shown below: Here is the formula view of the worksheet: CUMPRINC Another related function is CUMPRINC. CUMPRINC function is used to calculate cumul

ASP.NET Web API

ASP.NET Web API is a framework based on ASP.NET for building HTTP endpoints. The ASP.NET Web API can be built as a part of ASP.NET Webforms or MVC to function as the services layer of a  web, mobile or client desktop application. ASP.NET Web API is recommended over WCF in many situations except if you are limited to use .NET 3.5 and/or if you need to expose a SOAP based service endpoints. ASP.NET Web API is different from REST since it may not fully comply with a RESTful architecture, however, a  REST based service can be built on top of Web API. Creating a simple ASP.NET Web API 1. Open Visual studio 2. Create a new project Template > Visual C# > Web > ASP.NET Empty Web Application 3. Right click on the project > Manage NuGet Packages... > Search for  Web API   > select  Microsoft ASP.NET Web API  > click  Install > Click Close 4. Add a new class to the project, name it MyApiController. 5. Derive the new class from ApiCo

Excel PMT Function

PMT function is very useful for calculating monthly payment required to payback a loan or mortgage at a fixed rate. This function require a minimum of three inputs, periodic rate, number of periods, present value or the loan amount. Here is a simple example. Home Loan: 350,000.00 Interest rate: 4.5% Number of years to repay the loan: 25 Note: To calculate monthly payment, we need to find the monthly rate and number of months as shown above. Then it is simply a matter of substituting the values into the payment function, as shown in the formula view below.

Grouping Excel worksheets

Working with multiple worksheets Excel has a great feature that allows you to work in multiple worksheets simultaneously. This feature allows you to add content and/or format the contents in the multiple worksheet at the same time. Let's look at an example where this feature can be a great time saver. Let's say you have a yearly budget for five years and the data for each year is placed in a separate worksheet. For each year the structure of data set, column heading and row heading are the same. It has cell formatting and number formatting consistent across all worksheets. Now let's say that you want to modify all 5 worksheet simultaneously. This is when the grouping worksheets become very useful. Instead of modifying one worksheet and then copying the changes to other worksheets, you can modify all worksheets at the same time. To do this first group the worksheets that you want edit simultaneously. To group worksheets To group worksheets together use one of the

Service Instance and InstanceContextMode attribute

InstanceContextMode can be set to PerCall, Single or PerSession. InstanceContextMode.PerCall Description New service instance for each call. To enable set InstanceContextMode.PerCall Service Instance created when The instance is created when a request is received from the client Service Instance disposed when Disposed after servicing a single call. Benefits Scalable, Service instance disposed after each call. Issues Stateless, lowers performance, Clients not aware of multiple instances created during session. InstanceContextMode.Single Description Single instance is used to serve all calls. To enable set InstanceContextMode.Single Service Instance created when The instance is created when the service host is created Service Instance disposed when Disposed when service host is closed. Benefits Easy to manage

Controlling life cycle of a Service instance

1. Download the start file here . 2. To use a single service instance to handle request all clients, add the following annotation above the service implementation. [ ServiceBehavior (InstanceContextMode = InstanceContextMode .Single)] public class StudentService : IStudentService { ... 3. Run the ConsoleHost and ConsoleClient, add a student then use option 3 and 4. Notice the instance HashCode for all three service calls. 4. When the above ConsoleHost and ConsoleClient is running, add another ConsoleClient. 5. Using the new ConsoleClient, add a student then use the option 3 and 4. Switch to the first ConsoleClient and add another student. Then use option 4. 6. Notice that all of the above calls use just a single instance or a Singleton of the service. 7. Now, let's see how the PerCall ServiceInstanceMode behaves. To change it PerCall mode do the following changes. [ ServiceBehavior (InstanceContextMode =  InstanceContextMode .PerCall)] public   cla

Importing data into excel worksheet

Excel allows you to import data from various file formats. You can import data from websites, text files, XML files and many types of database files. Here is a simple text file that contains the following data. In this dataset, each field is separated by a comma and each record starts in a new line. To import above text file into an excel worksheet: 1. Select the cell where you want the data to be pasted. 2. Click the Data tab > click From Text >   Text Import Wizard dialog box opens 3. There are two options here, keep the default option selected. Check My data has headers . 4. Uncheck Tab and Select comma. Click Next. 5. In step 3 of the Text Import wizard dialog, select the first column and select text option, select the second column and check the text option and repeat for the third. 6. Click finish. A Import Data dialog appears, click OK to accept the default. 7. Now you should have successfully imported the comma separated

Creating a custom Service Host Factory

Creating a custom ServiceHostFactory 1. Follow the instructions in this blog to create a custom service host. 2. Follow the instructions in this blog to Host the service in a website 3. Open the NewProdSrvHost.cs file and change the constructor as shown below: public NewProdSrvHost( params Uri [] baseAddresses) : base ( typeof ( ProductService ),baseAddresses) { } 4. Move the NewProdSrvHost to the ProductServiceLibrary Project. 5. Right click productServiceLibrary project > select Add > Class > name: ProdSrvHostFactory. 6. Make the class public and derive it from ServiceHostFactory 7. Override CreateServiceHost method Protected override Sytem.ServiceModel.ServiceHost CreateServiceHost(type { return new NewProdSrvHost(baseAddresses); } 8. Go to Svc file and add Factory attribute <%@ ServiceHost Service="ProductServiceLibrary.ProductService" Factory="ProductServiceLibrary.ProdSrvHostFactory" %> 9. Open the Svc file in

Hosting WCF service in an ASP.NET website

WCF services can be hosted in IIS as an ASP.NET Website. This provides a number of benefits. First of all the service process need not be running for the request to be made, instead it is started when a request is made. Further, IIS mgr can be used to manage the service. One of the main disadvantage of hosting WCF service like this is that it forces the endpoints to use HTTP. 1. Open the solution attached  here . 2. Right click on the solution > select add > New Web Site... > select WCF Service template > use ProdSrvWebsiteHost as the name. 2. Expand App_code, look at IService.cs and Service.cs. Delete IService.cs and Service.cs  and open Service.svc and inspect. 3. Add reference to the ProductServiceLibrary 4. Add a ServiceHost directive with Service attribute pointing to Service.svc. <% @ ServiceHost service ="ProductServiceLibrary.ProductService" %> 5. Open web.config and notice that the base address is not specified. Base address spe