Internally there was a race for the best-performing-solution on the following scenario:

A function has a string-parameter containing only digits. The function has to increment the value and return a string having the very same format.
For example: input is ’0100′ the returnvalue is ’0101′

Take this for granted:
- input is always numeric
- the incremented value will never have more chars then the input.

Requirements:
- increment the input-string by one
- padding must be dynamically, depending on the input-value (must also work for ’010′ and ’00100′)

And here is the result, starting with the fastest one:

  • return (int.Parse(input) + 1).ToString().PadLeft(input.Length, ’0′);
  • return (int.Parse(input) + 1).ToString(CultureInfo.InvariantCulture.NumberFormat).PadLeft(input.Length, ’0′);
  • return (Convert.ToInt32(input)+1).ToString(“D” + input.Length);

And the slowest one:

  • return (Convert.ToInt32(input) + 1).ToString(input.Aggregate(“”, (current, t) => current + “0″));

Summary:
- assigning values to variables is slow, so do it all within 1 line.
- using FormatProviders is slow.
- using linq is maximum slow.
- ‘Convert.ToInt32′ checks for NULL, then calls ‘int.Parse’, so better use int.Parse, if you don’t care for null.

Share and Enjoy:
  • Technorati
  • Digg
  • Facebook
  • del.icio.us
  • Live
  • Google Bookmarks
  • DotNetKicks
  • DZone
  • TwitThis
  • Blogosphere News
  • Blogplay
  • LinkedIn
  • MisterWong
  • MisterWong.DE
  • MSN Reporter
  • MyShare
  • RSS
  • StumbleUpon
  • Suggest to Techmeme via Twitter
  • Tumblr
  • Twitter
  • Webnews.de
  • Yahoo! Bookmarks
  • Yigg

Note: this article will mention a free tool “Enar Spy” for Enterprise Architect. Get more information here: https://blog.lieberlieber.com/2011/09/22/enar-spy-update/


  • What are attributes?

In .NET attributes are used to combine code with declarations. e.g. is the class serializable, or is the property readonly.
Get more information here: codeproject

  • My Scenario:

In the internet you can find a couple of blogposts, dealing with setting attributes at runtime . I needed this to build a read-only property Grid, without modifying all the objects, I want to display.

Most information of this article is based on: dotnetfacts

In a short summary: the read-only attributes are set on all public properties except collections.  This is to keep the CollectionEditor button alive, which is disabled when setting readonly= true on collections too.

  • What I did:

You cannot create property-based attributes during runtime, but the readonly attribute exists for each property of your class by default. Even, if you do not add the Line “[ReadOnly(false)]“.
This is, why the following code-snippet works. It sets the readonly-attribute on each public property except collections.
change attributes at runtime

  • My Problem:

When assigning the class to the Property-Grid, all properties are displayed readonly. And next to collections you still have the button to investigate them.
But when opening the CollectionsEditor you might discover the following:

Although class “Connector” contains more properties than just a ToString-Method, it is treated like a string object.
For a tool like “Enar Spy” this is totally worthless, as you cannot investigate any collections.

  • Solution:

By accident, I found an article mentioning my problem in a single sentence:
“Add the readonly-attribute to your class’ properties declaration (= in source code). Because if you don’t, .NET will mix it up and do some crazy stuff.”
(Shame on me, I do not remember, where I found that hint!)

That’s why I ended up adding the line “[ReadOnly(false)]” to each property of each class I use in Enar Spy.

And guess what?
The propertyGrid’s collection editor now works like a charm:

This issue definitely needs some more investigation.

Does anybody have more information about this topic?

I appreciate each comment to this topic!

