SPSync is now open source!

I know a lot of you have been waiting for it. I have decided to publish it as open source, because the tool has so much potential, but I have no time to work on it.

You can find it here on GitHub: https://github.com/mwiedemeyer/SPSync

Hopefully you do some cool stuff with it.

Note: I will not answer support questions via mail anymore. If you found a bug, please fix it on your own or file an issue on GitHub.

Raspberry Pi Jukebox für Kinder

Vor einiger Zeit habe ich von der Toniebox erfahren. Das ist die “Revolution” für das Kinderzimmer. Ein Musikspieler ohne CDs und Kassetten. Dafür mit Spielfiguren und Musik aus der Cloud.

Nach einer kurzen Recherche gibt es die Idee in ähnlicher Form schon von vielen mit Hilfe eines Raspberry Pi umgesetzt, z.B. hier die Jukebox4Kids oder hier. Das Ziel war damit klar. Wir haben eine Kiste gefunden die eine gute Größe hat und ich habe dann nach den passenden Teilen gesucht. Die Hauptkomponente bildet der Raspberry Pi 3 mit einer 6 EUR USB Soundkarte, da der Raspi Audio Ausgang nicht ansatzweise einen erträglichen Klang liefert. Außerdem hat dieser bereits WLAN integriert um ihn später leicht mit neuer Musik bestücken zu können.

WP_20160704_14_59_24_Pro_LI

Die Idee von Tonie mit den Figuren war gut, aber ganz schön kostspielig. Daher habe ich zu einem China RFID Leser von Amazon (im Bild rechts an der Seitenwand) gegriffen plus die zugehörigen RFID Karten.

WP_20160706_22_54_22_Pro_LI

Das ganze ist günstiger und simpler als NFC. Der RFID Leser (6 EUR; 50 Karten ~15 EUR) funktioniert dabei per USB wie eine Tastatur direkt am Raspi. Nach jedem Lesevorgang “tippt” er die Nummer + ENTER ein. Auf dem Raspi selbst habe ich dazu MPD installiert und Mono. Der Raspi ist so konfiguriert, dass er direkt eingeloggt startet und über ein Startskript mono mit dieser Konsolenanwendung startet. Diese wartet im Wesentlichen auf Eingabe einer Zahl (+ENTER) und verwendet dann die Telnet Schnittstelle des MPD um eine Playliste zu laden und abzuspielen. Außerdem ist sie für die Auswertung der Taster zuständig.

Die Musik wird dabei direkt auf der SD Karte des Raspi gespeichert und eine Playliste mit der 10-stelligen Seriennummer der RFID Karte erstellt. Außerdem ist das Samba Paket installiert, womit man also jederzeit im WLAN zu Hause neue Musik und Playlisten auf der SD Karte ablegen kann. Dann noch ein Sticker auf die RFID Karte geklebt, damit leicht erkennbar ist, was “darauf” gespeichert ist.

WP_20160706_22_52_16_Pro_LI

Nun fehlte noch die Audioausgabe und ein paar Eingabemöglichkeiten (Play/Pause, Vor, Zurück, Lauter, Leiser). Für die Audioausgabe verwende ich eine Platine und Lautsprecher aus einem alten Radio (Werbegeschenk).

WP_20160706_21_03_06_Pro_LI

Hier sieht man links oben den Raspi, rechts die Verstärkerplatine aus dem Radio mit angeschlossenem Lautsprecher. Unten links liegt dabei noch ein “Übertrager” um das Audiosignal galvanisch zu trennen, da ansonsten ein Brummen auf dem Lautsprecher zu hören war. Dies liegt daran, dass der Verstärker zufällig mit 5V betrieben wird und ich diesen direkt an dem 5V Output des Raspi hängen habe. Die Verstärkerplatine hat auch gleichzeitig einen Kopfhörerausgang der bei Einstecken eines Kopfhörers den Lautsprecher unterbricht. Diese wird ebenfalls einfach nach außen am Gehäuse geführt.

Um das Gerät nicht nur anschalten zu können (was “hart” durch einen Einrastenden Taster mit LED Beleuchtung direkt in der USB Zuleitung passiert), sondern auch die anderen Funktionen verfügbar zu machen, habe ich "Arcade" Taster von eBay bestellt.

WP_20160706_21_01_38_Pro_LI WP_20160706_21_03_15_Pro_LI WP_20160706_21_02_26_Pro_LI

Die verfügbaren IO Ports am Raspi reichen um die 5 Taster aufzunehmen und die Verstärkerplatine und Power LED mit Strom zu versorgen.

Durch eine Powerbank kann das Gerät nicht nur im Kinderzimmer sondern auch im Auto und unterwegs verwendet werden. In Kürze kommt oben noch ein Griff dran und eine Markierung an die Seite an der der RFID Leser angebracht ist.

