5.7.10

Replace invalid characters with Regular Expression

The code snippet below replaces all invalid characters for a filename with Regex’ static Replace method;

/// <summary>
/// Replaces invalid path/file characters in given string with an underscore
/// </summary>
/// <param name="getString">string array to get string from CTX-Release</param>
/// <param name="lParamCount">number of parameteres which is set by CTX-Release while calling the function</param>
/// <returns>string with invalid characters replaced with underscore</returns>
public string ReplaceInvalidPathChars(object[] getString, int lParamCount)
{
string retValue = String.Empty;
if (getString.Length > 0)
{
retValue = getString[0].ToString();
char[] invalidChars = System.IO.Path.GetInvalidFileNameChars();
string invalidString = Regex.Escape(new string(invalidChars));
retValue = Regex.Replace(getString[0].ToString(), "[" + invalidString + "]", "_");
retValue = retValue.Replace(" ", "_");
}
return retValue;
}





(Source: C# in a Nutshell by Albahari)

29.6.10

XML Serialization objects generically

Below is an example to serialize and deserialize an object using generics in C#:

using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Xml;
using System.Xml.Serialization;

public class MyClass
{
public static void RunSnippet()
{
string test = "abc";
int number = 123;
WL(XMLSerializationUtility.SerializeObject(Encoding.UTF8, test));
WL(XMLSerializationUtility.SerializeObject(Encoding.UTF8, abc));

}

#region Helper methods

public static void Main()
{
try
{
RunSnippet();
}
catch (Exception e)
{
string error = string.Format("---\nThe following error occurred while executing the snippet:\n{0}\n---", e.ToString());
Console.WriteLine(error);
}
finally
{
Console.Write("Press any key to continue...");
Console.ReadKey();
}
}

private static void WL(object text, params object[] args)
{
Console.WriteLine(text.ToString(), args);
}

private static void RL()
{
Console.ReadLine();
}

private static void Break()
{
System.Diagnostics.Debugger.Break();
}

#endregion
}



public class XMLSerializationUtility
{
public static T DeserializeObject<T>( Encoding encoding, string xml )
{
try
{
using (MemoryStream memoryStream = new MemoryStream( StringToByteArray( encoding, xml ) ) )
{
using ( XmlTextWriter xmlTextWriter = new XmlTextWriter( memoryStream, encoding ) )
{
XmlSerializer xmlSerializer = new XmlSerializer( typeof( T ) );

return (T)xmlSerializer.Deserialize( memoryStream );
}
}
}
catch
{
return default( T );
}
}

public static string SerializeObject<T>( Encoding encoding, T obj )
{
try
{
using(MemoryStream memoryStream = new MemoryStream())
{
using ( XmlTextWriter xmlTextWriter = new XmlTextWriter( memoryStream, encoding ) )
{
XmlSerializer xmlSerializer = new XmlSerializer( typeof( T ) );
xmlSerializer.Serialize( xmlTextWriter, obj );

memoryStream = (MemoryStream)xmlTextWriter.BaseStream;
}

return ByteArrayToString( encoding, memoryStream.ToArray() );
}
}
catch
{
return string.Empty;
}
}

private static Byte[] StringToByteArray( Encoding encoding, string xml )
{
return encoding.GetBytes( xml );
}

private static string ByteArrayToString( Encoding encoding, byte[] byteArray )
{
return encoding.GetString( byteArray );
}
}






Source: http://www.dotnet-snippets.de/dns/objekt-serialisierung-SID1407.aspx

25.6.10

Early warning signs that an SW-Architecture is in trouble

  • The architecture is forced to match the current organization.
  • Top-level architecture components number more than 25.
  • One requirement drives the rest of the design.
  • The architecture depends upon alternatives in the system software.
  • Proprietary components are being used when standard components would do.
  • The component definition comes from the hardware division.
  • There is redundancy not needed for reliability (or load balancing).
  • The design is exception driven (emphasis on the extensibility, not on core commonalities).
  • The architect or project manager has difficulty identifying the stakeholders.
  • The project team has difficulty identifying the architect(s) of the system.
  • Developers have a plethora of choices in how they design and code.
  • The architect, when asked for architecture documentation, produces class diagrams and nothing else.
  • The architect, when asked for architecture documentation, provides a large stack of automatically generated documents which no humans has ever seen.
  • Documents provided are old and apparently not kept up to date.
  • A developer, when asked to describe the architecture, is either unable to or describes a much different architecture than the architect presented.

14.6.10

Checklist: questions the architect should plan to answer

  1. What are the driving architectural constraints, and where are they documented? Are they requirements or goals? Are they measurably quantitative or qualitative? In particular, what are the system's real-time constraints?
  2. What component types are defined? For each, what are its:
    • Responsibilities
    • Methods, data members
    • Limitations
    • Composition rules
    • Other characteristics
  3. What component instances are defined by the architecture?
  4. How do components communicate and synchronize? In particular:
    • Mechanisms used
    • Restrictions on use
  5. What are the system partitions?
    • Composition
    • Restrictions on use and visibility
    • Functional allocations
  6. What are the styles or architectural approaches used?
  7. What constitutes the system infrastructure?
    • Supplied functionality
    • Resource management
    • APIs
    • Restrictions
  8. What are the system interfaces? (this includes HMI, devices, external systems)
    • Participants
    • Mechanisms, formats, protocols, modes
    • Identification/typing/versioning What are the strategies and tools used for persistent storage?
  9. What are the strategies and tools for enforcing security requirements ?
    • Trust boundaries
    • Threat model
  10. What are the strategies and tools for handlings faults and failures ?
  11. What is the process/thread model of the architecture?
  12. What is the deployment model of the system?
    • Server and datastore partitioning/instances
    • Topology
    • Capacity and sizing
  13. What are the system states and modes?
    • Control
    • Responsibilities
    • State knowledge dispersal
  14. What COTS (Commercial off-the-shelf) are used? How are they chosen and integrated?
  15. What variability (in terms of implementation changes and not data or scenario changes) mechanisms and variation points are included in the architecture ?
  16. How far along is the development? Were the block delivery dates met? Did the blocks meet their functionality requirements?
  17. What documentation tree and human help do new employees get?
  18. What is the skill level and experience of the development team members?

11.6.10

3 arten der Serialisierung bzw Deserialisierung in C#

Man versteht darunter eine Abbildung von Objekten auf eine externe sequenzielle Darstellungsform. Serialisierung kann für das Erreichen von Persistenz für ein Objekt verwendet werden, aber auch in verteilten Softwaresystemen spielt Serialisierung eine bedeutende Rolle.[Quelle Wikipedia: http://de.wikipedia.org/wiki/Serialisierung]

Es gibt unter C# 3 Arten der Serialisierung:
* BinaryFormatter (Objekte werden binär abgespeichert)
* SoapFormatter (Objekte können gelesen werden)
* XMLSerializer (Objekte werden in eine XML Datei gespeichert)

using System;
using System.Collections.Generic;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Serialization.Formatters.Soap;
using System.Xml.Serialization;
using System.IO;
using System.Collections;


namespace SerializationSample
{
public class Tester
{

private readonly string serFolder;
private static ArrayList arrList = new ArrayList();

public Tester()
{
serFolder = Path.GetTempPath();
}

public static void Main()
{
Tester abc = new Tester();
arrList.Add((Person) abc.AddPerson("Hans", "Müller", "CH", 39));
arrList.Add((Person) abc.AddPerson("Luft", "Hansa", "D", 82));
arrList.Add((Person) abc.AddPerson("Soto", "Mayer", "ZSQ", 55));

abc.serializeXml();
abc.serializeSoap();
abc.serializeBinary();
Console.WriteLine("Press enter to begin deserialization...");
Console.ReadLine();
abc.deserializeXml();
abc.deserializeSoap();
abc.deserializeBinary();
Console.WriteLine("Press any key to continue...");
Console.ReadLine();
}

//....(ArrayList füllen .....)
private object AddPerson(string Vorname, string Name, string Land, int Alter)
{
Person p = new Person();
p.Vorname = Vorname;
p.Name = Name;
p.Land = Land;
p.Alter = Alter;
return p;
}

/*****************
* XmlSerializer *
*****************/
private void serializeXml() {
Console.WriteLine("Serializing in XML...\n");
using (FileStream fs = new FileStream(Path.Combine(serFolder, "Personen.xml"), FileMode.Create)) {
XmlSerializer xmlSer = new XmlSerializer(typeof(ArrayList), new Type[] { typeof(Person) });
xmlSer.Serialize(fs, arrList);
}
}

private void deserializeXml() {
try {
using (FileStream fs = new FileStream(Path.Combine(serFolder, "Personen.xml"), FileMode.Open)) {
XmlSerializer xmlSer = new XmlSerializer(typeof(ArrayList), new Type[] { typeof(Person) });
arrList = (ArrayList) xmlSer.Deserialize(fs);
}
Console.WriteLine("Deserializing XML...\n");
foreach (Person p in arrList)
Console.WriteLine(p.ToString());
}
catch (IOException ex) {
Console.WriteLine(ex.Message);
}
}

/******************
* Soap Formatter *
******************/
private void serializeSoap() {
Console.WriteLine("Serializing in SOAP...\n");
using (FileStream fs = new FileStream(Path.Combine(serFolder, "soap.dat"), FileMode.Create)) {
SoapFormatter soaFormatter = new SoapFormatter();
soaFormatter.Serialize(fs, arrList);
}
}

private void deserializeSoap() {
try {
using (FileStream fs = new FileStream(Path.Combine(serFolder, "soap.dat"), FileMode.Open)) {
SoapFormatter soaFormatter = new SoapFormatter();
arrList = (ArrayList)soaFormatter.Deserialize(fs);
}
Console.WriteLine("Deserializing SOAP...\n");
foreach (Person p in arrList)
Console.WriteLine(p.ToString());
}
catch (IOException ex) {
Console.WriteLine(ex.Message);
}
}

/********************
* Binary Formatter *
********************/
private void serializeBinary() {
Console.WriteLine("Serializing in Binary...\n");
using (FileStream fs = new FileStream(Path.Combine(serFolder, "binary.dat"), FileMode.Create)) {
BinaryFormatter binFormatter = new BinaryFormatter();
binFormatter.Serialize(fs, arrList);
}
}

private void deserializeBinary() {
try {
using (FileStream fs = new FileStream(Path.Combine(serFolder, "binary.dat"), FileMode.Open)) {
BinaryFormatter binFormatter = new BinaryFormatter();
arrList = (ArrayList)binFormatter.Deserialize(fs);
}
Console.WriteLine("Deserializing Binary...\n");
foreach (Person p in arrList)
Console.WriteLine(p.ToString());
}
catch (IOException ex) {
Console.WriteLine(ex.Message);
}
}
}

//Die zu serialisierende Klasse
//(Die XML-Attribute werden nur für die Xml-serialisierung gebraucht)
[Serializable()]
public class Person {
[XmlElement("Vorname",DataType="string")]
private string vorname;
[XmlElement("Nachname", DataType = "string")]
private string name;
[XmlElement("Alter", DataType = "int")]
private int alter;
[XmlAttribute("Land", DataType = "string")]
private string land;

public Person() { }

public string Vorname {
get { return vorname; }
set { vorname = value; }
}

public string Name {
get { return name; }
set { name = value; }
}

public int Alter {
get { return alter; }
set { alter = value; }
}

public string Land {
get { return land; }
set { land = value; }
}

public override String ToString() {
return vorname + "\t" + name + "\t" + alter + "\t" + land;
}
}
}





28.5.10

Systemcheck: Die 10 schlimmsten Performance-Bremsen

Bernd Greifeneder, Gründer und Chief Technology Officer von DynaTrace, hat für Computerworld den zehn häufigsten Performance-Bremsen für Entwickler zusammengefasst.

Weiter lesen unten Computerworld Artikel

8.4.10

Die Unfähigkeit,zu entscheiden

Manager müssen harte Entscheidungen treffen. Solche Entscheidungen werden verzögert oder an untere Chargen delegiert, um sich aus der Verantwortung zu stehlen.

Softskills für ProjektManager
Rund 90 Sekunden nach dem Abheben bemerkte ich: Da waren Vögel. Sie verdunkelten die gesamte Windschutzscheibe. Grosse Vögel. Zu nahe, um auszuweichen.» So beschrieb Airbus-Captain Sullenberger dem Nachrichtensender CBS im Februar 2009 den Beginn der wohl dramatischsten fünf Minuten seiner Pilotenlaufbahn. Am Ende dieser Odyssee setzte er das Flugzeug sicher auf dem Hudson River auf und rettete damit 154 Menschen das Leben. Angesichts der Tatsache, dass eine Notlandung auf dem Wasser zu den schwierigsten Manövern überhaupt zählt, kann Sullenbergers Tat sowohl menschlich als auch fachlich nicht hoch genug eingeschätzt werden. Geradezu euphorisch wurde er darum danach von allen Seiten gefeiert. Ein neuer amerikanischer Held war geboren und Präsident Barack Obama lud ihn zu seiner Amtseinführung nach Washington ein. Auf dem Höhepunkt der Finanzkrise, als Unsicherheit vorherrschte, weil viele US-Bürger um ihren Job bangten, zeigte Sully etwas, nach dem sich die Amerikaner, aber auch wir Schweizer sehnen: Die Bereitschaft eines Vorgesetzten, Verantwortung zu übernehmen und in Krisensituationen die richtigen Entscheidungen zu treffen.

Source: http://www.swissitmagazine.ch/services/ict-aus-weiterbildung/articles/257214/

Nvidia's GauGan App

NVIDIA's GauGAN AI Machine Learning Tool creates photorealistic images from Simple Hand Doodling http://nvidia-research-mingyuliu.com/...