AWG Blogs

Monday, April 30, 2012

Middleman Pattern

The DCI paradigm, specifically the canonical example of the account transfer seems unnatural. If I'm not mistaken, in most business domains the act of transferring resources between entities is performed by a middleman entity. Behavior is no more injected into entities than are entry-level checking account clerks trained on the spot to make transfers to investment accounts (imagine this is a bank in the pre-computing days).

So I propose the "Middleman Pattern." The following is an example. Note: the example could be abstracted in that concrete classes could be decoupled via interface implementation and dependency injection.



Edit: See also suggestion of "money transferrer" at http://pettermahlen.com/2010/09/10/dci-architecture-good-not-great-or-both/

Tuesday, April 24, 2012

SharePointMVC Note

When following the Deployment.docx, the instructions say to put the DLLs in the SharePoint website _app_bin. Well, I had to also put the web app DLL in the SharePoint website bin folder to get it working; otherwise I'd get the error: Could not load type 'SampleWebApplication.xxxxxx'.   at System.Web.UI.TemplateParser.GetType(String typeName, Boolean ignoreCase, Boolean throwOnError)
   at System.Web.UI.TemplateParser.ProcessInheritsAttribute(String baseTypeName, String codeFileBaseTypeName, String src, Assembly assembly)
   at System.Web.UI.TemplateParser.PostProcessMainDirectiveAttributes(IDictionary parseData)

Sunday, April 15, 2012

UML Aggregation Vs DDD Aggregate

The same root term "Aggregate" in DDD does not correspond to the UML "Aggregation" notation (filled diamond).

DDD use of root term "Aggregate":
OrderLines have no reason to exist without their parent Order, nor can they belong to any otherOrder. In this case, Order and OrderLines would probably be an Aggregate, and the Order would be the Aggregate Root

Sunday, March 18, 2012

Force Post in .load method

The following code:
$('div').load('Service.asmx/HelloWorld')
may produce the error in the Response as visible from the Console tab of Firebug: "Request format is unrecognized for URL unexpectedly ending in '/HelloWorld'."

This ASP.NET web service expects a POST. To force a POST change the code by adding a bogus object to the .load jQuery method:
$('div').load('Service.asmx/HelloWorld',{test:"blah"})

Update: Actual fix is to edit the web.config, see comment by Lotas here.

Monday, March 12, 2012

Setting Theme in Feature Receiver

When provisioning web sites, the theme was not taking. To get it working I made the following change to RestoreWebProperties, which was generated by SharePoint Solution Generator.

string key = xWebProperty.Attributes["Key"].Value;
string value = xWebProperty.Attributes["Value"].Value;
//this does not work for __IncludeSubSitesInNavigation, use AllProperties instead
/* if (web.Properties.ContainsKey(key))
{
web.Properties[key] = value;
}
else
{
web.Properties.Add(key, value);
} */
//need explicit set, apparently setting via property bag does not effect update
if (key == "vti_themedefault")
{
try
{
web.ApplyTheme(value);
}
catch { }

}
else
{
web.AllProperties[key] = value;

}



Note, get the theme key from TemplateID element in SPTHEMES.XML. Also do web.Update() instead of web.Properties.Update().

Friday, March 9, 2012

TFS Project Folders and Workspaces

In Source Control Explorer, one way to map separate folders to separate local paths, perhaps on a separate drive e.g., is to use Workspaces.

Do File, Source Control, Workspaces, Add Workspace. Name the Workspace as appropriate, e.g. "My Projects." Select the TFS project folder, and the corresponding Local folder. Click OK.

This way you can separate your local files on a separate local root folder, (e.g. c:\My Projects") from folders other team members own (e.g. mapping of c:\Other projects).

Sunday, February 26, 2012

Perl Map Chaining to Obtain Unique Subkeys

Say you have a file with contents:

AABB 7323|Jan 28, 2003|Random Data Here
YZZ 2852|Mar 3, 2007|Data Data
YZZ 2559|Aug 2, 2010|More Data
AABB 2383|Jun 1, 2011|Data Field Data

The following perl script can list the unique key types:

#!/usr/bin/perl

use strict;
use warnings;

my $filename = "testinput.txt";
open (ROWS, "<$filename");

my $delimiter = '\|';

my %values = map {split / /, $_ } keys %{{map { split $delimiter, $_, 2 } <ROWS>}};
my @uniques = keys %values;
print join ("\n", @uniques);

exit 0;

which outputs:

AABB
YZZ

Note: when assign an array to a hash lvalue, the array elements are assign sequentially in key value pairs, since there's no such thing as hash context. see http://tutorials.freeskills.com/professional-perl-part-3-prototypes.htm