Lync Box for the team

In my last vacation, I built a Lync Box for me and my team at work with a Raspberry Pi Model 2 and 15 LEDs.

The idea came from Jon Gallant who already built the same thing for a single user. He called it beakn, the Lync Status Light and tried not only a Raspi but also some other hardware. I took the idea and made a thing for the whole team (5 people)

Hardware

First of all: How does it look like?

WP_20151020_17_07_20_Pro

It is very simple and the inside and the box is not very nice. Maybe I should build one with a 3D printer. However, it is working and we will install it in front of our space. To connect the LEDs I have used an old IDE cable which perfectly fits on the IO ports of the Raspi (after cutting one of the sides).

WP_20151020_17_07_39_Pro

Software

I’m not using Windows 10 on the Raspi because as I started the project, Windows 10 IoT had no Wifi. It is using the default Raspian Linux Image with Mono. I’m running a .NET console app on it which actually checks an Azure queue every few seconds for new messages. On the clients I’m using a plain old WinForms app without a window and the Lync SDK. It checks for Lync status changes and then sends a message to the Azure queue.

You can find the software on Github here.

SharePoint 2013: Timeout on ClientContext.ExecuteQuery

Ok, this one is a strange issue.

I have created a console app with Visual Studio 2013. Added the "App for SharePoint Web Toolkit" NuGet package to get the SharePoint.Client.dll
Then wrote just a few lines to test if it works:

        static void Main(string[] args)
        {
            ClientContext context = new ClientContext("https://sharepoint/sites/test1");
            var web = context.Web;
            context.Load(web);
            context.ExecuteQuery();
            Console.WriteLine("Title: " + web.Title);
        }

This is against an on premises installation with Kerberos authentication (NTLM and Basic are also enabled). On the line context.ExeucteQuery(); it just waits a long time and then gives me a timeout and 400 error.

The weird thing: If Fiddler is open during the execution, everything works as expected. No timeout, no error.

Solution

The solution is fairly simple:

Just attach a handler to the ExecutingWebRequest event and set the WebRequest.PreAuthenticate to true:

        static void Main(string[] args)
        {
            ClientContext context = new ClientContext("https://sharepoint/sites/test1");
            context.ExecutingWebRequest += context_ExecutingWebRequest;
            var web = context.Web;
            context.Load(web);
            context.ExecuteQuery();
            Console.WriteLine("Title: " + web.Title);
        }

        static void context_ExecutingWebRequest(object sender, WebRequestEventArgs e)
        {
            e.WebRequestExecutor.WebRequest.PreAuthenticate = true;
        }

NuGet Package Manager or How to make “source code sharing” across projects much better

Introduction

In a company with more than one development project sometime it happens that someone says: Hey, we need a common logging component shared across all projects.
Now the solution could be to develop such a logging component and share the assembly with all projects. However, if there is some code that should/must be unique to each project it is a bit more complicated. If you want to do that with SharePoint 2010 and build a logging component on top of the ULS log and want each project to be configurable in the Central Administration you need to know all future projects and categories or you need some unique code.

Note: The logging component is only a very easy example and might not be the best one.

NuGet

Microsoft created NuGet. A package manager for Visual Studio. Quote of the official site:

NuGet is a Visual Studio extension that makes it easy to install and update open source libraries and tools in Visual Studio.

You can add it easily to Visual Studio 2010 by Tools->Extension Manager. Search for “NuGet”. After it is installed, you can add packages to a project by right clicking on a project in the Solution Explorer and click “Add Library Package Reference…”

image

Now as a company you don’t want your super-fancy code to show up for everyone as open-source. Therefore, NuGet can have more than one package source. You can even use a file share. Open Tools->Library Package Manager->Package Manager Settings:

image image

Bring it together

To get rid of “each project copy the source from the source of the other project from the source of the source of the source from another project” you can now use NuGet.

The idea is:
- Create the Logger.cs file
- Add TODOs to the code where the developer need to change something
- Make a NuGet package from it
- Let the project teams use the NuGet package (and distribute updates to the source automatically as well!)

Advantage: There is only one source! And if the owner of the NuGet package updates it, all project teams will be automatically notified about an update!

Create the NuGet package

In my example I talk about the comon logger component. A single Logger.cs file. However, NuGet can handle even more complex packages with PowerShell code, etc.

So download the NuGet command-line tool and create a new folder where all the stuff for the package will go to.

Open a command prompt and enter:

nuget spec

This will automatically create an empty package specification file called Package.nuspec. Open this file in notepad and modify the required values. Also rename the file to match the id property.

image

