Up | Example 01 - StructuredPropertyBag | Example 02 - WinForms Controls | Example 3 - Custom User Interface | Example 04 - TCP Socket Communication | Example 05 - Simple Text Print | Example 06 - Modeless .Net Dialog | Example 07 - StopWatch | Example 08 - Product Selection Page | Example 09 - PyScripter - Eclipse Test Program | Example 10 - Access Control with custom .Net Plugin

 

  

 
Example 01 - StructuredPropertyBag

The StructuredPropertyBag is a class used to manage a structured set of properties in sections and sub-sections in memory. The properties have attributes like name, type and value. The sections have only the name attribute. Names of properties (regardless of type) at one section level must be unique. Names of sub-sections at one section level must be unique.

The term property bag is well known in the programming community. The “structured-ness” of the StructuredPropertyBag class comes from the fact that it is a property bag implementation that can contain and manage other property bags.

Five types of Properties are defined (.NET framework types in parentheses):

  • Boolean (System.Boolean)
  • Integer (System.Int32)
  • FloatingPoint (System.Double)
  • Binary (System.Array of System.Byte)
  • Text (System.String)

One important feature of the class is the possibility to extract a section as a StructuredPropertyBag, and also to insert a StructuredPropertyBag as a new section in an existing StructuredPropertyBag.

Another important feature of the class is to export and import content on XML format (SpbXml vocabulary).

Access to properties and sections within a StructuredPropertyBag instance, is by means of “path” and name. Accessing properties or subsections at the top level is by an empty path (“”). Accessing items lower down in the structure is by means of a path composed of section names and a specified path delimiter character.

The following script demonstrates some of the capabilities of the Tordivel.StructuredPropertyBag component. Use the console window to see the generated output. A SpbXml file is also created on the profile path.

Access to properties and sections within a StructuredPropertyBag instance, is by means of “path” and name. Accessing properties or subsections at the top level is by an empty path (“”). Accessing items lower down in the structure is by means of a path composed of section names and a specified path delimiter character.

A corresponding profile Dotnet - StructuredPropertyBag is available on Scorpion Support Web.

Example 1: SPB operations

# Python start script goes here
print 'Central Start'

import CLR
profile = GetValue('System.Profile')

from CLR.System.Reflection import Assembly
Assembly.LoadWithPartialName("StructuredPropertyBag")
from CLR.Tordivel import StructuredPropertyBag

# Create global instance of StructuredPropertyBag
spb = StructuredPropertyBag()
spb.GenerateSpbXmlHeader = 1
spb.GenerateFormattedSpbXml = 1
spb.Name = "Test"
# Add integer property on the top level
spb.AddIntegerProperty("","MyIntegerProperty",123)
# Create a section
spb.AddSection("","MySection")
# Add a text property on the new section
spb.AddTextProperty("MySection","MyTextProperty","This is the text")
# Create another section on "MySection"
spb.AddSection("MySection","AnotherSection")
# Add a boolean property on the other section
spb.AddBooleanProperty("MySection.AnotherSection","MyBooleanProperty",1)

myIntegerValue = spb.IntegerPropertyValue("","MyIntegerProperty")
print 'This is my integer value: ',myIntegerValue

# Output the resulting XML text
print 'SpbXml for this bag'
print spb.SpbXml()
# Save to file
spb.SaveToSpbXmlFile(profile + r'\DotNet\Example.spb')
spb.RemoveAllContent()
print 'SpbXml for empty bag'
print spb.SpbXml()
# Load from fiel
spb.LoadFromSpbXmlFile(profile + r'\DotNet\Example.spb')
print 'SpbXml for reloaded bag'
print spb.SpbXml()
mySpbXml = spb.SpbXml()
# Create another structured property bag with name and formatting property values
anotherSpb = StructuredPropertyBag("AnotherBag",1,0)
print 'SpbXml for another bag'
print anotherSpb.SpbXml()
# Give the bag new content from the SpbXml text
anotherSpb.SetSpbXml(mySpbXml)
print 'SpbXml for bag with new content'
print anotherSpb.SpbXml()

Generated Output to Console

Profile : C:\Program Files\Tordivel AS\Scorpion_4\StructuredPropertyBag\
Central Start
 

SpbXml for this bag
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<SPB name="Test">
  <SPB name="MySection">
     <SPB name="AnotherSection">
        <NTP_BOOL name="MyBooleanProperty" value="true" />
     </SPB>
     <NTP_TXT name="MyTextProperty" value="This is the text" />
  </SPB>
  <NTP_INT name="MyIntegerProperty" value="123" />
</SPB>
 

SpbXml for empty bag
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
  <SPB name="Test">
  </SPB>
 

SpbXml for reloaded bag
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<SPB name="Test">
  <SPB name="MySection">
     <SPB name="AnotherSection">
       <NTP_BOOL name="MyBooleanProperty" value="true" />
     </SPB>
     <NTP_TXT name="MyTextProperty" value="This is the text" />
  </SPB>
  <NTP_INT name="MyIntegerProperty" value="123" />
</SPB>

 

 

Scorpion Vision Version XII : Build 646 - Date: 20170225
Scorpion Vision Software® is a registered trademark of Tordivel AS.
Copyright © 2000 - 2017 Tordivel AS.