Share and Enjoy:
  • Technorati
  • Digg
  • Facebook
  • del.icio.us
  • Live
  • Google Bookmarks
  • DotNetKicks
  • DZone
  • TwitThis
  • Blogosphere News
  • Blogplay
  • LinkedIn
  • MisterWong
  • MisterWong.DE
  • MSN Reporter
  • MyShare
  • RSS
  • StumbleUpon
  • Suggest to Techmeme via Twitter
  • Tumblr
  • Twitter
  • Webnews.de
  • Yahoo! Bookmarks
  • Yigg

Im ersten Teil „Business Solutions entwickeln mit OCF“ wurde beschrieben, wie einfach man zu einem fertigen Grundgerüst für eine Business Solution kommt und wie man mit Hilfe des Entity Wizard alle benötigten Klassen für einen neuen Businessobjekttyp bekommt.

Die konkrete Implementierung einer beispielhaften Businesslogik ist das Thema dieses Artikels. Mit OCF lässt sich jede Art von Businesslogik umsetzen, jedoch wird die Umsetzung von Anwendungen für den Verwaltungssektor besonders unterstützt. Im letzten Artikel wurde schon kurz beschrieben, welche Entity Typen der Wizard anbietet. Businessobject, BaseDocument und Businesscase sind Typen, die in eGov-Fachanwendungen sehr häufig vorkommen. Businessobject ist das Basisobjekt eines jeden Geschäftsobjektes, enthält u.a. ein Property Identificationstring zur Darstellung der Aktenzahl bzw. Geschäftszahl. BaseDocument und Businesscase (Geschäftsfall) sind Ableitungen.

Im Beispiel werden 2 Entities erzeugt: File (Akt) und Document. File wird auf Basis des Entity Typs „Archive Object“ erzeugt, Document mit „Base Document“. Document erhält zusätzlich noch einen Foreign Key, der auf „File“ verweist.

clip_image002

clip_image004Damit erhält man alle benötigten Klassen.

Im Design Modus des LinqToSql Mapping Files „Entities.dbml“ fügt man jetzt manuell eine Association zwischen „File“ und „Document“ ein. Damit wird „File“, also der „Akt“, zum Container für Dokumente. Ein typischer Use Case im Verwaltungsbereich.

clip_image006

Als nächstes folgen ein paar notwendige Anpassungen. Der DataContract „File“ muss um ein Property „Documents“ erweitert werden.

image

Die Klasse “FileTranslator”, die das Business Entity „File“ in den DataContract „File“ übersetzt, muss ebenfalls angepasst werden, damit etwa beim Abfragen eines Aktes die verlinkten Dokumente gleich mitgeliefert werden.

image

Damit sind die Vorbereitungen fertig und man kann die Service Methoden implementieren, beispielhaft die Methoden „CreateFile“, „CreateDocument“ und „GetFileByID“.

Dazu öffnet man das Interface „IBusinessService“ im Contracts-Projekt und ergänzt die Methoden.

image

Die Implementierung des ServiceContracts könnte so aussehen:

image

Damit ist die Implementierung der Businesslogik fertig. Nach dem Update der Service Referenz im Client-Projekt, kann man auf die Service Methoden zugreifen und ein kleines Testprogramm schreiben.

image

Damit hat man bereits das Grundgerüst einer „ELAK konformen Fachanwendung“. Eine interessante Erweiterung des Beispiels wäre die Anbindung an den Dms Service Ocf|Dms. Jedes Document Objekt wäre dann mit einem Content verlinkt.

Share and Enjoy:
  • Technorati
  • Digg
  • Facebook
  • del.icio.us
  • Live
  • Google Bookmarks
  • DotNetKicks
  • DZone
  • TwitThis
  • Blogosphere News
  • Blogplay
  • LinkedIn
  • MisterWong
  • MisterWong.DE
  • MSN Reporter
  • MyShare
  • RSS
  • StumbleUpon
  • Suggest to Techmeme via Twitter
  • Tumblr
  • Twitter
  • Webnews.de
  • Yahoo! Bookmarks
  • Yigg

Die LieberLieber Software GmbH liefert mit dem Open Components Framework (OCF) ein Entwicklungswerkzeug zur Generierung von Business Solutions. Die Architektur von OCF ist SOA basiert, also serviceorientiert. Ein vollständiger Datenlayer erleichtert die Umsetzung der gewünschten Businesslogik.

Setup: Nach der Installation stehen das Solution Template “OCF Business Solution” und der Entity Generierungsassistent “OCF Entity Wizard” zur Verfügung.

image 

Aufbau: Eine Business Solution wird nach einem vorgegebenen Pattern gebaut. Sie besteht nach der Generierung über das Template aus drei Projekten. Die Basis der Business Solution bildet ein WCF Service (Businessobjekt Service), der den wesentlichen Teil der Businesslogik enthält. Das Contracts-Projekt enthält die ServiceContracts und DataContracts. Das Client Projekt ist eine WPF Applikation mit einer Service Referenz auf den Businessobjekt Service.

Businesslogik: Für jede Entity werden eine Klasse im LinqToSql Objekt Modell (dbml file), eine DataContract Klasse, ein Repository (Entity factory) und ein Translator (übersetzt Entity in DataContract bzw. vice versa) benötigt. Diese Infrastruktur wird auf Wunsch generiert. Jedes generierte Repository ist von einem Basis Repository abgeleitet (Generic Repository, BusinessObject Repository, …). Das gleiche gilt für die anderen generierten Klassen. Etwa bei Wahl des Templates „Business Object“ wird das neue Repository vom BusinessObject Repository und der DataContract vom Basis DataContract „Business Object“ abgeleitet. Bei der Entity Klasse wird in diesem Fall das Interface IBusinessObject implementiert.

clip_image007

Für die Erzeugung dieser Infrastruktur gibt es den OCF Entity Wizard. Über den Menüeintrag „Create OCF Entity“ im Kontextmenü des Service Projekts startet man den Wizard. Sollen die Entity Klasse als auch die Tabelle in der Datenbank automatisch erzeugt werden, wählt man „Create new entity“. Im nächsten Schirm wählt man den Namen der neuen Entity, den Entity Typ (Objekttyp Template) und optional zusätzliche Felder aus. Es gibt zur Zeit fünf Entity Typen: Base Object, Archive Object, Business Object, Base Document und Business Case.

image

Mit Abschluss des Wizards werden die neuen Klassen erzeugt und man kann loslegen mit der Implementierung der eigenen Businesslogik.

Mehr dazu auf http://www.lieberlieber.com/Ocf.

Share and Enjoy:
  • Technorati
  • Digg
  • Facebook
  • del.icio.us
  • Live
  • Google Bookmarks
  • DotNetKicks
  • DZone
  • TwitThis
  • Blogosphere News
  • Blogplay
  • LinkedIn
  • MisterWong
  • MisterWong.DE
  • MSN Reporter
  • MyShare
  • RSS
  • StumbleUpon
  • Suggest to Techmeme via Twitter
  • Tumblr
  • Twitter
  • Webnews.de
  • Yahoo! Bookmarks
  • Yigg

Scan_Recognize

Ein Medienbruch ist bei einem Arbeitsprozess immer eine Herausforderung. Aus rechtlichen oder technischen Gründen ist eine persönliche Unterschrift manchmal unumgänglich. Das unterschriebene Dokument soll jedoch ohne Aufwand wieder in den elektronischen Arbeitsprozess zurückgeführt werden können.

Ocf|Recognition löst diese Herausforderung mit QrCodes. Auf das gewünschte Dokument wird an einer definierten Position ein QrCode aufgebracht. Dieser QrCode stellt im wesentlichen eine eindeutige ID (Guid) dar. Das Dokument kann dann ausgedruckt und unterschrieben werden. Mit Ocf|Recognition lässt sich das unterschriebene Dokument wieder einscannen, wird über den QrCode imagewiedererkannt und kann dem entsprechend in den elektronischen Arbeitsprozess wieder zurückgeführt werden.

