ASP.NET 5 Typescript AngularJS application with a grunt production configuration

Originally posted on Software Engineering:

This article demonstrates how to implement an AngularJS application using Typescript and grunt in ASP.NET 5. The application is built using Typescript and based on this example. The application uses grunt as its task runner. The grunt task runner produces a production configuration and can also be used in a CI process on any build server.

Code: https://github.com/damienbod/AspNet5TypescriptProductionGrunt

grunt setup

The grunt is setup so that the application uses only 4 files for all its javascript and css dependencies. This could also be optimized down to 2 files if preferred. The index.html file is implemented as follows: (You can see from the file that angular and angular-ui-router is used.)

This index file uses the javacript and the css files produced in the grunt tasks.The grunt file has two main tasks: development and buildserver. The development task creates the javascript files from the typescript files using grunt-ts, then concats all…

View original 651 more words

Evaluation of CodeFluent – Part 3

(This is the third part of a three part evaluation I am doing on SoftFluent’s CodeFluent Entities. Please read part 1 and part 2 before reading this.)

At the end of part 2 I had built the OrderProcess solution. And as I mentioned there, it had generated the necessary SQL scripts in order to build the OrderProcess database in SQL Server. Here’s what my Solution Explorer looks like now:

Solution Explorer after the build

Just because I’m a curious sort of guy I thought I’d take a look at one of the SQL Scripts that CodeFluent generated. Here’s some of the OrderProcess_tables.sql script (I’m ignoring the normal IF EXISTS() … DROP TABLE stuff which naturally precedes these CREATE TABLE definitions):

CREATE TABLE [dbo].[Order] (
 [Order_Reference] [uniqueidentifier] NOT NULL,
 [_trackLastWriteTime] [datetime] NOT NULL CONSTRAINT [DF_Ord__tc] DEFAULT (GETDATE()),
 [_trackCreationTime] [datetime] NOT NULL CONSTRAINT [DF_Ord__tk] DEFAULT (GETDATE()),
 [_trackLastWriteUser] [nvarchar] (64) NOT NULL,
 [_trackCreationUser] [nvarchar] (64) NOT NULL,
 [_rowVersion] [rowversion] NOT NULL,
 CONSTRAINT [PK_Ord_Ord_Ord] PRIMARY KEY NONCLUSTERED
 (
  [Order_Reference]
 ) ON [PRIMARY]
)

This looks pretty normal.

Building the solution also generated new classes in the class library project OrderProcess. Here’s what some of the Order.cs file looks like:

//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:4.0.30319.34014
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace OrderProcess
{
    using CodeFluent.Runtime;
    using CodeFluent.Runtime.Utilities;
    
    
    // CodeFluent Entities generated (http://www.softfluent.com). Date: Tuesday, 16 December 2014 15:16.
    // Build:1.0.61214.0796
    [System.CodeDom.Compiler.GeneratedCodeAttribute("CodeFluent Entities", "1.0.61214.0796")]
    [System.SerializableAttribute()]
    [System.ComponentModel.DataObjectAttribute()]
    [System.Diagnostics.DebuggerDisplayAttribute("EK={EntityKey}, Reference={Reference}")]
    [System.ComponentModel.TypeConverterAttribute(typeof(CodeFluent.Runtime.Design.NameTypeConverter))]
    public partial class Order : System.ICloneable, System.IComparable, System.IComparable<OrderProcess.Order>, CodeFluent.Runtime.ICodeFluentCollectionEntity<System.Guid>, System.ComponentModel.IDataErrorInfo, CodeFluent.Runtime.ICodeFluentMemberValidator, CodeFluent.Runtime.ICodeFluentSummaryValidator, System.IEquatable<OrderProcess.Order>
    {
        
        private bool _raisePropertyChangedEvents = true;
        
        private CodeFluent.Runtime.CodeFluentEntityState _entityState;
        
        private byte[] _rowVersion;
        
        private System.Guid _reference = CodeFluentPersistence.DefaultGuidValue;
        
        [System.NonSerializedAttribute()]
        private OrderProcess.ProductCollection _products;
        
        public Order()
        {
            this._reference = System.Guid.NewGuid();
            this._entityState = CodeFluent.Runtime.CodeFluentEntityState.Created;
        }
        
        [System.ComponentModel.BrowsableAttribute(false)]
        [System.Xml.Serialization.XmlIgnoreAttribute()]
        public virtual bool RaisePropertyChangedEvents
        {
            get
            {
                return this._raisePropertyChangedEvents;
            }
            set
            {
                this._raisePropertyChangedEvents = value;
            }
        }
  //the rest of the code is left out, for brevity's sake
 }
}

