Archive for August, 2008

h1

UML crib #2 – UML transformed to C# (1)

August 31, 2008

 

This article should contain, what generates Enterprise Architect, when you created UML design. It demostrates what means relations between classes. Generating of classes you can execute from menu Element->Source code engeneering ->Generate selected files. Another articles from this cathegory you can find here.

Association

image

  public class ClassA {
     public
ClassA(){}
     ~ClassA(){}
     public virtual void Dispose(){}
   }//end ClassA

  public class ClassB {
    
public ClassA m_ClassA;
     public ClassB(){}
     ~ClassB(){}
     public virtual void Dispose(){}
  }//end ClassB

 

 


Aggregation

image

public class ClassC {
   public ClassC(){}
   ~ClassC(){}
  public virtual void Dispose(){}
}//end ClassC

 

public class ClassD {
   public ClassC m_ClassC;
   public ClassD(){}
   ~ClassD(){}
   public virtual void Dispose(){}
}//end ClassD


 

 

Composition

image

public class ClassD
{
  
public ClassC m_ClassC;
   public ClassD(){}
   ~ClassD(){}
   public virtual void Dispose(){}
}//end ClassD


 

public class ClassE
{
   public ClassE(){}
   ~ClassE(){}
  public virtual void Dispose(){}
}//end ClassE

 


Nested class

image

  public class ClassG
      public class ClassH {
       
public ClassH(){}
       
~ClassH(){}
      
public virtual void Dispose(){}
     
}//end ClassH

  public ClassG(){}
  ~ClassG(){}
  public virtual void Dispose(){}
}//end ClassG

 

 

 

Generalization

Inheriting classes.ClassK iherits from ClassJ.

image

public class ClassJ {
  public ClassJ(){}
  ~ClassJ(){}
  public virtual void Dispose(){}
}//end ClassJ

 

public class ClassK : ClassJ {
  public ClassK(){}
  ~ClassK(){}
  public override void Dispose(){}
}//end ClassK

 

 

Realize

image

public class ClassM {
 
public ClassM(){}
  ~ClassM(){}
  public virtual void Dispose(){}
}//end ClassM

 

public class ClassN : ClassM {
   public ClassN(){}
   ~ClassN(){}
   public virtual void Dispose(){}
}//end ClassN

 

 

 

Dependency

image

public class ClassO {
  
public ClassO(){}
   ~ClassO(){}
   public virtual void Dispose(){}
}//end ClassO

 

public class ClassP {
   public ClassP(){}
   ~ClassP(){}
   public virtual void Dispose(){}
}//end ClassP

 

 


Derive

Implementing of interface

image

public interface Interface1 {
}//end Interface1

public class ClassN {
   public ClassN(){}
   ~ClassN(){}
   public virtual void Dispose(){}
}//end ClassN

 

 

 

 

 

Abstract class

image

public abstract class AbstractClassR {
  
public AbstractClassR(){}
   ~AbstractClassR(){}
  public virtual void Dispose(){}
}//end AbstractClassR


 

 

Singleton

image

/// <summary>
///
This class (a) defines an Instance operation that lets clients access its
///
unique instance, and (b) may be responsible for creating its own unique
///
instance.
///
</summary>
public class Singleton {
  private int singletonData;
  private static int uniqueInstance;
  public Singleton(){}
  ~Singleton(){}
  public virtual void Dispose(){}
  public void GetSingletonData(){}
  public static void Instance(){
  //return uniqueInstance
  }
  public void SingletonOperation(){}
}//end Singleton

 

Links

h1

Serializable dictionary

August 31, 2008

 

One time I had to make cache  for  user interface settings. Cache had to keep last setted values for combo boxes and grouping settings for DevExpress GridViews. We must to ensure, that cache will be extensible for next components (it depends on user requirements). My implementation was established on Dictionary which kept unique key for component and value. Value was List<GridColumnItem> for grid columns (this list contained mandatory information for particular columns). Value contained DictionarySetting object for DropDown lists. In the future I can create another kind of objects. How you can see.

Unhappiness is , that classes which implements IDictionary is impossible to serialise.  I found good article to serializable Dictionary here .  It is good way, how to do it, but it is a little bit complicated to serialize different types of values in the one Dictionary.

Finally I solved this problem by implementation of mine special collection. This collection is based on List<NameValueObject>. List is easy to serialize. Nested NameValueObject is an object which keeps string Key and  object Value. It enables to simulate Dictionary for me.  For serialization of different types of objects you must adjust metadata for Value property in List<NameValueObject>. That’s all !! Disadvantage of this solution is recompilation of collection however you want to serialise new  types of objects.

 

And now implementation:

ISerialisableDictionary.cs

