Author Archive

AngularJS CheatSheet

ng-app (usually on html)

ng-controller (on the body or on the container)

‘use strict’;

scripts order: Jquery – Angular (in the head possibly) other scripts: 

var testApp = angular.module(‘myFirstAng’, []);
testApp.controller(‘myController’, function ($scope) {
$scope.Test = “hello world”;


use of $http:

myApp.controller(‘myController’, function ($scope, $http) {

dataType: ‘json’, headers: {
“Content-Type”: “application/json”
}, data: ”, method: ‘GET’,
url: ‘/api/Sdb’
}).success(function (data, status, headers, config) {
$scope.Result = data;
.error(function (data, status, headers, config) {


NG-Repeat: ng-repeat=”friend in friends”


data-ng-options=”bg.Name for bg in businessGroups”
data-ng-change=”ChangeEvent()” >
<option value=””>-Select-</option>



 <div class=“gridStyle” ng-grid=“gridOptions” style=“width: 90%; height: 90%”></div>


 $scope.gridOptions = {
                data: ‘users’, columnDefs: [
                    { field: ‘FullName’, displayName: ‘FullName’, resizable:true, width:200 },
                    { field: ‘UserName’, displayName: ‘UserName’, resizable: true },
                        field: ‘LastLogin’, displayName: ‘LastLogin’,
                        cellFilter: “date:’dd/MM/yyyy HH:mm'”
                    { field: ‘AssignedRoles’, displayName: ‘AssignedRoles’, resizable: true, cellFilter: ‘stringArrayFilter’ }]
                            function (dataReturned) {
                                $scope.users = dataReturned;

Jasmine testing:
describe("myApp", function() {
    describe("SimpleController", function() {
        var scope;
        beforeEach(inject(function($rootScope, $controller) {
            scope = $rootScope.$new();
            $controller("SimpleController", {
                $scope: scope
        it("should double the numbers", function() {
Categories: DEV, Test Tags: ,

Migrate Users Across Sitecore Databases

This script is used to migrate users in a specific role from two different Sitecore Instances.

As you can imagine, it runs on the Core databases.

begin tran
declare @roleId  uniqueidentifier
declare @destinationRoleId  uniqueidentifierselect TOP 1 @roleId  =RoleId from dbo.aspnet_Roles where LoweredRoleName=’sitecore\sourcegroup’

select @roleId

select TOP 1 @destinationRoleId =RoleId from [OtherDB].dbo.aspnet_Roles where LoweredRoleName=’sitecore\destinationgroup’
select @destinationRoleId
select *from aspnet_UsersInRoles where RoleId=  @roleId

select *from aspnet_Roles where RoleId=  @roleId

select *from [OtherDB].dbo.aspnet_Roles where RoleId=  @destinationRoleId

select distinct sourceUsers.ApplicationId, sourceUsers.UserId,sourceUsers.UserName,sourceUsers.LoweredUserName,sourceUsers.MobileAlias,sourceUsers.IsAnonymous,sourceUsers.LastActivityDate
into #TmpUsers
from dbo.aspnet_Users as sourceUsers
inner join dbo.aspnet_UsersInRoles on sourceUsers.UserId = aspnet_UsersInRoles.UserId
where aspnet_UsersInRoles.RoleId=@roleId
and sourceUsers.LoweredUserName not in (select distinct LoweredUserName from  [OtherDB].dbo.aspnet_Users )

select * from #TmpUsers

INSERT into [OtherDB].dbo.aspnet_Users
select * from #TmpUsers

INSERT into [OtherDB].dbo.aspnet_UsersInRoles
select UserId, @destinationRoleId as RoleId from #TmpUsers

select distinct gcu.ApplicationId, gcu.UserId,gcu.UserName,gcu.LoweredUserName,gcu.MobileAlias,gcu.IsAnonymous,gcu.LastActivityDate
into #TmpExistingUsers
from dbo.aspnet_Users as sourceUsers inner join dbo.aspnet_UsersInRoles on sourceUsers.UserId = aspnet_UsersInRoles.UserId
inner join [OtherDB].dbo.aspnet_Users gcu on gcu.LoweredUserName = sourceUsers.LoweredUserName
where aspnet_UsersInRoles.RoleId=@roleId

select * from #TmpExistingUsers

INSERT into [OtherDB].dbo.aspnet_UsersInRoles
select ExistingUsers.UserId, @destinationRoleId as RoleId from #TmpExistingUsers ExistingUsers
left outer join [OtherDB].dbo.aspnet_UsersInRoles   on ExistingUsers.UserId = [OtherDB].dbo.aspnet_UsersInRoles.UserId and [OtherDB].dbo.aspnet_UsersInRoles.RoleId = @destinationRoleId
where [OtherDB].dbo.aspnet_UsersInRoles.UserId is null

drop table #TmpUsers

drop table #TmpExistingUsers

select *from [OtherDB].dbo.aspnet_UsersInRoles where RoleId=  @destinationRoleId

–rollback tran
commit tran

Categories: DEV Tags: ,

Tweeting with TweetSharp

I had the chance to try TweetSharp for tweeting and reading some tweets from an account…

I found it pretty simple to use. Obviously in order to use it you need to have a twitter account and you need to get the “KEYS” from Twitter  Developer Center….

This is the code to start using TweetSharp, btw that’s based on Auth 1.1 and TweetSharp 2.3.1

var oauth_consumer_key = “xxxxxxx”;
var oauth_consumer_secret = “xxxxxxX”;

var key = “xxxxxxX”;
var keysecret = “xxxxxxX”;

var service = new TwitterService(key, keysecret);
service.AuthenticateWith(oauth_consumer_key, oauth_consumer_secret);

var tweets = service.ListTweetsOnHomeTimeline( new ListTweetsOnHomeTimelineOptions ());

//foreach (var tweet in tweets)

Console.WriteLine( “Got tweets ” + tweets.Count() );

var testresult = service.SendTweet( new SendTweetOptions { Status = “test” + DateTime    .Now.ToShortTimeString() });
Console.WriteLine( “tweet sent”);
catch ( Exception xx)
Console.WriteLine( “error sending tweet ” +xx.Message );

Categories: DEV Tags:

Sitecore Logging – Log4Net – CastleWindsor

As most of you probably already know, Sitecore (until 6.6.0) use an old version of Log4Net in the Sitecore.Logging assembly, you can read more about this issue here

So there are 2 options:

1) Use Sitecore Logging as your logging strategy

2) Use CastleWindsor Logging facilities

In order to implement the second option you have to:

Implement your logging facility:

public class  XXXContainerInstaller : IWindsorInstaller
public void Install(Castle.Windsor.IWindsorContainer container,
Castle.MicroKernel.SubSystems.Configuration.IConfigurationStore store)

//Load your Custom Configuration from a different config “using a more advanced pattern expression

container.AddFacility<Castle.Facilities.Logging.LoggingFacility>(f => f.LogUsing(LoggerImplementation.Log4net).WithConfig(“log4net.xml”));




Prepare your config:

<facility id=”logging” type=”Castle.Facilities.Logging.LoggingFacility, Castle.Facilities.Logging” loggingApi=”log4net”/>
<component id=”loggingSetup” service=”XXX.ILoggingSetup, AssemblyName” type=”XXXX.Log4NetLoggingSetup, Asos.Framework” lifestyle=”AssemblyName”/>
<component id=”loggingContext” service=”XXX.ILoggingContext, AssemblyName” type=”XXXX.Log4NetLoggingContext, AssemblyName” lifestyle=”singleton”/>

The Log4Net Section will still be required and shared between your Castle Logging and SiteCore Logging…

<section name=”log4net” type=”log4net.Config.Log4NetConfigurationSectionHandler, log4net”/>

<appender name=”eventLogAppender” type=”log4net.Appender.EventLogAppender, log4net” logName=”Application”>
<param name=”LogName” value=”Application”/>
<param name=”ApplicationName” value=”XXXXX”/>
<layout type=”log4net.Layout.PatternLayout”>
<conversionPattern value=”%appdomain [%thread] %-5level – %message%newline [%properties]%newline %exception”/>
<level value=”ERROR”/>
<appender-ref ref=”eventLogAppender”/>

Be also aware that the SitecoreLogging does not support the latest log4net formatting syntax like %exception

and Sitecore formatting expression prefer the OldLog4Net syntax with all abbreviated letters

<conversionPattern value=”%4t %d{ABSOLUTE} %-5p %m%n” />

More references about this issue can be found:

How To Create a Custom Culture in Sitecore

1) Create a culture on the server and register it

CultureAndRegionInfoBuilder cib = new CultureAndRegionInfoBuilder( “x-en-US-sample”, CultureAndRegionModifiers.None);

CultureInfo ci = new CultureInfo(“en-US”);



2) Install a custom culture (copy files and deploy registry keys)

3) Create Icon files (for the right sizes in Sitecore)

4) Compress the Icon in a zip file

in the folder sitecore\shell\Themes\Standard\

4) Create Custom Language in Sitecore (specifying dictionary, iso codes etc)


Categories: DEV, Infrastructure Tags: , ,

Run your MVC controller ignoring SiteCore 6.6 Pipeline….

there are 3 Steps to do to achieve it:

1) write your controller inheriting from Controller

public class TestController : Controller


[ HttpGet]

public ActionResult Stelio()


//This throw an exception

//var footerRoot = Sitecore.Context.Database.GetItem(“/sitecore/content/Global/Footer”);

return Content( “this is a test to run an MVC controller in a SiteCore 6.6 site outside of SiteCore Context” );



2) Exlude the URL from the web.config

<setting name=”IgnoreUrlPrefixes” value=”/TestController/Stelio|/sitecore/default.aspx|/trace.axd|/webresource.axd|/sitecore/shell/Controls/Rich Text Editor/Telerik.Web.UI.DialogHandler.aspx|/sitecore/shell/applications/content manager/telerik.web.ui.dialoghandler.aspx|/sitecore/shell/Controls/Rich Text Editor/Telerik.Web.UI.SpellCheckHandler.axd|/Telerik.Web.UI.WebResource.axd|/sitecore/admin/upgrade/|/layouts/testing “/>

3) Register your route

public static void RegisterRoutes(RouteCollection routes)


routes.IgnoreRoute( “{resource}.axd/{*pathInfo}”);


“Default”, // Route name

“{controller}/{action}/”, // URL with parameters

new { controller = “TestController”, action = “stelio” , } );


Remember that you cannot use SiteCore Context (Sitecore.Context will throw an exception)

Categories: DEV Tags: , , ,

Azure Set custom Cache Expiration on items stored in a blob

// cache time
var cacheMaxAge = (60 * 60);

 // 3600 second (1 hour) caching// file upload

// setting Content-Type
blobFile.Properties.ContentType = contentType;

// setting cache for CDN
blobFile.Properties.CacheControl = "max-age=" + cacheMaxAge;



Categories: DEV Tags: ,