Ozcode’s export object(s) feature, a first review (part 1)

Nearly half a year ago, in November 2015 I wrote a first article about a feature of the OzCode, an awesome debugging tool that plugs into Visual Studio and enhances it by many features in the debugging field I don’t want to miss again.

Recently Version 2.0 of OzCode has been published and today I finally found the time to test it in more depth. The whole article is based on OzCode version

For testing I wrote a very small test project with some XUnit tests. Unit testing as such is not necessary in this case, but these tests are easy to run as a single, separated piece of code, so it was the easiest way to go. The test project is published on GitHub as ozcode-export-test.

When OzCode 2.0 was announced on twitter and I asked for a test version, they finally answered (fixed the link here that was a wrong shortlink on Twitter due to missing space):

@jongleur1983 Wait is over http://o.oz-code.com/announcing-ozcode-v2.1-beta. Doesn’t address the issues you mentioned in your post yet, but we will be looking into that.

So I do not expect any issue mentioned in my first post to be addressed, but nevertheless the feature might be quite useful, so let’s give it a try.

As this article get’s lengthy again and it’s past midnight, I decided to split it, so this post is about single-object exports only for now, I’ll try to write a next one about exporting object graphs assembled from more than one object. Ozcode’s export object(s) feature, a first review (part 1) weiterlesen

Wrapping Arbitrary HTML to Assign a common Universal Attribute

A few days ago I checked the HTML validity of my own blog. I have to admit that I didn’t do that after I wrote the jugglingPostLang plugin (wrote about that in my blog post Simple Language-Defined Posts in WordPress) for WordPress. I realized that my plugin produced invalid html in many cases, so that was an issue:

The issue is, that <span> elements forbid block level content, while <div> elements are not allowed as a child of any element that only accepts phrasing content (which is roughly running text and what’s inside).

To solve that I read through the html specifications to find a solution but unfortunately there isn’t a simple solution on the horizon.

In the following I’m going to summarize the html specification details on the topic and give a rough sketch on the algorithm to determine what’s a valid wrapping node. Wrapping Arbitrary HTML to Assign a common Universal Attribute weiterlesen

Strange behaviour of String Interpolation Refactorings in VisualStudio 2015/Roslyn/Resharper

We switched to VisualStudio 2015 at work a few days ago, using Resharper inside as before. VisualStudio has some great new features in this version, a few bugs, and some strange behaviours I don’t understand.

In some articles I’m going to talk about some strange refactoring suggestions I discovered, starting with string interpolations here.

Just to ask beforehand: Is there any way to identify where a refactoring comes from (is it a suggestion and/or implementation of Roslyn or Resharper?) Strange behaviour of String Interpolation Refactorings in VisualStudio 2015/Roslyn/Resharper weiterlesen

Open Question: How to always run a custom tool in Visual Studio on Project Build?

In a project at work we have some T4 templates running in a Visual Studio (2015) environment. Those templates should run whenever some dependent files have changed. As it’s kind of a compilation step, a best fit, I thought, would be to run the templates on every (re-)build of the project, but how to achieve that? Open Question: How to always run a custom tool in Visual Studio on Project Build? weiterlesen

HTML5-Audioplayer für 1LIVE

In einem anderen Artikel habe ich bereits darüber geschrieben, wie unnötig die großen deutschen Medienanstalten bis heute auf den Flash-Player als Abspielsoftware für Medieninhalte setzen.

Die Audio-Streams auf einslive.de habe ich mir mal etwas genauer angesehen. HTML5-Audioplayer für 1LIVE weiterlesen

Flash-Zwang beim öffentlich-rechtlichen Rundfunk

Vor einigen Tagen habe ich Windows frisch installiert. Wie üblich kommt dann die wichtigste Software zuerst, weniger Wichtiges kommt erst später, oder fällt dabei letztlich weg, weil ich feststelle, dass ich es doch nicht benötige.

Diesmal traf es (beinahe) Adobes Flash-Player: Zunächst hatte ich nur etwas weniger Werbung im Netz (obwohl sich hier offenbar viele Werbetreibenden mittlerweile von Flash abgewandt haben oder zumindest Alternativen ausliefern).

