<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Hex and Bugs and Rock &#38; Roll</title>
	<atom:link href="https://mfpedraza.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>https://mfpedraza.wordpress.com</link>
	<description>The vices of a .Net developer.</description>
	<lastBuildDate>Sun, 11 Sep 2022 20:34:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<site xmlns="com-wordpress:feed-additions:1">8986539</site><cloud domain='mfpedraza.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>https://secure.gravatar.com/blavatar/01715f780d9a590688e8452f5421b9ad8ccf9962b489016d3cbb9235a58a97f0?s=96&#038;d=https%3A%2F%2Fs2.wp.com%2Fi%2Fwebclip.png</url>
		<title>Hex and Bugs and Rock &#038; Roll</title>
		<link>https://mfpedraza.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="https://mfpedraza.wordpress.com/osd.xml" title="Hex and Bugs and Rock &#38; Roll" />
	<atom:link rel='hub' href='https://mfpedraza.wordpress.com/?pushpress=hub'/>
	<item>
		<title>The Great Gig In The Sky&#8211;Windows Phone 7 Launch Event</title>
		<link>https://mfpedraza.wordpress.com/2010/10/01/the-great-gig-in-the-skywindows-phone-7-launch-event/</link>
					<comments>https://mfpedraza.wordpress.com/2010/10/01/the-great-gig-in-the-skywindows-phone-7-launch-event/#respond</comments>
		
		<dc:creator><![CDATA[mfpedraza]]></dc:creator>
		<pubDate>Fri, 01 Oct 2010 21:37:32 +0000</pubDate>
				<category><![CDATA[Uncategorized]]></category>
		<guid isPermaLink="false">http://mfpedraza.wordpress.com/2010/10/01/the-great-gig-in-the-skywindows-phone-7-launch-event/</guid>

					<description><![CDATA[If you are into Microsoft’s reboot of their mobile phone operating system like I am, and you can’t make it to one of the live events, you should sign up for the MSDN Simulcast of a full day of training on WP7 or check out the schedule of live events for one in your area.]]></description>
										<content:encoded><![CDATA[<p>If you are into Microsoft’s reboot of their mobile phone operating system like I am, and you can’t make it to one of the live events, you should sign up for <a href="https://msevents.microsoft.com/CUI/WebCastEventDetails.aspx?EventID=1032458870&amp;EventCategory=2&amp;culture=en-US&amp;CountryCode=US">the MSDN Simulcast of a full day of training on WP7</a> or check out <a href="http://www.msdnevents.com/wp7devlaunch">the schedule of live events</a> for one in your area.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://mfpedraza.wordpress.com/2010/10/01/the-great-gig-in-the-skywindows-phone-7-launch-event/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">42</post-id>
		<media:content url="https://2.gravatar.com/avatar/5bf34dd006e73a00dc7a8892dfb1ef59fb2c87ae4405e89812077404cf60f5b0?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">mfpedraza</media:title>
		</media:content>
	</item>
		<item>
		<title>On the Run &#8211; PropertyTree in Action</title>
		<link>https://mfpedraza.wordpress.com/2009/12/04/on-the-run-propertytree-in-action/</link>
					<comments>https://mfpedraza.wordpress.com/2009/12/04/on-the-run-propertytree-in-action/#comments</comments>
		
		<dc:creator><![CDATA[mfpedraza]]></dc:creator>
		<pubDate>Sat, 05 Dec 2009 00:47:26 +0000</pubDate>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[PropertyTree]]></category>
		<guid isPermaLink="false">http://mfpedraza.wordpress.com/2009/12/04/on-the-run-propertytree-in-action/</guid>

					<description><![CDATA[In the previous post in this series I introduced PropertyTree a dynamic data structure that can be used from .Net and JavaScript. In this entry I will show you examples of using PropertyTree. Working with Nodes In it’s simplest form, you assign values to nodes of the tree (PropertyNodes) by specifying the name of the [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>In the <a href="https://mfpedraza.wordpress.com/2009/09/21/welcome-to-the-machine-introducing-propertytree/" target="_blank">previous post in this series</a> I introduced <strong>PropertyTree</strong> a dynamic data structure that can be used from .Net and JavaScript.</p>
<p>In this entry I will show you examples of using <strong>PropertyTree</strong>.</p>
<h4>Working with Nodes</h4>
<p>In it’s simplest form, you assign values to nodes of the tree (<strong>PropertyNodes</strong>) by specifying the name of the node and assigning an object to the <strong>Value</strong> property.</p>
<p>The following example shows how to create a <strong>PropertyTree</strong>, populate it with values and read back those values:</p>
<p><strong>In C#:</strong></p>
<pre class="brush: csharp; title: ; notranslate">PropertyTree pt = new PropertyTree();

pt.Node(&quot;FirstName&quot;).Value = &quot;Pink&quot;;
pt.Node(&quot;LastName&quot;).Value = &quot;Floyd&quot;;
pt.Node(&quot;Birthdate&quot;).Value = new DateTime(1969, 9, 1);
pt.Node(&quot;Salary&quot;).Value = 100000M;

string firstName = pt.Node(&quot;FirstName&quot;).Value;
string lastName = pt.Node(&quot;LastName&quot;).Value;
DateTime birthdate = pt.Node(&quot;Birthdate&quot;).Value;
decimal salary = pt.Node(&quot;Salary&quot;).Value;</pre>
<p><strong>In VB:</strong></p>
<pre class="brush: vb; title: ; notranslate">Dim pt As New PropertyTree()

pt.Node(&quot;FirstName&quot;).Value = &quot;Pink&quot;
pt.Node(&quot;LastName&quot;).Value = &quot;Floyd&quot;
pt.Node(&quot;Birthdate&quot;).Value = New Date(1969, 9, 1)
pt.Node(&quot;Salary&quot;).Value = 100000D

Dim firstName As String = pt.Node(&quot;FirstName&quot;).Value
Dim lastName As String = pt.Node(&quot;LastName&quot;).Value
Dim birthdate As DateTime = pt.Node(&quot;Birthdate&quot;).Value
Dim salary As Decimal = pt.Node(&quot;Salary&quot;).Value</pre>
<p>In this case the type of the node value is the type of the object assigned. The .Net types that a property node can support are:</p>
<ul>
<li>System.String</li>
<li>System.Char</li>
<li>System.DateTime</li>
<li>System.Boolean</li>
<li>System.Byte</li>
<li>System.Int16</li>
<li>System.Int32</li>
<li>System.Int64</li>
<li>System.Decimal</li>
<li>System.Single</li>
<li>System.Double</li>
<li>System.SByte</li>
<li>System.UInt16</li>
<li>System.UInt32</li>
<li>System.UInt64</li>
<li>System.Xml.XmlDocument</li>
<li>System.Byte[] (Array of Byte)</li>
</ul>
<p>Now for the “tree” part of <strong>PropertyTree</strong>. The <strong>PropertyTree</strong> class inherits from <strong>PropertyNode</strong> and every node has a <strong>Node</strong> default property that is used to access sub-nodes. To add sub-nodes to a node you can do the following:</p>
<p><strong>In C#:</strong></p>
<pre class="brush: csharp; auto-links: true; collapse: false; first-line: 1; gutter: true; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;">// Add values hierarchically
pt.Node("Customer").Node("FirstName").Value = "Sponge Bob";
pt.Node("Customer").Node("LastName").Value = "Square Pants";
pt.Node("Customer").Node("Address").Node("Street").Value = "123 Pineapple Dr";
pt.Node("Customer").Node("Address").Node("City").Value = "Bikini Bottom";
pt.Node("Customer").Node("Address").Node("State").Value = "HI";
pt.Node("Customer").Node("Address").Node("Country").Value = "US";
pt.Node("Customer").Node("Address").Node("ZipCode").Value = 96850;</pre>
<p><strong>In VB:</strong></p>
<pre class="brush: vb; auto-links: true; collapse: false; first-line: 1; gutter: true; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;">' Add values hierarchically
pt.Node("Customer").Node("FirstName").Value = "Sponge Bob"
pt.Node("Customer").Node("LastName").Value = "Square Pants"
pt.Node("Customer").Node("Address").Node("Street").Value = "123 Pineapple Dr"
pt.Node("Customer").Node("Address").Node("City").Value = "Bikini Bottom" pt.Node("Customer").Node("Address").Node("State").Value = "HI"
pt.Node("Customer").Node("Address").Node("Country").Value = "US"
pt.Node("Customer").Node("Address").Node("ZipCode").Value = 96850</pre>
<p>Since the <strong>Node</strong> property is the default property (an <em>indexer</em> in <strong>C#</strong>), you can use the following syntax to simplify the code:</p>
<p><strong>In C#:</strong></p>
<pre class="brush: csharp; auto-links: true; collapse: false; first-line: 1; gutter: true; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;">// Add values hierarchically
pt["Customer"]["FirstName"].Value = "Sponge Bob";
pt["Customer"]["LastName"].Value = "Square Pants";
pt["Customer"]["Address"]["Street"].Value = "123 Pineapple Dr";
pt["Customer"]["Address"]["City"].Value = "Bikini Bottom";
pt["Customer"]["Address"]["State"].Value = "HI";
pt["Customer"]["Address"]["Country"].Value = "US";
pt["Customer"]["Address"]["ZipCode"].Value = 96850;</pre>
<p><strong>In VB:</strong></p>
<pre class="brush: vb; auto-links: true; collapse: false; first-line: 1; gutter: true; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;">' Add values hierarchically
pt("Customer")("FirstName").Value = "Sponge Bob"
pt("Customer")("LastName").Value = "Square Pants"
pt("Customer")("Address")("Street").Value = "123 Pineapple Dr"
pt("Customer")("Address")("City").Value = "Bikini Bottom"
pt("Customer")("Address")("State").Value = "HI"
pt("Customer")("Address")("Country").Value = "US"
pt("Customer")("Address")("ZipCode").Value = 96850</pre>
<p>Also, you can access a node using a “dot” notation in the node <em>name</em> parameter:</p>
<p><strong>In C#:</strong></p>
<pre class="brush: csharp; auto-links: true; collapse: false; first-line: 1; gutter: true; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;">// Doing the same thing using "dot" notation
pt["Customer.FirstName"].Value = "Sponge Bob";
pt["Customer.LastName"].Value = "Square Pants";
pt["Customer.Address.Street"].Value = "123 Pineapple Dr";
pt["Customer.Address.City"].Value = "Bikini Bottom";
pt["Customer.Address.State"].Value = "HI";
pt["Customer.Address.Country"].Value = "US";
pt["Customer.Address.ZipCode"].Value = 96850;</pre>
<p><strong>In VB:</strong></p>
<pre class="brush: vb; auto-links: true; collapse: false; first-line: 1; gutter: true; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;">' Doing the same thing using "dot" notation
pt("Customer.FirstName").Value = "Sponge Bob"
pt("Customer.LastName").Value = "Square Pants"
pt("Customer.Address.Street").Value = "123 Pineapple Dr"
pt("Customer.Address.City").Value = "Bikini Bottom"
pt("Customer.Address.State").Value = "HI"
pt("Customer.Address.Country").Value = "US"
pt("Customer.Address.ZipCode").Value = 96850</pre>
<p>Notice how the parent node doesn’t have to exist in order to assign a value to a child node (that also doesn’t exist), all nodes in the path are created automatically.</p>
<h4>JavaScript</h4>
<p>With the exception of tree, node and type creation, <strong>PropertyTrees</strong> can be used from <strong>JavaScript</strong>. To do so, you create the <strong>PropertyTree</strong> on the server and serialize it to the client. In this next example assume that <em>xml</em> contains a string with the serialized version of the <strong>PropertyTree</strong> from the previous example:</p>
<p><strong>In JavaScript:</strong></p>
<pre class="brush: jscript; title: ; notranslate">var pt = new Properties.PropertyTree(xml)

// Retrieve values

var firstName = pt.node(&quot;Customer&quot;).node(&quot;FirstName&quot;).get_value()
var lastName = pt.node(&quot;Customer&quot;).node(&quot;LastName&quot;).get_value()
var zip = pt.node(&quot;Customer.Address.ZipCode&quot;).get_value()

// Update values
pt.node(&quot;Customer&quot;).node(&quot;LastName&quot;).set_value(&quot;Pink&quot;)
pt.node(&quot;Customer&quot;).node(&quot;LastName&quot;).set_value(&quot;Floyd&quot;)
pt.node(&quot;Customer.Address.Country&quot;).set_value(&quot;UK&quot;)
pt.node(&quot;Customer.Address.ZipCode&quot;).set_value(90210)</pre>
<p>In a future post I’ll go deeper into this topic.</p>
<h4>Creating Nodes</h4>
<p>In the previous examples the property nodes are created implicitly, each node is typed with the value that was assigned to it and it can hold any valid value for that type.</p>
<p>To create nodes and set restrictions on the values that it can hold we create nodes explicitly with the <strong>CreateNode</strong> function:</p>
<p><strong>In C#:</strong></p>
<pre class="brush: csharp; auto-links: true; collapse: false; first-line: 1; gutter: true; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;">PropertyTree pt = new PropertyTree();

pt.CreateNode&lt;String&gt;("FirstName");</pre>
<p><strong>In VB:</strong></p>
<pre class="brush: vb; auto-links: true; collapse: false; first-line: 1; gutter: true; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;">Dim pt As New PropertyTree()

pt.CreateNode(Of String)("FirstName")</pre>
<p><strong>PropertyNode</strong> names are case-sensitive.</p>
<p>The <strong>CreateNode</strong> function returns an object of type <strong>PropertyNodeNew</strong> which has the following methods:</p>
<table border="1" cellspacing="0" cellpadding="2" width="600">
<tbody>
<tr>
<td width="115" valign="top">MinValue(<em>obj</em>)</td>
<td width="485" valign="top">The minimum value accepted by the node.</td>
</tr>
<tr>
<td width="115" valign="top">MaxValue(<em>obj</em>)</td>
<td width="485" valign="top">The maximum value accepted by the node.</td>
</tr>
<tr>
<td width="115" valign="top">MinLength(<em>int</em>)</td>
<td width="485" valign="top">The minimum character length. Applies only to <strong>System.String</strong>.</td>
</tr>
<tr>
<td width="115" valign="top">MaxLength(<em>int</em>)</td>
<td width="485" valign="top">The maximum character length. Applies only to <strong>System.String</strong>.</td>
</tr>
<tr>
<td width="115" valign="top">Mask(<em>string</em>)</td>
<td width="485" valign="top">A Regular Expression to filter text. Applies only to <strong>System.String</strong>.</td>
</tr>
<tr>
<td width="115" valign="top">Format(<em>string</em>)</td>
<td width="485" valign="top">A format string used when outputting the value as a <strong>String</strong>.</td>
</tr>
<tr>
<td width="115" valign="top">Value(<em>string</em>)</td>
<td width="485" valign="top">The initial value of the node.</td>
</tr>
<tr>
<td width="115" valign="top">Attribute(<em>string</em>, <em>string</em>)</td>
<td width="485" valign="top">Adds a user-defined attribute and it’s value to the node.</td>
</tr>
<tr>
<td width="115" valign="top">ReadOnly()</td>
<td width="485" valign="top">Indicates that the property value can only be read.</td>
</tr>
<tr>
<td width="115" valign="top">Required()</td>
<td width="485" valign="top">Indicates that a value must be assigned to the property node.</td>
</tr>
</tbody>
</table>
<p>Each one of these functions returns a <strong>PropertyNodeNew</strong> object which allows for a more fluent interface:</p>
<p><strong>In C#:</strong></p>
<pre class="brush: csharp; auto-links: true; collapse: false; first-line: 1; gutter: true; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;">PropertyTree pt = new PropertyTree();

pt.CreateNode&lt;String&gt;("Name")
    .MaxLength(32)
    .Mask("^[a-zA-Z]{1}[a-zA-Z0-9_]*$")
    .Required();
pt.CreateNode&lt;Decimal&gt;("Salary")
    .MinValue(1)
    .MaxValue(100000)
    .Format("C");

pt["Name"].Value = "GoodName";
pt["Salary"].Value = 25000;

// The next two lines will raise a PropertyValidationException
pt["Name"].Value = "A Bad Name";	// Contains spaces.
pt["Salary"].Value = 250000;	// The new value is out of range.</pre>
<p><strong>In VB:</strong></p>
<pre class="brush: vb; auto-links: true; collapse: false; first-line: 1; gutter: true; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;">Dim pt As New PropertyTree()

pt.CreateNode(Of String)("Name") _
    .MaxLength(32) _
    .Mask("^[a-zA-Z]{1}[a-zA-Z0-9_]*$") _
    .Required()
pt.CreateNode(Of Decimal)("Salary") _
    .MinValue(1) _
    .MaxValue(100000) _
    .Format("C")

pt["Name"].Value = "GoodName"
pt["Salary"].Value = 25000

' The next two lines will raise a PropertyValidationException
pt["Name"].Value = "A Bad Name"     ' Contains spaces.
pt["Salary"].Value = 250000         ' The new value is out of range.</pre>
<p><strong>CreateNode</strong> is not available in <strong>JavaScript</strong> but all restrictions on a node such as validation rules and formatting are implemented.</p>
<h4>Creating Types</h4>
<p>After a while you may find that you are creating many different properties with the same restrictions or validation rules.</p>
<p>You can create <strong>PropertyTypes</strong> that can be used when defining a <strong>PropertyNode</strong> and can even be the basis for other <strong>PropertyTypes</strong> that can define more specific restrictions. To do this you use the <strong>CreateType</strong> method of the <strong>Types</strong> property:</p>
<p><strong>In C#:</strong></p>
<pre class="brush: csharp; auto-links: true; collapse: false; first-line: 1; gutter: true; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;">PropertyTree pt = new PropertyTree();

pt.Types.CreateType&lt;Decimal&gt;("SalaryType")
    .MinValue(1)
    .MaxValue(100000)
    .Format("C");

pt.CreateNode("Salary", "SalaryType");

pt["Salary"].Value = 25000;</pre>
<p><strong>In VB:</strong></p>
<pre class="brush: vb; auto-links: true; collapse: false; first-line: 1; gutter: true; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;">Dim pt As New PropertyTree()

pt.Types.CreateType(Of Decimal)("SalaryType") _
    .MinValue(1) _
    .MaxValue(100000) _
    .Format("C")

pt.CreateNode("Salary", "SalaryType")

pt("Salary").Value = 25000</pre>
<p><strong>PropertyType</strong> names are case-sensitive.</p>
<p>The <strong>CreateType</strong> method returns an object of type <strong>PropertyTypeNew</strong> that can have any of the following methods:</p>
<table border="1" cellspacing="0" cellpadding="2" width="600">
<tbody>
<tr>
<td width="172" valign="top">MinValue(<em>obj</em>)</td>
<td width="428" valign="top">The minimum value accepted by the node.</td>
</tr>
<tr>
<td width="172" valign="top">MaxValue(<em>obj</em>)</td>
<td width="428" valign="top">The maximum value accepted by the node.</td>
</tr>
<tr>
<td width="172" valign="top">MinLength(<em>int</em>)</td>
<td width="428" valign="top">The minimum character length. Applies only to <strong>System.String</strong>.</td>
</tr>
<tr>
<td width="172" valign="top">MaxLength(<em>int</em>)</td>
<td width="428" valign="top">The maximum character length. Applies only to <strong>System.String</strong>.</td>
</tr>
<tr>
<td width="172" valign="top">Mask(<em>string</em>)</td>
<td width="428" valign="top">A Regular Expression to filter text. Applies only to <strong>System.String</strong>.</td>
</tr>
<tr>
<td width="172" valign="top">Format(<em>string</em>)</td>
<td width="428" valign="top">A format string used when outputting the value as a <strong>String</strong>.</td>
</tr>
<tr>
<td width="172" valign="top">AllowedValue(<em>obj</em>,<em>[string]</em>)</td>
<td width="428" valign="top">A value of the defined type that is allowed. Any number of values can be added to form lists of allowed values.An optional <strong>System.String</strong> can be included for each value to be returned when using the <strong>ToString()</strong> method of a <strong>PropertyNode</strong> value.</td>
</tr>
</tbody>
</table>
<p>Type inheritance is also available to create a type based on another type:</p>
<p><strong>In C#:</strong></p>
<pre class="brush: csharp; auto-links: true; collapse: false; first-line: 1; gutter: true; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;">PropertyTree pt = new PropertyTree();

pt.Types.CreateType&lt;Decimal&gt;("SalaryType")
    .MinValue(1)
    .MaxValue(100000)
    .Format("C");
pt.Types.CreateType("ExecutiveSalaryType", "SalaryType")
    .MinValue(50000);

pt.CreateNode("Salary", "ExecutiveSalaryType");

pt["Salary"].Value = 80000;</pre>
<p><strong>In VB:</strong></p>
<pre class="brush: vb; auto-links: true; collapse: false; first-line: 1; gutter: true; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;">Dim pt As New PropertyTree()

pt.Types.CreateType(Of Decimal)("SalaryType") _
    .MinValue(1) _
    .MaxValue(100000) _
    .Format("C")

pt.Types.CreateType("ExecutiveSalaryType", "SalaryType") _
    .MinValue(50000)

pt.CreateNode("Salary", "ExecutiveSalaryType")

pt(Salary).Value = 80000</pre>
<p>When inheriting from a another type, you can only set ranges within the limits of the base type otherwise an Exception will be raised.</p>
<p><strong>CreateType</strong> is not available in <strong>JavaScript</strong> but all restrictions on a type such as validation rules and formatting are implemented.</p>
<h4>What’s Next?</h4>
<p>In future posts I’ll show more examples of how to use validation as well as programmatically navigating the tree along with the full <strong>PropertyTree</strong> API. Also I’ll show how to create a <strong>PropertyTree</strong> using an XML Document syntax and how to use a <strong>PropertyTree</strong> from <strong>JavaScript</strong>.</p>
<p>Although in the near future I may set it up as an open-source project, I would currently like to make the <strong>PropertyTree</strong> library bits available to download and I will as soon as I figure out a good (free) way to do so. If you have any suggestions, please add a comment.</p>
<div id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:5c9b58f0-932b-4d46-b626-ffafb953096d" class="wlWriterSmartContent" style="display:inline;float:none;margin:0;padding:0;">Technorati Tags: <a rel="tag" href="http://technorati.com/tags/PropertyTree">PropertyTree</a>,<a rel="tag" href="http://technorati.com/tags/.Net">.Net</a>,<a rel="tag" href="http://technorati.com/tags/JavaScript">JavaScript</a></div>
<div class="wlWriterHeaderFooter" style="text-align:right;margin:0;padding:4px 0;"><a href="http://digg.com/submit?url=http%3a%2f%2fmfpedraza.wordpress.com%2f2009%2f12%2f04%2fon-the-run-propertytree-in-action%2f&amp;title=On+the+Run+%e2%80%93+PropertyTree+in+Action"><img style="border:0;" title="Digg This" src="https://i0.wp.com/digg.com/img/badges/100x20-digg-button.png" border="0" alt="Digg This" width="100" height="20" /></a></div>
]]></content:encoded>
					
					<wfw:commentRss>https://mfpedraza.wordpress.com/2009/12/04/on-the-run-propertytree-in-action/feed/</wfw:commentRss>
			<slash:comments>5</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">13</post-id>
		<media:content url="https://2.gravatar.com/avatar/5bf34dd006e73a00dc7a8892dfb1ef59fb2c87ae4405e89812077404cf60f5b0?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">mfpedraza</media:title>
		</media:content>

		<media:content url="http://digg.com/img/badges/100x20-digg-button.png" medium="image">
			<media:title type="html">Digg This</media:title>
		</media:content>
	</item>
		<item>
		<title>Us and Them &#8211; Privilege Based versus Role Based Security</title>
		<link>https://mfpedraza.wordpress.com/2009/10/03/us-and-them-privilege-based-versus-role-based-security/</link>
					<comments>https://mfpedraza.wordpress.com/2009/10/03/us-and-them-privilege-based-versus-role-based-security/#respond</comments>
		
		<dc:creator><![CDATA[mfpedraza]]></dc:creator>
		<pubDate>Sun, 04 Oct 2009 06:06:03 +0000</pubDate>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Privilege Based Security]]></category>
		<category><![CDATA[Role Based Security]]></category>
		<guid isPermaLink="false">http://mfpedraza.wordpress.com/2009/10/03/us-and-them-privilege-based-versus-role-based-security/</guid>

					<description><![CDATA[I&#8217;d like to talk about Privilege-based security because I haven&#8217;t found anything on the Web about it and I really think you should consider it if you haven&#8217;t already done so. A bit of history A while back when programmers added security to their applications they would assign rights to access functions of a program [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>I&#8217;d like to talk about Privilege-based security because I haven&#8217;t found anything on the Web about it and I really think you should consider it if you haven&#8217;t already done so.</p>
<h4>A bit of history</h4>
<p>A while back when programmers added security to their applications they would assign rights to access functions of a program directly to individual users defined in some Users table. They would then use code like the following to perform authorization to a given right:</p>
<blockquote>
<p>if (user.CanCreateDocument == true) {&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; // Allow some document creation       <br />}</p>
</blockquote>
<p>Of course this meant that every right had to be assigned or denied individually to each user, this made for an administration nightmare.</p>
<p>With the introduction of <strong>Role based security</strong> a level of indirection was introduced that simplified administration. Rights to functions were granted to Roles and roles were assigned to Users, usually with entries in a security database.</p>
<p>Now when you performed authorization you used code like the following:</p>
<blockquote>
<p>if (user.BelongsToRole(&quot;Administrators&quot;)) {&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; // Allow some code       <br />}</p>
</blockquote>
<p>This simplified administration because now you only needed to assign (or remove) a right to a role in the security database and all members of that role would acquire the right.</p>
<h4>The problem I have with Role based security</h4>
<p>Of course you probably know all this and have used it so you&#8217;re asking &quot;What&#8217;s the problem?&quot;, well recently while working on the security system of a framework on my day job I came across the following problem: users can change their personal passwords on our system and also users who belong to the Administrators role can also change the password of any user. You can see this in this code example:</p>
<blockquote>
<p>if (user == userToUpdate || user.BelongsToRole(&quot;Administrators&quot;)) {&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; // Change the password       <br />}</p>
</blockquote>
<p>Again you&#8217;re asking &quot;So what&#8217;s the problem?&quot;, well the customer later required that a Supervisor be able to change a users password but that supervisor could not be member of the application Administrators role because that would grant Supervisors too many rights. &quot;No problem, just create another role, right?&quot; well you can but this is my problem, the authorization code would have to change like so:</p>
<blockquote>
<p>if (user == userToUpdate || user.BelongsToRole(&quot;Administrators&quot;)&#160; <br />&#160;&#160;&#160; <strong>|| user.BelongsToRole(&quot;Supervisors&quot;))</strong> {&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; // Change the password       <br />}</p>
</blockquote>
<p>In fact any time you need to add a new role for an existing right you have to edit the code to test for the new role and recompile. Now maybe this doesn&#8217;t happen too often but if the code is already in the field you just traded an <u>administration</u> nightmare for a <u>deployment</u> one.</p>
<h4>Why use Privilege based security</h4>
<p>With <strong>Privilege based security</strong> you create a <em>privilege</em> for every function in code that needs authorization and you test for this:</p>
<blockquote>
<p>if (user == userToUpdate || <strong>user.HasPrivilege(&quot;ChangeUserPassword&quot;)</strong> {&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; // Change the password       <br />}</p>
</blockquote>
<p>You then assign privileges to roles and when you need to, you can create new roles and assign <em>existing</em> privileges <u>without</u> needing to recompile.</p>
<p>In fact, you could assign (or deny) certain users privileges beyond those found in the roles that they belong to.</p>
<h4>In the Real world</h4>
<p>When applying this model in our framework, we did find that the more granular the security requirements of an application the more privileges where needed. This added more administrative work if the privileges were assigned individually to roles.</p>
<p>Our solution to this problem was to organize privileges hierarchically and permit the assignment or denial of privileges to be inherited to all sub-privileges of a privilege. For example we created the following privilege tree:</p>
<blockquote>
<p><font>+ Security</font></p>
<p><font>+—+ User</font></p>
<p><font>&#160;&#160;&#160;&#160;&#160; +&#8211;+ Create User</font></p>
<p><font>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; + Delete User</font></p>
<p><font>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; + View User Profile</font></p>
<p><font>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; + Change User Password</font></p>
</blockquote>
<p>If we assign the User privilege to a Role then that role is allowed all privileges underneath (i.e. Create User, Delete User, View User Profile and Change User Password). This is similar to how security works in the NTFS File system.</p>
<h4>In conclusion</h4>
<p>Privilege based security adds a level of flexibility to the already proven Role based security model by creating a single privilege in code for each function in a program that needs to be secured and then assigning that privilege to any roles that require it in a security database. Administrators can then customize and adapt security to real world requirements in the field without recompiling existing code.</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:a44cc382-eeac-464e-9630-5e39ddea70b4" class="wlWriterEditableSmartContent">Technorati Tags: <a href="http://technorati.com/tags/Privilege+Based+Security" rel="tag">Privilege Based Security</a>,<a href="http://technorati.com/tags/Role+Based+Security" rel="tag">Role Based Security</a></div>
]]></content:encoded>
					
					<wfw:commentRss>https://mfpedraza.wordpress.com/2009/10/03/us-and-them-privilege-based-versus-role-based-security/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">12</post-id>
		<media:content url="https://2.gravatar.com/avatar/5bf34dd006e73a00dc7a8892dfb1ef59fb2c87ae4405e89812077404cf60f5b0?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">mfpedraza</media:title>
		</media:content>
	</item>
		<item>
		<title>Welcome to the Machine &#8211; Introducing PropertyTree</title>
		<link>https://mfpedraza.wordpress.com/2009/09/21/welcome-to-the-machine-introducing-propertytree/</link>
					<comments>https://mfpedraza.wordpress.com/2009/09/21/welcome-to-the-machine-introducing-propertytree/#comments</comments>
		
		<dc:creator><![CDATA[mfpedraza]]></dc:creator>
		<pubDate>Mon, 21 Sep 2009 16:17:36 +0000</pubDate>
				<category><![CDATA[PropertyTree]]></category>
		<guid isPermaLink="false">http://mfpedraza.wordpress.com/2009/09/21/welcome-to-the-machine-introducing-propertytree/</guid>

					<description><![CDATA[In this first post I will introduce you to PropertyTree, a data structure that I developed to handle the problem of adding custom fields to a record in a database and that has also proven very useful for client/server communication, validation and filling a whole host of other needs. The Problem It all started when [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>In this first post I will introduce you to <strong>PropertyTree</strong>, a data structure that I developed to handle the problem of adding custom fields to a record in a database and that has also proven very useful for client/server communication, validation and filling a whole host of other needs.</p>
<h4>The Problem</h4>
<p>It all started when I began developing a <strong>Business Process Modeling</strong> framework to replace the old Workflow framework that is the platform for all applications developed by the company I currently (2005-2010) work for.</p>
<p>One of the features of the current framework is the ability to store arbitrary bits of information for a given <strong>Activity Instance</strong> in a <strong>SQL Server</strong> database. To do this, for each Activity Instance record in the <strong>activity_instance</strong> table, one or more data items are stored in a separate <strong>activity_instance_items</strong> table. This proves to be a problem when you need to retrieve the data items because you have to pivot the data to produce a package with all the required data bits.</p>
<p>The other problem is that the data is stored as a string in a <strong>varchar(8000)</strong> so on retrieval the programmer needs to cast the string into the original data type and the only way of knowing the appropriate data type is to inspect the data records directly or treat them all as string, something that happens quite a lot.</p>
<h4>The Solution</h4>
<p>As I designed the new framework, I figured that a better way would be to store all the data items of an Activity Instance directly in its record in an <strong>XML</strong> field. That would keep all data items together with their respective instance in the same table. Also, since we are using XML, now we have the ability to store items hierarchically along with meta-data to describe each item.</p>
<h4>And So PropertyTree Was Born</h4>
<p>A <strong>PropertyTree</strong> allows you to store data items kind of like the old <strong>PropertyBag</strong> of early Visual Basic (pre .Net) or the <a href="http://msdn.microsoft.com/en-us/library/87069683(VS.71).aspx" target="_blank" rel="noopener">Session-State Store</a> in <strong>ASP.Net</strong>.</p>
<p>Data items are stored as a collection of nodes from a root node and each node itself can have a collection of nodes allowing for a tree-like structure to be formed.</p>
<p>Each node has meta-data to indicate, among other things, the data type of its stored data, formatting information and validation rules. You can also add your own meta-data items through custom attributes.</p>
<p>A <strong>PropertyTree</strong> also exposes events for changes in values of properties and attributes as well as when validating value assignments and for handling validation errors.</p>
<h4>Features</h4>
<p>This is a list of features that are exposed by the <strong>PropertyTree</strong>:</p>
<ul>
<li>Hierarchical collection of data items (<strong>PropertyNodes</strong>).</li>
<li><strong>PropertyNodes</strong> contain strongly-typed values.</li>
<li><strong>PropertyNodes</strong> can have meta-data in the form of attributes.</li>
<li>Validation information can be defined for a <strong>PropertyNode</strong> like for example:
<ul>
<li>Minimum value</li>
<li>Maximum value</li>
<li>Minimum and maximum length</li>
<li>A regular expression mask of allowed characters</li>
<li>A list of allowed values</li>
</ul>
</li>
<li>These validation rules can be applied to a single <strong>PropertyNode</strong> or in <strong>Types</strong> that can be reused on any number of nodes.</li>
<li>An output format for a <strong>PropertyNode</strong> can be defined.</li>
<li>Events are raised for:
<ul>
<li>After a change in <strong>PropertyNode</strong> value (<em><strong>PropertyChanged</strong></em> event)</li>
<li>After a change in an attribute of a <strong>PropertyNode</strong> (<strong><em>PropertyAttributeChanged</em></strong> event)</li>
<li>When a non-existing <strong>PropertyNode</strong> is referenced (<strong><em>PropertyNotFound</em></strong> event)</li>
<li>A hook to allow custom validation to be performed (<strong><em>ValidateValue</em></strong> event)</li>
<li>When a value assigned to a <strong>PropertyNode</strong> has caused a validation error (<strong><em>ValidationException</em></strong> event)</li>
</ul>
</li>
<li>A <strong>PropertyTree</strong> can be used on a client of a web app using a <strong>JavaScript</strong> implementation that has also been created.<br />
<h4></h4>
</li>
</ul>
<h4>What’s Next?</h4>
<p>In future posts I’ll dive deeper into each of these features starting with <a href="https://mfpedraza.wordpress.com/2009/12/04/on-the-run-propertytree-in-action/" target="_blank" rel="noopener">how to create an instance of a PropertyTree</a> and add nodes with validation.</p>
<div id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:9dee62a9-0a05-4a95-a64d-1226adb48664" class="wlWriterSmartContent" style="display:inline;float:none;margin:0;padding:0;">Technorati Tags: <a href="http://technorati.com/tags/PropertyTree" rel="tag">PropertyTree</a>,<a href="http://technorati.com/tags/.Net" rel="tag">.Net</a>,<a href="http://technorati.com/tags/data+structures" rel="tag">data structures</a></div>
<div class="wlWriterHeaderFooter" style="text-align:right;margin:0;padding:4px 0;"><a href="http://digg.com/submit?url=http%3a%2f%2fmfpedraza.wordpress.com%2f2009%2f09%2f21%2fwelcome-to-the-machine-introducing-propertytree%2f&amp;title=Welcome+to+the+Machine+-+Introducing+PropertyTree"><img style="border:0;" title="Digg This" src="https://i0.wp.com/digg.com/img/badges/100x20-digg-button.png" alt="Digg This" width="100" height="20" border="0" /></a></div>
]]></content:encoded>
					
					<wfw:commentRss>https://mfpedraza.wordpress.com/2009/09/21/welcome-to-the-machine-introducing-propertytree/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">11</post-id>
		<media:content url="https://2.gravatar.com/avatar/5bf34dd006e73a00dc7a8892dfb1ef59fb2c87ae4405e89812077404cf60f5b0?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">mfpedraza</media:title>
		</media:content>

		<media:content url="http://digg.com/img/badges/100x20-digg-button.png" medium="image">
			<media:title type="html">Digg This</media:title>
		</media:content>
	</item>
		<item>
		<title>Careful with That Axe, Eugene &#8211; Using ToString() with a .Net Decimal Type</title>
		<link>https://mfpedraza.wordpress.com/2009/09/11/careful-with-that-axe-eugene-using-tostring-with-a-net-decimal-type/</link>
					<comments>https://mfpedraza.wordpress.com/2009/09/11/careful-with-that-axe-eugene-using-tostring-with-a-net-decimal-type/#respond</comments>
		
		<dc:creator><![CDATA[mfpedraza]]></dc:creator>
		<pubDate>Fri, 11 Sep 2009 21:53:00 +0000</pubDate>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Programming]]></category>
		<guid isPermaLink="false">http://mfpedraza.wordpress.com/2009/09/11/careful-with-that-axe-eugene-using-tostring-with-a-net-decimal-type/</guid>

					<description><![CDATA[A Problem With Decimals Yesterday I ran into a problem with the ToString() function on a .Net Decimal type. Actually the problem was mine but it revealed something I didn’t know about Decimal types that actually IS in the documentation but no one really reads the documentation, do they? Well they do when they run [&#8230;]]]></description>
										<content:encoded><![CDATA[<h4>A Problem With Decimals</h4>
<p>Yesterday I ran into a problem with the ToString() function on a .Net Decimal type.</p>
<p>Actually the problem was mine but it revealed something I didn’t know about Decimal types that actually <strong>IS</strong> in the documentation but no one really reads the documentation, do they? Well they do when they run into problems.</p>
<p>Try the following in a .Net console application (C# or VB.Net or whatever you prefer):</p>
<pre class="csharpcode">    <span class="kwrd">decimal</span> dec1 = 10.0M;
    <span class="kwrd">decimal</span> dec2 = Decimal.Parse(<span class="str">"10.00"</span>);
    Console.Write(<span class="str">"dec1 == dec2 : "</span>);
    Console.WriteLine(dec1 == dec2);
    Console.Write(<span class="str">"dec1.ToString() == dec2.ToString() : "</span>);
    Console.WriteLine(dec1.ToString() == dec2.ToString());</pre>
<p>The output is the following:</p>
<blockquote><p>dec1 == dec2 : True</p>
<p>dec1.ToString() == dec2.ToString() : False</p></blockquote>
<p>Now, both <em>dec1</em> and <em>dec2</em> contain a decimal <em>10</em> value so mathematically they are equal, but the output of ToString() for each of them is:</p>
<blockquote><p>dec1.ToString() : 10.0</p>
<p>dec2.ToString() : 10.00</p></blockquote>
<p>So you see the strings are not identical.</p>
<h4>The Reason Behind It</h4>
<p>The reason that the two ToString() calls are not equal is because Decimal preserves the position of the decimal point so when we parse the string “10.00” both zeros to the right of the decimal point are kept.</p>
<p>This is all detailed in the <a href="http://msdn.microsoft.com/en-us/library/system.decimal(VS.96).aspx" target="_blank">MSDN documentation on the Decimal structure</a> :</p>
<blockquote><p>The scaling factor also preserves any trailing zeroes in a Decimal number. Trailing zeroes do not affect the value of a Decimal number in arithmetic or comparison operations. However, trailing zeroes can be revealed by the <a href="http://msdn.microsoft.com/en-us/library/system.decimal.tostring(VS.96).aspx">ToString</a> method if an appropriate format string is applied.</p></blockquote>
<p>I stumbled upon this while working on the Serialize/De-serialize functions of <strong>PropertyTree</strong> a data structure that I will post about soon (really).</p>
<div id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:6dc3d68c-91b3-4bde-a915-eefb005831d9" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;">Technorati Tags: <a rel="tag" href="http://technorati.com/tags/.Net">.Net</a>,<a rel="tag" href="http://technorati.com/tags/System.Decimal">System.Decimal</a></div>
]]></content:encoded>
					
					<wfw:commentRss>https://mfpedraza.wordpress.com/2009/09/11/careful-with-that-axe-eugene-using-tostring-with-a-net-decimal-type/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">9</post-id>
		<media:content url="https://2.gravatar.com/avatar/5bf34dd006e73a00dc7a8892dfb1ef59fb2c87ae4405e89812077404cf60f5b0?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">mfpedraza</media:title>
		</media:content>
	</item>
		<item>
		<title>Is There Anybody Out There? &#8211; Welcome to my new blog</title>
		<link>https://mfpedraza.wordpress.com/2009/08/13/welcome/</link>
					<comments>https://mfpedraza.wordpress.com/2009/08/13/welcome/#comments</comments>
		
		<dc:creator><![CDATA[mfpedraza]]></dc:creator>
		<pubDate>Fri, 14 Aug 2009 03:23:18 +0000</pubDate>
				<category><![CDATA[Uncategorized]]></category>
		<guid isPermaLink="false">http://mfpedraza.wordpress.com/2009/08/13/welcome/</guid>

					<description><![CDATA[This is the obligatory 1st entry to my new blog. Like the tag line says, I plan on writing about coding in .Net mostly, some projects that I plan to open source, ideas on designing the (almost) perfect company and of course some off-topic but hopefully not off-color stuff (hopefully). The first subject I plan [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>This is the obligatory 1st entry to my new blog. Like the tag line says, I plan on writing about coding in .Net mostly, some projects that I plan to open source, ideas on designing the (almost) perfect company and of course some off-topic but hopefully not off-color stuff (hopefully).</p>
<p>The first subject I plan on writing about is a data structure I’ve been working on for a while that is a modern kind of “Property Bag”. I’ll introduce it and release the bits for you to play with and most likely add it to <a href="http://www.codeplex.com" target="_blank">Codeplex</a> soon.</p>
<p>Well that’s it for now, I hope this blog has something of value to offer you for the time you spend here.</p>
<p>&#160;</p>
<p>Macario</p>
]]></content:encoded>
					
					<wfw:commentRss>https://mfpedraza.wordpress.com/2009/08/13/welcome/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">5</post-id>
		<media:content url="https://2.gravatar.com/avatar/5bf34dd006e73a00dc7a8892dfb1ef59fb2c87ae4405e89812077404cf60f5b0?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">mfpedraza</media:title>
		</media:content>
	</item>
	</channel>
</rss>
