Programming

Why Functional Programming Matters?

Dated, but a highly recommended reading for functional programmers by John Hughes of Institutionen  Datavetenskap,

 

Abstract: As software becomes more and more complex, it is more and more important to structure it well. Well-structured software is easy to write, easy to debug, and provides a collection of modules that can be re-used to reduce future programming costs. Conventional languages place conceptual limits on the way problems can be modularised. Functional languages push those limits back. In this paper we show that two features of functional languages in particular, higher-order functions and lazy evaluation, can contribute greatly to modularity. As examples, we manipulate lists and trees, program several numerical algorithms, and implement the alpha-beta heuristic (an algorithm from Artificial Intelligence used in game-playing programs). Since modularity is the key to successful programming, functional languages are vitally important to the real world.

The paper is available as postscript and pdf.  - Why Functional Programming Matters

Share

Resolution for the group's SID could not be resolved Error

I have recently encountered the following error when enumerating through the UserPrincipal.GetAuthorizationGroups collection.

System.DirectoryServices.AccountManagement.PrincipalOperationException: An error (1301) occurred while enumerating the groups.  The group's SID could not be resolved.

The problem was introduction of the domain controller running Server 2012 while the machine running my application was win7 VM (applies to Win2K8 as well)

7536.errorMessage3

With little googling, it appears that for the Windows 7 VM with introduction of 2012 domain controller, this SID error appears to be a known issue. When a 2012 domain controller is involved, the GetAuthorizationGroups() function would fail on groups (SIDs) that are added to a user by default.

Installing KB2830145 fixed my problem.

References

 

Share

[Book Review] Angular JS Services

Angular JS services by Jim Levin is a delightful addition to a topic which isn’t discussed as much as the framework itself. Angular, as a powerful structural framework for dynamic web apps has been topic of various well publicized texts. However the services, which provide the core of backend functionality, don’t get much lime-light. c’est la vie.

 

download

In Angular, services are designed as substitutable objects that are wired together using dependency injection (DI); therefore the understanding of law of demeter is quite important. Author started with fundamentals without much ado, and seamlessly transitioned into discussion about testability, mocking, data management and business logic handling. Handling cross cutting concerns (chapter 4) and Mash-ups (chapter 6) are especially interesting topics. BDD using Jasmine spies (test doubles) is also a treat for behavior-driven development fans.

The notion of designing services, tenets, best practices and architecting services for testability are topics every developer should pay attention to. Levin discusses service building best practices, factories and providers in a concrete and concise fashion with easy to understand code samples.

angular-js-logo

The book assumes that one is already familiar with JavaScript and have some experience writing applications using Angular. The quality of print vs. cost is a letdown; I hope it improves in next editions.

[Disclaimer] I have received the review copy from the publisher.

Share

Teaching Functional Programming to Professional .NET Developers

An informative paper by Tomas Petricek of University of Cambridge.

Abstract. Functional programming is often taught at universities to first-year or second-year students and most of the teaching materials have been written for this audience. With the recent rise of functional programming in the industry, it becomes important to teach functional concepts to professional developers with deep knowledge of other paradigms, most importantly object-oriented. We present our experience with teaching functional programming and F# to experienced .NET developers through a book Real-World Functional Programming and commercially offered F# trainings. The most important novelty in our approach is the use of C# for relating functional F# with object-oriented C# and for introducing some of the functional concepts. By presenting principles such as immutability, higher-order functions and functional types from a different perspective, we are able to build on existing knowledge of professional developers. This contrasts with a common approach that asks students to forget everything they know about programming and think completely differently. We believe that our observations are relevant for trainings designed for practitioners, but perhaps also for students who explore functional relatively late in the curriculum.

 

 

Honorable mention to A Look at F# from C#’s corner 

Share

GAC Changes in Windows Server 2012

Prior to Windows Server 2012, gacutil is typically used to install DLL files in the Windows Global Assembly Cache (GAC). With Windows Server 2012 unfortunately it's not quite so easy. Being able to simply open the GAC in Explorer and drag/drop is gone (so yeah, no shell!). Also GacUtil.exe is not present on the server by default as part of runtime. In order to use gacutil like earlier versions of Windows, we would need to install the .NET SDK on the server which is not really a good idea (defense in depth; only have runtime on server). Of course copying-pasting gacutil.exe doesn’t work (dependencies).