using System;
using System.Collections.Generic;
using System.Text;
namespace XmlSerializerTest
{
/// <summary>
/// Defines serializable dictionary
/// </summary>
public interface ISerializableDictionary
{
/// <summary>
/// Gets or sets object from collection by index.
/// Throws an exception if index doesn’t exist.
/// </summary>
/// <param name=“index”></param>
/// <returns></returns>
object this[int index] { get; set; }

///
<summary>
/// Gets or sets object from collecton by key.
/// Throws an exception if index doesn’t exist.
/// </summary>
/// <param name=“key”></param>
/// <returns></returns>
object this[string key] { get; set; }

/// <summary>
/// Add value to collection. If element exists in the collection, it will throw exception.
/// </summary>
/// <param name=“key”></param>
/// <param name=“value”></param>
void Add(string key, object value);

///
<summary>
/// Try to get value from collection if exist
/// </summary>
/// <param name=“key”></param>
/// <param name=“value”></param>
/// <returns>True if value exist elese returns false</returns>
bool TryGetValue(string key, out object value);

/// <summary>
/// returns true if item with defined key exists in the collection
/// </summary>
/// <param name=“key”></param>
/// <returns></returns>
bool Contains(string key);
}
}

SerialisableDictionary.cs

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

namespace
XmlSerializerTest
{
/// <summary>
/// Simulation of Name value collection to list, which is serialisable.
/// </summary>

[XmlRoot("SerializableDictionary")]
[Serializable]
public class SerializableDictionary : ISerializableDictionary
{
 
private List<NameValueObject> list = new List<NameValueObject>();
 
///
<summary>
/// Serialize collecton
/// </summary>
/// <returns></returns>
 
public string Serialize()
 
{
 
StringBuilder stringBuilder = new StringBuilder();
 
XmlSerializer serializer = new XmlSerializer(typeof(SerializableDictionary));
  TextWriter writer = new StringWriter(stringBuilder);
  se
rializer.Serialize(writer, this);
 
XmlDocument document = new XmlDocument();
 
document.LoadXml(stringBuilder.ToString());
 
return document.DocumentElement.OuterXml;
 
}

/// <summary>
/// Deserialise collection
 
/// </summary>
 
/// <param name=“xml”></param>
 
/// <returns></returns>
 
public static SerializableDictionary Deserialize(string xml)
{
 
SerializableDictionary serializableDictionary = null;
 
XmlSerializer serializer = new XmlSerializer(typeof(SerializableDictionary));
 
TextReader reader = new StringReader(xml);
 
serializableDictionary = (serializer.Deserialize(reader) as  SerializableDictionary);
 
return serializableDictionary;
 
}

public List<NameValueObject> List

 
get { return list; }
 
}

 

#region ISerializableDictionary Members

public object this[int index]
{
 
get
 
{
 
if (list.Count > index)
   
return list[index].Value;
 
throw new IndexOutOfRangeException(string.Format(“{0} contains just {1}  elements.”,this,this.list.Count));
 
}
 
set
{
 
if (list.Count > index)
   
list[index].Value = value;
 
throw new IndexOutOfRangeException(string.Format(“{0} contains just {1} elements.”, this, this.list.Count));
}
}

public object this[string key]
{
get
{
 
int index = GetIndexByKey(key);
  
if (index >= 0)
    
return list[index].Value;
 
throw new IndexOutOfRangeException(string.Format(“{0} doesn’t defined for {1} key.”, this, key));
}
 
set
 
{
 
int index = GetIndexByKey(key);
 
if (index >= 0)
   
list[index].Value = value;
 
throw new IndexOutOfRangeException(string.Format(“{0} doesn’t defined for {1} key.”, this, key));
 
}
}

public void Add(string key, object value)
{
 
if (!this.Contains(key))
 
list.Add(new NameValueObject(key, value));
 
else
   throw new Exception(string.Format(“Value for key {0} exists in the collection”, key));
 
}

public bool TryGetValue(string key, out object value)
{
 
bool b = this.Contains(key);
 
if (b)
  
value = this[key];
 
else
  
value = null;
 
return b;
 
}

public bool Contains(string key)
{
  
return this.GetIndexByKey(key) == -1 ? false : true;
}

private int GetIndexByKey(string key)
{
 
return list.FindIndex(delegate(NameValueObject nameValueObject) { return nameValueObject.Key == key; });
}

#endregion

#region NameValueObject

/// <summary>
/// Name value nested class simulates dictionary in the list
/// </summary>
[Serializable]
[XmlRoot("NameValueObject")]
public class NameValueObject
{
 
private string key;
 
private object value; 

public NameValueObject(string key, object value)
 
{
 
this.value = value;
 
this.key = key;
 
}

//Each serializable object must contain implicit constructor
public
NameValueObject(){}

public string Key
{
 
get { return key; }
 
set { key = value; }
}

/// <summary>
///
!!!!!!!!!!!!!!!!
///
If you will create new kind of object, that contains value,
///
than YOU MUST UPDATE THIS METADATA!!!!!
///
and nothing else !!!!!!!!!!!!!!!!!
///
</summary>
[XmlElementAttribute("ArrayOfAaa", typeof(List<Aaa>))]
[XmlElementAttribute("ArrayOfBbb", typeof(List<Bbb>))]
public object Value
{
  get { return value; }
  set { this.value = value; }
}
}
#endregion
}
}

 

Program.cs

namespace XmlSerializerTest
{
#region neisted classes

[Serializable]
public class Aaa
{
 
private int _aaa;
 
private int _bbb;
 
public Aaa(int aaa, int bbb)
{
 
this._aaa = aaa; this._bbb = bbb;
 
}

public Aaa(){}

public int Aaaa
{
 
get{ return _aaa; }
 
set {_aaa = value;}
}

public int Bbbb
{
 
get {return _bbb;}
 
set {_bbb = value;}
}

}

[Serializable]
public class Bbb
{
 
private string _aaa;
 
private int _bbb;
 
public Bbb(string aaa, int bbb)
 
{    this._aaa = aaa;   this._bbb = bbb;  }

  public Bbb(){}
 
public string Aaaa
 
{
   
get {return _aaa;}
   
set {_aaa = value;}
 
}

public int Bbbb
{
 
get{return _bbb;}
 
set{_bbb = value;}
 
}

}

#endregion

public class Program
{
 
public static void Main()
 
{
   
SerializableDictionary serializableDictionary = new SerializableDictionary();
    List
<Aaa> list = new List<Aaa>();
   
List<Bbb> list11 = new List<Bbb>();
   
list.Add(new Aaa(5, 69));
   
list.Add(new Aaa(5, 70));
   
list.Add(new Aaa(5, 71));
   
list11.Add(new Bbb(“ahooj”, 69));
   
list11.Add(new Bbb(“jak se mas”, 667));
   
serializableDictionary.Add(“list”, list);
   
serializableDictionary.Add(“list141″, list11);
   
string aaa = serializableDictionary.Serialize();
   
SerializableDictionary dict2 = SerializableDictionary.Deserialize(aaa);
  
}
 
}
}

 

Output

<SerializableDictionary xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xmlns:xsd=”http://www.w3.org/2001/XMLSchema”>
<List>
<NameValueObject>
  <Key>list</Key>
  <ArrayOfAaa>
    <Aaa>
     <Aaaa>5</Aaaa>
     <Bbbb>69</Bbbb>
    </Aaa>
   <Aaa>
   
<Aaaa>5</Aaaa>
    <Bbbb>70</Bbbb>
   </Aaa>
   <Aaa>
    <Aaaa>5</Aaaa>
    <Bbbb>71</Bbbb>
   </Aaa>
  </ArrayOfAaa>
</NameValueObject>
<NameValueObject>
  <Key>list141</Key>
  <ArrayOfBbb>
   <Bbb>
     <Aaaa>ahooj</Aaaa>
     <Bbbb>69</Bbbb>
   </Bbb>
   <Bbb>
     <Aaaa>jak
se mas</Aaaa>
     <Bbbb>667</Bbbb>
   </Bbb>
  </ArrayOfBbb>
  </NameValueObject>
</List>
</SerializableDictionary>

 

Links

h1

Jak jsme shaneli byt bez RK

August 21, 2008

Porc tohle pisu?? Protoze nekdy v budoucnu budu opet hledat byt a chci se vyvarovat opetovnym chybam.

Chteli jsme s kamaradem byt v Praze s dobrou dostupnosti MHD a parkovacim mistem. Dali jsme si inzerat do webove annonce (zaroven s tim jsem zjistil, ze tyto inzeraty vychazeji posleze i v tistene forme).  Nikdo se neozyval. Pro zvyseni priority inzeratu lze inzeratu priradit body. 1 bod = 5 kc. Po delsim otaleni jsem dal svemu inzeratu 2 body, cimz jsem naz inzerat posunul mezi prvni 3 pricky inzeratu. To je cool. Problem je, ze minimalni platba na annonci je 100,- (Holt jsou vychcany).  Takze v annonci mam v tuto chvili stale jeste 85 korun na jejich pseudo uctu, ktere asi jen tak nespotrebuju. Tech 5 korun navic je nejake oramovani pro zvyrazneni inzeratu. Zjistil jsem, ze lide obecne nechteji investovat do inzeratu, takze jsem byl asi jeden z mala, co jim tam ty penize poslal. Proc to pisu. Zni to zajimave, ale z anonce se nam za cely tyden ozvala jedina osoba. A to jeste na inzerat, ktery jsme vlozili drive – bez bodu (nejlacinejsi forma inzeratu – ZDARMA).

