Thursday 18 December 2008

Guide to understanding flow charts

click on picture to get it in full size:

Monday 27 October 2008

Have WSDL or XSD; Need c# Class Interface

When you want to access a external web service inside you .NET c# code, you take the WSDL and generate a stub class.

To do this you can use the WSDL.exe which can be found inside the Visual studio folders (in my case here: "C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\wsdl.exe" )


Microsoft link: link



If you on the other hand wants to use some classes described in an XML-file, you should instead use xsd.exe

C:\projects\ebXML>xsd.exe rim.xsd /classes

that will autogenerate .NET c# classes for each element in the xsd.

Thursday 31 July 2008

Find dublicates when SQL is your friend

Just to remember it another day. If you want to find which elements there is more then one time.


SELECT CODE
FROM table
GROUP BY CODE
HAVING count(CODE) > 1


It helped me a lot, so I hope you, my reader can utilise it as well.

Tuesday 1 July 2008

Add entry macro in my word document

I am using a word document, to document may daily tasks and doings. And as the good geek I am, I wanted to implement a macro in MS word to make a day entry at the punch of a short cut.

After playing alot with the anything-but-intuitive vb I finally finished the following macro:

Sub addEntry()
'
' addEntry Macro
' Macro recorded 4/7/2008 by kim
'
' write headline ("Diario di bordo ")
Selection.Font.Name = "Courier New"
Selection.Font.Bold = True
Selection.Font.Underline = True
Selection.TypeText Text:="Diario di bordo "
Selection.InsertDateTime DateTimeFormat:="dd/MM/yyyy HH:mm:ss", _
InsertAsField:=False, DateLanguage:=wdItalian, CalendarType:= _
wdCalendarWestern, InsertAsFullWidth:=False
Selection.TypeParagraph
Selection.Style = ActiveDocument.Styles("Normal")

' add bold headline ("Should-does:")
Selection.Font.Bold = wdToggle
Selection.TypeText Text:="Should-dos:"
' add point lists.
Selection.TypeParagraph
Selection.MoveUp Unit:=wdLine, Count:=1
Selection.TypeParagraph
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.Style = ActiveDocument.Styles("List Bullet")

' if it is friday, add "Write Status report" to bullet list.
today = Weekday(Date$, vbMonday)
If (today = vbFriday) Then
Selection.TypeText Text:="Write Status report"
End If

Selection.TypeParagraph
Selection.TypeParagraph
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.MoveLeft Unit:=wdCharacter, Count:=1
' remove type type.
Selection.Range.ListFormat.RemoveNumbers NumberType:=wdNumberParagraph
End Sub

Which does exactly as I have described in the comments (the stuff in green). And produces the following in my diary.



Diario di bordo 01/07/2008 17:43:57

Should-dos:

·

·



