Wednesday, May 14, 2014

Scaling Agile Across the Enterprise

Microsoft put out some videos about "Scaling Agile Across the Enterprise".  I particularly like the video which talks about how the waterfall method is not a good way to design software anymore and how businesses struggle with that.

It can be found here: https://www.youtube.com/watch?v=n79fJUiQ-PU


Wednesday, March 12, 2014

Nhibernate, Abstract Base Classes and JSON.NET

While working on a project I ran into an issue where JSON.NET was not serializing and deserializing my nhibernate entities that used polymorphism. I found plenty of examples that showed how to do this with objects directly but none with Lists and Collections. This code isn't generic like it should be but worked for my purposes. So here is my code:

POCO:

 
[JsonConverter(typeof(LineItemConverter))]
public virtual ICollection LineItems { get; set; }

JsonConverter:

 
public class LineItemConverter : JsonConverter
    {
        public override bool CanConvert(Type objectType)
        {
            return typeof(LineItem).IsAssignableFrom(objectType);
        }

        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {

            var lineitems = JArray.Load(reader);
            var lineItemObjects = new List();


            foreach (var lineitem in lineitems)
            {
                switch (EnumUtil.ParseEnum(lineitem["lineItemType"].Value()))
                {
                    case LineItemType.Assessorial:
                        lineItemObjects.Add(lineitem.ToObject());
                        break;

                    case LineItemType.DeficitWeight:
                        lineItemObjects.Add(lineitem.ToObject());
                        break;

                    case LineItemType.Discount:
                        lineItemObjects.Add(lineitem.ToObject());
                        break;

                    case LineItemType.FloorAdjustment:
                        lineItemObjects.Add(lineitem.ToObject());
                        break;

                    case LineItemType.Freight:
                        lineItemObjects.Add(lineitem.ToObject());
                        break;

                    case LineItemType.Fuel:
                        lineItemObjects.Add(lineitem.ToObject());
                        break;

                    case LineItemType.Other:
                        lineItemObjects.Add(lineitem.ToObject());
                        break;

                    default:
                        break;

                } 
            }

            return lineItemObjects;
            
        }


        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {

            var lineitems = value as ICollection;
            serializer.Serialize(writer, lineitems.ToArray());
            
        }

Tuesday, January 28, 2014

Angluar JS + c# Web API decimals not routing

For some reason when i would put/get decimal values with the angularjs $resource i would get a 404. After lots of research i found out that this is due to $resource dropping trailing slashes (more info here: http://stackoverflow.com/questions/14533117/angular-trailing-slash-for-resource ). There is talk that in angular 1.3 they will add this as an option but for now we need to use a hack.
HACK: Add "\\/" to the end of your url in the $resource. For example: return $resource('/api/pricingAgreementItem/:id/:action/:value\\/', { id: '@id' },... See below for a more complete example.
 Javascript: C#:

Wednesday, November 20, 2013

Simple Membership + WebMatrix.Data & WebMatrix.WebData

In order to use simple membership roles with an MVC5 project you need WebMatrix.WebData reference.  To obtain this Reference you need to use nuget and install Microsoft.AspNet.WebHelpers.  I am documenting it here so i don't forget. Non-MVC projects need Microsoft.AspNet.WebPages.OAuth (Install-Package Microsoft.AspNet.WebPages.OAuth) http://stackoverflow.com/questions/13324544/how-to-add-asp-net-membership-provider-in-a-empty-mvc-4-project-template/13325883#13325883

Sunday, November 17, 2013

Visual Studio 2013 + Angularjs + JasmineJS + Resharper 7/8 (or Chutzpah)

I recently started a project which used the following technologies: Visual Studio 2013 + Angularjs + JasmineJS + Resharper 7/8 (or Chutzpah).

I was having a rough time getting JasmineJS to work with Resharper/Chutzpah.  The strange thing was that it would work in the specrunner but not in the actual resharper or chutzpah interfaces which directly integrate into Visual Studio (which is what i wanted).

After spending a couple hours of research i came upon this blog: http://microsoftwindowsblogger.blogspot.com/2013/10/best-unit-testing-angularjs-with.html

Basically you have to inject the script references into the unit test files (which i knew) but they must ALSO BE RELATIVE PATHS TO THE TEST FILE!

Here is an example of a working Jasmine Unit Test which integrates angularjs and works with both Chutzpah and Resharper 7+:

Wednesday, October 9, 2013

SQL Express 2012 Automated Backup Script

SQL Express doesn't come with the SQL Server Agent and so you can not use the Full SQL server backup maintenance plans.  To get around this I am using the following script which is executed once a day by the task scheduler.

sp_BackupDatabases can be found here: http://support.microsoft.com/kb/2019698

database_backup.bat

md c:\temp_database_bak
sqlcmd -S {{MACHINE_NAME}}\SQLEXPRESS -Q "EXEC sp_BackupDatabases @backupLocation='c:\temp_database_bak\', @backupType='F'"

FOR %%A IN (%Date%) DO (
    FOR /F "tokens=1-3 delims=/-" %%B in ("%%~A") DO (
        SET Today=%%D%%B%%C
    )
)

"C:\Program Files\7-Zip\7z.exe" a c:\backup_mssql\Database_BAK.%TODAY%.7z "C:\temp_database_bak\"

rmdir c:\temp_database_bak /S /Q

Thursday, June 13, 2013

Visio Alternative

If you are a developer you probably have Visio but if you don’t https://www.draw.io/ is a great alternative and its free.

Phoenix

I am resurrecting this tech blog for notes related to Azure Logic Apps with SAP.