Since we are all too familiar to.NET versions prior to 4.0, GAC used to be in the c:\windows\assembly window and had a custom shell extension to flatten the directory structure into a list of assemblies. Like mentioned earlier, the shell extension is no longer used for .NET versions 4.0 and up. Since we have .NET 4.5 on server machines, its GAC is stored in c:\windows\microsoft.net\assembly. You just get to see the actual directory structure. Locating the assembly isn't that difficult, start in the GAC_MSIL directory and you should have no trouble locating your assembly there by its name. Locate the folder with the same display name as your assembly. It will have a subdirectory that has an unspeakable name that's based on the version and public key token, that subdirectory contains the DLL.

Therefore, PowerShell is the recommended approach to do the GAC install. Following are the instructions on how to install the dll to GAC in Windows 2012 Server. For EL6, we ended up writing the following powershell script.

Set-location "C:\tmp"
 [System.Reflection.Assembly]::Load("System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
 $publish = New-Object System.EnterpriseServices.Internal.Publish
 $publish.GacInstall("c:\tmp\Microsoft.Practices.EnterpriseLibrary.Common.dll")
 $publish.GacInstall("c:\tmp\Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.dll")
 $publish.GacInstall("c:\tmp\Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.dll")
 $publish.GacInstall("c:\tmp\Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF.dll")
 $publish.GacInstall("c:\tmp\Microsoft.Practices.EnterpriseLibrary.Logging.dll")

Happy Coding!

Share

WCF Handling Nested Attributes in AttributeGroup

tldr; SVCUtil does not Generate Code for Nested Attributes in AttributeGroup; here is the code (github repo) and explanation of a workaround.

Beyond Controlled HelloWorld() samples, interoperability standards are not black and white, rather a process that has shades of gray. If you've worked on consuming 3rd party 'enterprise' API's, you may have encountered problems with flattening of WSDL’s, or when generating a service proxy using svcutil.exe, noticed that not all attribute groups gets generated.  For instance, an attributeGroup wrapping another which contains attributes, those attributes will NOT be generated.

I tried a few things like using the DataContractSerializer but it appears that the attributeGroup is ignored by design. The only workaround appears to be removing the extra attributeGroup wrapping. DataContractSerializer does not recognize the attributeGroup (see Data Contract Schema Reference) and as you have already noticed, Xsd (essentially the XmlSerializer) does not recognize nested attributeGroups.

One Reference workaround that is described here, essentially asks you to replace the attributeGroup elements with the actual attributes.

For example:

<xs:attributeGroup name="myAttributeGroup">
<xs:attribute name="someattribute1" type="xs:integer"/>
<xs:attribute name="someattribute2" type="xs:string"/>
</xs:attributeGroup>

<xs:complexType name="myElementType">
<xs:attributeGroup ref="myAttributeGroup"/>
</xs:complexType>

should be transformed into:

<xs:complexType name="myElementType">
<xs:attribute name="someattribute1" type="xs:integer"/>
<xs:attribute name="someattribute2" type="xs:string"/>
</xs:complexType>

To do this in a repeatable manner, following code provides a good starting point on how to handle the attributeGroup issue. Here is a before and after screenshot of WSDL's.

SVCUtil does not Generate Code for Nested Attributes in AttributeGroup

 

I created a small C# app to transform the data, and then run svcutil to generate the WSDL. essentially replacing all instances of <attributeGroup ref=”xxx”> with the definitions of <attributeGroupname=”xxx”>, just as described in the link that I provided earlier.

XDocument wsdl = XDocument.Load(inputFile);

IEnumerable<XElement> attributeGroupDefs =
wsdl.Root.Descendants("{http://www.w3.org/2001/XMLSchema}attributeGroup")
.Where(w => w.Attribute("name") != null)
.Select(x => x);

foreach (
XElement r in
wsdl.Root.Descendants("{http://www.w3.org/2001/XMLSchema}attributeGroup")
.Where(w => w.Attribute("ref") != null))
{
string refValue = r.Attribute("ref").Value;

foreach (XElement d in attributeGroupDefs)
{
string defValue = d.Attribute("name").Value;
if (refValue == defValue)
{
IEnumerable<XElement> s =
d.Elements("{http://www.w3.org/2001/XMLSchema}attribute").Select(x => x);
foreach (XElement e in s)
{
r.AddBeforeSelf(e);
}
break;
}
}
}

wsdl.Root.Descendants("{http://www.w3.org/2001/XMLSchema}attributeGroup")
.Where(w => w.Attribute("ref") != null)
.Remove();
wsdl.Save(outFile);

 

This may require some more tweaking, but it appears have corrected all / most of the attributeGroup issues (I only spot checked this).

Happy Coding!

Share

LyX/LaTeX formatting for the C# code

If you are googling trying to find a good way to insert C# code in LyX, this is where you'd probably end up. MaPePer has provided a very good solution; I have modified it slightly (hiding tabs and removing comments) and following is illustration on how to use it in LyX.

First thing you'd need is a Lyx document (LyxC#CodeListing.lyx). Empty one works well.

Add the following to Preamble (Document-> Settings-> LaTeX Preamble)

\usepackage{color}
\usepackage{listings}

\lstloadlanguages{% Check Dokumentation for further languages ...
C,
C++,
csh,
Java
}

\definecolor{red}{rgb}{0.6,0,0} % for strings
\definecolor{blue}{rgb}{0,0,0.6}
\definecolor{green}{rgb}{0,0.8,0}
\definecolor{cyan}{rgb}{0.0,0.6,0.6}

\lstset{
language=csh,
basicstyle=\footnotesize\ttfamily,
numbers=left,
numberstyle=\tiny,
numbersep=5pt,
tabsize=2,
extendedchars=true,
breaklines=true,
frame=b,
stringstyle=\color{blue}\ttfamily,
showspaces=false,
showtabs=false,
xleftmargin=17pt,
framexleftmargin=17pt,
framexrightmargin=5pt,
framexbottommargin=4pt,
commentstyle=\color{green},
morecomment=[l]{//}, %use comment-line-style!
morecomment=[s]{/*}{*/}, %for multiline comments
showstringspaces=false,
morekeywords={ abstract, event, new, struct,
as, explicit, null, switch,
base, extern, object, this,
bool, false, operator, throw,
break, finally, out, true,
byte, fixed, override, try,
case, float, params, typeof,
catch, for, private, uint,
char, foreach, protected, ulong,
checked, goto, public, unchecked,
class, if, readonly, unsafe,
const, implicit, ref, ushort,
continue, in, return, using,
decimal, int, sbyte, virtual,
default, interface, sealed, volatile,
delegate, internal, short, void,
do, is, sizeof, while,
double, lock, stackalloc,
else, long, static,
enum, namespace, string},
keywordstyle=\color{cyan},
identifierstyle=\color{red},
}
\usepackage{caption}
\DeclareCaptionFont{white}{\color{white}}
\DeclareCaptionFormat{listing}{\colorbox{blue}{\parbox{\textwidth}{\hspace{15pt}#1#2#3}}}
\captionsetup[lstlisting]{format=listing,labelfont=white,textfont=white, singlelinecheck=false, margin=0pt, font={bf,footnotesize}}

 

In the preamble (Document-> Settings-> LaTeX Preamble)
preamble

 

Now add a program listing block. Hopefully you have the listing package installed otherwise you can always use the listing MikTeX update.

 

insert-program-listing-lyx


Now add the code to the listing block.


lyx-screen

and then Ctrl-R

 

CodeListing

 

Tada!

 

Happy Lyxing

 

References & download LyxC#CodeListing.lyx

 

 

Share

tracert 216.81.59.173

Pretty cool eh!

tracert

Share

AngularJS Learning Resources

AngularJS Overviews/Whirlwind Tours

Everything you need to understand to start with AngularJS
http://stephanebegaudeau.tumblr.com/post/48776908163/everything-you-need-to-understand-to-start-with

 

AngularJS 101: Everything you need to know to get started
http://www.slideshare.net/sbegaudeau/angular-js-101-everything-you-need-to-know-to-get-started

One Hour AngularJS Boot Camp

AngularJS Fundamentals in 60-ish Minutes (free video training)
http://weblogs.asp.net/dwahlin/archive/2013/04/12/video-tutorial-angularjs-fundamentals-in-60-ish-minutes.aspx

 

AngularJS in 60 Minutes (free eBook)
http://fastandfluid.com/publicdownloads/AngularJSIn60MinutesIsh_DanWahlin_May2013.pdf

In-Depth Online Courses

A Better Way to Learn AngularJS
http://www.thinkster.io/pick/GtaQ0oMGIl/a-better-way-to-learn-angularjs

 

AngularJS Tutorial: Learn to Build Modern Web Apps
http://www.thinkster.io/pick/GUIDJbpIie/angularjs-tutorial-learn-to-build-modern-web-apps

Learn-By-Example

Learn AngularJS: 5 Practical Examples
http://tutorialzine.com/2013/08/learn-angularjs-5-examples/

 

Learning AngularJS By Example: The Customer Manager Application
http://weblogs.asp.net/dwahlin/archive/2013/10/25/learning-angularjs-by-example-the-customer-manager-application.aspx

Paid Video Courseware

Pluralsight course: AngularJS Fundamentals Course
http://pluralsight.com/training/Courses/TableOfContents/angularjs-fundamentals

 

Pluralsight course: AngularJS Best Practices
http://pluralsight.com/training/courses/TableOfContents?courseName=angular-best-practices&highlight=

Unit Testing Resources

Unit Testing Best Practices in AngularJS
http://andyshora.com/unit-testing-best-practices-angularjs.html

 

Full Spectrum Testing with AngularJS and Karma
http://www.yearofmoo.com/2013/01/full-spectrum-testing-with-angularjs-and-karma.html

AngularJS Best Practices

AngularJS Advanced Design Patterns & Best Practices
http://trochette.github.io/Angular-Design-Patterns-Best-Practices/#/intro

 

AngularJS Best Practices: I’ve Been Doing It Wrong!
http://blog.artlogic.com/2013/05/02/ive-been-doing-it-wrong-part-1-of-3/

 

AngularJS Best Practices Wiki
https://github.com/angular/angular.js/wiki/Best-Practices

 

AngularJS Anti-Patterns Wiki
https://github.com/angular/angular.js/wiki/Anti-Patterns

 

Building Huuuuuge Apps with AngularJS
http://briantford.com/blog/huuuuuge-angular-apps.html

 

Angular Style Guide
https://github.com/mgechev/angularjs-style-guide

Cheat Sheets

AngularJS Cheat Sheet (Cheatography)
http://www.cheatography.com/proloser/cheat-sheets/angularjs/pdf/

 

AngularJS Cheat Sheet (Opitz Consulting)
http://www.opitz-consulting.com/fileadmin/redaktion/veroeffentlichungen/pdf/CheatSheet-angularJS.pdf

Additional Resources

AngularJS for .NET Developers
http://henriquat.re/

Guide to AngularJS Documentation
http://docs.angularjs.org/guide/

 

Thanks to David Lazar for these links. You rock!

Share

Study Notes for 70-487 - Developing Windows Azure and Web Services

After taking 70-486 - Developing ASP.NET MVC 4 Web Applications couple of weeks ago, I decided to take the final exam  70-487 - Developing Windows Azure and Web Services last week to finish my MCSD certification.

Adnan Masood Microsoft Certified Solution Developer 2

Following are the set of notes I used along with MCT material which may help those preparing for the exam. The topic-by-topic breakdown is courtesy of a colleague and friend Frank Liao.

Accessing Data (24%)

  • Choose data access technologies

    • This objective may include but is not limited to: Choose a technology (ADO.NET [link], Entity Framework [link], WCF Data Services [link link]) based on application requirements

  • Implement caching [link link]

    • This objective may include but is not limited to: Cache static data [link], apply cache policy (including expirations) [link]; Use CacheDependency to refresh cache data [link link]; query notifications [link]

  • Implement transactions [link] [link link link link link link]

    • This objective may include but is not limited to: manage transactions by using the API from System.Transactions namespace; implement distributed transactions; specify transaction isolation level [link]

  • Implement data storage in Windows Azure [link link link link link link]

    • This objective may include but is not limited to: access data storage in Windows Azure; Choose data storage mechanism in Windows Azure (blobs [link], tables [link], queues [link], SQL Database [link link]); Distribute data by using the Content delivery network (CDN) [link]; Handle exceptions by using retries (SQL Database) [link]; manage Windows Azure Caching [link link]

  • Create and implement a WCF Data Services service [link]

    • This objective may include but is not limited to: Address resources [link]; implement filtering [link]; create a query expression [link]; access payload formats (including JSON) [link]; use data service interceptors [link link] and service operators [link]

  • Manipulate XML data structures [link link link link link link link]

    • This objective may include but is not limited to: Read, filter, create, modify XML data structures; Manipulate XML data by using XMLReader [link], XMLWriter [link], XMLDocument [link], XPath [link], LINQ to XML [link]; transform XML by using XSLT transformations [link]

Querying and Manipulating Data by Using the Entity Framework (20%)

  • Query and manipulate data by using the Entity Framework.

    • This objective may include but is not limited to: Query [link], update, and delete data by using DbContext [link]; build a query that uses deferred execution [link]; implement lazy loading and eager loading [link link link]; create and run compiled queries [link link]; query data by using Entity SQL [link]

  • Query and manipulate data by using Data Provider for Entity Framework [link]

    • This objective may include but is not limited to: Query and manipulate data by using Connection, DataReader, Command from the System.Data.EntityClient namespace [link link link]; perform synchronous and asynchronous operations [link link]; manage transactions (API) [link link]

  • Query data by using LINQ to Entities. [link]

    • This objective may include but is not limited to: query data by using LINQ operators (for example, project, skip, aggregate, filter, and join) [link link link link]; log queries [link link]; implement query boundaries (IQueryable vs. IEnumerable) [link link link]

  • Query and manipulate data by using ADO.NET [link]

    • This objective may include but is not limited to: Query and manipulate data by using Connection, DataReader, Command, DataAdapter, DataSet [link link link]; Perform synchronous and asynchronous operations [link link]; Manage transactions (API) [link]

  • Create an Entity Framework data model. [link link]

    • This objective may include but is not limited to: Structure the data model using Table per type [link link], table per class, table per hierarchy [link link]; Choose and implement an approach to manage a data model (code first [link link] vs. model first [link] vs. database first [link]); implement POCO objects [link link link]; Describe a data model by using conceptual schema definitions, storage schema definition, and mapping language (CSDL, SSDL, MSL) [link link]

Designing and Implementing WCF Services (19%)

  • Create a WCF service

    • This objective may include but is not limited to: Create contracts (service [link], data [link], message [link], callback [link link], and fault [link]); implement message inspectors [link]; implement asynchronous operations in the service [link]

  • Configure WCF services by using configuration settings [link link link]

    • This objective may include but is not limited to: Configure service behaviors; Configure service endpoints; configure binding; specify a service contract; expose service metadata (XSDs, WSDL, and metadata exchange endpoint)

  • Configure WCF services by using the API [link link link]

    • This objective may include but is not limited to: Configure service behaviors [link]; Configure service endpoints [link link]; configure binding [link]; specify a service contract; Expose service metadata (XSDs, WSDL, and metadata exchange) [link]; WCF routing [link] and discovery [link] features

  • Secure a WCF service

    • This objective may include but is not limited to: Implement message level security [link], implement transport level security [link]; implement certificates [link link]

  • Consume WCF services

    • This objective may include but is not limited to: Generate proxies by using SvcUtil [link]; generate proxies by creating a service reference [link]; create and implement channel factories [link]

  • Version a WCF service [link link link link]

    • This objective may include but is not limited to: Version different types of contracts (message, service, data); configure address, binding, and routing [link] service versioning

  • Create and configure a WCF service on Windows Azure [link link link link link link]

    • This objective may include but is not limited to: Create and configure bindings for WCF services (Azure SDK-- extensions to WCF); Relay bindings to Azure using service bus endpoints [link link link]; integrate with the Azure service bus relay [link]

  • Implement messaging patterns [link link]

    • This objective may include but is not limited to: Implement one way [link], request/reply [link], streaming [link], and duplex communication [link]; implement Windows Azure Service Bus [link] and Windows Azure Queues [link] [link link link]

  • Host and manage services

    • This objective may include but is not limited to: Manage services concurrency (single, multiple, reentrant) [link link link]; Create service hosts; Choose a hosting mechanism [link link]; choose an instancing mode (per call, per session, singleton) [link link]; activate and manage a service by using AppFabric [link link link]; implement transactional services [link link]; host services in an Windows Azure worker role [link]

Creating and Consuming Web API-based services (18%) [link]

  • Design a Web API [link link link link link]

    • This objective may include but is not limited to: define HTTP resources with HTTP actions; plan appropriate URI space, and map URI space using routing; choose appropriate HTTP method (get, put, post, delete) to meet requirements; choose appropriate format (Web API formats) for responses to meet requirements; plan when to make HTTP actions asynchronous

  • Implement a Web API [link link]

    • This objective may include but is not limited to: accept data in JSON format (in JavaScript, in an AJAX callback) [link]; use content negotiation to deliver different data formats to clients [link]; define actions and parameters to handle data binding [link]; use HttpMessageHandler to process client requests and server responses [link]; implement dependency injection, along with the dependency resolver, to create more flexible applications [link]; implement action filters and exception filters to manage controller execution [link]; implement asynchronous and synchronous actions; implement streaming actions

  • Secure a Web API [link]

    • This objective may include but is not limited to: implement HTTPBasic authentication over SSL; implement Windows Auth; enable cross-domain requests [link link]; prevent cross-site request forgery (XSRF); implement, and extend, authorization filters to control access to the application [link]

  • Host and manage Web API [link]

    • This objective may include but is not limited to: host Web API in an ASP.NET app [link link]; self-host a Web API in your own process (a Windows service) [link link]; host services in a Windows Azure worker role [link link]; restricting message size [link]; configure the host server for streaming [link]

  • Consume Web API web services

    • This objective may include but is not limited to: consume Web API services by using HttpClient synchronously and asynchronously [link]; send and receive requests in different formats (JSON/HTML/etc.) [link]

Deploying Web Applications and Services (19%)

  • Design a deployment strategy

    • This objective may include but is not limited to: Create an IIS install package [link link]; deploy to web farms [link]; deploy a web application by using XCopy [link link]; automate a deployment from TFS or Build Server [link link link link link]

  • Choose a deployment strategy for a Windows Azure web application

    • This objective may include but is not limited to: Perform an in-place upgrade and VIP swap [link link]; configure an upgrade domain [link]; create and configure input and internal endpoints [link link]; specify operating system configuration [link link]

  • Configure a web application for deployment

    • This objective may include but is not limited to: switch from production/release mode to debug mode; use SetParameters to set up an IIS app pool [link link], set permissions and passwords) [link]; configure WCF endpoints, bindings, and behaviors [link link link link link]; transform web.config by using XSLT (for example, across development, test, and production/release environments) [link link]; configure Azure configuration settings [link]

  • Manage packages by using NuGet [link link]

    • This objective may include but is not limited to: Create and configure a NuGet package [link]; install and update an existing NuGet package [link link]; connect to a local repository cache for NuGet [link], set up your own package repository [link]

  • Create, configure, and publish a web package [link]

    • This objective may include but is not limited to: Create an IIS InstallPackage [link]; configure the build process to output a web package [link]; apply pre- and post- condition actions to ensure that transformations are correctly applied [link]; include appropriate assets (web content, certificates) [link]

  • Share assemblies between multiple applications and servers

    • This objective may include but is not limited to: Prepare the environment for use of assemblies across multiple servers (interning) [link]; sign assemblies by using a strong name [link]; deploy assemblies to the global assembly cache [link link]; implement assembly versioning [link]; create an assembly manifest [link]; configure assembly binding redirects (for example, from MVC2 to MVC3 [link]

Share
Go to Top