Share and Enjoy:
  • Technorati
  • Digg
  • Facebook
  • del.icio.us
  • Live
  • Google Bookmarks
  • DotNetKicks
  • DZone
  • TwitThis
  • Blogosphere News
  • Blogplay
  • LinkedIn
  • MisterWong
  • MisterWong.DE
  • MSN Reporter
  • MyShare
  • RSS
  • StumbleUpon
  • Suggest to Techmeme via Twitter
  • Tumblr
  • Twitter
  • Webnews.de
  • Yahoo! Bookmarks
  • Yigg
Fulltext Search On XML Files using XDocument
Given the following XML-Document:
<Customers>
<Customer>
 <Name>Jerry</Name>
 <Age>26</26>
 <Addresses>
<Address>
<Street>Main Street</Street>
<Address>
<Addresses>
<Customers>
1) How would you implement a fulltext search to return a List of Customer-Names?
public void StartRead(string searchTerm)
{
XDocument xDocument = XDocument.Parse(GetFile());
//get all retval-nodes (allthough it’s just 1)
var customers = from cmd in xDocument.Descendants(“Customer”)
select cmd;
//loop through retval-nodes (still only 1)
foreach (XElement cust in customers)
{
if (RecursiveParser(cust, searchTerm))
{
this.textBox1.Text += cust.Element(“Name”).Value + @” ### “;
}
else
{
this.textBox1.Text += @”empty ### “;
}
}
}
public bool RecursiveParser(XElement element, string searchTerm)
{
if (element.IsEmpty) return false;
if (element.HasElements)
{
foreach (XElement xElement in element.Elements())
{
if (xElement.Value.ToLower().Contains(searchTerm))
return true;
if (RecursiveParser(xElement, searchTerm))
return true;
}
}
return false;
}
2. How would you implement a fulltext search for addresses only?
Just replace “Customer” by “Address”:
//get all retval-nodes (allthough it’s just 1)
var customers = from cmd in xDocument.Descendants(“Address”)
select cmd;

Given the following XML-Document (it’s the output of a serialized List<Customer>):

<ArrayOfCustomer>
<Customer>
<Name>Jerry</Name>
<Age>26</Age>
<Addresses>
<Address>
<Street>Main Street</Street>
</Address>
</Addresses>
</Customer>
</ArrayOfCustomer>

1) How would you implement a fulltext search to return a List of Customer-Names?

(weiterlesen…)

Share and Enjoy:
  • Technorati
  • Digg
  • Facebook
  • del.icio.us
  • Live
  • Google Bookmarks
  • DotNetKicks
  • DZone
  • TwitThis
  • Blogosphere News
  • Blogplay
  • LinkedIn
  • MisterWong
  • MisterWong.DE
  • MSN Reporter
  • MyShare
  • RSS
  • StumbleUpon
  • Suggest to Techmeme via Twitter
  • Tumblr
  • Twitter
  • Webnews.de
  • Yahoo! Bookmarks
  • Yigg

Maybe I should consider to rethinking my code style guidlines. As I opened my AMUSE project today I got the following message from Visual Studio (9.0).

Never seen it bevor ;)

image

Just checked witch file was responsible for this,… seems like VS doesn’t like the embedded MDG Technology file (XML) of Enterprise Architect.

Share and Enjoy:
  • Technorati
  • Digg
  • Facebook
  • del.icio.us
  • Live
  • Google Bookmarks
  • DotNetKicks
  • DZone
  • TwitThis
  • Blogosphere News
  • Blogplay
  • LinkedIn
  • MisterWong
  • MisterWong.DE
  • MSN Reporter
  • MyShare
  • RSS
  • StumbleUpon
  • Suggest to Techmeme via Twitter
  • Tumblr
  • Twitter
  • Webnews.de
  • Yahoo! Bookmarks
  • Yigg