(sorry the mess of HTML (if you look in "document source" of this HTML, its pretty ugly, but I just did a copy paste from Word).

If its a friday, it will add the "Write status report" to the list of "Should dos"

Thursday 26 June 2008

c# with XmlDocument and xpaths

Im almost embarrassed to admit it but I have spend almost a day playing around with the XmlDocument .NET class and xpaths. My problem was that I have the XML shown below(only a snipped of it is pasted below)

And wanted to get hold of the "id" tag inside patient. To do this I found that the fast way was to use the method SelectSingleNode to and a xpath expression like the following:

"/ClinicalDocument/recordTarget/patientRole/id".

In the following way:

XmlDocument xml = new XmlDocument();
xml.LoadXml(cda.Xmlcda);
XmlNode node = xml.SelectSingleNode("/ClinicalDocument/recordTarget/patientRole/id");

But no element was found. I tried quite a lot of different stuff. But nothing worked.

Until finally I found this article: (link) (which I only skimmed(to be completely honest))which described the funny thing that even if the elements is not prefixed in the XML the base namespace is used anyway. So to enable me to Xpath my way to the patient Id tag I needed a XmlNameSpaceManager to handle the namespaces.


The working code looks like this:
XmlDocument xml = new XmlDocument();
xml.LoadXml(cda.Xmlcda);
XmlNamespaceManager nsmgr = new XmlNamespaceManager(xml.NameTable);
nsmgr.AddNamespace("cda", "urn:hl7-org:v3");
XmlNode node = xml.SelectSingleNode("/ClinicalDocument/recordTarget/patientRole/id", nsmgr);



The XML:

<!-- ?xml-stylesheet type="text/xsl" href="CDA.xsl"? -->
<!-- Readers should be aware of the evolving "Using SNOMED CT in HL7 Version 3" implementation guide, currently in a draft state. The guide, co-developed by HL7 and the College of American Pathologists, will be balloted by HL7 as an Informative Document. Recommendations in the final published guide should usurp patterns of SNOMED CT usage found in this sample instance. -->
<clinicaldocument xmlns="urn:hl7-org:v3" voc="urn:hl7-org:v3/voc"
xsi="http://www.w3.org/2001/XMLSchema-instance"
schemalocation="urn:hl7-org:v3 CDA.xsd">
<!-- ******************************************************** CDA Header ******************************************************** -->
<typeid root="2.16.840.1.113883.1.3" extension="POCD_HD000040">
<templateid root="2.16.840.1.113883.3.27.1776">
<id extension="c266" root="2.16.840.1.113883.19.4">
<code code="11488-4" codesystem="2.16.840.1.113883.6.1" codesystemname="LOINC" displayname="Consultation note">
<title>Good Health Clinic Consultation Note</title>
<effectivetime value="20000407">
<confidentialitycode code="N" codesystem="2.16.840.1.113883.5.25">
<languagecode code="en-US">
<setid extension="BB35" root="2.16.840.1.113883.19.7">
<versionnumber value="2">
<recordtarget>
<patientrole>
<id extension="12345" root="2.16.840.1.113883.19.5">
<patient>
<name>
</name></patient></id></patientrole></recordtarget></versionnumber></setid></languagecode></confidentialitycode></effectivetime></code>

Tuesday 10 June 2008

"?" - Question mark in c# code (Nullable value types)

In a piece of auto generated code, I found the following property


public DateTime? EffettiveTime
{
get { return m_effettiveTime; }
set { this.m_effettiveTime = value; }
}


This was the first time I seen the question mark in the c# code (at least in this context) The problem arose when I wanted to do the following:


someInstance.date = EffettiveTime.ToString("yyyy-mm-dd");


It returned an error saying that the ToString method does not have any overload methods, which takes a string. I looked up DateTime and found the overloaded method, so why couldn't I use it.

After some googling I found the wikipedia site for c-sharp (link) where I found the following:


Nullable value types (denoted by a question mark, e.g. int? i = null;) which add null to the set of allowed values for any value type. This provides improved interaction with SQL databases, which can have nullable columns of types corresponding to C# primitive types: an SQL INTEGER NULL column type directly translates to the C# int?.


But then there is just the problem that this new type (DateTime?) did not implement the method that I needed, so I had to cast it to DateTime before continuing, on. This seemed to work:

DateTime eTime = (DateTime) EffettiveTime;
someInstance.date = eTime.ToString("yyyy-mm-dd");





The "?" question mark is also used for short if statements. The following can be written much shorter:


SomeClasse someInstance = null;
if(<someBoolean>)
{
someInstance= <doSomething>;
}
else
{
someInstance = <doSomethingElse>;
}



This could be written like this instead

SomeClasse someInstance = <someBoolean> ? <doSomething> : <doSomethingElse>;

Thursday 8 May 2008

androMDA.net download

In a new project, I heard that it would be of great use to auto generate some code. and that AndroMDA is the tool to use.

Sadly I had only reached about a 100 lines into the how-to androMDA before running into problems. I was not able to download the mavenplugin (which is AndroMDA).

So when the tutorial (link) wrote the following

To install the C# Application plugin open a Command Prompt and Execute the following command. Make sure you get a "BUILD SUCCESSFUL" message at the end of the command output.

maven plugin:download -DgroupId=andromda -DartifactId=maven-andromdacsapp-plugin -Dversion=1.0-SNAPSHOT

Notice that you will now have maven-andromdacsapp-plugin-1.0-SNAPSHOT.jar installed at MAVEN_HOME\plugins ( C:\Program Files\Apache Software Foundation\Maven 1.0.2\plugins for this example).

I just got a lot of errors instead of actually downloading anything. Luckily I wasnt the first one to have this problem, to after a bit of search I found the following solution (link)


After a long fight with maven, I found a solution to the problem.
Maven 1.x doesn't support redirection thus we must indicate a non redirected repository. So in build.properties :

maven.repo.remote=http://www.ibiblio.org/maven,http://team.andromda.org/maven
become
maven.repo.remote=http://repo1.maven.org/maven,http://team.andromda.org/maven

and a valid command line is :

maven plugin:download -DartifactId=maven-torque-plugin -DgroupId=torque -Dversion=3.3-RC1

if you try to use an other apache's server, it seems that jsch isn't created. [neria]



Joy and happiness, now I can continue, my androMDA tutorial, and actually download androMDA, with the following command:


maven plugin:download -DgroupId=andromda -DartifactId=maven-andromdacsapp-plugin -Dversion=1.0-SNAPSHOT

Wednesday 16 April 2008

Found in System.Uri in the .NET lib


Protected Overridable Sub CheckSecurity()
Member of: System.Uri
Summary:
Calling this method has no effect.


Wonder how many no-effect-methods is needed to run windows. and if all their CheckSecurity methods have no effect.

Sunday 6 April 2008

Reading rails 1.2 while learning rails 2.0

Learning rails 2.0 from a book about rails 1.2.6 keeps you awake, cause there are things that does not do exactly what it is described in the book.


depot>rails depot


Generates lots of code. Now to setup the database open the database.yml file in depot\config\ and correct it to match your database:


# SQLite version 3.x
# gem install sqlite3-ruby (not necessary on OS X Leopard)
development:
adapter: mysql
database: depot_development
user: userNam
password: pass
test:
adapter: mysql
database: depot_test
user: userNam
password: pass

production:
adapter: mysql
database: depot_production
user: userNam
password: pass


then make use of the rake tool, to create the databases:


rake db:create:all


then to make the product scaffolding do the following:


depot>ruby script/generate scaffold Product title:string description:text image_url:string


And now its possible to start the server (ruby script/server) and create a product. following this url:


http://localhost:3000/products

Tuesday 1 April 2008

Greetings from RubyFools in Copenhagen

The first RubyFools ever is placed at the IT university of Copenhagen. The buildings have just been build, and everything is nice beautiful, straightlined and very grey and Danish.

Dave Thomas gave the introduction keynote, where he talked about why he is a ruby fool. As it is custom, the keynote didn't really introduce anything, but was just a nice relaxed talk about the things that Dave likes about the language.

Listing to the talk, it seems to me ( even if it makes me sound old) like history is repeating it self. Some of the things that Dave points out as the new good things about Ruby is also some of the arguments for leaving C++ and go to Java:

.- multi paradigm language,
-.- OOP, prototype based, almost functional
.- expressiveness
-.- lots of ways to say the samething

After listing these things he went on to say the it was imperfect, and said that was a good things, things "Perfection is the enemy of all creation" (He was very convincing and I agree with him on this point)

Then followed some notes about how much Ruby and the community had grown.

always remember
TO HAVE FUN


-- pictures will be added when I can --

Friday 7 March 2008

My list

I have this list of things that I should study, to get up-to-date on the new things in the computer science world. The list changes all the time, but today its:

1. Ruby programming language
2. Javascript
3. Ruby on Rails.
4. RestFULL webservices.
5. Git (version Control system)
6. Behaviour Driven Development(BDD)
7. erlang (Erlang is a general-purpose concurrent programming language)

To support the first element on the list, I was encouraged to buy the following books:
- The Ruby Programming Language
- JavaScript the Definitive Guide.

Anybody ( if anybody reads this) have anything else...

Wednesday 5 March 2008

A dead horse

Dakota tribal wisdom says that when you discover you are riding a dead horse, the best strategy is to dismount.

I found this page that describes this old saying and (if you follow the link) gives a few stupid examples of what businesses today do when they discover that they are in fact riding smelly one.

Cant help wondering how many people are currently riding a dead horse, and knows it. one can always say that there is fair risk that a software project fail, but thinking back on projects and friends projects, there is a surprisingly large number of riders who have been on dead horses and knew it was dead.

What about your project, is that a dead horse.....

Wednesday 30 January 2008

rails 2.0 with sql-server


gem install activerecord-sqlserver-adapter --source=http://gems.rubyonrails.org


get the Ruby-dbi from this site rubyForge

After downloading it, use WinAce (or something else )to unpack the files and copy the following file lib/dbd/ADO.rb to /ruby/lib/ruby/site_ruby/1.8/DBD/ADO/ADO.rb

Now insert the following in the database.yml file (in \config dir of your rails app)

development:
adapter: sqlserver
database: "DATABASENAME"
host: .
username: "USERNAME"
password: "PASSWORD"

where databasename, username, and password (remove comeplete tag) should be inserted. and if the sql server is not running on the local host, then the "." should be exchanged to the proper path. fx. if my server was called "ruby" and my username was "user" and password was "user" then it should look like this:

development:
adapter: sqlserver
database: ruby
host: .
username: user
password: pass

How to get ruby on rails

To get rails, one can just download ruby, and then ask it to fetch the gems, that contains rails.

First download ruby (following link is to the currently most present version):
rubyForge

when everything is installed correctly, run the following command:


C:\private\projects\ruby>gem install rails --include-dependencies

this will generate the following output:


C:\private\projects\ruby>gem install rails --include-dependencies
Bulk updating Gem source index for: http://gems.rubyforge.org
Successfully installed rails-2.0.2
Successfully installed activesupport-2.0.2
Successfully installed activerecord-2.0.2
Successfully installed actionpack-2.0.2
Successfully installed actionmailer-2.0.2
Successfully installed activeresource-2.0.2
Installing ri documentation for activesupport-2.0.2...
Installing ri documentation for activerecord-2.0.2...
Installing ri documentation for actionpack-2.0.2...
Installing ri documentation for actionmailer-2.0.2...
Installing ri documentation for activeresource-2.0.2...
Installing RDoc documentation for activesupport-2.0.2...
Installing RDoc documentation for activerecord-2.0.2...
Installing RDoc documentation for actionpack-2.0.2...
Installing RDoc documentation for actionmailer-2.0.2...
Installing RDoc documentation for activeresource-2.0.2...


Now to the coding!

Tuesday 8 January 2008

MS video and youtube

Isnt it wonderful with Microsoft. I just read in a Danish paper that Bill Gates is leaving Ms, and that he have made a video about his last day at work. The article included a link to MSN video, to where the video should be. Instead I get "Sorry the video is unavailable". Going to YouTube (The competition), search "Bill Gates", and the Video starts.... The following, is the YouTube video. which works:



Bravo Microsoft.

Monday 7 January 2008

Do we learn from our mistakes

Its always very easy to tell when something has gone wrong during a project, and often also easy to see why its has gone wrong. Yet on the next project, the same things often goes wrong.

Then what ? Get use to the fact that history repeats its self, or try to actuly think and learn about things that were good and bad, in just finished projects, and try to avoid pitfalls and enhance good tricks. This revolutionary thought is being examined in the following Google representation, given by Diana Larsen: