How to get full class name, including module name from an instance at runtime in TypeScript

Let’s assume we have the class [GuidGenerator] in a TypeScript module [research.my.long.namespace] and at runtime you have an instance of the GuidGenerator, how do you get the full class name including module name, in this case: “research.my.long.namespace.GuidGenerator”.

Well you walk the object graph starting with the root / global object, in the browser this will be the window object.

 

NOTE: all code is in “strict” modus.

 

TypeScript Class [GuidGenerator]:

module research.my.long.namespace {
"use strict";
export interface IGuidGenerator {
generate(): string;
}
export class GuidGenerator implements IGuidGenerator {
generate() {
var randomNumberToGuid = function (c) {
var r = Math.random() * 16 | 0, v = c == 'x' ? r : r & 0x3 | 0x8;
return v.toString(16);
}
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, randomNumberToGuid);
}
}
}

We use the resolver object to get the full class name:

var resolver = new NameResolver();
var generator = new research.my.long.namespace.GuidGenerator();
var name = resolver.getFullClassNameFromInstance(generator, window)
console.log(name);

Result

image

The resolver class

module research.metadata {
"use strict";
interface IProcessResult {
fnFound: boolean;
path: Array<string>;
}
export interface INameResolver {
getFullClassNameFromInstance(instance: any, global: any): string;
}
export class NameResolver implements INameResolver {
private _fn: any;
private _global: any;
private _processed: Array<any>;
/**
To handle recursiveness in the object graph, collect all handled nodes in the object graph,
so an object is only traversed once.
*/
isProcessed(obj: any): boolean {
var result = false;
for (var i, length; i < length; i += 1) {
if (this._processed[i] === obj) {
return true;
}
}
return result;
}
processProperty(obj: any, key: string, path: Array<string>): IProcessResult {
var result: IProcessResult = {
fnFound: false,
path: path
}
if (obj.hasOwnProperty(key)) {
try {
var prop = obj[key];
if (prop === this._fn) {
// Function found, stop traversing the object graph.
result.fnFound = true;
return result;
}
// Continue traversing the object graph.
result = this.processObject(prop, path);
if (result.fnFound) {
// Function found, stop traversing the object graph.
return result;
}
} catch (error) {
// Access to some properties result in exceptions.
}
}
return result;
}
processObject(obj: any, path: Array<string>): IProcessResult {
var result: IProcessResult = {
fnFound: false,
path: path
}
if (this.isProcessed(obj)) {
return result;
}
this._processed.push(obj);
for (var key in obj) {
var pathCopy = path.slice();
pathCopy.push(key);
var processResult = this.processProperty(obj, key, pathCopy);
if (processResult.fnFound) {
return processResult;
}
}
return processResult;
}
getFullClassNameFromInstance(instance: any, global: any): string {
this._fn = instance["constructor"];
this._global = global;
this._processed = [];
var processResult = this.processObject(this._global, []);
var fullFnName = "";
if (processResult.fnFound) {
fullFnName = processResult.path.join(".");
}
return fullFnName;
}
}
}

GSS reimagines CSS layout by replacing the browser’s layout engine with the same algorithm Apple uses to compute native layout.

 

Very interesting: https://gridstylesheets.org/:

 

Soon after the W3C introduced Cascading Style Sheets, Greg Badros, the author of the Cassowary Constraint Solver & recently retired Facebook VP, proposed Constraint CSS (CCSS) as a general solution for CSS layout. Back in ’99 Badros demonstrated responsive layouts with CCSS that today’s designers still can’t reproduce without grinding out piles of JavaScript. For more than a decade, no one seemed to take notice outside of academia until Apple implemented Cassowary & Greg’s pioneering concepts in its new AutoLayout engine with the launch of OS X Lion. Despite the evolutionary leap for app developers, web designers have had to settle with float-based & table-based layouts that have remained unimproved to this day.

 

Some examples:

http://gridstylesheets.org/guides/vfl/

Microsoft ASP.NET and Web Tools 2015 (Beta8) – Visual Studio 2015

Just a reminder beta 8 for ASP .NET is out:

http://www.microsoft.com/en-us/download/confirmation.aspx?id=49442

 

If you don’t install this tooling, you will get an error (see below), when manual upgrading from beta 5 to 8 in the project.json file.

Don’t forget to set the Solution DNX SDK version of your project to 1.0.0-beta8.

 

image

 

Also make sure you set the default document, when using only static files and target the .NET Core runtime.

 

image

 

 

Server Error in ‘/’ Application.


Could not load file or assembly ‘Microsoft.Dnx.Host.Clr’ or one of its dependencies. The system cannot find the file specified.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IO.FileNotFoundException: Could not load file or assembly ‘Microsoft.Dnx.Host.Clr’ or one of its dependencies. The system cannot find the file specified.
Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Assembly Load Trace: The following information can be helpful to determine why the assembly ‘Microsoft.Dnx.Host.Clr’ could not be loaded.

=== Pre-bind state information ===
LOG: DisplayName = Microsoft.Dnx.Host.Clr
(Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: Microsoft.Dnx.Host.Clr | Domain ID: 3
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
LOG: Appbase = file:///C:/Users/roel/.dnx/runtimes/dnx-clr-win-x86.1.0.0-beta5/bin
LOG: Initial PrivatePath = NULL
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Configuration file C:\Program Files (x86)\IIS Express\iisexpress.exe.config does not exist.
LOG: No application configuration file found.
LOG: Using host configuration file: C:\Users\roel\Documents\IISExpress\config\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Users/roel/.dnx/runtimes/dnx-clr-win-x86.1.0.0-beta5/bin/Microsoft.Dnx.Host.Clr.DLL.
LOG: Attempting download of new URL file:///C:/Users/roel/.dnx/runtimes/dnx-clr-win-x86.1.0.0-beta5/bin/Microsoft.Dnx.Host.Clr/Microsoft.Dnx.Host.Clr.DLL.
LOG: Attempting download of new URL file:///C:/Users/roel/.dnx/runtimes/dnx-clr-win-x86.1.0.0-beta5/bin/Microsoft.Dnx.Host.Clr.EXE.
LOG: Attempting download of new URL file:///C:/Users/roel/.dnx/runtimes/dnx-clr-win-x86.1.0.0-beta5/bin/Microsoft.Dnx.Host.Clr/Microsoft.Dnx.Host.Clr.EXE.

Stack Trace:

[FileNotFoundException: Could not load file or assembly 'Microsoft.Dnx.Host.Clr' or one of its dependencies. The system cannot find the file specified.]
[TypeLoadException: The domain manager specified by the host could not be instantiated.]
System.Web.HttpRuntime.HostingInit(HostingEnvironmentFlags hostingFlags, PolicyLevel policyLevel, Exception appDomainCreationException) +303
[HttpException (0x80004005): The domain manager specified by the host could not be instantiated.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9922864
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +90
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +261


Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.6.106.0

Some DEVintersection notes (in dutch)

 

OpenSource en crossplatform

Is de toekomst, maar waarom krijg je dat van Microsoft en partners te horen? Daar is 1 reden voor bij Microsoft:

We want your FOR loop!!!

Wij (microsoft) verkopen compute, wij willen jouw code draaien, windows is afgeschreven als cach cow.

 

Windows containers

Kan zeer goed gebruikt worden voor immutable infrastructure

 

Virtualisatie

  • Virtual Machines (opstarten in minuten, grote: zo groot als de software die je erin zet + volledige operating system)
  • Containers (opstarten in seconden, grote: zo groot als de software die je erin zet)
  • Virtual processen, zoals in GO, Erlang / Elixer ( in 1 ms opgestart, grote: +/- 4kb) = performance niet normaal 🙂

 

User Experience

http://chulakov.com/menu

JavaScript – Fetch API

De opvolger van XMLHttpRequest,

https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API

The Fetch API provides an interface for fetching resources (e.g., across the network.) It will seem familiar to anyone who has used XMLHttpRequest, but the new API provides a more powerful and flexible feature set.

 

HTTP2

  • geen bundeling meer nodig
  • geen image spriting meer nodig
  • Standaard TLS
  • Perfomance verbetering die behoorlijk kan oplopen van 50% tot 400%, zie https://http2.akamai.com/demo
  • Server push
  • Er wordt nog maar 1 verbinding gelegd en behouden, waarover gecommuniceerd wordt via onder andere multiplexing, frames hebben een ID.
  • Prioriteit geven aan bepaalde data in bepaalde situaties
  • Voor IIS beschikbaar in windows 10 / server 2016

 

ES6

  • Iterators
  • Generators
  • Template strings, let op je kunt waardes een stukjes tekst indexed, benaderen als je functie gebruikt bijv.: let items = test `${user.firstName} ${user.lastName}` let op de functie "test" wordt dan dus zonder haken aangeroepen, de test functies kan dan een values parameter hebben, waar de twee waardes in staan, lees meer op MDN.
  • Destruction
  • Symbol (kan gebruikt worden voor private members).
  • Lamda (=>) heeft lexical scope, this je kunt altijd this. Gebruiken, zonder let self = this; of function.bind the gebruiken.
  • … = rest parameter, maar kan ook spread operator zijn, ligt eraan waar hij staat
  • Defaults voor parameters
  • Gebruik for(item of items) als vervanger van for(var i = 1; length; i < length; i+=1) { }, indien index niet van belang is.

JavaScript libraries die tegenwoordig gebruikt worden rondom modules:

  • Babel.js
  • Core.js
  • TypeScript
  • JSPM
  • System.js (kan conditional lazy, modules laden)
  • Webpack
  • Browserify
  • Bower
  • NPM

Allemaal hebben ze wat overlap, maar doen ze allemaal net wat anders.

 

Transpilers

  • TypeScript (gebruiken als je typesafety belangrijk vindt, anders babel.js gebruiken)
  • Babel.js
  • Traceur (niet gebruiken)

Outsourcing

  • Naar lage loonlanden, is in vele gevallen, vele male duurder, dan zelf bouw of outsourcing in eigen land.

 

Scaffolding tool

http://yeoman.io/ het is krachtig om code / projecten te genereren, volgens mij gaat microsoft zelf hier ook gebruik van maken in Visual Studio.

 

Handige sites

http://caniuse.com/

ASP.NET 5 op ASP .NET Core (DNX) is de toekomst voor wat betreft ASP .NET

 

Uitzoeklijst

En dan zijn er nog tal van zaken die op mijn uitzoeklijst zijn terecht gekomen:

How to prevent data to be changed, when copying over linked server connection in SQL Server

 

When I was inserting and updating data over a SQL Server linked server connection, special characters in “strings” were altered.

 

A character “ë” was changed to the character “Ù”.

 

Now the first thing I checked was the collation on both databases and columns.

They were exactly the same, so I expected the data NOT to be altered.

I think this is a bug in SQL Server, but I have a workaround: set the collation of the linked server connection:

 

use master

go

exec sp_serveroption ’93_WGD’, ‘collation compatible’, ‘false’

go

exec sp_serveroption ’93_WGD’, ‘use remote collation’, ‘false’

go

exec sp_serveroption ’93_WGD’, ‘collation name’, ‘Latin1_General_BIN2’

go

What I learned today

 

SQL Server

You can’t copy a complete record to an other table, when the table contains a timestamp field.

http://stackoverflow.com/questions/10262426/sql-server-cannot-insert-an-explicit-value-into-a-timestamp-column

 

Microsoft Surface Book

I would have bought the Microsoft Surface Book if they switched to thunderbolt 3 / USB 3.1 type-c for docking and power, but the Microsoft Surface Book has still the proprietary connector “Surface Connect”.

The moment I have been waiting for the last 10 years: universal docking from DELL

 

In 2004 I started my career as software engineering consultant and I moved from customer to customer dragging a laptop and huge power supply and all kinds of cables with me.

 

Since that time, I wanted a docking that could connect my laptop with power and “data” by using one cable.

So I could leave the docking on my work place connected to network, external monitor, external HDD, keyboard, mouse etc. and when I started in the morning I just had to connect one cable.

 

And most of all I wanted a universal docking, so when I switched laptop’s or someone else wants to use the docking, this should be possible.

 

The new DELL precision workstation 5510 laptop has thunderbolt / USB type-c connector and it supports the new universal dell docking, the future is now:

 

 

http://en.community.dell.com/dell-blogs/direct2dell/b/direct2dell/archive/2015/10/01/new-dell-docking-solutions-help-improve-productivity-and-expand-connectivity-options-for-mobile-workers

 

When we talk about the mobile workforce, it usually brings to mind two kinds of people: those who spend the day on their feet, typically using a tablet or 2-in-1 (retailers, police officers, and healthcare workers, for example) and those who use laptops in a variety of settings such as a conference room, airplane seat, coffee shop or couch. Yet even in the modern mobile workforce, most employees are still doing some portion of their work from a desk at the office or at home where access to larger displays, external keyboards and mice help improve multi-tasking, content creation and overall comfort.

clip_image001

We recognize it’s not enough for a device to exclusively function in its mobile state and that workers need technologies that can facilitate their “hybrid” workdays, moving seamlessly from the mobile environment to the desktop. In fact, our customers are asking for a few key things:

  • Thinner, lighter devices with multiple connectivity options to help improve productivity
  • Common docking experience across platforms with USB Type-C port(s) having data, video and power capabilities
  • Fewer cables and wires, allowing for docking anywhere, whether at a fixed desktop or hot desk/hotel cube

So beginning in early 2016, Dell will begin offering the next generation of cable docking that utilizes two new technologies and their enhanced benefits:

  • DisplayPort™ over USB Type-C:  A new type of connector designed to replace any port on a user’s system, supporting USB, Display Port 1.2 and power (up to 130w) all through a single cable
  • Intel® Thunderbolt™ 3:  Single cable for audio, multiple 4K video support, faster data transfer and power (up to 130w)*

Dell Docks leverage a new type of connector, USB Type-C, to allow users to quickly connect their laptop or tablet to a single data and power source with a single cable, no matter the media type, and get a reliable connection. For power users such as our Precision customers, the Dell Thunderbolt™ Dock with Intel® Thunderbolt 3 technology provides a way to quickly connect their mobile workstation to a single data and power source while allowing for ultimate display performance—up to two 4K displays—and faster data transfers—up to 40 Gbps.

clip_image002

Just as our customers requested, these docks provide one common docking experience across Dell and non-Dell platforms for all media. Providing a cable docking solution for the desk will allow us to further innovate throughout our client portfolio and create even thinner and lighter laptops, tablets and workstations while still providing the fully integrated multi-screen experience people need for productivity.

We see our new docks being the ultimate choice for a variety of use cases:

Desk: People in all sizes of businesses with a variety of compatible Dell and non-Dell systems will be able to quickly and easily connect their laptops and tablets to the Dell Dock, enabling fast, efficient connectivity to multiple displays and essential peripherals through one cable.

“Hotel” Cubes and Hot Desks: In offices with shared spaces, IT decision makers will be able to outfit their hotel cubes and hot desks with the Dell Dock, allowing for one easy purchasing decision across all compatible systems. The small size will also create more desk space; meanwhile, workers will be able to easily connect systems to displays and peripherals.

Conference Room Collaboration: Users can easily take their laptop or tablet from their desk to the conference room and connect to the Dell Dock in order to share their screen with a conference room display or projector.

Power Users: The Dell Thunderbolt™ Dock will enable power users and traditional workstation clients to connect three FHD displays or two 4K displays at 60Hz. Data transfers of up to 40 Gbps will allow lightning-fast transfers of larger files such as video editing files.

We see a lot of possibilities in the new connections that can consolidate the footprint of our notebooks and tablets as well as power the device and peripherals, but we will continue to give our customers a variety of connection options on our client products so they can continue using their favorite legacy peripherals as well. We’re raising awareness about the upcoming docking solutions now to help make the purchasing decision easier for your IT team and the hybrid workday more seamless for your mobile workforce. As we continue to develop mobile solutions, we’ll do so with the small, simplified form factor of these docks as a guiding inspiration.

As always, your wants, needs and opinions are what drives our innovation. We can’t wait to share these new docks with you and look forward to hearing your feedback.