<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>welt-held.de &#187; C#</title>
	<atom:link href="http://www.welt-held.de/category/programmierung/c-sharp/feed" rel="self" type="application/rss+xml" />
	<link>http://www.welt-held.de</link>
	<description>Sind wir nicht alle Welt Held?</description>
	<lastBuildDate>Wed, 23 Nov 2011 09:14:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>StringWriter mit anderem Encoding</title>
		<link>http://www.welt-held.de/2008-stringwriter-mit-anderem-encoding.html</link>
		<comments>http://www.welt-held.de/2008-stringwriter-mit-anderem-encoding.html#comments</comments>
		<pubDate>Thu, 03 Nov 2011 05:43:53 +0000</pubDate>
		<dc:creator>Björn</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[serialize]]></category>
		<category><![CDATA[stringwriter]]></category>
		<category><![CDATA[utf16]]></category>
		<category><![CDATA[utf8]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.welt-held.de/?p=2008</guid>
		<description><![CDATA[Vor einer ganzen Weile habe ich mal die StringWriter-Klasse empfohlen.
Die StringWriter-Klasse nutzt intern UTF-16, wodurch zum Beispiel bei der Xml-Serialisierung von Klassen auch das Ergebnis in UTF-16 vorliegt. Dies ist nicht zwangsläufig gewünscht, bei mir hat dadurch ein Backend-Service  [...]]]></description>
			<content:encoded><![CDATA[<p>Vor einer ganzen Weile habe ich mal die <a href="http://www.welt-held.de/1964-tipp-stringreader-und-stringwriter.html">StringWriter</a>-Klasse empfohlen.<br />
Die StringWriter-Klasse nutzt intern UTF-16, wodurch zum Beispiel bei der Xml-Serialisierung von Klassen auch das Ergebnis in UTF-16 vorliegt. Dies ist nicht zwangsläufig gewünscht, bei mir hat dadurch ein Backend-Service gestreikt.<br />
Um trotzdem den StringWriter weiter zu verwenden, muss man sich eine eigene Klasse schreiben, welche von der StringWriter ableitet und das Encoding-Property überschreibt:</p>
<pre class="brush: csharp; title: ; notranslate">using System;
using System.IO;
using System.Text;

namespace Utilities.IO
{

	/// &lt;summary&gt;
	/// 	A simple class derived from StringWriter, but which allows
	/// 	the user to select which Encoding is used. This is most
	/// 	likely to be used with XmlTextWriter, which uses the Encoding
	/// 	property to determine which encoding to specify in the XML.
	/// &lt;/summary&gt;
	public class StringWriterWithEncoding : StringWriter
	{
		private Encoding _encoding;

		/// &lt;summary&gt;
		/// 	Initializes a new instance of the StringWriterWithEncoding class
		/// 	with the specified encoding.
		/// &lt;/summary&gt;
		/// &lt;param name = &quot;encoding&quot;&gt;The encoding to report.&lt;/param&gt;
		public StringWriterWithEncoding(Encoding encoding)
			: base()
		{
			this._encoding = encoding;
		}

		/// &lt;summary&gt;
		/// 	Initializes a new instance of the StringWriter class with the
		/// 	specified format control and encoding.
		/// &lt;/summary&gt;
		/// &lt;param name = &quot;encoding&quot;&gt;The encoding to report.&lt;/param&gt;
		/// &lt;param name = &quot;formatProvider&quot;&gt;An IFormatProvider object that controls formatting.&lt;/param&gt;
		public StringWriterWithEncoding(Encoding encoding, IFormatProvider formatProvider)
			: base(formatProvider)
		{
			this._encoding = encoding;
		}

		/// &lt;summary&gt;
		/// 	Initializes a new instance of the StringWriter class that writes to the
		/// 	specified StringBuilder, and reports the specified encoding.
		/// &lt;/summary&gt;
		/// &lt;param name = &quot;encoding&quot;&gt;The encoding to report.&lt;/param&gt;
		/// &lt;param name = &quot;sb&quot;&gt;The StringBuilder to write to. &lt;/param&gt;
		public StringWriterWithEncoding(Encoding encoding, StringBuilder sb)
			: base(sb)
		{
			this._encoding = encoding;
		}

		/// &lt;summary&gt;
		/// 	Initializes a new instance of the StringWriter class that writes to the specified
		/// 	StringBuilder, has the specified format provider, and reports the specified encoding.
		/// &lt;/summary&gt;
		/// &lt;param name = &quot;encoding&quot;&gt;The encoding to report.&lt;/param&gt;
		/// &lt;param name = &quot;sb&quot;&gt;The StringBuilder to write to. &lt;/param&gt;
		/// &lt;param name = &quot;formatProvider&quot;&gt;An IFormatProvider object that controls formatting.&lt;/param&gt;
		public StringWriterWithEncoding(Encoding encoding, StringBuilder sb, IFormatProvider formatProvider)
			: base(sb, formatProvider)
		{
			this._encoding = encoding;
		}

		/// &lt;summary&gt;
		/// 	Gets the Encoding in which the output is written.
		/// &lt;/summary&gt;
		public override Encoding Encoding
		{
			get { return this._encoding; }
		}
	}
}
</pre>
<p><strong>Update:</strong><br />
Habe die Klasse mal um Kommentare erweitert.</p>
<div class="bottomcontainerBox" style="background-color:#F0F4F9;">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.welt-held.de%2F2008-stringwriter-mit-anderem-encoding.html&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://www.welt-held.de/2008-stringwriter-mit-anderem-encoding.html"></g:plusone>
			</div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.welt-held.de/2008-stringwriter-mit-anderem-encoding.html"  data-text="StringWriter mit anderem Encoding" data-count="horizontal" data-via="trashar">Tweet</a>
			</div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div> <p><a href="http://welt-held.de/?flattrss_redirect&amp;id=2008&amp;md5=67cf5eb483bf133c953176986f619a70" title="Flattr" target="_blank"><img src="http://welt-held.de/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.welt-held.de/2008-stringwriter-mit-anderem-encoding.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" href="http://welt-held.de/?flattrss_redirect&amp;id=2008&amp;md5=67cf5eb483bf133c953176986f619a70" type="text/html" />
	</item>
		<item>
		<title>XML serialisierbares Dictionary</title>
		<link>http://www.welt-held.de/2002-xml-serialisierbares-dictionary-tkey-tvalue.html</link>
		<comments>http://www.welt-held.de/2002-xml-serialisierbares-dictionary-tkey-tvalue.html#comments</comments>
		<pubDate>Mon, 17 Oct 2011 14:24:08 +0000</pubDate>
		<dc:creator>Björn</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Programmierung]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[dictionary]]></category>
		<category><![CDATA[generic]]></category>
		<category><![CDATA[serialize]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.welt-held.de/?p=2002</guid>
		<description><![CDATA[Ich verstehe zwar nicht, warum es standardmäßig nicht im .NET Framework implementiert ist, allerdings ist es ohne Hilfsmittel nicht möglich, eine Klasse mit einem Dictionary mittels XmlSerializer zu serialisieren! Mit folgender Hilfsklasse funktioniert es dahin anstandslos, vorausgesetzt sowohl  [...]]]></description>
			<content:encoded><![CDATA[<p>Ich verstehe zwar nicht, warum es standardmäßig nicht im .NET Framework implementiert ist, allerdings ist es ohne Hilfsmittel nicht möglich, eine Klasse mit einem Dictionary<tkey ,TValue> mittels <a href="http://msdn.microsoft.com/de-de/library/system.xml.serialization.xmlserializer(v=vs.80).aspx">XmlSerializer</a> zu serialisieren! Mit folgender Hilfsklasse funktioniert es dahin anstandslos, vorausgesetzt sowohl TKey und TValue sind Xml-serialisierbar.</p>
<pre class="brush: csharp; title: ; notranslate">
using System.Collections.Generic;
using System.Xml.Serialization;

namespace Utilities.Generic
{
	[XmlRoot(&quot;dictionary&quot;)]
	public class SerializableDictionary&lt;TKey, TValue&gt; : Dictionary&lt;TKey, TValue&gt;, IXmlSerializable
	{
		#region Constructors

		public SerializableDictionary():base() {}

		public SerializableDictionary(IDictionary&lt;TKey, TValue&gt; dictionary) : base(dictionary) { }

		public SerializableDictionary(IDictionary&lt;TKey, TValue&gt; dictionary, IEqualityComparer&lt;TKey&gt; comparer) : base(dictionary, comparer) {}

		public SerializableDictionary(int capacity, IEqualityComparer&lt;TKey&gt; comparer) : base(capacity, comparer) { }

		public SerializableDictionary(IEqualityComparer&lt;TKey&gt; comparer) : base(comparer) { }

		public SerializableDictionary(int capacity) : base(capacity) { }

		#endregion

		private const string ItemTagName = &quot;item&quot;;
		private const string KeyTagName = &quot;key&quot;;
		private const string ValueTagName = &quot;value&quot;;

		/// &lt;summary&gt;
		/// Diese Methode ist reserviert und sollte nicht verwendet werden. Wenn Sie die IXmlSerializable-Schnittstelle implementieren, sollten Sie null (Nothing in Visual Basic) von der Methode zurückgeben und stattdessen das &lt;see cref=&quot;T:System.Xml.Serialization.XmlSchemaProviderAttribute&quot;/&gt; auf die Klasse anwenden, wenn ein benutzerdefiniertes Schema erforderlich ist.
		/// &lt;/summary&gt;
		/// &lt;returns&gt;
		/// Ein &lt;see cref=&quot;T:System.Xml.Schema.XmlSchema&quot;/&gt; zur Beschreibung der XML-Darstellung des Objekts, das von der &lt;see cref=&quot;M:System.Xml.Serialization.IXmlSerializable.WriteXml(System.Xml.XmlWriter)&quot;/&gt;-Methode erstellt und von der &lt;see cref=&quot;M:System.Xml.Serialization.IXmlSerializable.ReadXml(System.Xml.XmlReader)&quot;/&gt;-Methode verwendet wird.
		/// &lt;/returns&gt;
		public System.Xml.Schema.XmlSchema GetSchema()
		{
			return null;
		}

		/// &lt;summary&gt;
		/// Generiert ein Objekt aus seiner XML-Darstellung.
		/// &lt;/summary&gt;
		/// &lt;param name=&quot;reader&quot;&gt;Der &lt;see cref=&quot;T:System.Xml.XmlReader&quot;/&gt;-Stream, aus dem das Objekt deserialisiert wird.&lt;/param&gt;
		public void ReadXml(System.Xml.XmlReader reader)
		{
			XmlSerializer keySerializer = new XmlSerializer(typeof(TKey));
			XmlSerializer valueSerializer = new XmlSerializer(typeof(TValue));

			bool wasEmpty = reader.IsEmptyElement;
			reader.Read();

			if (wasEmpty)
			{
				return;
			}

			while (reader.NodeType != System.Xml.XmlNodeType.EndElement)
			{
				reader.ReadStartElement(ItemTagName);

				reader.ReadStartElement(KeyTagName);
				TKey key = (TKey)keySerializer.Deserialize(reader);
				reader.ReadEndElement();

				reader.ReadStartElement(ValueTagName);
				TValue value = (TValue)valueSerializer.Deserialize(reader);
				reader.ReadEndElement();

				this.Add(key, value);

				reader.ReadEndElement();
				reader.MoveToContent();
			}
			reader.ReadEndElement();
		}

		/// &lt;summary&gt;
		/// Konvertiert ein Objekt in seine XML-Darstellung.
		/// &lt;/summary&gt;
		/// &lt;param name=&quot;writer&quot;&gt;Der &lt;see cref=&quot;T:System.Xml.XmlWriter&quot;/&gt;-Stream, in den das Objekt serialisiert wird.&lt;/param&gt;
		public void WriteXml(System.Xml.XmlWriter writer)
		{
			XmlSerializer keySerializer = new XmlSerializer(typeof(TKey));
			XmlSerializer valueSerializer = new XmlSerializer(typeof(TValue));

			foreach (TKey key in this.Keys)
			{
				writer.WriteStartElement(ItemTagName);

				writer.WriteStartElement(KeyTagName);
				keySerializer.Serialize(writer, key);
				writer.WriteEndElement();

				writer.WriteStartElement(ValueTagName);
				TValue value = this[key];
				valueSerializer.Serialize(writer, value);
				writer.WriteEndElement();

				writer.WriteEndElement();
			}
		}
	}
}</pre>
<p>Den ursprünglichen Code habe ich <a href="http://weblogs.asp.net/pwelter34/archive/2006/05/03/444961.aspx">hier</a> her.</tkey></p>
<p><strong>Update:</strong><br />
Habe die Klasse mal um die Standardkonstruktoren der Basis-Klasse erweitert um ein bestehendes Dictionary einfach umwandeln zu können.</p>
<div class="bottomcontainerBox" style="background-color:#F0F4F9;">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.welt-held.de%2F2002-xml-serialisierbares-dictionary-tkey-tvalue.html&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://www.welt-held.de/2002-xml-serialisierbares-dictionary-tkey-tvalue.html"></g:plusone>
			</div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.welt-held.de/2002-xml-serialisierbares-dictionary-tkey-tvalue.html"  data-text="XML serialisierbares Dictionary<TKey,TValue>" data-count="horizontal" data-via="trashar">Tweet</a>
			</div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div> <p><a href="http://welt-held.de/?flattrss_redirect&amp;id=2002&amp;md5=a29081684b9356ba8ec932604d93c0c8" title="Flattr" target="_blank"><img src="http://welt-held.de/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.welt-held.de/2002-xml-serialisierbares-dictionary-tkey-tvalue.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" href="http://welt-held.de/?flattrss_redirect&amp;id=2002&amp;md5=a29081684b9356ba8ec932604d93c0c8" type="text/html" />
	</item>
		<item>
		<title>Verschiedene ContextMenues bei einem NotifyIcon</title>
		<link>http://www.welt-held.de/1996-verschiedene-contextmenues-bei-einem-notifyicon.html</link>
		<comments>http://www.welt-held.de/1996-verschiedene-contextmenues-bei-einem-notifyicon.html#comments</comments>
		<pubDate>Mon, 25 Jul 2011 20:31:14 +0000</pubDate>
		<dc:creator>Björn</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[contextmenu]]></category>
		<category><![CDATA[notifyicon]]></category>
		<category><![CDATA[source]]></category>

		<guid isPermaLink="false">http://www.welt-held.de/?p=1996</guid>
		<description><![CDATA[In einer kleinen Applikation mit NotifyIcon in der Taskbar wollte ich unterschiedliche ContextMenues öffnen, je nachdem, ob man mit der linken oder rechten Maustaste auf das Icon klickt.
Die erste Hürde, welche es zu nehmen gilt, ist es, dass ContextMenü auch bei einem Links-Klick zu öffnen. Man  [...]]]></description>
			<content:encoded><![CDATA[<p>In einer kleinen Applikation mit NotifyIcon in der Taskbar wollte ich unterschiedliche ContextMenues öffnen, je nachdem, ob man mit der linken oder rechten Maustaste auf das Icon klickt.</p>
<p>Die erste Hürde, welche es zu nehmen gilt, ist es, dass ContextMenü auch bei einem Links-Klick zu öffnen. Man kann zwar eine entsprechende Methode nutzen, jedoch gibt es damit <a href="http://stackoverflow.com/questions/2208690/invoke-notifyicons-context-menu/2208910#2208910">Probleme</a>. Daher sollte man hier Reflection nutzen:</p>
<pre class="brush: csharp; title: ; notranslate">
// constructor..
this._trayIcon.MouseDown += this.TrayIconMouseDown;

private void TrayIconMouseDown(object sender, MouseEventArgs e)
{
	if (e.Button == MouseButtons.Left)
	{
		MethodInfo mi = typeof (NotifyIcon).GetMethod(&quot;ShowContextMenu&quot;, BindingFlags.Instance | BindingFlags.NonPublic);
		mi.Invoke(this._trayIcon, null);
	}
}
</pre>
<p>Nun öffnet sich schon mal das Kontextmenü auch beim Linksklick. Und hier kann man ansetzen, um das Menü entweder zu manipulieren oder zu ersetzen. Ich selbst habe mir einfach zwei Objekte vorbereitet, welche ich je nach Mausklick austausche:</p>
<pre class="brush: csharp; title: ; notranslate">
private void TrayIconMouseDown(object sender, MouseEventArgs e)
{
	if (e.Button == MouseButtons.Left)
	{
		this._trayIcon.ContextMenu = this._leftClickMenu;
		MethodInfo mi = typeof (NotifyIcon).GetMethod(&quot;ShowContextMenu&quot;, BindingFlags.Instance | BindingFlags.NonPublic);
		mi.Invoke(this._trayIcon, null);
	}
	else if (e.Button == MouseButtons.Right)
	{
		this._trayIcon.ContextMenu = this._rightClickMenu;
		MethodInfo mi = typeof(NotifyIcon).GetMethod(&quot;ShowContextMenu&quot;, BindingFlags.Instance | BindingFlags.NonPublic);
		mi.Invoke(this._trayIcon, null);
	}
}
</pre>
<p>Beim Testen ist mir aufgefallen, dass es mehrere Events gibt, an die man sich hängen könnte, etwa &#8220;MouseUp&#8221;, &#8220;MouseClick&#8221; usw. Beim Testen hat bei mir allerdings nur &#8220;MouseDown&#8221; korrekt funktioniert, bei den anderen hatte ich das Problem, dass zum Teil das Menü erst angezeigt wurde und dann der Eventhandler durchlaufen wurde (ich glaube sogar immer, wenn ich mit der linken Maustaste geklickt habe). Erklären konnte ich es mir allerdings nicht.</p>
<div class="bottomcontainerBox" style="background-color:#F0F4F9;">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.welt-held.de%2F1996-verschiedene-contextmenues-bei-einem-notifyicon.html&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://www.welt-held.de/1996-verschiedene-contextmenues-bei-einem-notifyicon.html"></g:plusone>
			</div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.welt-held.de/1996-verschiedene-contextmenues-bei-einem-notifyicon.html"  data-text="Verschiedene ContextMenues bei einem NotifyIcon" data-count="horizontal" data-via="trashar">Tweet</a>
			</div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div> <p><a href="http://welt-held.de/?flattrss_redirect&amp;id=1996&amp;md5=13599e4f664332ff77c98333f55ca252" title="Flattr" target="_blank"><img src="http://welt-held.de/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.welt-held.de/1996-verschiedene-contextmenues-bei-einem-notifyicon.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" href="http://welt-held.de/?flattrss_redirect&amp;id=1996&amp;md5=13599e4f664332ff77c98333f55ca252" type="text/html" />
	</item>
		<item>
		<title>Signieren einer XML-Datei in C#</title>
		<link>http://www.welt-held.de/1983-signieren-einer-xml-datei-in-c.html</link>
		<comments>http://www.welt-held.de/1983-signieren-einer-xml-datei-in-c.html#comments</comments>
		<pubDate>Mon, 20 Jun 2011 18:03:54 +0000</pubDate>
		<dc:creator>Björn</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[asymmetrische verschlüsselung]]></category>
		<category><![CDATA[rsa]]></category>
		<category><![CDATA[signatur]]></category>
		<category><![CDATA[signieren]]></category>
		<category><![CDATA[xml signatur]]></category>

		<guid isPermaLink="false">http://www.welt-held.de/?p=1983</guid>
		<description><![CDATA[Vielleicht haben sich schon einige von euch mit Lizenzen beschäftigt. Man erstellt eine Software, verkauft sie und möchte natürlich nicht, dass sie einfach von anderen kostenlos genutzt wird. Ich möchte daher heute eine Möglichkeit vorstellen. Sie ist recht simpel aber dennoch sehr flexibel  [...]]]></description>
			<content:encoded><![CDATA[<p>Vielleicht haben sich schon einige von euch mit Lizenzen beschäftigt. Man erstellt eine Software, verkauft sie und möchte natürlich nicht, dass sie einfach von anderen kostenlos genutzt wird. Ich möchte daher heute eine Möglichkeit vorstellen. Sie ist recht simpel aber dennoch sehr flexibel gestaltet.</p>
<p>Um meinen Ansatz zu verstehen, muss man wissen, was eine <a href="http://de.wikipedia.org/wiki/Asymmetrisches_Kryptosystem">asymmetrische Verschlüsselung</a> funktioniert. Während bei einer symmetrischen Verschlüsselung mit einem Passwort sowohl ver- als auch entschlüsselt wird, gibt es bei der asymmetrischen Verschlüsselung zwei Schlüssel. Den Private und den Public Key. Während der Private und der Public Key verschlüsseln können, ist nur der Private Key in der Lage wieder zu entschlüsseln. Will man hingegen wissen, ob eine Nachricht wirklich vom Besitzer des Private Keys kommt, spricht man von Signierung. Signieren kann nur der Besitzer des Privaten Schlüssels, während jeder Public Key Besitzer dies verifizieren kann.</p>
<p>Dieses Verhalten kann man ausnutzen, der Hersteller der Software ist im Besitz des Private Keys und signiert Dateien, welche von der Software, welche den Public Key kennt, verifiziert. Sollte die Signatur nicht gültig sein, verweigert die Software ihren Dienst. Sollte jemand den Inhalt der Datei manipulieren, so muss sie wieder mit dem Private Key neu signiert werden.</p>
<p>Ich habe mir daher eine kleine, aber feine Klasse erstellt, welche entweder ein XML-Dokument oder eine Klasse, welche per XmlSerializer serialisierbar ist, signieren kann. So kann man theoretisch jede Information in eine XML-Lizenz-Datei hinterlegen, etwa wie lange die Lizenz gültig ist. Die nötigen Klassen befinden sich alle im .NET-Framework ab Version 2.0. Der Code ist zum Teil aus der MSDN (siehe Links am Ende des Beitrages).</p>
<p>Diese Möglichkeit bietet keinen absoluten Schutz. Leute könnten mit Programmen wie <a href="http://www.jetbrains.com/decompiler/">dotPeek</a> an den SourceCode gelangen und die Prüfung ausbauen. Mit einem <a href="http://de.wikipedia.org/wiki/Obfuscator">Obfuscator</a> kann dies erschwert werden. Zudem dürft ihr niemals den privaten Schlüssel herausgeben, da dieser sowohl signieren als auch einen Public Key erstellen kann.</p>
<h3>Beispielapplikation:</h3>
<p><a href='http://welt-held.de/files/XmlSign.zip'>Hier</a> findet ihr eine kleine Beispielanwendung. Die Form ist sehr trivial, erstellt erst die Keys, dann die Dummy-Klasse, signieren und zum Schluss validieren.</p>
<h4>Links:</h4>
<p><a href="http://msdn.microsoft.com/en-us/library/ms229745%28v=VS.85%29.aspx">How to: Sign XML Documents with Digital Signatures </a><br />
<a href="http://msdn.microsoft.com/en-us/library/ms229950(v=VS.85).aspx">How to: Verify the Digital Signatures of XML Documents </a><br />
<a href='http://welt-held.de/files/XmlSign.zip'>Beispielanwendung</a></p>
<div class="bottomcontainerBox" style="background-color:#F0F4F9;">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.welt-held.de%2F1983-signieren-einer-xml-datei-in-c.html&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://www.welt-held.de/1983-signieren-einer-xml-datei-in-c.html"></g:plusone>
			</div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.welt-held.de/1983-signieren-einer-xml-datei-in-c.html"  data-text="Signieren einer XML-Datei in C#" data-count="horizontal" data-via="trashar">Tweet</a>
			</div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div> <p><a href="http://welt-held.de/?flattrss_redirect&amp;id=1983&amp;md5=f5b9245bc323013a844eb016241d056b" title="Flattr" target="_blank"><img src="http://welt-held.de/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.welt-held.de/1983-signieren-einer-xml-datei-in-c.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" href="http://welt-held.de/?flattrss_redirect&amp;id=1983&amp;md5=f5b9245bc323013a844eb016241d056b" type="text/html" />
	</item>
		<item>
		<title>Tipp: StringReader und StringWriter</title>
		<link>http://www.welt-held.de/1964-tipp-stringreader-und-stringwriter.html</link>
		<comments>http://www.welt-held.de/1964-tipp-stringreader-und-stringwriter.html#comments</comments>
		<pubDate>Wed, 23 Mar 2011 21:05:09 +0000</pubDate>
		<dc:creator>Björn</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[.net 3.5]]></category>
		<category><![CDATA[.net 4]]></category>
		<category><![CDATA[stringreader]]></category>
		<category><![CDATA[stringwriter]]></category>
		<category><![CDATA[tipp]]></category>

		<guid isPermaLink="false">http://www.welt-held.de/?p=1964</guid>
		<description><![CDATA[Ein kleiner Tipp für die Leute, die .NET Version 3.5 oder höher einsetzen:
Wer Text an Methoden / Klassen weitergeben will, die mit Streams arbeiten, sollte dies nicht umständlich über den MemoryStream lösen, sondern sich lieber mal die beiden Klassen StringReader und StringWriter anschauen. Geht  [...]]]></description>
			<content:encoded><![CDATA[<p>Ein kleiner Tipp für die Leute, die .NET Version 3.5 oder höher einsetzen:</p>
<p>Wer Text an Methoden / Klassen weitergeben will, die mit Streams arbeiten, sollte dies nicht umständlich über den <a href="http://msdn.microsoft.com/de-de/library/system.io.memorystream(v=vs.80).aspx">MemoryStream</a> lösen, sondern sich lieber mal die beiden Klassen <a href="http://msdn.microsoft.com/en-us/library/system.io.stringreader.aspx">StringReader</a> und <a href="http://msdn.microsoft.com/en-us/library/system.io.stringwriter.aspx">StringWriter</a> anschauen. Geht deutlich einfacher und man braucht nicht umständlich mit irgendwelchen Encodings / Bytes / Stream-Positionen rumspielen.</p>
<div class="bottomcontainerBox" style="background-color:#F0F4F9;">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.welt-held.de%2F1964-tipp-stringreader-und-stringwriter.html&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://www.welt-held.de/1964-tipp-stringreader-und-stringwriter.html"></g:plusone>
			</div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.welt-held.de/1964-tipp-stringreader-und-stringwriter.html"  data-text="Tipp: StringReader und StringWriter" data-count="horizontal" data-via="trashar">Tweet</a>
			</div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div> <p><a href="http://welt-held.de/?flattrss_redirect&amp;id=1964&amp;md5=d8ac50cc28ac33490d759ceb2addf30a" title="Flattr" target="_blank"><img src="http://welt-held.de/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.welt-held.de/1964-tipp-stringreader-und-stringwriter.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<atom:link rel="payment" href="http://welt-held.de/?flattrss_redirect&amp;id=1964&amp;md5=d8ac50cc28ac33490d759ceb2addf30a" type="text/html" />
	</item>
		<item>
		<title>XSLT Transformation in C#</title>
		<link>http://www.welt-held.de/1960-xslt-transformation-in-c.html</link>
		<comments>http://www.welt-held.de/1960-xslt-transformation-in-c.html#comments</comments>
		<pubDate>Wed, 23 Mar 2011 20:58:24 +0000</pubDate>
		<dc:creator>Björn</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[short end tag]]></category>
		<category><![CDATA[transform]]></category>
		<category><![CDATA[xslcompiledtransform]]></category>
		<category><![CDATA[xslt]]></category>

		<guid isPermaLink="false">http://www.welt-held.de/?p=1960</guid>
		<description><![CDATA[Ich hatte ein recht umfangreiches Xml-Schema. Dieses wird ständig mal erweitert und eine andere Applikation benötigt nur einen Teil dieses Schemas. Dazu wurde es immer von Hand für die andere Applikation geändert. Um mir das Leben einfacher zu machen, wollte ich dies über eine XSLT-Transformation  [...]]]></description>
			<content:encoded><![CDATA[<p>Ich hatte ein recht umfangreiches Xml-Schema. Dieses wird ständig mal erweitert und eine andere Applikation benötigt nur einen Teil dieses Schemas. Dazu wurde es immer von Hand für die andere Applikation geändert. Um mir das Leben einfacher zu machen, wollte ich dies über eine XSLT-Transformation lösen, schließlich ist ein Schema auch nur eine XML-Datei. Ein großer Teil wurde einfach nur kopiert, dennoch sah die Ausgabe anders aus als die Eingabe. Mein Kopiertemplate sah folgendermaßen aus:</p>
<pre class="brush: xml; title: ; notranslate">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;
    xmlns:msxsl=&quot;urn:schemas-microsoft-com:xslt&quot; exclude-result-prefixes=&quot;msxsl&quot;
&gt;
    &lt;xsl:output method=&quot;xml&quot; indent=&quot;yes&quot;/&gt;
    &lt;xsl:template match=&quot;@* | node()&quot;&gt;
        &lt;xsl:copy&gt;
            &lt;xsl:apply-templates select=&quot;@* | node()&quot;/&gt;
        &lt;/xsl:copy&gt;
    &lt;/xsl:template&gt;
&lt;/xsl:stylesheet&gt;
</pre>
<p>Einfach alle Nodes und Attribute kopieren, also nichts wildes. Dennoch wurde aus:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;xs:element name=&quot;comment&quot; type=&quot;xs:string&quot; minOccurs=&quot;0&quot; /&gt;
</pre>
<p>folgendes:</p>
<pre class="brush: xml; title: ; notranslate">&lt;xs:element name=&quot;comment&quot; type=&quot;xs:string&quot; minOccurs=&quot;0&quot;&gt;&lt;/xs:element&gt;</pre>
<p>Das Schema ist noch valide und funktioniert tadellos, nur sieht es nicht wirklich schön aus. Nachdem ich im Netz nach einen bestimmten Parameter im C#-Code und ähnliches gesucht hatte, wurde ich doch noch fündig. Das .NET-Framework bietet zwei verschiedene Methoden zur Transformation.<br />
<a href="http://msdn.microsoft.com/de-de/library/system.xml.xsl.xsltransform.aspx">XslTransform</a> und <a href="http://msdn.microsoft.com/de-de/library/system.xml.xsl.xslcompiledtransform.aspx">XslCompiledTransform</a>. Der Kommentar in der MSDN sagt eigentlich alles:</p>
<blockquote><p>Die XslCompiledTransform-Klasse ist ein XSLT-Prozessor, der die XSLT 1.0 Syntax unterstützt. Dies ist eine neue Implementierung, die im Vergleich zur veralteten XslTransform-Klasse die Leistung verbessert. Die Struktur der XslCompiledTransform-Klasse ist der XslTransform-Klasse sehr ähnlich.</p></blockquote>
<p>Nebenbei werden auch noch das ShortEndTag unterstützt, womit mein Problem gelöst wäre. Der Vollständigkeit halber sollte noch auf diesen Blogeintrag hingewiesen werden: <a href="http://blogs.msdn.com/b/antosha/archive/2006/07/16/xslcompiledtransform-slower-than-xsltransform.aspx">XslCompiledTransform Slower than XslTransform?</a>, denn auch noch die veraltete XslTransform-Klasse scheint noch ihre Daseinsberechtigung zu haben.</p>
<div class="bottomcontainerBox" style="background-color:#F0F4F9;">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.welt-held.de%2F1960-xslt-transformation-in-c.html&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://www.welt-held.de/1960-xslt-transformation-in-c.html"></g:plusone>
			</div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.welt-held.de/1960-xslt-transformation-in-c.html"  data-text="XSLT Transformation in C#" data-count="horizontal" data-via="trashar">Tweet</a>
			</div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div> <p><a href="http://welt-held.de/?flattrss_redirect&amp;id=1960&amp;md5=cc06b2a782246bed56510c97502e9971" title="Flattr" target="_blank"><img src="http://welt-held.de/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.welt-held.de/1960-xslt-transformation-in-c.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" href="http://welt-held.de/?flattrss_redirect&amp;id=1960&amp;md5=cc06b2a782246bed56510c97502e9971" type="text/html" />
	</item>
		<item>
		<title>Löschen von Nodes in einem XML-Dokument</title>
		<link>http://www.welt-held.de/1951-loschen-von-nodes-in-einem-xml-dokument.html</link>
		<comments>http://www.welt-held.de/1951-loschen-von-nodes-in-einem-xml-dokument.html#comments</comments>
		<pubDate>Mon, 07 Mar 2011 20:43:21 +0000</pubDate>
		<dc:creator>Björn</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[deleteself]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[xmldocument]]></category>
		<category><![CDATA[xpathnavigator]]></category>

		<guid isPermaLink="false">http://www.welt-held.de/?p=1951</guid>
		<description><![CDATA[Ich hatte letztens ein XML-Dokument, welches ich etwas verschlanken wollte. Das Format war in etwa folgendes:
Ich wollte nur die &#8220;node1&#8243; &#8211; Node behalten, sprich alle anderen entfernen. Daher mein erster Ansatz:
Funktioniert und gut.
Nun wollte ich den Ansatz umdrehen, und alle Nodes entfernen, die  [...]]]></description>
			<content:encoded><![CDATA[<p>Ich hatte letztens ein XML-Dokument, welches ich etwas verschlanken wollte. Das Format war in etwa folgendes:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;root&gt;
  &lt;node1&gt;Content&lt;/node1&gt;
  &lt;node2&gt;Content&lt;/node2&gt;
  &lt;node3&gt;Content&lt;/node3&gt;
  &lt;node4&gt;Content&lt;/node4&gt;
&lt;/root&gt;
</pre>
<p>Ich wollte nur die &#8220;node1&#8243; &#8211; Node behalten, sprich alle anderen entfernen. Daher mein erster Ansatz:</p>
<pre class="brush: csharp; title: ; notranslate">
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.LoadXml(&quot;&lt;root&gt;&lt;node1&gt;Content&lt;/node1&gt;&lt;node2&gt;Content&lt;/node2&gt;&lt;node3&gt;Content&lt;/node3&gt;&lt;node4&gt;Content&lt;/node4&gt;&lt;/root&gt;&quot;);
XPathNavigator navigator = xmlDocument.CreateNavigator();

string[] nodesToRemove = new[] {&quot;//node2&quot;, &quot;//node3&quot;, &quot;//node4&quot;};

foreach (var nodeName in nodesToRemove)
{
	XPathNavigator node = navigator.SelectSingleNode(nodeName);
	if (node != null)
	{
		node.DeleteSelf();
	}
}

Console.WriteLine(xmlDocument.OuterXml);</pre>
<p>Funktioniert und gut.</p>
<p>Nun wollte ich den Ansatz umdrehen, und alle Nodes entfernen, die nicht den Namen &#8220;node1&#8243; haben. </p>
<pre class="brush: csharp; title: ; notranslate">XmlDocument xmlDocument = new XmlDocument();
xmlDocument.LoadXml(&quot;&lt;root&gt;&lt;node1&gt;Content&lt;/node1&gt;&lt;node2&gt;Content&lt;/node2&gt;&lt;node3&gt;Content&lt;/node3&gt;&lt;node4&gt;Content&lt;/node4&gt;&lt;/root&gt;&quot;);
XPathNavigator navigator = xmlDocument.CreateNavigator();

string xpath = &quot;/root/node()[name()!='node1']&quot;;

XPathNodeIterator nodes = navigator.Select(xpath);
while(nodes.MoveNext())
{
	if(nodes.Current != null)
	{
		nodes.Current.DeleteSelf();
	}
}

Console.WriteLine(xmlDocument.OuterXml);</pre>
<p>Leider war das Ergebnis nicht so wie erwartet, obwohl der XPath korrekt ist und die anderen Nodes selektiert. Es wurde nur &#8220;node2&#8243; gelöscht, sprich die erste Node, welche mit dem NodeIterator angesprochen wird. Durch das DeleteSelf() liefert MoveNext() automatisch false zurück, wenn es wieder aufgerufen wird. Ähnliche Probleme gibt es etwa auch, wenn in einer foreach()-Schleife der Enumerator geändert wird. Eine mögliche Lösung wäre folgendes:</p>
<pre class="brush: csharp; title: ; notranslate">while(nodes.MoveNext())
{
	if(nodes.Current != null)
	{
		nodes.Current.DeleteSelf();
		nodes = navigator.Select(xpath);
	}
}</pre>
<p>Nach dem Löschen wird der XPath einfach noch mal ausgeführt. Meiner Meinung nach keine wirklich schöne Lösung, leider aber die einzige die ich gefunden habe, welche auch funktioniert.</p>
<div class="bottomcontainerBox" style="background-color:#F0F4F9;">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.welt-held.de%2F1951-loschen-von-nodes-in-einem-xml-dokument.html&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://www.welt-held.de/1951-loschen-von-nodes-in-einem-xml-dokument.html"></g:plusone>
			</div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.welt-held.de/1951-loschen-von-nodes-in-einem-xml-dokument.html"  data-text="Löschen von Nodes in einem XML-Dokument" data-count="horizontal" data-via="trashar">Tweet</a>
			</div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div> <p><a href="http://welt-held.de/?flattrss_redirect&amp;id=1951&amp;md5=3f4299721257612a493b4e792875198d" title="Flattr" target="_blank"><img src="http://welt-held.de/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.welt-held.de/1951-loschen-von-nodes-in-einem-xml-dokument.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<atom:link rel="payment" href="http://welt-held.de/?flattrss_redirect&amp;id=1951&amp;md5=3f4299721257612a493b4e792875198d" type="text/html" />
	</item>
		<item>
		<title>HowTo: C# Programm nur mit NotifyIcon ohne Form starten</title>
		<link>http://www.welt-held.de/1935-howto-c-programm-nur-mit-notifyicon-ohne-form-starten.html</link>
		<comments>http://www.welt-held.de/1935-howto-c-programm-nur-mit-notifyicon-ohne-form-starten.html#comments</comments>
		<pubDate>Sat, 08 Jan 2011 11:32:23 +0000</pubDate>
		<dc:creator>Björn</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[How To]]></category>
		<category><![CDATA[application]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[notifyicon]]></category>
		<category><![CDATA[winforms]]></category>

		<guid isPermaLink="false">http://www.welt-held.de/?p=1935</guid>
		<description><![CDATA[Für den Fall, dass ihr eine Anwendung erstellen wollt, welche (zum Start) nur ein NotifyIcon (also ein Symbol in der Taskleiste besitzt), müsst ihr den Standardprogrammaufruf etwas abändern.
Der standardmäßig erstellte Code von VisualStudio startet automatisch eine Form. Diese könnte man nun  [...]]]></description>
			<content:encoded><![CDATA[<p>Für den Fall, dass ihr eine Anwendung erstellen wollt, welche (zum Start) nur ein NotifyIcon (also ein Symbol in der Taskleiste besitzt), müsst ihr den Standardprogrammaufruf etwas abändern.<br />
Der standardmäßig erstellte Code von VisualStudio startet automatisch eine Form. Diese könnte man nun ausblenden (WindowState = Minimized, ShowInTaskBar = false) aber es geht auch eleganter. Erstellt einfach ein NotifyIcon mit Icon und Visible = true und ruft Application.Run() ohne Parameter auf.</p>
<pre class="brush: csharp; title: ; notranslate">		/// &lt;summary&gt;
		/// 	Der Haupteinstiegspunkt für die Anwendung.
		/// &lt;/summary&gt;
		[STAThread]
		private static void Main()
		{
			Application.EnableVisualStyles();
			Application.SetCompatibleTextRenderingDefault(false);

			_trayIcon = new NotifyIcon {Icon = Icon.FromHandle(new Bitmap(&quot;Gear.png&quot;).GetHicon()), Visible = true};
			_trayIcon.Click += TrayIconClick;

			Application.Run();
			_trayIcon.Dispose();
		}</pre>
<p>Im Anhang findet ihr eine Beispielsolution. Wichtig ist, dass ihr euch selbst ums Dispose() kümmern müsst, damit etwa das NotifyIcon aus der Taskleiste verschwindet, sobald die Applikation beendet wird. Das Beispiel öffnet beim Klick auf das NotifyIcon eine leere Form. Wird diese geschlossen, wird das ganze Programm beendet.</p>
<p>Download: <a href='http://welt-held.de/files/StartWithNotifyIcon.zip'>Beispiel Solution &#8211; Start App With Notify Icon</a></p>
<div class="bottomcontainerBox" style="background-color:#F0F4F9;">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.welt-held.de%2F1935-howto-c-programm-nur-mit-notifyicon-ohne-form-starten.html&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://www.welt-held.de/1935-howto-c-programm-nur-mit-notifyicon-ohne-form-starten.html"></g:plusone>
			</div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.welt-held.de/1935-howto-c-programm-nur-mit-notifyicon-ohne-form-starten.html"  data-text="HowTo: C# Programm nur mit NotifyIcon ohne Form starten" data-count="horizontal" data-via="trashar">Tweet</a>
			</div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div> <p><a href="http://welt-held.de/?flattrss_redirect&amp;id=1935&amp;md5=786e015a4eb30ec008b2a77ab6ccc0c5" title="Flattr" target="_blank"><img src="http://welt-held.de/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.welt-held.de/1935-howto-c-programm-nur-mit-notifyicon-ohne-form-starten.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" href="http://welt-held.de/?flattrss_redirect&amp;id=1935&amp;md5=786e015a4eb30ec008b2a77ab6ccc0c5" type="text/html" />
	</item>
		<item>
		<title>Icons in Visual Studio 2010</title>
		<link>http://www.welt-held.de/1917-icons-in-visual-studio-2010.html</link>
		<comments>http://www.welt-held.de/1917-icons-in-visual-studio-2010.html#comments</comments>
		<pubDate>Tue, 26 Oct 2010 07:32:58 +0000</pubDate>
		<dc:creator>Björn</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[icons]]></category>
		<category><![CDATA[visual studio]]></category>

		<guid isPermaLink="false">http://www.welt-held.de/?p=1917</guid>
		<description><![CDATA[Ich habe immer das Problem, geeignete Icons für meine Applikationen zu finden, meistens wird dann wild bei Google nach etwas passendem und schönen gesucht. 
Dabei bringt Visual Studio 2010 eine Reihe von wunderschönen Icons mit.

			
			
			
			
			
			
			Tweet
						
			]]></description>
			<content:encoded><![CDATA[<p>Ich habe immer das Problem, geeignete Icons für meine Applikationen zu finden, meistens wird dann wild bei Google nach etwas passendem und schönen gesucht. </p>
<p><a href="http://blogs.msdn.com/b/olivers/archive/2010/10/25/visual-studio-2010-anwendungen-entwickeln-mit-schicken-icons.aspx">Dabei bringt Visual Studio 2010 eine Reihe von wunderschönen Icons mit</a>.</p>
<div class="bottomcontainerBox" style="background-color:#F0F4F9;">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.welt-held.de%2F1917-icons-in-visual-studio-2010.html&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://www.welt-held.de/1917-icons-in-visual-studio-2010.html"></g:plusone>
			</div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.welt-held.de/1917-icons-in-visual-studio-2010.html"  data-text="Icons in Visual Studio 2010" data-count="horizontal" data-via="trashar">Tweet</a>
			</div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div> <p><a href="http://welt-held.de/?flattrss_redirect&amp;id=1917&amp;md5=5318977fd5667a17c27cdb22e42bed11" title="Flattr" target="_blank"><img src="http://welt-held.de/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.welt-held.de/1917-icons-in-visual-studio-2010.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" href="http://welt-held.de/?flattrss_redirect&amp;id=1917&amp;md5=5318977fd5667a17c27cdb22e42bed11" type="text/html" />
	</item>
		<item>
		<title>Passwort Karte</title>
		<link>http://www.welt-held.de/1912-passwort-karte.html</link>
		<comments>http://www.welt-held.de/1912-passwort-karte.html#comments</comments>
		<pubDate>Sat, 23 Oct 2010 07:15:45 +0000</pubDate>
		<dc:creator>Björn</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[password card]]></category>

		<guid isPermaLink="false">http://www.welt-held.de/?p=1912</guid>
		<description><![CDATA[Ich habe vor ein paar Tagen beim Hostblogger von der Passwort-Karte gelesen. Ich finde die Idee nicht schlecht, und es ist besser als Passwörter oder PINs versteckt auf kleinen Zettelchen in der Geldbörse zu haben oder in seinem Handy als Notiz.
Jedoch hat der Generator vom Manuel Schmitt einen  [...]]]></description>
			<content:encoded><![CDATA[<p>Ich habe vor ein paar Tagen beim <a href="http://www.hostblogger.de/">Hostblogger</a> von der <a href="http://www.hostblogger.de/blog/archives/4951-Passwort-Karte-5.html">Passwort-Karte</a> gelesen. Ich finde die Idee nicht schlecht, und es ist besser als Passwörter oder PINs versteckt auf kleinen Zettelchen in der Geldbörse zu haben oder in seinem Handy als Notiz.</p>
<p>Jedoch hat der Generator vom Manuel Schmitt einen kleinen Nachteil. Nun gibt es Passwörter / PINs die ich mir nicht merken kann aber auch nicht ändern kann. Sprich ich muss eine Möglichkeit haben, meine vorhandenen Daten in so ein &#8220;Zufallsbild&#8221; hineinzubekommen. Und daran arbeite ich gerade.<br />
Aktuell kann man sich die Passwortkarte schon generieren, eigene Daten kann man aber noch nicht angeben.</p>
<p><a href="http://welt-held.de/files/pc.jpg"><img src="http://welt-held.de/files/pc-150x150.jpg" alt="" title="Password Card Generator" width="150" height="150" class="aligncenter size-thumbnail wp-image-1913" /></a></p>
<p>Wenn der Kram fertig ist, gibs ihn hier zum herunterladen!</p>
<div class="bottomcontainerBox" style="background-color:#F0F4F9;">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.welt-held.de%2F1912-passwort-karte.html&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://www.welt-held.de/1912-passwort-karte.html"></g:plusone>
			</div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.welt-held.de/1912-passwort-karte.html"  data-text="Passwort Karte" data-count="horizontal" data-via="trashar">Tweet</a>
			</div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div> <p><a href="http://welt-held.de/?flattrss_redirect&amp;id=1912&amp;md5=1dc660a4abf8334b2c606cdc4e6586ea" title="Flattr" target="_blank"><img src="http://welt-held.de/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.welt-held.de/1912-passwort-karte.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" href="http://welt-held.de/?flattrss_redirect&amp;id=1912&amp;md5=1dc660a4abf8334b2c606cdc4e6586ea" type="text/html" />
	</item>
		<item>
		<title>Ein Dictionary als DataSource</title>
		<link>http://www.welt-held.de/1858-ein-dictionary-als-datasource.html</link>
		<comments>http://www.welt-held.de/1858-ein-dictionary-als-datasource.html#comments</comments>
		<pubDate>Mon, 23 Aug 2010 21:44:22 +0000</pubDate>
		<dc:creator>Björn</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[bindingsource]]></category>
		<category><![CDATA[combobox]]></category>
		<category><![CDATA[databinding]]></category>
		<category><![CDATA[datasource]]></category>
		<category><![CDATA[dictionary]]></category>

		<guid isPermaLink="false">http://www.welt-held.de/?p=1858</guid>
		<description><![CDATA[Ich habe ein Dictionary nach folgendem Schema:
Die Werte möchte ich in einer ComboBox haben, die Values als anzuzeigenden Text, die Values soll er mir im Code zurückgeben. Ein Dictionary kann man jedoch nicht direkt als DataSource binden. Da die Lösung selbst bei Google etwas versteckt ist, hier  [...]]]></description>
			<content:encoded><![CDATA[<p>Ich habe ein Dictionary nach folgendem Schema:</p>
<pre class="brush: csharp; title: ; notranslate">
var dic = new Dictionary&lt;string, string&gt;()
       	{
	{&quot;de&quot;, &quot;Deutsch&quot;},
	{&quot;en&quot;, &quot;Englisch&quot;}
       	};
</pre>
<p>Die Werte möchte ich in einer ComboBox haben, die Values als anzuzeigenden Text, die Values soll er mir im Code zurückgeben. Ein Dictionary kann man jedoch nicht direkt als DataSource binden. Da die Lösung selbst bei Google etwas versteckt ist, hier die Lösung:</p>
<pre class="brush: csharp; title: ; notranslate">
combobox1.DataSource = new BindingSource(dic, null);
combobox1.DisplayMember = &quot;Value&quot;;
combobox1.ValueMember = &quot;Key&quot;;
</pre>
<p>Und schon werden alle Einträge aus dem Dictionary angezeigt <img src='http://welt-held.de/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>(via <a href="http://madprops.org/blog/bind-a-combobox-to-a-generic-dictionary/">Mad Props</a>)</p>
<div class="bottomcontainerBox" style="background-color:#F0F4F9;">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.welt-held.de%2F1858-ein-dictionary-als-datasource.html&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://www.welt-held.de/1858-ein-dictionary-als-datasource.html"></g:plusone>
			</div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.welt-held.de/1858-ein-dictionary-als-datasource.html"  data-text="Ein Dictionary als DataSource" data-count="horizontal" data-via="trashar">Tweet</a>
			</div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div> <p><a href="http://welt-held.de/?flattrss_redirect&amp;id=1858&amp;md5=8364c30d06be5c1f2b4f0b156b106bd5" title="Flattr" target="_blank"><img src="http://welt-held.de/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.welt-held.de/1858-ein-dictionary-als-datasource.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" href="http://welt-held.de/?flattrss_redirect&amp;id=1858&amp;md5=8364c30d06be5c1f2b4f0b156b106bd5" type="text/html" />
	</item>
		<item>
		<title>Dämlicher Programmierfehler</title>
		<link>http://www.welt-held.de/1756-damlicher-programmierfehler.html</link>
		<comments>http://www.welt-held.de/1756-damlicher-programmierfehler.html#comments</comments>
		<pubDate>Tue, 23 Mar 2010 10:30:37 +0000</pubDate>
		<dc:creator>Björn</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[index]]></category>
		<category><![CDATA[list]]></category>
		<category><![CDATA[out of range]]></category>
		<category><![CDATA[problem]]></category>

		<guid isPermaLink="false">http://www.welt-held.de/?p=1756</guid>
		<description><![CDATA[Grad bestimmt 20 Minuten bei der Fehlersuche drauf gegangen. Folgender Code:
Mein Code war natürlich nicht mit Integerwerten. Ich musste noch ein paar andere Sachen machen, daher war ein RemoveRange() nicht möglich.
Nun wer findet den Fehler?
Ich liste es einfach mal auf:
Beim letzten Durchlauf  [...]]]></description>
			<content:encoded><![CDATA[<p>Grad bestimmt 20 Minuten bei der Fehlersuche drauf gegangen. Folgender Code:</p>
<pre class="brush: csharp; title: ; notranslate">

List&lt;int&gt; _list = new List&lt;int&gt;();
_list.Add(1);
_list.Add(2);
_list.Add(3);
_list.Add(4);

for(int i = 1; i &lt;= 3; i++) {
   int x = _list[i];
   _list.Remove(x);
}
</pre>
<p>Mein Code war natürlich nicht mit Integerwerten. Ich musste noch ein paar andere Sachen machen, daher war ein RemoveRange() nicht möglich.<br />
Nun wer findet den Fehler?</p>
<p>Ich liste es einfach mal auf:</p>
<pre class="brush: plain; title: ; notranslate">
Durchlauf: 1 - Lösche Element 1 - Rest 2
Durchlauf: 2 - Lösche Element 2 - Rest 1
Durchlauf: 3 - Lösche Element 3 - Rest 0
</pre>
<p>Beim letzten Durchlauf wird er immer Probleme kriegen. Das Element gibt es nicht mehr. Durch Remove() rücken die Elemente in der Indizierung nach.<br />
Es müsste also heißen:</p>
<pre class="brush: plain; title: ; notranslate">
Durchlauf: 1 - Lösche Element 1 - Rest 2
Durchlauf: 2 - Lösche Element 1 - Rest 1
Durchlauf: 3 - Lösche Element 1 - Rest 0
</pre>
<p> oder in C#-Code:</p>
<pre class="brush: csharp; title: ; notranslate">for(int i = 1; i &lt;= 3; i++) {
   int x = _list[1];
   _list.Remove(x);
}
</pre>
<p>Vor allem wenn man in den Debugger schaut, kamen da merkwürdige Werte raus. <a href="http://welt-held.de/files/csharpproblem.jpg"><img src="http://welt-held.de/files/csharpproblem-150x150.jpg" alt="" title="C# Problem mit Liste." width="150" height="150" class="alignnone size-thumbnail wp-image-1757" /></a><br />
Ich sehe, dass die Methode &#8220;DeleteEntries()&#8221; mit dem Count-Parameter 2 aufgerufen wird, oben zeigt mir der Debugger aber 1 an. Liegt daran, dass in der Liste bereits ein Element entfernt wurde. Somit ist also, wenn man es genau nimmt, beides richtig.</p>
<div class="bottomcontainerBox" style="background-color:#F0F4F9;">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.welt-held.de%2F1756-damlicher-programmierfehler.html&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://www.welt-held.de/1756-damlicher-programmierfehler.html"></g:plusone>
			</div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.welt-held.de/1756-damlicher-programmierfehler.html"  data-text="Dämlicher Programmierfehler" data-count="horizontal" data-via="trashar">Tweet</a>
			</div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div> <p><a href="http://welt-held.de/?flattrss_redirect&amp;id=1756&amp;md5=4ea2a531bd52f782cc51981bf0c93904" title="Flattr" target="_blank"><img src="http://welt-held.de/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.welt-held.de/1756-damlicher-programmierfehler.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" href="http://welt-held.de/?flattrss_redirect&amp;id=1756&amp;md5=4ea2a531bd52f782cc51981bf0c93904" type="text/html" />
	</item>
		<item>
		<title>C#4.0 &#8211; Problematik bei Default Values</title>
		<link>http://www.welt-held.de/1715-c4-0-problematik-bei-default-values.html</link>
		<comments>http://www.welt-held.de/1715-c4-0-problematik-bei-default-values.html#comments</comments>
		<pubDate>Fri, 12 Mar 2010 17:43:02 +0000</pubDate>
		<dc:creator>Björn</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[How To]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[c#4.0]]></category>
		<category><![CDATA[default values]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[lösung]]></category>
		<category><![CDATA[problem]]></category>

		<guid isPermaLink="false">http://www.welt-held.de/?p=1715</guid>
		<description><![CDATA[Golo Roden erwähnte es bereits in den Kommentaren, daher möchte ich noch mal genauer darauf eingehen.
Dazu erstelle ich eine Solution in Visual Studio 2010 mit einer Konsolenapplikation, welche ich &#8220;DefaultValues&#8221; nenne.
Die alte Schreibweise
Die Schreibweise unter C#3.0 mit Überladung wäre also in  [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.des-eisbaeren-blog.de/">Golo Roden</a> erwähnte es bereits in den <a href="http://www.welt-held.de/1713-c-4-0-default-values-und-delegates.html#comment-19050">Kommentaren</a>, daher möchte ich noch mal genauer darauf eingehen.<br />
Dazu erstelle ich eine Solution in Visual Studio 2010 mit einer Konsolenapplikation, welche ich &#8220;DefaultValues&#8221; nenne.<span id="more-1715"></span></p>
<h3>Die alte Schreibweise</h3>
<p>Die Schreibweise unter C#3.0 mit Überladung wäre also in etwa so:</p>
<pre class="brush: csharp; title: ; notranslate">    public class Program
    {
        static void Main(string[] args)
        {

            AddValues(&quot;Ich bin ein&quot;, &quot;String&quot;);
            Console.WriteLine(_value);

            AddValues(&quot;Ich bin ein&quot;, &quot;String&quot;, true);

            Console.ReadLine();
        }

        public static string _value;

        public static void AddValues(string value1, string value2)
        {
            AddValues(value1, value2, false);
        }
        public static void AddValues(string value1, string value2, bool output)
        {
            _value = string.Format(&quot;{0} {1}&quot;, value1, value2);
            if(output)
            {
                Console.WriteLine(_value);
            }
        }
    }</pre>
<p>Wenn wir nun das Projekt ausführen erhalten wir folgende Ausgabe.</p>
<pre class="brush: plain; title: ; notranslate">Ich bin ein String
Ich bin ein String</pre>
<p>Die erste Ausgabe erfolgt manuell, die zweite direkt in der Methode, wie gewünscht.</p>
<h3>C#4.0 mit Default Values</h3>
<p>Unter C#4.0 mit Default Values kann man die ganze Sache nun vereinfachen:</p>
<pre class="brush: csharp; title: ; notranslate">public static void AddValues(string value1, string value2, bool output = false)
{
    _value = string.Format(&quot;{0} {1}&quot;, value1, value2);
    if(output)
    {
        Console.WriteLine(_value);
    }
}</pre>
<p>Die Ausgabe ist identisch. Die erste Zeile wird manuell ausgegeben, die zweite über den Methodenaufruf. Das macht die Sache einfach, spart Code, macht ihn leserlicher. Man findet sicherlich noch weitere Vorteile.</p>
<h3>Das Problem erkennen</h3>
<p>Kommen wir nun zu den Problemen. Bevor ich die erläutern kann, muss man wissen, wie C# die Default Values behandelt. Wenn man sich die Anwendung per <a href="http://reflector.red-gate.com/Download.aspx">Reflector</a> ansieht, sieht man folgenden Code (in der C#-Ansicht):</p>
<pre class="brush: csharp; title: ; notranslate">
private static void AddValues(string value1, string value2, [Optional, DefaultParameterValue(false)] bool output);
</pre>
<p>Die Zeile spricht für sich. Der Standardwert lautet &#8220;false&#8221;. Nun erstellen wir ein neues Projekt (&#8220;TestApp&#8221;) und referenzieren auf unsere Methode mit dem Default Value:</p>
<pre class="brush: csharp; title: ; notranslate">namespace TestApp
{
    class Program
    {
        static void Main(string[] args)
        {
            DefaultValues.Program.AddValues(&quot;Ich bin ein&quot;, &quot;String&quot;);
            Console.WriteLine(DefaultValues.Program._value);

            Console.ReadLine();
        }
    }
}</pre>
<p>Ausgegben wird eine Zeile, wie erwartet, durch die manuelle Ausgabe. Nun sehen wir uns die zweite Exe-Datei mal im Reflector an:</p>
<pre class="brush: csharp; title: ; notranslate">
Program.AddValues(&quot;Ich bin ein&quot;, &quot;String&quot;, false);
</pre>
<p>Auf einmal sind drei Parameter vorhanden, obwohl wir nur zwei im Sourcecode angegeben haben. Der Compiler setzt automatisch den dritten Parameter mit dem Standardwert, in dem Fall <em>false</em>.<br />
Nun ändern wir die AddValues()-Methode, die Ausgabe soll standardmäßig sofort in der Methode erfolgen, zudem ändern wir den String etwas:</p>
<pre class="brush: csharp; title: ; notranslate">public static void AddValues(string value1, string value2, bool output = true)
{
    _value = string.Format(&quot;Zusammengesetzt: {0} {1}&quot;, value1, value2);
    if (output)
    {
        Console.WriteLine(_value);
    }
}</pre>
<p>Nun kompilier ich <strong>nur</strong> das Projekt &#8220;DefaultValues&#8221; und kopiere die DefaultValues.exe in das Bin-Verzeichnis der TestApp. Wenn ich nun die TestApp.exe starte erhalte ich folgende Ausgabe:</p>
<pre class="brush: plain; title: ; notranslate">Zusammengesetzt: Ich bin ein String</pre>
<p>Allerdings haben wir den Standardwert für die Ausgabe auf true gesetzt, daher müsste die Ausgabe doppelt erscheinen, einmal direkt über den Methodenaufruf und einmal durch die manuelle Ausgabe.</p>
<h3>Problem beheben</h3>
<p>Dieses Problem resultiert daher, dass der Standardwert nicht &#8220;on-the-fly&#8221; aus der DefaultValue.exe geholt wird, sondern vom Compiler in der TestApp.exe gesetzt wurde.<br />
Die Methode aus der DefaultValues.exe wird also immer noch mit &#8220;AddValues(&#8220;Ich bin ein&#8221;, &#8220;String&#8221;, <strong>false</strong>);&#8221; aufgerufen. Und so lange wir das TestApp-Projekt nicht neu kompilieren, wird sich an der Ausgabe nichts ändern. </p>
<h3>Fazit</h3>
<p>Default Values sind eine nette Sache, um sich Überladungen zu sparen, den Code leserlicher zu machen und dem Programmierer das Leben leichter. Aber eigentlich gibt es keine Default Value, der Compiler setzt einfach nur die Werte, die man vorher manuell gesetzt hat. Wenn man diesen Aspekt nicht vergisst, können DefaultValues eine schöne Sache sein, ansonsten sucht man sich wahrscheinlich dumm und dämlich, bis man den Fehler gefunden hat.</p>
<p>Vielen Dank hier noch mal an <a href="http://www.sturmnet.org/blog/">Oliver Sturm</a>, welcher die Problematik auf der Basta kurz aber verständlich erklärt hat.</p>
<p>Beispielsolution: <a href='http://welt-held.de/files/BeispielSolutionDefaultValues.zip'>DefaultValues.zip</a></p>
<div class="bottomcontainerBox" style="background-color:#F0F4F9;">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.welt-held.de%2F1715-c4-0-problematik-bei-default-values.html&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://www.welt-held.de/1715-c4-0-problematik-bei-default-values.html"></g:plusone>
			</div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.welt-held.de/1715-c4-0-problematik-bei-default-values.html"  data-text="C#4.0 &#8211; Problematik bei Default Values" data-count="horizontal" data-via="trashar">Tweet</a>
			</div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div> <p><a href="http://welt-held.de/?flattrss_redirect&amp;id=1715&amp;md5=e4971f6553803c5035b2e9dac05704c5" title="Flattr" target="_blank"><img src="http://welt-held.de/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.welt-held.de/1715-c4-0-problematik-bei-default-values.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<atom:link rel="payment" href="http://welt-held.de/?flattrss_redirect&amp;id=1715&amp;md5=e4971f6553803c5035b2e9dac05704c5" type="text/html" />
	</item>
		<item>
		<title>ShowDialog() verzögert Applikation</title>
		<link>http://www.welt-held.de/1710-showdialog-verzogert-applikation.html</link>
		<comments>http://www.welt-held.de/1710-showdialog-verzogert-applikation.html#comments</comments>
		<pubDate>Wed, 10 Mar 2010 21:38:45 +0000</pubDate>
		<dc:creator>Björn</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[problem]]></category>
		<category><![CDATA[showdialog]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://www.welt-held.de/?p=1710</guid>
		<description><![CDATA[Gestern bin ich mal wieder über das selbe Problem wie damals gestoßen. Ich hab es damals nicht weiter erläutert. Und zwar sollte auf Knopfdruck eine Form erscheinen, welche über den ganzen Bildschirm geht, womit der Benutzer interagieren kann. Im Prinzip bestand die Form nur aus einer PictureBox  [...]]]></description>
			<content:encoded><![CDATA[<p>Gestern bin ich mal wieder über das <a href="http://www.welt-held.de/720-showdialog-umbauen.html">selbe Problem</a> wie damals gestoßen. Ich hab es damals nicht weiter erläutert. Und zwar sollte auf Knopfdruck eine Form erscheinen, welche über den ganzen Bildschirm geht, womit der Benutzer interagieren kann. Im Prinzip bestand die Form nur aus einer PictureBox und er sollte dort einen Bereich auswählen.<br />
Lasse ich mir die Form per Show() anzeigen habe ich keine Probleme, per ShowDialog() hängt er jeweils 4 Sekunden (geschätzt).<br />
Diese 4 Sekunden reichen aber dem normalen Benutzer schon aus, um sich darüber zu beschweren.<br />
Gelöst habe ich es wieder einmal mit einem Show() und einen Closed-Event. Zusammen mit TopMost hatte ich den gewünschten Effekt. Erklären kann ich es mir dennoch und vor allem immer noch nicht.</p>
<p>(Wenn Interesse besteht, lade ich mal eine Beispielsolution hoch).</p>
<div class="bottomcontainerBox" style="background-color:#F0F4F9;">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.welt-held.de%2F1710-showdialog-verzogert-applikation.html&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://www.welt-held.de/1710-showdialog-verzogert-applikation.html"></g:plusone>
			</div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.welt-held.de/1710-showdialog-verzogert-applikation.html"  data-text="ShowDialog() verzögert Applikation" data-count="horizontal" data-via="trashar">Tweet</a>
			</div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div> <p><a href="http://welt-held.de/?flattrss_redirect&amp;id=1710&amp;md5=01c3b3c10f968199bdc7a2589cd778cf" title="Flattr" target="_blank"><img src="http://welt-held.de/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.welt-held.de/1710-showdialog-verzogert-applikation.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" href="http://welt-held.de/?flattrss_redirect&amp;id=1710&amp;md5=01c3b3c10f968199bdc7a2589cd778cf" type="text/html" />
	</item>
		<item>
		<title>File Transfer Planer &#8211; FTP</title>
		<link>http://www.welt-held.de/1698-file-transfer-planer-ftp.html</link>
		<comments>http://www.welt-held.de/1698-file-transfer-planer-ftp.html#comments</comments>
		<pubDate>Fri, 05 Mar 2010 22:09:54 +0000</pubDate>
		<dc:creator>Björn</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[File-Transfer-Planer]]></category>
		<category><![CDATA[Programmierung]]></category>
		<category><![CDATA[ftp]]></category>
		<category><![CDATA[programm]]></category>
		<category><![CDATA[programmieren]]></category>

		<guid isPermaLink="false">http://www.welt-held.de/?p=1698</guid>
		<description><![CDATA[Aktuell arbeite ich an eine kleinen Applikation, welche ich &#8220;File Transfer Planer&#8221; getauft habe. Mit dieser wird es möglich sein, zeitgesteuert Dateien auf einen FTP zu schieben oder eben herunter zu laden.
Das Backend steht zum Teil, einen Teil der GUI ebenfalls, daher mal ein paar Screenshots.
   [...]]]></description>
			<content:encoded><![CDATA[<p>Aktuell arbeite ich an eine kleinen Applikation, welche ich &#8220;File Transfer Planer&#8221; getauft habe. Mit dieser wird es möglich sein, zeitgesteuert Dateien auf einen FTP zu schieben oder eben herunter zu laden.<br />
Das Backend steht zum Teil, einen Teil der GUI ebenfalls, daher mal ein paar Screenshots.</p>
<div style="text-align:center"><a href="http://welt-held.de/files/ftpplaner1.jpg"><img src="http://welt-held.de/files/ftpplaner1-150x150.jpg" alt="" title="File Transfer Planer - Grundeinstellungen" width="150" height="150" class="alignnone size-thumbnail wp-image-1699" /></a> <a href="http://welt-held.de/files/ftpplaner2.jpg"><img src="http://welt-held.de/files/ftpplaner2-150x150.jpg" alt="" title="File Transfer Planer - Task: Zum FTP Verbinden" width="150" height="150" class="alignnone size-thumbnail wp-image-1700" /></a> <a href="http://welt-held.de/files/ftpplaner3.jpg"><img src="http://welt-held.de/files/ftpplaner3-150x150.jpg" alt="" title="File Transfer Planer - Task: Lokales Verzeichnis auswählen" width="150" height="150" class="alignnone size-thumbnail wp-image-1701" /></a></div>
<p>Die GUI ist nicht mehr ganz so aktuell. Aktuell bin ich mir noch nicht so sicher, wie ich die Daten speicher, momentan tendiere ich dazu, die Daten als XML-Datei auf der Platte zu speichern.</p>
<div class="bottomcontainerBox" style="background-color:#F0F4F9;">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.welt-held.de%2F1698-file-transfer-planer-ftp.html&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://www.welt-held.de/1698-file-transfer-planer-ftp.html"></g:plusone>
			</div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.welt-held.de/1698-file-transfer-planer-ftp.html"  data-text="File Transfer Planer &#8211; FTP" data-count="horizontal" data-via="trashar">Tweet</a>
			</div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div> <p><a href="http://welt-held.de/?flattrss_redirect&amp;id=1698&amp;md5=074c321e2fd6f03958c988ca04f12f08" title="Flattr" target="_blank"><img src="http://welt-held.de/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.welt-held.de/1698-file-transfer-planer-ftp.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" href="http://welt-held.de/?flattrss_redirect&amp;id=1698&amp;md5=074c321e2fd6f03958c988ca04f12f08" type="text/html" />
	</item>
		<item>
		<title>C# &#8211; PrintDialog.ShowDialog() funktioniert nicht</title>
		<link>http://www.welt-held.de/1681-c-printdialog-showdialog-funktioniert-nicht.html</link>
		<comments>http://www.welt-held.de/1681-c-printdialog-showdialog-funktioniert-nicht.html#comments</comments>
		<pubDate>Tue, 02 Mar 2010 09:15:39 +0000</pubDate>
		<dc:creator>Björn</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[fehler]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[printdialog]]></category>
		<category><![CDATA[problem]]></category>
		<category><![CDATA[showdialog]]></category>

		<guid isPermaLink="false">http://www.welt-held.de/?p=1681</guid>
		<description><![CDATA[Bin gerade auf ein sehr merkwürdiges Problem gestoßen, dass doch locker eine Stunde wertvolle Lebenszeit gekostet hat.
Folgender Code:
Nichts großes, sollte einfach nur so ein Druckerfenster öffnen, wo der Drucker ausgewählt wird etc. Leider öffnete sich der erhoffte Dialog nicht. Der Debugger  [...]]]></description>
			<content:encoded><![CDATA[<p>Bin gerade auf ein sehr merkwürdiges Problem gestoßen, dass doch locker eine Stunde wertvolle Lebenszeit gekostet hat.<br />
Folgender Code:</p>
<pre class="brush: csharp; title: ; notranslate">
PrintDialog pd = new PrintDialog();
if (pd.ShowDialog() == DialogResult.OK)
{
    // do nothing

}
</pre>
<p>Nichts großes, sollte einfach nur so ein Druckerfenster öffnen, wo der Drucker ausgewählt wird etc. Leider öffnete sich der erhoffte Dialog nicht. Der Debugger läuft dahin, aber er führt den ShowDialog() einfach nicht aus. </p>
<p>Wenn ich die Eigenschaft &#8220;UseEXDialog&#8221; auf &#8220;true&#8221; setze, funktioniert es.<br />
Jedoch wollte ich nicht den XP-Dialog, sondern den anderen. Auch im Netz fand ich keine wirkliche Lösung.<br />
Da diese Codezeilen aus einem bestehenden Projekt stammen, habe ich kurzerhand neue Projekte in den Frameworks 2.0, 3.5 und 4.0 angelegt. Jeweils mit dem Codeschnippsel oben. Und siehe da, es funktioniert problemlos, in jeder Frameworkversion. Nun die Unterschiede gesucht.</p>
<p>Fündig wurde ich den Projekteigenschaften unter &#8220;Build&#8221; bzw. &#8220;Erstellen&#8221;.<br />
Ich muss dazu sagen, dass die Applikation vorher auf einem anderen Rechner mit einem 32-bit Windows entwickelt wurde. So stand hier unter dem Punkt &#8220;Platform target:&#8221; (auf Deutsch vermutlich Zielplattform) &#8220;Any CPU&#8221;.<br />
Stellt die Anwendung hier auf 32-bit (x86) und der PrintDialog() wird hervorragend funktionieren. x64 oder Any CPU funktioniert nicht.<br />
Auf so etwas muss man erstmal kommen, warum das so ist, keine Ahnung. </p>
<p>So habe ich noch mal in der <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.printdialog.aspx">MSDN</a> nachgeschlagen: </p>
<blockquote><p>This class may not work on AMD64 microprocessors unless you set the UseEXDialog property to true.</p></blockquote>
<p>Ich bin zwar nun nicht der technisch versierte Mensch, aber für mich hört sich das nach einem Problem mit einem <strong>AMD</strong> Prozessor an, ich habe jedoch einen Intel (ich lasse es mir aber dennoch gerne erklären).</p>
<div class="bottomcontainerBox" style="background-color:#F0F4F9;">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.welt-held.de%2F1681-c-printdialog-showdialog-funktioniert-nicht.html&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://www.welt-held.de/1681-c-printdialog-showdialog-funktioniert-nicht.html"></g:plusone>
			</div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.welt-held.de/1681-c-printdialog-showdialog-funktioniert-nicht.html"  data-text="C# &#8211; PrintDialog.ShowDialog() funktioniert nicht" data-count="horizontal" data-via="trashar">Tweet</a>
			</div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div> <p><a href="http://welt-held.de/?flattrss_redirect&amp;id=1681&amp;md5=6b3f4f984ca1470338714e2f3cee3714" title="Flattr" target="_blank"><img src="http://welt-held.de/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.welt-held.de/1681-c-printdialog-showdialog-funktioniert-nicht.html/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		<atom:link rel="payment" href="http://welt-held.de/?flattrss_redirect&amp;id=1681&amp;md5=6b3f4f984ca1470338714e2f3cee3714" type="text/html" />
	</item>
		<item>
		<title>Linq und string.Contains() &#8211; Problem</title>
		<link>http://www.welt-held.de/1628-linq-und-string-contains-problem.html</link>
		<comments>http://www.welt-held.de/1628-linq-und-string-contains-problem.html#comments</comments>
		<pubDate>Fri, 29 Jan 2010 11:25:03 +0000</pubDate>
		<dc:creator>Björn</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[contains]]></category>
		<category><![CDATA[linq]]></category>
		<category><![CDATA[lösung]]></category>
		<category><![CDATA[problem]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[workaround]]></category>

		<guid isPermaLink="false">http://www.welt-held.de/?p=1628</guid>
		<description><![CDATA[Ich hatte eine kleine Methode, um mir bestimmte Datensätze aus einer Datenbank zu holen. Dazu nutze ich Linq, da es schön einfach ist.
Über die Variable &#8220;filter&#8221; wollte ich die Daten eingrenzen. Allerdings sollte es auch möglich sein, sich alle Datensätze anzusehen. In der MSDN zu string.Contains()  [...]]]></description>
			<content:encoded><![CDATA[<p>Ich hatte eine kleine Methode, um mir bestimmte Datensätze aus einer Datenbank zu holen. Dazu nutze ich Linq, da es schön einfach ist.</p>
<pre class="brush: csharp; title: ; notranslate">
        public IEnumerable&lt;Data&gt; Search(string filter)
        {
            var dataSet = from data in this.bigDataSet
                          where data.Name.Contains(filter)
                          select data;

            return dataSet;
        }
</pre>
<p>Über die Variable &#8220;filter&#8221; wollte ich die Daten eingrenzen. Allerdings sollte es auch möglich sein, sich alle Datensätze anzusehen. In der MSDN zu <a href="http://msdn.microsoft.com/de-de/library/dy85x1sa(VS.80).aspx">string.Contains()</a> lautet es:</p>
<blockquote><p>
<strong>Rückgabewert</strong><br />
<strong>true</strong>, wenn der value-Parameter in dieser Zeichenfolge vorkommt oder value eine leere Zeichenfolge (&#8220;&#8221;) ist, andernfalls <strong>false</strong>.
</p></blockquote>
<p>Heißt für mich, dass ich &#8220;filter&#8221; leer lassen kann und so alle Datensätze bekomme. Funktionierte aber nicht. Ich vermute mal, es liegt daran, dass ich Linq-to-Ent verwende. Das Workaround funktioniert aber ganz gut:</p>
<pre class="brush: csharp; title: ; notranslate">
        public IEnumerable&lt;Data&gt; Search(string filter)
        {
            var dataSet = from data in this.bigDataSet
                          where (!string.IsNullOrEmpty(filter) ? data.Name.Contains(filter) : true)
                          select data;

            return dataSet;
        }
</pre>
<p>Vielleicht hat ja jemand genauere Informationen, warum der erste Ansatz nicht funktioniert. Auf Anhieb habe ich nichts gefunden.</p>
<div class="bottomcontainerBox" style="background-color:#F0F4F9;">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.welt-held.de%2F1628-linq-und-string-contains-problem.html&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://www.welt-held.de/1628-linq-und-string-contains-problem.html"></g:plusone>
			</div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.welt-held.de/1628-linq-und-string-contains-problem.html"  data-text="Linq und string.Contains() &#8211; Problem" data-count="horizontal" data-via="trashar">Tweet</a>
			</div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div> <p><a href="http://welt-held.de/?flattrss_redirect&amp;id=1628&amp;md5=6c3a1a7f62aa6f1fda9efea11489eb76" title="Flattr" target="_blank"><img src="http://welt-held.de/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.welt-held.de/1628-linq-und-string-contains-problem.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" href="http://welt-held.de/?flattrss_redirect&amp;id=1628&amp;md5=6c3a1a7f62aa6f1fda9efea11489eb76" type="text/html" />
	</item>
		<item>
		<title>HowTo: Aero Glass in C# Forms nutzen</title>
		<link>http://www.welt-held.de/1609-howto-aero-glass-in-c-forms-nutzen.html</link>
		<comments>http://www.welt-held.de/1609-howto-aero-glass-in-c-forms-nutzen.html#comments</comments>
		<pubDate>Wed, 20 Jan 2010 13:31:59 +0000</pubDate>
		<dc:creator>Björn</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[aero glass]]></category>
		<category><![CDATA[programmieren]]></category>
		<category><![CDATA[windows 7]]></category>
		<category><![CDATA[wpf]]></category>

		<guid isPermaLink="false">http://www.welt-held.de/?p=1609</guid>
		<description><![CDATA[Mich hat mal interessiert, wie ich die Aero Glass Effekte unter Windows 7 in C# Windows Forms nutzen kann. Auf codeproject.com fand ich dazu einen Artikel. Der funktioniert soweit auch schon ganz gut. Der Artikel zeigt, wie man einen Rand um seine Arbeitsfläche zieht, der den Aero Glass Effekt  [...]]]></description>
			<content:encoded><![CDATA[<p>Mich hat mal interessiert, wie ich die Aero Glass Effekte unter Windows 7 in C# Windows Forms nutzen kann. Auf codeproject.com fand ich dazu einen <a href="http://www.codeproject.com/KB/vista/AeroGlassForms.aspx">Artikel</a>. Der funktioniert soweit auch schon ganz gut. Der Artikel zeigt, wie man einen Rand um seine Arbeitsfläche zieht, der den Aero Glass Effekt nutzt. Möchte man nun aber den ganzen Hintergrund durchsichtig haben, so müssen die Margins auf -1 gesetzt werden:</p>
<pre class="brush: csharp; title: ; notranslate">
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            if (DwmIsCompositionEnabled())
            {
                // Paint the glass effect.
                this.margins = new MARGINS {Top = -1, Left = -1, Bottom = -1, Right = -1};
                DwmExtendFrameIntoClientArea(this.Handle, ref margins);
            }
        }</pre>
<p>Nun ist der ganze Arbeitsbereich durchsichtig. Doch sobald man GDI+-Controlls verwendet, ergibt sich folgender Grafikfehler:<br />
<a href="http://www.welt-held.de/files/aeroGlassButton.jpg"><img src="http://www.welt-held.de/files/aeroGlassButton.jpg" alt="" title="Aero Glass Grafikfehler bei GDI+-Controlls" width="134" height="55" class="aligncenter size-full wp-image-1610" /></a><br />
Um dies zu umgehen, müsst ihr in der Main()-Methode folgendes einfügen (bzw. anpassen)</p>
<pre class="brush: csharp; title: ; notranslate">Application.SetCompatibleTextRenderingDefault(true);</pre>
<p>Das Ergebnis sieht schon besser aus, leider immer noch nicht so wie gewünscht.<br />
<a href="http://www.welt-held.de/files/aeroGlassButton1.jpg"><img src="http://www.welt-held.de/files/aeroGlassButton1.jpg" alt="" title="Aero Glass Button" width="130" height="56" class="aligncenter size-full wp-image-1611" /></a><br />
Leider liegt das aber am System bzw. den Controls im .NET-Framework. Unter WPF gibt es dieses Problem zum Beispiel nicht.<br />
Wie ihr die Aero Glass Effekte in WPF nutzen könnt, findet ihr etwa bei <a href="http://code-inside.de/blog/2008/01/17/howto-wpf-windows-mit-dem-vista-glass-effekt-ausstatten/">Robert Mühsig</a>.</p>
<p>Ach ja, falls ihr nun Bereiche haben wollt, die nicht durchsichtig sind, könnt ihr zum Beispiel ein Panel nutzen. Das Ergebnis sieht in etwa so aus:<a href="http://www.welt-held.de/files/aeroGlassForm.jpg"><img src="http://www.welt-held.de/files/aeroGlassForm-150x150.jpg" alt="" title="Aero Glass Effekt - die fertige Form mit Button und Panel" width="150" height="150" class="aligncenter size-thumbnail wp-image-1612" /></a></p>
<div class="bottomcontainerBox" style="background-color:#F0F4F9;">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.welt-held.de%2F1609-howto-aero-glass-in-c-forms-nutzen.html&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://www.welt-held.de/1609-howto-aero-glass-in-c-forms-nutzen.html"></g:plusone>
			</div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.welt-held.de/1609-howto-aero-glass-in-c-forms-nutzen.html"  data-text="HowTo: Aero Glass in C# Forms nutzen" data-count="horizontal" data-via="trashar">Tweet</a>
			</div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div> <p><a href="http://welt-held.de/?flattrss_redirect&amp;id=1609&amp;md5=7c05035d4567130ad01fb27dd7dca86d" title="Flattr" target="_blank"><img src="http://welt-held.de/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.welt-held.de/1609-howto-aero-glass-in-c-forms-nutzen.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<atom:link rel="payment" href="http://welt-held.de/?flattrss_redirect&amp;id=1609&amp;md5=7c05035d4567130ad01fb27dd7dca86d" type="text/html" />
	</item>
		<item>
		<title>HowTo: Bilder mit CKEditor und ASP.NET MVC hochladen</title>
		<link>http://www.welt-held.de/1588-howto-bilder-mit-ckeditor-und-asp-net-mvc-hochladen.html</link>
		<comments>http://www.welt-held.de/1588-howto-bilder-mit-ckeditor-und-asp-net-mvc-hochladen.html#comments</comments>
		<pubDate>Thu, 14 Jan 2010 13:40:29 +0000</pubDate>
		<dc:creator>Björn</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[ckeditor]]></category>
		<category><![CDATA[controller]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[mvc]]></category>
		<category><![CDATA[upload]]></category>
		<category><![CDATA[wysiwyg]]></category>

		<guid isPermaLink="false">http://www.welt-held.de/?p=1588</guid>
		<description><![CDATA[Ich hatte gerade das Problem, dass ich mit dem WYSIWYG-Editor CKEditor Bilder hoch laden möchte, um sie direkt in meinen Text einzupflegen.
Dazu wird irgendwo im View der Editor definiert:
Wichtig ist hier der Parameter &#8220;filebrowserUploadUrl&#8221;. Dies ist der Pfad, wohin das Bild beim Upload gesendet  [...]]]></description>
			<content:encoded><![CDATA[<p>Ich hatte gerade das Problem, dass ich mit dem WYSIWYG-Editor <a href="http://ckeditor.com/">CKEditor</a> Bilder hoch laden möchte, um sie direkt in meinen Text einzupflegen.<br />
Dazu wird irgendwo im View der Editor definiert:</p>
<pre class="brush: jscript; title: ; notranslate">
  &lt;script type=&quot;text/javascript&quot;&gt;
      window.onload = function() {
          CKEDITOR.replace('ckEditor', {
            skin: 'office2003',
            filebrowserUploadUrl: '&lt;%=Url.Action(&quot;UploadImage&quot;) %&gt;'
      });
  };

&lt;/script&gt;</pre>
<p>Wichtig ist hier der Parameter &#8220;filebrowserUploadUrl&#8221;. Dies ist der Pfad, wohin das Bild beim Upload gesendet wird.<br />
Im Controller wird das ganze nun verarbeitet:</p>
<pre class="brush: csharp; title: ; notranslate">
        [AcceptVerbs(HttpVerbs.Post)]
        public string UploadImage()
        {
            // Datei speichern
            var identifier = Guid.NewGuid();
            string[] fileExt = Request.Files[0].FileName.Split('.');
            string safeFile = identifier + &quot;.&quot; + fileExt[fileExt.Length - 1];
            Request.Files[0].SaveAs(Path.Combine(HostingEnvironment.MapPath(&quot;~/UploadedImages/&quot;), safeFile));

            // Daten an CKEditor zurück geben
            string result = &quot;&lt;script type=\&quot;text/javascript\&quot;&gt;&quot;;
            result += &quot;window.parent.CKEDITOR.tools.callFunction(&quot; + Request.QueryString[&quot;CKEditorFuncNum&quot;] + &quot;, \&quot;&quot; +
                      Path.Combine(Url.Content(&quot;~/UploadedImages/&quot;), safeFile) + &quot;\&quot;,\&quot;\&quot;);&lt;/script&gt;&quot;;
            return result;
        }
</pre>
<p>Erst speicher ich das Bild irgendwo und gebe dann den Pfad per Javascript zurück. Da ich nur das JS ausführen lassen muss, gebe ich kein komplettes View zurück. Die Url wird dann korrekt an CKEditor übergeben (siehe Screenshots). Der letzte Parameter des callFunction()-Aufrufes kann für Fehlermeldungen genutzt werden, Bild zu groß o.ä.<br />
Mich hat dieser kleine Aufruf bestimmt eine Stunde gekostet!</p>
<div style="text-align:center">
<a href="http://www.welt-held.de/files/ckeditor1.jpg"><img src="http://www.welt-held.de/files/ckeditor1-150x150.jpg" alt="CKEditor - Datei auswählen, Hochladen" title="CKEditor - Datei auswählen, Hochladen" width="150" height="150" class="alignnone size-thumbnail wp-image-1589" /></a> <a href="http://www.welt-held.de/files/ckeditor2.jpg"><img src="http://www.welt-held.de/files/ckeditor2-150x150.jpg" alt="CKEditor - Datei hochgeladen und Pfad übergeben" title="CKEditor - Datei hochgeladen und Pfad übergeben" width="150" height="150" class="alignnone size-thumbnail wp-image-1590" /></a></div>
<div class="bottomcontainerBox" style="background-color:#F0F4F9;">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.welt-held.de%2F1588-howto-bilder-mit-ckeditor-und-asp-net-mvc-hochladen.html&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://www.welt-held.de/1588-howto-bilder-mit-ckeditor-und-asp-net-mvc-hochladen.html"></g:plusone>
			</div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.welt-held.de/1588-howto-bilder-mit-ckeditor-und-asp-net-mvc-hochladen.html"  data-text="HowTo: Bilder mit CKEditor und ASP.NET MVC hochladen" data-count="horizontal" data-via="trashar">Tweet</a>
			</div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div> <p><a href="http://welt-held.de/?flattrss_redirect&amp;id=1588&amp;md5=053010f84484c5783086c075b50b758d" title="Flattr" target="_blank"><img src="http://welt-held.de/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.welt-held.de/1588-howto-bilder-mit-ckeditor-und-asp-net-mvc-hochladen.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" href="http://welt-held.de/?flattrss_redirect&amp;id=1588&amp;md5=053010f84484c5783086c075b50b758d" type="text/html" />
	</item>
		<item>
		<title>Linq: Group By mit mehren Werten</title>
		<link>http://www.welt-held.de/1561-linq-group-by-mit-mehren-werten.html</link>
		<comments>http://www.welt-held.de/1561-linq-group-by-mit-mehren-werten.html#comments</comments>
		<pubDate>Sun, 03 Jan 2010 07:30:27 +0000</pubDate>
		<dc:creator>Björn</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[linq]]></category>
		<category><![CDATA[mvc]]></category>

		<guid isPermaLink="false">http://www.welt-held.de/?p=1561</guid>
		<description><![CDATA[Um bei einer Seite auf alte News zu greifen zu können, wollte ich eine Liste wie hier im Blog anhand &#8220;Monat Jahr&#8221; bekommen. Daher musste ich nach zwei Werten gruppieren, dies geht am einfachsten mit einem anonymen Wertetyp:
Habe mir kurz als Debugmeldung einen String daraus gebastelt:
Als Rückgabe  [...]]]></description>
			<content:encoded><![CDATA[<p>Um bei einer Seite auf alte News zu greifen zu können, wollte ich eine Liste wie hier im Blog anhand &#8220;Monat Jahr&#8221; bekommen. Daher musste ich nach zwei Werten gruppieren, dies geht am einfachsten mit einem anonymen Wertetyp:</p>
<pre class="brush: csharp; title: ; notranslate">
            var dateListe = from dateStamps in this.DataList
                             group dateStamps by
                                 new {dateStamps.PostedTime.Year, dateStamps.PostedTime.Month}
                             into g
                                 select new
                                           {
                                               Year = g.Key.Year,
                                               Month = g.Key.Month,
                                               Count = g.Count()
                                           };
</pre>
<p>Habe mir kurz als Debugmeldung einen String daraus gebastelt:</p>
<pre class="brush: csharp; title: ; notranslate">            foreach (var liste in linkListe)
            {
                ViewData[&quot;test&quot;] += &quot;Datum: &quot; + liste.Month + &quot; &quot; + liste.Year + &quot; Anzah: &quot; + liste.Count + &quot;&lt;br /&gt;&quot;;
            }</pre>
<p>Als Rückgabe erhaltet ihr eine Liste:</p>
<pre class="brush: plain; title: ; toolbar: false; notranslate">
Datum: 1 2006 Anzah: 1
Datum: 3 2006 Anzah: 2
</pre>
<p>Damit kann man Arbeiten <img src='http://welt-held.de/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<div class="bottomcontainerBox" style="background-color:#F0F4F9;">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.welt-held.de%2F1561-linq-group-by-mit-mehren-werten.html&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width=85px; height:21px;" allowTransparency="true"></iframe></div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://www.welt-held.de/1561-linq-group-by-mit-mehren-werten.html"></g:plusone>
			</div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.welt-held.de/1561-linq-group-by-mit-mehren-werten.html"  data-text="Linq: Group By mit mehren Werten" data-count="horizontal" data-via="trashar">Tweet</a>
			</div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div> <p><a href="http://welt-held.de/?flattrss_redirect&amp;id=1561&amp;md5=ce843f65891a6c93993a0e07edd5b755" title="Flattr" target="_blank"><img src="http://welt-held.de/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.welt-held.de/1561-linq-group-by-mit-mehren-werten.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" href="http://welt-held.de/?flattrss_redirect&amp;id=1561&amp;md5=ce843f65891a6c93993a0e07edd5b755" type="text/html" />
	</item>
	</channel>
</rss>