Again, this looks like what you’d expect.

Getting into SSMS you can see that it’s created the OrderProcess database for us. Here’s what my Object Explorer now looks like in SSSMS 2014:

Object Explorer after creating the OrderProcess database

At this point you’ve got a working API for any .NET project you’d need to add it to. The instructions for the tutorial uses a console app to illustrate how this can be done. Add a console app named OrderProcecss.ConsoleApp to the OrderProcess solution.

Next you’ll need to add a reference to the OrderProcess project, in the new console app OrderProcess.ConsoleApp project. Also you’ll have to add a reference to the CodeFluent runtime DLL (CodeFluent.Runtime.dll), which on my system I found in C:\Program Files (x86)\SoftFluent\CodeFluent\x64.

Then we’ll enter the following code into the console app’s Main() function:

static void Main(string[] args)
{
 Product car = new Product();
 car.Name = "Car";
 car.Price = 15000.0;
 car.Save();
 ProductCollection products = ProductCollection.LoadAll();
 foreach (var p in products)
 {
  Console.WriteLine(p.Trace());
 }
 Console.WriteLine("\n\r\n\rPress Enter to exit.");
 Console.ReadLine();
}

You also have to add some configuration information to the console app’s configuration file. Within the <configuration> section add the following:

<configSections>
<section name="OrderProcess"
   type="CodeFluent.Runtime.CodeFluentConfigurationSectionHandler, CodeFluent.Runtime"/>
</configSections>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
<OrderProcess connectionString="server=LOCALHOST;database=OrderProcess;Trusted_Connection=true" />
</configSections>

(Just a word of advice, I misspelled “connectionString” and had a devil of a time finding that error until the SoftFluent technical support pointed out my mistake.) Once you’ve done making those changes, you can run the application. When I ran it this is what I got:

Command Prompt Window

As you can see by this, the ID is a GUID, but Name and Price both have what I assigned to them within the main() function of the console app. It even lists the EntityState (Unchanged, in this case).

This concludes my evaluation of SoftFluent’s CodeFluent Entities via their getting started tutorial. I hope that you’ve found this helpful.

Evaluation of CodeFluent – Part 2

