Migrating Sidekick App 1.(1-2) to 1.4

Upgrading your Sidekick binaries and finding that you no longer can resolve your ScsHttpHandler type?  You will need to migrate.

Why did this happen?  Previously the ScsHttpHandler was a custom built HTTP handler built from the ground up, this allowed a guaranteed isolated context.  However i decided that the security and feature set of MVC was a far better medium for these apps and easier to understand than something custom.  Unfortunately this means some changes are required in order to convert your current Apps to use the new model.

The old way

namespace ScsJobViewer
{
	public class JobViewerHandler : ScsHttpHandler
	{
		//THE BELOW STUFF IS REGISTRATION STUFF, IT NOW BELONGS IN THE REGISTRATION FILE
		public JobViewerHandler(string roles, string isAdmin, string users)
			: base(roles, isAdmin, users)
		{
		}

		public override string Directive { get; set; } = "jvdirective";
		public override NameValueCollection DirectiveAttributes { get; set; }
		public override string ResourcesPath { get; set; } = "ScsJobViewer.Resources";
		public override string Icon => "/scs/jvgearwheels.png";
		public override string Name => "Job Viewer";
		public override string CssStyle => "width:600px";
		//THE BELOW STUFF IS THE CONTROLLER STUFF, IT NOW BELONGS IN THE CONTROLLER
		public override void ProcessRequest(HttpContextBase context)
		{
			string file = this.GetFile(context);

			if (file == "jvgetjobs.json")
			{
				this.ReturnJson(context, this.GetJobs(context));
			}
			else
			{
				this.ProcessResourceRequest(context);
			}
		}
		private object GetJobs(HttpContextBase context)
		{
			var data = GetPostData(context);
			var model = JobManager.GetJobs().Where(x => data.running ? !x.IsDone : x.IsDone).OrderBy(x => x.QueueTime);
			return model.Select(x => new JobModel(x));
		}
	}
}

Step 1

Take the routing part of your ScsHttpHandler and move it into a controller implementing ScsController.
Your old code:

		public override void ProcessRequest(HttpContextBase context)
		{
			string file = this.GetFile(context);

			if (file == "jvgetjobs.json")
			{
				this.ReturnJson(context, this.GetJobs(context));
			}
			else
			{
				this.ProcessResourceRequest(context);
			}
		}
		private object GetJobs(HttpContextBase context)
		{
			var data = GetPostData(context);
			var model = JobManager.GetJobs().Where(x => data.running ? !x.IsDone : x.IsDone).OrderBy(x => x.QueueTime);
			return model.Select(x => new JobModel(x));
		}

IMPORTANT
the controller should be decorated with an ActionName attribute that matches the request name made from the angular factory.
Should be mapped like this:

	class ScsJobViewerController : ScsController
	{
		//The action name should match what the angular factory is calling, note that case sensitivity isn't an issue.
		[ActionName("jvgetjobs.json")]
		public ActionResult GetJobs(bool running)
		{
			var model = JobManager.GetJobs().Where(x => running ? !x.IsDone : x.IsDone).OrderBy(x => x.QueueTime);
			return model.Select(x => new JobModel(x));
		}
	}

Step 2

Take the registration part of your ScsHttpHandler and move it into a class that implements ScsRegistration.
your old code:

		public JobViewerHandler(string roles, string isAdmin, string users)
			: base(roles, isAdmin, users)
		{
		}

		public override string Directive { get; set; } = "jvdirective";
		public override NameValueCollection DirectiveAttributes { get; set; }
		public override string ResourcesPath { get; set; } = "ScsJobViewer.Resources";
		public override string Icon => "/scs/jvgearwheels.png";
		public override string Name => "Job Viewer";
		public override string CssStyle => "width:600px";

Should be translated like so
IMPORTANT
There is a new field for Identifier, this is a 2 letter code that is unique to your app, this is used for routing (which we will address later). Additionally you need to define your controller type.


	class ScsJobViewerRegistration : ScsRegistration
	{
		public ScsJobViewerRegistration(string roles, string isAdmin, string users) : base(roles, isAdmin, users)
		{
		}

		public override string Identifier => "jv";
		public override string Directive => "jvmasterdirective";
		public override NameValueCollection DirectiveAttributes { get; set; }
		public override string ResourcesPath => "ScsJobViewer.Resources";
		public override Type Controller => typeof(ScsJobViewerController);
		public override string Icon => "/scs/jv/resources/jvgearwheels.png";
		public override string Name => "Job Viewer";
		public override string CssStyle => "min-width:600px;";
	}

Step 3

Update your relative paths
In order to automate the routing a more specific route is defined which requires adjustment for all your paths defined in the angular factory.

/scs/jvgearwheels.png => /scs/jv/resources/jvgearwheels.png

/scs/jvgetjobs.json => /scs/jv/jvgetjobs.json

Step 4

UPdate your config file

<processor type="ScsJobViewer.JobViewerHandler, ScsJobViewer" >

should now point to the registration type

<processor type="ScsJobViewer.ScsJobViewerRegistration, ScsJobViewer" >