Get current, future or most recent item

In the application I’m working on I had to repeatedly show information based on relevance by date. I wrote a little extension method to help select the current item, if there is no current item, then select the first future item, if there are no future items, then select the most recent item in the past.


public static class RelevantItemExtension
{
    public static T GetCurrentFutureOrMostRecent( this IEnumerable list,
                                                  Func<T, DateTime> dateSelector )
                                                  where T : class
    {
        if ( list.Count() == 0 )
        {
            return null;
        }
        else if ( list.Count() == 1 )
        {
            return list.First();
        }
        else
        {
            var currentOrFuture =
                list.Where( x => dateSelector( x ).Date >= DateTime.Today.Date )
                    .OrderBy( x => dateSelector( x ) )
                    .FirstOrDefault();

            if ( currentOrFuture != null )
            {
                return currentOrFuture;
            }
            else
            {
                return list.OrderBy( x => dateSelector( x ) )
                            .Last();
            }
        }
    }
}

I’m able to use this method as follows:

[TestMethod]
public void RelevantItemExtension_Future()
{
    // Arrange
    List list = new List() {
        new DataItem() { Value = 1, Date = DateTime.Today.AddDays(-21) },
        new DataItem() { Value = 2, Date = DateTime.Today.AddDays(-7) },
        new DataItem() { Value = 3, Date = DateTime.Today.AddDays(-14) },
        //new DataItem() { Value = 4, Date = DateTime.Today },
        new DataItem() { Value = 5, Date = DateTime.Today.AddDays(7) }
    };

    // Act
    var item = list.GetCurrentFutureOrMostRecent( x => x.Date );

    // Assert
    Assert.AreEqual( 5, item.Value );
}

HoloLens – Hello World

What a day it has been… today I unboxed my HoloLens and started my augmented reality adventures.

This slideshow requires JavaScript.

After going through the tutorial and learning about Gaze, Gestures and Voice commands and then ofcourse some initial playing around with Holograms, RoboRaid and my first HoloLens Skype call it was time to get ready and start work on my first HoloLens app.

But first I needed to get the right tools:

  • Install the tools on the Windows Dev Center is good place to start, it offers links to the most recent versions of the HoloLens Emulator and Unity HoloLens (currently still in technical preview).
  • Microsoft HoloLens application for Windows is an awesome tool the let’s you live stream the video from your HoloLens to your PC and makes it easy to create videos of your augmented world.

After updating Visual Studio, installing the emulator, installing Unity 3D and creating a Unity account and for good measure, following Unity 3D on Twitter, I figured I was ready to go.

I watched the welcome to Unity video and figured as a coder it might be easier to start with a simple Visual Studio only trial app. Well…. After looking at the DirectX 11 template app  that comes with installed with the SDK and running a colorful cube in the HoloLens emulator I quickly figured I needed an easier start so I build a 2D Universal Windows Application with my “Hello AR World” message. On this page I found how to an over the air WiFi deploy directly from Visual Studio to the HoloLens, nice!

Oh, and after messing around with ‘transparent’ settings for the background of my Window I suddenly remember something Dennis had told me: HoloLens knows no black and so black is considered transparent.

HelloWorld

Note: The screen capture shows the transparent window much darker than how you really see it when you wear the HoloLens.

Tip: use Cortana if you need to reboot, just say ‘Hey Cortana’ followed by ‘Reboot’.

Also, I have a feeling my laptop is going to need an upgrade soon… 8GB of memory appears to be barely enough to run the necessary HoloLens emulator, twice I’ve had to restart my machine and make sure that the emulator is started first, before starting other apps.

Next step… building a Unity 3D application… to be continued 🙂

 

Unlocking VSTS files from a user that left the team

In the past I had used the tf.exe command line tool to unlock files that were locked by a co-worker that had left.

Today I discovered a cool free tool that makes it much easier to delete obsolete workspaces. By deleting the workspace all locks held by the workspace are automatically released.

Go to http://www.attrice.info/cm/tfs/index.htm to download the Attrice Team Foundation Sidekicks.

The Sidekicks tool worked excellent against our online Visual Studio Team Services repository.

VS2015 – Files locked after unit tests

I haven’t figured out yet why it is happening, but after a recent update I suddenly ran into an issue where when I ‘Run All Unit Tests’ in Visual Studio 2015 (Update 3) I end up with locked assemblies. This in turn does not allow me to run any subsequent tests.

Workaround is to kill the unit test processes that are locking the files using a command line (run as administrator account):

taskkill /F /IM vstest* /T

2016-07-26

Not the most elegant solution, but it will work for now.

Unable to drop database role in SQL Server

I just ran into an issue where I was unable to delete a database role, somehow my custom database role had become the owner of the db_datareader role.

Deletion of the role was not possible due to the following error:

Error: 15138 The database principal owns a schema in the database, and cannot be dropped.

The solution is straightforward:

First find out which schema is being owned by the rolename:

SELECT name FROM sys.schemas WHERE principal_id = USER_ID( ‘<rolename here>‘ )

Then change ownership using:

ALTER AUTHORIZATION ON SCHEMA::<schemaname here> TO dbo

After which you can drop the role

DROP ROLE <rolename here>