Now create a folder called “content”. Everything in this folder will be merged into the solution on installation of the package. So I put the file Logger.cs in this folder.
However, I don’t want that all users are required to use the same namespace, so you can change the file extension to “.cs.pp” to let NuGet “pre-process” the file.

Within the file you can then set some tokens to be replaced on installation. You can find a list of available properties here on MSDN.

The folder structure looks like this:

image

And the Logger.cs.pp in the content folder:

image

As you can see, I used the token $rootnamespace$. That one will be replaced by the root namespace of the target project.

Ok, lets make a package:

nuget pack

The output is a file called SPLogger.1.0.nupkg. You can publish it to the official NuGet package server or use it only internally by copying it to a file share.
Now open Visual Studio add the file share as a package source and search for it in the “Add Library Package Reference” window or open the NuGet console in Visual Studio (View->Other Windows->Package Manager Console) and type:

Install-Package SPLogger

image

That’s it. If you change the version number in your .nuspec file, create a new package and copy it also to your file share, the project team can decide to update to the latest version in the “Library Package Reference” dialog. You can even uninstall the package and everything will be removed from the project without leaving anything behind.

Windows 7 Location API – A new feature for Proxy Switcher

Overview

Currently, I’m investigating what can be improved in the new release of Proxy Switcher.

For those of you, who don’t know what Proxy Switcher is a few facts:

  • Proxy Switcher automatically set the proxy depending on your current network connection
  • Beside of that, it can set other things too. E.g.: Execute scripts, change default printer, etc.
  • Click here to go to the project site for more info

Windows 7 Sensor and Location Platform

With Windows 7 Microsoft created a new “Sensor and Location Platform��. Until now, there is not much hardware compatible with it, but this hopefully will change in the near future.
With this API, applications can easily access the available sensors. Here you can find some examples and also a “manual” location provider by clicking on a map.

For the location API, there is a cool free “software” device called Geosense. From their website:

Geosense is designed to use a hybrid mix of geolocation service providers and geolocation methods to pinpoint the most accurate location information possible - including but not limited to WiFi triangulation, cell tower triangulation and IP lookup. Source: http://www.geosenseforwindows.com/

While your laptop vendor has not yet integrated a Windows 7 compatible hardware GPS sensor, Geosense is a good compromise.

Proxy Switcher Integration

For Proxy Switcher this will become a new option for switching proxy configurations, or doing some other stuff as you can see here:

image  (click to open in a new window)

 

Code

To access the Windows 7 location API all you need is the .NET Framework 4. There is a new System.Device.dll (contained in the Client Profile of the .NET Framework). Adding a reference allows you to access the current location.

First, add the following using statement:

using System.Device.Location;

Use the following code  to get the address:

GeoCoordinateWatcher watcher = new GeoCoordinateWatcher();
watcher.TryStart(false, TimeSpan.FromMilliseconds(1000));
// Get the location, including lat, long, speed, altitude, etc.
GeoCoordinate location = watcher.Position.Location;
// Try to get the current address, including street, city, etc.
CivicAddressResolver resolver = new CivicAddressResolver();
CivicAddress address = resolver.ResolveAddress(location);

Summary

With this new functionality, Proxy Switcher is not a pure “Proxy Switcher” anymore, but a multi-functional network/location based “generic” extensible execution tool. New actions can be easily created by developers through the MEF AddIn Framework. More on this in a later post.

 

If you want to become a beta tester, feel free to contact me at “mail” at thisdomain.

Proxy Switcher v1.5 – How to create your own switcher?

Proxy Switcher arbeitet derzeit mit dem Internet Explorer und Firefox zusammen. In der Regel greifen Anwendungen automatisch auf die Proxy Einstellungen des Internet Explorers zurück, weshalb es normalerweise vollkommen ausreichend ist.

Hat man nun aber einen Sonderfall, also eine Applikation die nicht auf die Internet Explorer settings zurückgreifen kann, benötigt man ein zusätzlichen “Switcher”.

In diesem Artikel zeige ich, wie einfach es ist, selbst einen zu entwickeln und im Proxy Switcher zu verwenden.

Implementierung