This is a continuation of SoftFluent’s CodeFluent Entities evaluation which I started in Part 1. Please see if before continuing here. Continuing with the CodeFluent Entities tutorial I’ll generate some code which can be used for different data store technologies. (This reminds me of Microsoft’s Entity Framework’s Code First way of generating storage entities.) CodeFluent Entities has 20 different providers that it can work with from the get go. The next step is to add a class library project to the OrderProcess solution. We’re going to name this new project OrderProcess. Remember in Part 1 we created a CodeFluent Entities project named OrderProcess.Model, so no conflict in project names. We delete the default class Class1 from the project. We add a folder named “Persistence Scripts” to this  project, which will have the SQL scripts that will generate the SQL Server scripts. In order to add this functionality we need to add a SQL Server Producer to the original OrderProcess.Model project. In there is a Producers folder, right clicking on it will bring up the Add New Producer dialog: Add New Producer According to the instructions for the tutorial we’re to open up the “Persistence Layer Producers” node. However, before doing that I did some poking around to see what else was available. Under the “Application Producers” node there’s things like Microsoft Office Lists, including lists from either MS Access of Excel. I also see “WPF CllickOnce Smart Client”, which apparently is in beta. This is of interest to me, as I’ve done some WPF development, and so I might come back later and see what that could lead to, but will have to save that for another time. There’s “Business Layer Producers”, which only has “Business Object Model”. The “Utility Producers” includes Entity Framework! It also has command line execution and Silverlight Object Model. And the last in the list on the dialog box is “Web Producers”, which has things in it like ASP.NET Web Controls and ASP.NET Web Service both labeled legacy. I would presume this means things like .asmx and possibly WCF. There are other things under “Web Producers”. It also includes SharePoint WebParts, which I imagine would be of interest to SharePoint developers. But in this case we’re working with the “Persistence Layer Producers”, which is for database types like MySQL, Oracle, PostgreSQL, SQL Server and SQL Server Azure. For this purpose I’m working with SQL Server, so I’ll select that. I then get this: Add New Producer SQL Server As you can see there’s a validation error here, but that’s because we’ve got to specify a folder to put the scripts generated. Here we choose that “Persistence Scripts” folder that we created in the new OrderProcess project. This pops up a Browse for Path or Project Folder dialog, which looks like this on my machine: Browse for Path of Project The next step wasn’t too obvious to me, but what you had to do was click on the empty textbox next to Connection String in the Add New Producer dialog. According to the tutorial instructions it says you’re to, “Click in the cell corresponding to the ‘Connection String’ value and type-in your connection string thanks to the ‘Connection String Editor’ window and click OK to validate the connection.” At this point I don’t know what my connection string is, as I don’t have a database out there to use. What I believe we’re to do is click on the button with the three dots in it that you see when you click on the textbox next to “Connection String”. Clicking on that you then get this: Connection String Editor My connection string looks different from what’s in the instructions, but that might be de to the version of SQL Server I’m using. (I’m using SQL Server 2014 Developer Edition.) I clicked on the Test Connection button, which is my habit. It couldn’t find the database, but it did suggest that it might be because the database doesn’t yet exist, which certainly is true. Or I could use the Master database, which I certainly do not want to do! Nevertheless, this s helpful. According to the instructions  CodeFluent Entities will create the database if it doesn’t exist, so I’ll click on the OK button instead. Clicking OK on the Add New Producer dialog adds the producer to the OrderProcess.Model project. My solution explorer now looks like this: Solution Explorer Next we’ll add a business object model producer. Going back to the Producers folder in the OrderProcess.Model project, we once again right click on the Producers folder, but this time we choose Business Layer Producers and under that Business Object Models. Once again you’ll see that the Target Directory has a validation error, but that’s only because we’re just adding this producer. In tis case we’ll select the OrderProcess folder and click OK. (I think it is important to point out here that “Business Object Model” doesn’t mean something related to Crystal Reports. I made that mistake, so don’t think that it has anything to do with Crystal Reports.) Here is how the Add New Producer dialog now looks on my machine: Add New Producer after adding BOM At this point we’re ready to build our solution, so I do a Control+Shift+B to build it. When I did I got the following error:

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 – Could not open a connection to SQL Server)

I believe this is caused by the server name in the connection string dialog box being 127.0.0.1. I’m going to go into the connection string dialog box and change that to include (Local). I got to that by double clicking on the SQL Server producer so I could go to the connection string. This is how I changed it: Connection String Editor, with correction Now let’s try that build again. That fixed that problem. So if you encounter that error I got above, change your connection string to not use the IP address, but instead use local for your SQL Server. (Note: I am doing this with the local, default instance of SQL Server on my development box. Naturally if you’re using a named instance or a SQL Server instance remotely, then make appropriate adjustments.) Now that we’ve got the build to work, it generated a lot of the code to generate necessary SQL objects. The SQL scripts are written in the Persistence Scripts folder. I’ll continue this in part 3 of this evaluation.