Dale jsme shaneli nabidku bytu k pronajmu – reality na seznamu a v annonci. Vsude same Realitni kancelare (RK). Co s tim… Prochazel jsem fotky. Nektere nabidky byli stejne na obou serverech , ale od jinych RK. Podle ulice a fotek jsem si dokazal poskladat, kde se dane domy nachazeji (nekdy bylo uvedeno, nebo vyfocene  i C.P. domu.  Diky tomuto katastru jsem si nasel i vlastniky. Vlastnici se daji i googlovat. Lze za nimi i primo prijet a zeptat se jich, jestli nepronajimaji byt. Da se s nimi domluvit. Tohle je forma, jakou lze ziskat byt k pronajmu bez posranych provizi pro RK (vyhozene penize z okna).

Nakonec to vyslo s majitelkou bytu, ktera se ozvala pres annonci, zacala ale spekulovat o cene. To se rychle zmenilo, kdyz jsme rekli ze ne a cena zustala na puvodni hodnote. 

Dale jsem zjistil, ze lze byty hledat i na realitach v seznamu. Vetsinou tam davaji inzeraty realitni kancelare, ale pokud je inzerat bez kontaktu na RK anebo ma zadavatel v inzeratu “normalni” mail adresu (@seznam.cz,  @iol.cz, ….) pak je to vetsinou primy majitel.  A hleda primeho zajemce.

Je dobre si vytvorit excel z nabidkama na gmai documents.  Usetri to hromadu nervu.

LINKS

h1

Urychlení workflow

August 18, 2008

Workflow se dá zrychlovat. V práci jsme řešili tento problém: Jednotlivé akce softwaru generují tasky. Jedny tasky mohou generovat spoustu jiných tásků, servicy spouštějí tasky atd… společně s tasky se spouští i WFL.   Při velikém objemu dat to ale může celé bouchnout na výkonu. Proto je dobré se zamyslet, jestli nestačí zapsat záznam do DB a instanci  WFL pro Task spustit jen tehdy, pokud se actor rozhodne na daném tasku pracovat. Očekávaný výkon takového systému s WFL na pozadí je pro nás cca 10% původního výkonu.

h1

Blocked files VS2005

August 18, 2008

This article should afford help in the situations , when you could not compile project, becouse some of files are blocked.

I am obtaining error messages like this:

  • Unable to copy file “obj\Debug\xyz.dll” to “bin\Debug\xyz.dll  
  • Unexpected error creating debug information file ‘C:\Workspace\WcfClient\obj\Debug\XXX.YYYY.WcfClient.PDB’
    ‘C:\Workspace\XXX.YYYY.WcfClient\obj\Debug\XXX.YYYY.WcfClient.pdb: The process cannot access the file because it is being used by another process.

Solution

Just install this cool and free application. And unblock the process.

 

Links

h1

NIN -ten DO

August 10, 2008

Orginal version

Remix version

h1

Messiah Remix

August 10, 2008
h1

Order of constructor calling

August 10, 2008

 

//implicitly internal class
public class Aaa
{
   private string _s;
   private int _a;
   private int _b;

   //Initialized before calling constructors
   private int initializedBeforeCallingConstructors = 10;

   //constructor c1
   public Aaa()
   {
      _b = 5;
   }

   //constructor c2
   public Aaa(int a) : this()
   {
      _a = a;
   }

   //constructor c3 => order of calling is c1 is called first,
   //than c2 and finally is called _s=s in c3.
   public Aaa (string s, int a) : this(a)
   {
      _s = s;
   }
}

h1

VS2005 general shortcuts #3 – Environment

August 6, 2008

Main Explorer Window

  • Design Editor (Shift – F7)
  • Solution explorer (Ctrl-W, S )
  • Class View (Ctrl-W, C )
  • Object Browser (Ctrl-W, J )
  • Code Editor ( F7 ) 

Help Windows

  • Error List (Ctrl-W, E)
  • Output (Ctrl-W, O)
  • Property Window (F4)
  • Task List (Ctrl-W, T)
  • Watch (Ctrl-Alt-W,1..4)

 

Links

h1

VS2005 general shortcuts #2 – Code editing

August 6, 2008

 

¨

Outlining

  • Toggle Outlining expansion: Ctrl M, M
  • ¨Toggle All Outlining: Ctrl M, L
  • ¨Stop Outlining: Ctrl M, P

 

Comments

  • Comment: Select text and Ctrl K, C
  • ¨Uncomment: Select text and Ctrl K, U

 
 

Links