Größere Probleme hatten interessanterweise vor allem der öffentlich-rechtliche Rundfunk. Flash-Zwang beim öffentlich-rechtlichen Rundfunk weiterlesen

Simple Language-Defined posts in WordPress

For different audiences I write blog posts in different languages. Developers usually understand English and often even talk in English, it’s their lingua franca of the programming domain.
On the other hand other articles are about more local topics, so their target audience is mainly Germans. Here I prefer writing in my mother tongue. Unfortunately there seems to be no easy and simple solution to define the language per article in WordPress, so I considered to write one myself.

The plugin is available for download on github now.

Read further for more details on What it does, How it is done, Why I did it and What could be added. Simple Language-Defined posts in WordPress weiterlesen

IEnumerable, ICollection, IReadOnlyCollection – an API analysis on .NET and XUnit

Today for the first time since I use XUnit I wrote a theory where the individual test parameters could not be easily defined as compile time constants.

In the next chapter I’m going to explain the motivation and the use case that arose here, before the next chapter will try to give a summary over the .NET API that’s behind that issue and what’s wong with it. IEnumerable, ICollection, IReadOnlyCollection – an API analysis on .NET and XUnit weiterlesen

Ozcode upcoming feature tweet: serializing objects for debugging

Currently oz_code asks about what developers want to see in future versions of their Visual Studio extensions to simplify and enhance debugging experience.

We use oz_code at work for complex .NET/WPF desktop applications and it is an invaluable tool for various use cases while debugging.

Today I read this tweet from @oz_code:

Would you like to be able to serialize objects from your debugging session and then use those objects in a Unit Test? (feature planning)

And I didn’t have to think twice about it: yes! But it didn’t take a minute thinking about what would be possible – and was a developer myself: What might be challenges of such a feature (even though I don’t have to implement it myself).

Ozcode upcoming feature tweet: serializing objects for debugging weiterlesen

Customized WordPress-Template for Category-Subtree

For the Advent calendar categories I wanted to have a custom template that applies to all categories below the Adventskalender category (that one included).

WordPress has a great Template system, using inheritance between templates, as shown in the Codex. Utilizing this system it is possible to customize all category pages or one category page in particular – but there seems to be no way to customize a set of categories based on the category hierarchy.

On the other hand WordPress contains a function to get a Breadcrumb trail from the root to the current category. For this function, get_category_parents() no non-grapical equivalent seems to exist unfortunately.

On the other hand the code is quite simple: Start at the category of your choice and recursively get the parent category up to the root.

My current solution is based on a fixed „root“ category, as that is what I want to have (more ideas on how the template system could be extended nicely see below).

My solution utilizes the action hook  ‚category_template‘ which is not documented unfortunately in the codex (although listed in the filter reference). The following is the code listing of the function:

function get_advent_category_template( $archive_template )
  // get the category:
  $catId = get_query_var('cat');
  $found = false;

  $yourcat = get_category($catId);
  do {
    if ($yourcat->slug == 'adventskalender')
      return dirname(__FILE__).'/category-adventskalender.php';
    $yourcat = get_category($yourcat->parent);
  } while (true);

  // not found in the parent hierarchy, return the default template:
  return $archive_template;

The parameter of this function is the default template that would be applied without the hook implemented here. We have to detect if we’re in a matching category and if so, overwrite that template by returning our customized one. Therefore the loop from the current category up to the root category and search for our anchor category which is the root for the categories we want to apply the custom template for.

If found, we return the custom template file, otherwise we return the default one.

Now this function has to be registered, and that’s it:

add_filter( 'category_template', 'get_advent_category_template' ) ;

How the WordPress Template system could be extended

When I stumbled over this issue I asked in the WordPress IRC channel after not seeing a proper solution, where I was told that it is a quite common problem, and more people asked for a solution in the past.

In fact it would be quite easy to extend the WordPress template system by another template „class“ in the second line of the graphical overview. Inserting another variant between category-$id.php and category.php would fit nicely from a logical point of view.

A Category archive that is defined for a single category is preferred (left of the new one), but the tree-based category template (the new one) is preferred over the generic category template.