Zunächst erstellt man ein neues Class Library Projekt im Visual Studio 2008. Dies ist auch mit der kostenlosen Variante Visual Studio 2008 Express (C# oder VB.NET) ohne Probleme möglich.

image

Als nächstes fügt man eine Referenz auf ProxySwitcher.Shared.dll hinzu. Dort befindet sich die benötigte Basisklasse.

image

Nun noch die Class1.cs Datei umbenennen, z.B. in DemoSwitcher.cs. Dadurch wird auch automatisch die Klasse umbenannt. Diese Klasse muss nun von der SwitcherBase Klasse erben, wofür außerdem das using statement hinzugefügt werden muss:

image

Über das SmartTag was erscheint wenn man SwitcherBase ausgeschrieben hat, lassen sich automatisch alle benötigten Methoden erzeugen. Das wären “DisableProxy”, “EnableProxy” und die Eigenschaft “Name”.

image

Über die Name Eigenschaft kann man einen Namen vergeben, der später dann im Proxy Switcher angezeigt wird.

Enable und Disable sollte sich von selbst erklären. Innerhalb der Methoden kann man auf this.CurrentProxyEntry zugreifen um die Daten abzurufen, die nun aktiviert/deaktiviert werden sollen.

image

Damit hätten wir die minimal Implementierung beendet.

Erweiterte Funktionen

Man kann nun noch für seinen Switcher Einstellungen laden und speichern und auch einen Settings Dialog als Windows Form anbieten (wofür dann noch eine Referenz auf “System.Windows.Forms” hinzugefügt werden muss):

image 

Deployment

Nachdem man alles soweit fertig hat, muss das Projekt noch kompiliert werden. Dadurch entsteht eine DLL, in meinem Fall PSDemoSwitcher.dll.

Diese muss nur noch in das Verzeichnis kopiert werden, wo auch ProxySwitcher.exe liegt. Also normalerweise “C:\Programme\ProxySwitcher”.

Startet man nun den ProxySwitcher, erscheint im ersten Tab direkt mein neuer Switcher und kann selektiert werden, damit er auch aufgerufen wird.

image

 

Update:

Die dokumentierte Beispielimplementierung gibt es hier zum download.

Windows 7: Open a new Form from the Jumplist

With the Windows API Code Pack, Microsoft released a really cool managed wrapper for most of the new Windows 7 features. See here for more details and download.

One thing you can do is to create a .NET app with Jumplist support. Jumplists are these cool menus appearing on right click on an icon in the task bar:

image

But there is something wrong with the jumplist: It can only launch new apps! The demo solution for the Code Pack launches notepad and some other things, but there is no word about how to open the same app but with a new form.

So here is my solution, which is not very nice, but it works like a charm.

Scencario:
AppInstance1 is running –> click on a jumplist item starts a new instance –> appInstance2 now knows, that this is the second instance, so appInstance2 calls appInstance1 through remoting (IPC) and terminates–> appInstance1 receives the remoting call und execute something.

Ok, how to implement this?

First of all, create a new Windows Forms app and go to the Program.cs file. Within this class create a new class which works as your service for the remoting part and also a static reference to your form:

static class Program
    {
        public class RemotingService : MarshalByRefObject
        {
            public RemotingService() { }

            public void ShowText(string text)
            {
                Program.formMain.SetTextToTextBox(text);
            }
        }

        internal static Form1 formMain;

Then you will need some remoting code for the communication. I created two methods “InitRemoting” and “CallRunningInstance”. InitRemoting is called from the main method if this is the first instance. CallRunningInstance is called if the main method detects, that this is the second instance.

For the detection I use a system wide mutex.

I hope you get the idea. Because there are some more lines of code I created a demo project for you to download:

 Download the entire working demo solution here.

 

The file is not checked out. You must first check out this document before making any changes.

If you ever got this message and don’t know where it came from, here is the solution.

I got it if I click on “Edit Page” on a publishing page. So after some investigation it seems to be a problem with the web parts on the page.

My page layout contains some EditModePanels, so the user have different views in display and edit mode of the page. Therefore we also have one web part in a web part zone which is in one of the EditModePanels for display only.

<PublishingWebControls:EditModePanel PageDisplayMode="Display">
  <WebPartZone ID="zone1" ...>
      the web part added through the onet.xml site definition

The same web part zone “zone1” does not exists for editing, because I do not want the user to edit the web part. There is another web part zone “zone2” which lives outside of any EditModePanel.

Now comes SharePoint.

If you check out the page and then click on “Edit Page”, everything is working. Except of, that the web part from zone 1 has moved to zone 2! Automatically! Thank you SharePoint…

It seems that SharePoint think it has to show the web part in edit mode. And because the original web part zone is not visible, SharePoint moves the web part to the next available zone which is visible also in edit mode.

So remember:

Never put a web part zone in an EditModePanel which is only visible in display mode.

Maybe the solution is to make the web part not editable, but I didn’t tested this. My fast workaround hack is to create a div instead of the EditModePanel and makes it “runat=server” and give it an ID. Then I wrote this code on top of the page:

<script runat="server">
protected override void OnLoad(EventArgs e)
{
    base.OnLoad(e);
    this.navleftdiv.Visible = (this.SPWebPartManager1.DisplayMode == WebPartManager.BrowseDisplayMode);
}
</script>

Now it works like a charm.