Private „Putzete“

Im Schwäbischen gibt’s einen Begriff namens „Putzete“ oder „Dorfputzete„.

Mit diesem Begriff wird das (meist gemeinschaftliche) Aufsammeln von Müll und Unrat am Straßenrand, auf Wiesen, im Wald, usw. bezeichnet.

Da ich oft mit meiner Hündin Jara im Stauferpark Göppingen unterwegs bin und dort immer viiiiiiiiiel Müll herumliegt, habe ich seit ein paar Wochen angefangen, in unregelmäßigen Abständen diesen einzusammeln:

Meist mache ich das während Hundespaziergängen, da bin ich ja eh unterwegs.

Eine leere Mülltüte ausm Büro mitgenommen ist meistens gegen Ende immer randvoll. Auf obigem Bild habe ich eine Tüte die ich unterwegs gefunden habe mit Unrat gefüllt.

Warum ich das mache?

Schlicht weil mich der Müll stört und meckern/jammern ist einfach, praktisch und nutzlos.

Deswegen habe ich die für mich einzig sinnvolle Konsequenz gezogen und sammle das Zeugs halt ein und werfe es in den Mülleimer.

(Bin mal gespannt ob ich das hier auch wegbekomme ;-))

Serialize a DataTable to a string

Just a short code snippet that helped me recently:

public static string SerializeTableToString(
    DataTable table )
{
    if (table == null)
    {
        return null;
    }
    else
    {
        using (var sw = new StringWriter())
        using (var tw = new XmlTextWriter(sw))
        {
            // Must set name for serialization to succeed.
            table.TableName = @"MyTable";

            // --
            // http://bit.ly/a75DK7

            tw.Formatting = Formatting.Indented;

            tw.WriteStartDocument();
            tw.WriteStartElement(@"data");

            ((IXmlSerializable)table).WriteXml(tw);

            tw.WriteEndElement();
            tw.WriteEndDocument();

            // --

            tw.Flush();
            tw.Close();
            sw.Flush();

            return sw.ToString();
        }
    }
}

Hopefully it is useful for someone out there, too.

SVN Ignore Pattern

Just for reference purposes, this is my current SVN ignore pattern:

*.o *.lo *.la *.al .libs *.so *.so.[0-9]* *.a *.pyc *.pyo *.rej *~ #*# .#* .*.swp .DS_Store _ReSharper.* */obj *.user *.suo *.pch *.ilk *.obj *.idb *.ncb *.log* thumbs.db */int *.bsc *.resharper

To set this pattern, right-click on any SVN-controlled folder in Windows File Explorer and select „Settings“:

tortoise-pattern-01

Then choose „General“ and fill the „Global ignore pattern“ field.

tortoise-pattern-02

Marshalling .NET Exceptions between Threads

Introduction

Today I faced a strange issue; I was catching an Exception in a BackgroundWorker’s thread, threw a new exception and handled it in the main GUI thread by showing the exception’s Message in a message box.

The strange thing was, that no matter what I did, the main GUI thread always displayed the message of the first generated exception in the background thread.

Cause

As described by user „nobugz“ in this discussion, the cause is:

This is an architectural limitation to the way exceptions are marshalled from one thread (the BGW’s) to another (the UI thread).  Only a single exception object can get copied, the designers chose the first one thrown as the most likely to be relevant.  You’ll need to work around this restriction.

Interestingly enough this behavior seems to occur only in an Application.ThreadException handler which seems to pick up the exception from somewhere (maybe TLS?)

Resolution

The resolution is to handle the exception directly in the RunWorkerCompleted handler where it gets forwarded to and not to throw the exception any further, until the Application.ThreadException handler of the GUI thread handles it.

Example application

To show the error in a small example project I created a tiny Windows Forms application which you may download from here.

Main Window with erroneous Behavior

When the check box is activated, the erroneous behavior is being performed when clicking the button:

The first generated exception is being displayed to the end user instead the actual one that is being thrown later in the background thread.

Main Window with expected Behavior

When the check box is not activated when clicking the button, the expected result is being displayed; the latest thrown exception:

Summary

I’ve just shown you a case where (in my eyes) the .NET Framework behaves wrong.

Maybe you find this article useful or even prove that I am wrong or how to handle in a more elegant way.

Looking forward for your feedback!

Fehlermeldung „Invalid URI: The hostname could not be parsed.“

Fehlermeldung

Beim Laden aus einer XML-Datei erhielt ein Kunde unseres CMS Zeta Producer folgende Fehlermeldung:

System.UriFormatException

—————–

Invalid URI: The hostname could not be parsed.

—————–

at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
at System.Uri..ctor(String uriString, UriKind uriKind)
at System.Xml.XmlResolver.ResolveUri(Uri baseUri, String relativeUri)
at System.Xml.XmlUrlResolver.ResolveUri(Uri baseUri, String relativeUri)
at System.Xml.XmlTextReaderImpl..ctor(String url, XmlNameTable nt)
at System.Xml.XmlDocument.Load(String filename)
at Zeta.EnterpriseLibrary.Tools.Storage.PersistentXmlFilePairStorage.load()
at Zeta.EnterpriseLibrary.Tools.Storage.PersistentXmlFilePairStorage.set_FilePath(FileInfo value)
at ZetaProducer.RuntimeBusinessLogic.Code.AppHost.Host.InitializeInstance()
at ZetaProducer.RuntimeMain.Code.AppHost.Host.InitializeInstance()
at ZetaProducer.Main.Code.AppHost.Host.InitializeInstance()
at ZetaProducer.Main.Code.AppHost.Host.process()

Ursache

Ursache war, dass der Kunde Parallels unter Mac OS X verwendet hat um Zeta Producer in einer virtuellen Maschine laufen zu lassen.

Gleichzeitig lagen die „Eigenen Dateien“ auf Mac OS X und wurden via Parallels in die virtuelle Maschine eingebunden.

Der Pfad war sichtbar als:

\\.psf\Home\Documents\Zeta Producer 9

Damit scheint die Uri-Klasse von .NET nicht zurecht zu kommen.

Lösung

Eine schnelle Lösung aus Anwendersicht ist, den UNC-Pfad „\\.psf\Home\Documents\Zeta Producer 9“ als Laufwerksbuchstaben unter Windows zu verbinden und dieses Laufwerk dann als Home-Ordner zu konfigurieren.

Eine programmierte Lösung wird so aussehen, dass ich das Laden eines XmlDocument selbst durchführe (via Stream) und dann den geladenen Stream (bzw. die Zeichenfolgen als string) an das XmlDocument übergebe. So umgehe ich die Uri-Klasse, die wohl mit UNC-Pfaden die mit „.“ beginnen Schwierigkeiten hat.

Kühlschrank

Vermutlich ist unser Kühlschrank im Büro zu kalt eingestellt.

Zumindest fand ich heute morgen folgendes Szenario vor:

Eine Schande wie sich das kostbare Nass namens „Deit“ sinnlos über die Innereien des Kühlschranks ergoss. Trauer!

Und das alles, obwohl der Kühlschrank schon nur auf halber Kühlung fährt.

Mal überlegen ob ich das weg mache oder bis Montag liegen lasse wenn (hoffentlich) unsere Putzfrau kommt…

Update: Ich hab’s selbst geputzt.

Schaut wieder perfekt aus.

Text mit C# aus einer Datei lesen

Dieser Artikel ist für mich als Referenz, weil ich es immer wieder mal recherchiere.

HOWTO: Text mit .NET/C# aus einer Textdatei lesen

1. Möglichkeit: Microsoft-Knowledge-Base-Artikel How to read a text file by using System.IO and Visual C#.

2. Möglichkeit: So wie in der MSDN-Dokumentation beschrieben: How to: Read Text from a File.

In aller Kürze:

string line;
using (var sr = new StreamReader("TestFile.txt"))
{
    line = sr.ReadToEnd();
}

// ...do something with line...

Ich hoffe es hilft mir und Euch da draußen mal.

BOM size for different encodings

The number of bytes for the Byte Order Mark („BOM“) differs among the used encodings.

public static bool IsBomRelevantEncoding(
    Encoding encoding,
    out int bomSizeBytes )
{
    if ( encoding == Encoding.Unicode )
    {
        bomSizeBytes = 2;
        return true;
    }
    else if ( encoding == Encoding.UTF32 )
    {
        bomSizeBytes = 4;
        return true;
    }
    else if ( encoding == Encoding.UTF8 )
    {
        bomSizeBytes = 3;
        return true;
    }
    else if ( encoding == Encoding.UTF7 )
    {
        bomSizeBytes = 4;
        return true;
    }
    else
    {
        bomSizeBytes = 0;
        return false;
    }
}

References:

SharePoint

Liebe Leser, ich möchte hiermit gerne nochmals einen Artikel veröffentlichen um als „Link seed“ für ein paar Seiten die ich angelegt habe zu dienen.

Ich bitte höflichst um Toleranz, es wird sich auf ein Minimum beschränken. Danke!

Als Ausgleich ein Hundebild, Jara beim Verspeisen einer Fledermaus:

jara-fledermaus

Microsoft-SharePoint-Know-How

Wir, die zeta software GmbH, unterstützen Sie bei der maßgeschneiderten Implementierung und Integration von Microsoft Office SharePoint Services (MOSS) in Ihre vorhandene IT-Infrastruktur in Ihrem Unternehmen.

Wir sind in den Regionen Filstal und mittlerer Neckar tätig, von Ulm über GeislingenGöppingenEsslingen und Nürtingen bis nach Stuttgart.