Posts

Loading an assembly from a specific path, including all sub dependencies

public static class AssemblyLoader { private static readonly ConcurrentDictionary<string, bool> AssemblyDirectories = new ConcurrentDictionary<string, bool>(); static AssemblyLoader() { AssemblyDirectories[GetExecutingAssemblyDirectory()] = true; AppDomain.CurrentDomain.AssemblyResolve += ResolveAssembly; } public static Assembly LoadWithDependencies(string assemblyPath) { AssemblyDirectories[Path.GetDirectoryName(assemblyPath)] = true; return Assembly.LoadFile(assemblyPath); } private static Assembly ResolveAssembly(object sender, ResolveEventArgs args) { string dependentAssemblyName = args.Name.Split(’,’)[0] + ".dll"; List<string> directoriesToScan = AssemblyDirectories.Keys.ToList(); foreach (string directoryToScan in directoriesToScan) { string dependentAssemb

Running dotnet core xUnit tests on Visual Studio Team Services (VSTS)

Image
1: Run dotnet restore to restore package dependencies. 2: Run dotnet build to build the binaries. 3: Run dotnet test to run the tests. Note the additional parameters --no-build to prevent a rebuild and --logger "trx;LogFileName=tests-log.trx " to ensure the test results are written to disk, 5: Use  a Publish Test Results tasks to output the results of the tests. Make sure you set the following properties Test Result Format = VSTest Test Results Files = **/tests-log.trx And under the Advanced section make sure you set the Run This Task option so that it will run even if the previous task failed.

Get list of object keys in Angular

import { PipeTransform, Pipe } from "@angular/core"; @Pipe({ name: 'keys' }) export class KeysPipe implements PipeTransform {   transform(value, args:string[]) : any {     return Object.keys(value);   } } Then to get a list of errors for a form element you can do this <ul *ngIf="form.get('userName').invalid" class="help-block with-errors">    <li *ngFor="let error of form.get('userName').errors | keys">{{ error.key }}</li> </ul>

Preventing Unity3D IL2CPP from stripping your code

I was trying to get a list of a type's constructors at runtime using reflection, so that I could create an instance of the class using dependency injection. All worked just fine until we tried to build the app for iOS. At first we were using Mono as the scripting back-end, but it seems that new versions of iOS pop up a dialog telling the user the app is 32 bit and may run slowly (i.e. "Your app is crap"). When switching the backend scripting to IL2CPP (in File->Builder->Player Settings) the app suddenly wasn't working. It turns out that SomeType.GetConstructors().Count was returning zero, which was a problem because obviously I wanted to invoke those constructors with dependencies. The problem was that because these constructors weren't being calling explicitly from anywhere in my app IL2CPP decided I didn't need them, and stripped them out. The solution is to create a file in your Assets folder called link.xml and fill it in like so.... <lin

Forcing a device-orientation per scene in Unity3D

Unity3D has a Screen class with an orientation property that allows you to force orientation in code, which lets you have different scenes with different orientations (useful in mini-games). this works fine for Android but crashes on iOS. The problem is the file UnityViewControllerBaseiOS.mm that gets generated during the build for iOS has an assert in it which inadvertently prevents this property from being used. It is possible to create a post-build class that runs after the iOS build files have been generated that can alter the generated code before you compile it in XCode. Just create a C# script named iOSScreenOrientationFix.cs and paste in the following code - adapted from  this Unity3D forum post . using UnityEngine; using UnityEditor; using UnityEditor.Callbacks; using System.IO; namespace Holovis { public class iOSScreenOrientationFix : MonoBehaviour { #if UNITY_CLOUD_BUILD // This method is added in the Advanced Features Settings on UCB // PostBuildProc

A UI thread dispatcher for Unity3D

I've recently been working on implementing an IHttpService that can work outside of a MonoBehaviour and call out to web services asynchronously. Rather than providing my IHttpService.JsonPost method with callbacks I decided to have it return a Promise, the code for which I took from this  Real Serious Games  GitHub repository. The problem is that when you use WebClient's async methods they call back the Complete events on the worker thread, so code like this won't work because you cannot manipulate UI from any thread other than the main one. httpService.JsonPost<MyInfo>(url)   .Then(myInfo => someTextUiObject.text = myInfo.Name); And there seems to be no kind of thread Dispatcher in Unity3D for UI updates as there is in Windows.Forms - so I wrote my own. using System.Collections; using System; using System.Threading; using System.Collections.Generic; using UnityEngine; public class UiThreadDispatcher : Singleton<MonoBehaviour> {     static volatil

NodeJS, Web-Express, and TypeScript from scratch

Over the past year I've been spending my time contracting for a company in Norway. Now that project is completed it is time for me to start playing again, so I thought I'd pick up an old Node Express project. This time I intend to use TypeScript instead of Javascript. I'd also like to write unit tests and dependency injection - both are something I'm very familiar with in the C# world, but not in Node. I'm going to use this blog to record what I did; I will undoubtedly revisit some of these posts and make changes as I learn. In this first blog I intend to cover how to get up and running with Node, Express, and WebStorm (optional) from a fresh installation of Ubuntu Linux. The first thing we need to do is use apt-get to install Node. sudo apt-get install nodejs I've noticed that some Linux apps will look for a command "node" and others will look for "nodejs", so after installing I want to make an alias so that both commands

[Solved] MVCApplication Parser Error

I have this problem because I have to develop with VS running as administrator in order to use Local IIS hosting. When files are added (or generated by compiling) I think VS was setting the owner as Administrator, which IIS then cannot read. Start a command prompt as Administrator and type in the following icacls c : \devpath\yourwebsite / grant everyone :( OI )( CI ) F / T

How to Create a Self Signed Certificate in IIS 7

I know I am going to want this link again in the future!

VSTO Office plugin not appearing in Office 2007

If you have an office VSTO plugin that is working in other versions of Office but not appearing in Office 2007 then try setting the following registry value HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\12.0\Common\General\ Name = EnableLocalMachineVSTO Value (DWORD) = 1

Watching a single property in an array in AngularJS

A typescript example that converts the array's property into a single string that can be watched. $scope . $watch ( () => this . someArray . map ( x => x . selected ? "1" : "0" ). join ( "" ), ( newValue , oldValue , scope ) => this . onSelectionChanged ( this . getSelectedItems ()));

Getting an AngularJS directive to call back a method on its parent's controller

Here is a TypeScript example of how to call back a method on the controller from an embedded directive. The most important thing to note is that the directive's parameter name for your callback uses a & when defined, and when calling that callback you should not use positional parameters but instead use an object with properties having the names of the parameters in the target. Register the directive when you create your app module: module MyApp { var app : angular . IModule = angular . module ( "MyApp" ); MyApp . Directives . FileUploader . register ( app ); } The registration code is as follows: module MyApp . Directives . FileUploader { class FileUploaderDirective implements angular . IDirective { public restrict : string = "E" ; public templateUrl : string = "/app/Directives/FileUploader/FileUploaderDirective.html" ; //IMPORTANT - Use & to identify this as a method reference

AngularJs - binding HTML

The directive ng-bind will escape HTML to avoid data acting maliciously. If you want to output html you need to use ng-bind-html <div ng-bind-html="someHtmlBody"/> The important step to getting this working is to ensure the script angular-sanitize.js is referenced on your page, and it is specified as a dependency when creating a module.... var app = angular.module("MyApp", ["ngSanitize", "OtherDependencies"]);

AngularJS routes with ASP MVC Forms authentication

The ASP MVC app I am working on uses forms authentication with a timeout. This means that when the session has timed out and the user clicks refresh they get redirected to a login page, and after that they get directed back to the original page without the deep-linked client-side # part of the url.  The solution to this is as follows: The first thing to do is to have the ASP MVC server side capture any URLs that should related to your client-side angular routing and return the single-page app HTML. When registering your ASP MVC routes add the following rule routes . MapRoute ( name : "Angular" , url : "x/{*clientPath}" , Where the "x/" is the base part of your client app, of course you can do without the "x" in the URL if your entire app is a single-page angular app, in which case you will need to add a preceding rule to render your ASP MVC server side account-login page. Then in your Angular app make

Node.js Express, form validation, and keeping previously posted form values

I've been playing with Node.js and the Express webserver framework as a learning experience, it's good fun :) In the C# ASP MVC world using the Razor view engine I can define my user interface elements like this... @Html.TextBoxFor(x => x.EmailAddress) @Html.ValidationMessageFor(x => x.EmailAddress) This will do three things It will create the html output for an input element If the view is being rendered as a result of a POST it will set the value of the input to the value posted.  This is useful for when you have a form validation error and don't want to have to force the user to re-enter all of their input. If there is an error message registered for EmailAddress it will display the error text *Note that error messages are registered using ModelState.AddModelError("EmailAddress", "The error message") Node.js, Express, and Jade Express is a very light weight framework so doesn't do any of this stuff for you, so I had to h

AngularJS - Triggering code whenever ng-view updates

//Create the module var app = angular.module('someapp', ['ngRoute']); //Config the routes app.config(configRoutes); function configRoutes($routeProvider) { $routeProvider .when('/', { templateUrl: '/angular/viewtemplates/admin/index.html', controller: 'AdminController' }) .when('/categories', { templateUrl: 'angular/viewtemplates/admin/categories/index.html', controller: 'CategoryIndexController' }) } //Make sure we are notified whenever the ng-view is updated app.run(function($rootScope) { $rootScope.$on('$viewContentLoaded', function() { $('table[data-toggle="table"]').bootstrapTable(); }); });

Windows welcome screen slow

Image
After I log in to Windows 7 the welcome screen stays on for ages, in the past it was almost instant.  I’ve tried various suggestions from forums and none of them worked, then it struck me what it was! Windows was trying to reconnect network drives after I had logged in, but one of them (a connection to my iMac) was unobtainable because my iMac was off.  I disconnected the mapped network drives and speed is back to normal

Installing Ruby on Rails, RubyMine and MongoDB on Ubuntu Linux

Here are some really basic instructions which should work on a virgin installation of Ubuntu Linux.  I tried following some instructions in a book but they were awful, these are what I ended up with. Install some installation helper tools etc sudo apt-get install build-essential git-core sudo apt-get install curl bash -s stable < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer) echo '[[ -s "/home/x/.rvm/scripts/rvm" ]] && source "/home/x/.rvm/scripts/rvm"' >> ~/.bashrc source ~/.bashrc Install JavaScript interpreter sudo apt-get install nodejs Install MongoDB server and clients sudo apt-get install mongodb-server sudo apt-get install mongodb-clients Install Rails sudo apt-get install rails Install Ruby 1.9.3 and set it as the default version to use rvm install 1.9.3 rvm use --default 1.9.3 Install Gems required by Ruby ge