chinuiala cu sandcastle

azi la servici m-am chinuit de am innebunit cu SandCastle pentru a genera documentatia proiectului…
Am tot cautat pe net -dar toate imi dadeau acceasi eroare: ca ii trebuie un fisier XML – si asta la o comanda cu pipa (|)…
Am renuntat, am luat versiunea de NDOC pentru 2.0
Si am generat documentatie tip HTML ( MSDN nu a iesit… izcea ceva de object not set)

La naiba cu sandcastle… de ce o fi asa de complicat, chiar si pentru un CTP ?

programarea in .NET – partea a 3-a – codul pentru obiecte

Ar fi folositor sa cititi partea 1 si partea a 2-a


Acum la creearea obiectelor


Fiecare obiect trebuie sa aiba proprietati care corespund cimpurilor din Baza de date si , pentru usurinta, alte proprietati/metode


O sa scriu codul pentru Publisher si o sa las pe celelalte ca un exercitiu pentru dvoastra. Pentru a salva/sterge/creea un obiect de tip Publisher o sa implementam corespondentele metode corresponding method update / delete / insert.


Faptul ca un publisher trebuie sa aiba un nume unic o sa il scriem mai tirziu.


Stim deja ca trebuie sa avem doua baze de date, asa incit o sa avem doua stringuri de conexiune -pentru Access si pentru SQL Server)


Pentru a usura scrierea stringurilor de conexiune, va rog sa consultati www.connectionstrings.com




PEntru a vedea toate inregistrarile din tabela publisher, trebuie sa stocam undeva multimea lor. Aceasta multime va fi o clasa numita ColPublisher. Ea va contine o metoda numita Load care va incarca Publisher-ul din baza de date si le va stoca intr-o colectie.



Acum , cind stim ce avem de facut in continuare, hai sa scriem ceva cod


Start Visual C# Express( daca e prima oara cind il lansati, va va intreba setarile -puneti pe cele de C#)si creati un nou proiect numit Books



si salvati in C:\book





De obicei, the System.Data.dll este listat in referinte. Daca nu, va rog sa il adaugati. Oricum, adaugati va rog si o referinta la System.Configuration.


Click dreapta pe Solution Explorer si Add reference laOleDBConnection ca mai jos :





Redenumiti Class1.cs dinproprietati( click pe fisier in Solution Explorer si apasati F4) in Publisher.cs


Daca raspundeti “yes” la urmatoarea intrebare, numele clasei va fi schimbat din Class1 in Publisher – si faceti-o public class



Acum o sa scriem proprietatile de baza pentru un Publisher :


using System;


using System.Collections.Generic;


using System.Text;



namespace BookObjects


{


public class Publisher


{


#region Database properties


private int m_IDPublisher;


public int IDPublisher


{


get


{


return m_IDPublisher;


}


set


{


m_IDPublisher = value;


}


}



private string m_Name;



public string Name


{


get


{


return m_Name;


}


set


{


m_Name = value;


}


}



private string m_Site;



public string Site


{


get


{


return m_Site;


}


set


{


m_Site = value;


}


}


#endregion



}


}




Trebuie sa le incarcam aceste proprietati din Baza de date, asa incit o sa scriem o metoda Fill:


O sa o scriem astfel incit sa nu avem dependenta de BD:




#region Database methods


public void FillObject(System.Data.IDataReader idr)


{


this.Name = idr[“NamePublisher”].ToString();


this.Site = idr[“SitePublisher”].ToString();


}


#endregion





ACum va trebui sa scriem codul de incarcare din BD a diverselor inregistrari. Asaugati o noua clasa ( Project => Add Class) si denumiti-o ColPublisher.cs.


Din nou , faceti-o public class si haide sa scriem metoda care incarca datele din BD.



public void Load()


{



}


ACum ne dam seama ca ne trebuie cele doua conexiuni – si o metoda de a vedea pe care din ele le incarcam.


Asa incit vom incepe sa scriem cod spre a incarca conexiunile :


public static string ConnectionStringMDB


{


get


{


return System.Configuration.ConfigurationManager.ConnectionStrings[“MDB”];


}


}


public static string ConnectionStringSQLServer


{


get


{


return System.Configuration.ConfigurationManager.ConnectionStrings[“SQLServer”];


}


}




Asa cum am tot spus, avem doua stringuri de conexiune.


A venit timpul sa stim cind incarcam una si cind cealalta in functia Load.


O sa adaug o noua clasa numita Settings si o sa pun acolo setarile comune


O sa adaug o enumerare care o sa imi spuna ce baza de date voi utiliza



public enum DatabaseUsed


{


None,


MDB,


SQLServer


}


si o sa o citim din fisierul de configurare(App.config sau Web.Config) :


public static DatabaseUsed TheDatabase


{


get


{


return Enum.Parse(typeof(DatabaseUsed), System.Configuration.ConfigurationManager.AppSettings[“DatabaseUsed”];


}


}



Puteti obserava ca am pus configurarea in Appsetting . Putem stoca si stringurile de conexiune in acelasi loc – dar am vrut sa fim compatibili cu standardul Microsoft.


Codul poate fi obtinut de aici


Data viitoare o sa scriem cod pentru a incarca datele din BD si a le pune in colectie.



De citit:


Pentru .NET best practices, puteti citi http://www.ssw.com.au/ssw/Standards/default.aspx


PEntru construirea unui ORM (Object-relational_mapping) cum facem aici, cititi articolul urmator de pe Wikipedia (http://en.wikipedia.org/wiki/Object-relational_mapping) si puteti gasi o lista de ORM la adresa http://en.wikipedia.org/wiki/List_of_object-relational_mapping_software . Cred ca ar trebui sa cititi cel putin unul, de exemplu Nhibernate : http://www.hibernate.org/343.html


Pentru a genera acelasi cod plecind de la tabele dintr-o baza de date, cititi Code Generation (http://en.wikipedia.org/wiki/Code_generation) si poate CodeSmith (http://www.codesmithtools.com/)









Programming in .NET – part 3 -initial object code

It would be usefull to read part 1 and part 2

Now back to the object creation

Every object must have some properties that correspond to
the DB fields of the table and , for easier of use, other properties/methods.

We will wrote those Publisher and we left others as an
exercise for the user. For saving /delete /creating a Publisher object we will
implement corresponding method update / delete / insert.

The fact that a publisher must have an unique name will be
handled later.

From the previous part, we know that we have to handle two
different databases ( Access and SQL Server)

So we must have two connections strings – one for each
database.To set up easy the connection , please see www.connectionstrings.com

 

 

For viewing all the Publisher records, we must store in some
part the set of records. This set will be a class named ColPublisher. This
class will contain a method named Load that will load the Publisher from the
database and store them into the collection.

 

Now, when the path of what to do is more clear, let’s write
some code.

Start Visual C# Express( make the settings appropiate for
C#, if it is the first time you launch) and create a new class library project
named BookObjects

and save in the C:\book

 

 

By default, the System.Data is listed on the References . If
not, please add as following the reference to System.Data.But anyway, add a
reference to System.Configuration.

Click right on Solution Explorer and Add reference to
OleDBConnection as in the figure :

 

 

Rename the Class1.cs by clickingon his properties ( click the file on
Solution Explorer and press F4) to Publisher.cs

If you answer yes to the next question, the class name in
Class1 will be renamed into Publisher – and make it a publicclass

 

Now we will wrote the basic properties for Publisher :

using
System;

using
System.Collections.Generic;

using

System.Text;


 

namespace

BookObjects

{




public
class
Publisher



{



#region

Database properties




private
int m_IDPublisher;




public
int IDPublisher



{




get



{






return
m_IDPublisher;



}




set



{



m_IDPublisher = value;



}



}


 




private
string m_Name;


 




public
string Name



{




get



{




return
m_Name;



}




set



{



m_Name = value;



}



}


 




private
string m_Site;


 




public
string Site



{




get



{




return
m_Site;





}




set



{



m_Site = value;



}



}



#endregion


 



}

}

 

 

We must fill those properties from database, so we must
wrote code to Fill the object:

For this, we can wrote like this, obtaining independence
from the database:

 

 



#region

Database
methods




public
void FillObject(System.Data.IDataReader
idr)



{




this.Name
= idr[“NamePublisher”].ToString();




this.Site
= idr[“SitePublisher”].ToString();



}



#endregion


 

 

 

Now we must REALLY load data from the database, so we must
add a new class ( Project => Add Class) and name it ColPublisher.cs.

Again , make it a publicclass
and let’s wrote code to load data:

 



public


void Load()



{


 



}

Now we see that we must differentiate between the two
connections – and load them from somewhere.

So we wrote code to load connection first:








public
static
string
ConnectionStringMDB





{




get



{




return
System.Configuration.ConfigurationManager.ConnectionStrings[“MDB”];



}



}




public
static
string
ConnectionStringSQLServer



{




get



{






return
System.Configuration.ConfigurationManager.ConnectionStrings[“SQLServer”];



}



}


 


 

As you know , we have two connection strings – one for
each database.

The moment is now to differentiate between those two – the
Load function must know what connection string to use .

I will add a new class named Settings and we will put there
all the common settings.

I will add an enumeration to know which database we will use


 



public


enum
DatabaseUsed



{



None,





MDB,



SQLServer



}

and we will read from the database :



public


static
DatabaseUsed
TheDatabase



{




get



{




return
Enum.Parse(typeof(DatabaseUsed), System.Configuration.ConfigurationManager.AppSettings[“DatabaseUsed”];



}



}

 

You can observe from here that we put the type of database
in a Appsetting . We can store the connection strings at the same place, but we
want to be compatible with the Microsoft standard.

The code can be downloaded from here

Next time we will wrote code to load data from the database
and put into the collection and more, to easily indentify the objects.

 

Further readings:

For .NET related best practices, you can read http://www.ssw.com.au/ssw/Standards/default.aspx

For ORM (Object-relational_mapping) as we do here, you can
read the article on Wikipedia (http://en.wikipedia.org/wiki/Object-relational_mapping)
and see a list of ORM-s at http://en.wikipedia.org/wiki/List_of_object-relational_mapping_software
. I think that you can read at least one, as Nhibernate : http://www.hibernate.org/343.html

For generating same code from tables in database, you can
try reading Code Generation (http://en.wikipedia.org/wiki/Code_generation)
and specifically CodeSmith (http://www.codesmithtools.com/)

 

 

 

 

 

 

 

din dilema

Test psihologic: sacrificati un om(gras) pentru a salva 5 persoane? Raspunsul depinde de starea de spirit – risul ne face mai – lucizi sau cinici sau nepasator ( adica raspunzi da daca ai fost bine “distrat” in prealabil – dar procentul urca de la 15% la 30%)

Adrian Cioroianu despre 3 generatii de comunisti : – una care a crezut, alta care a fost solidara in rau si a treia care a mimat.
Tin minte cum m-au facut pionier -in ultima transa – si n-am avut chef sa invat carticica rosie. Era clasa a 8-a, nu stiam ca sunt miop -desi banuiam ceva in neregula cu ochii mei. Se puneau intrebari din carticica de catre prezidiul de profesori, iar altul tinea carticica deschisa sa citeasca loazele raspunsul.Cind mi-a venit rindul, am spus – dati carticica mai aproape , ca nu vad. Cel care scria procesul verbal a intrebat: Sa scriu ? – Ris general la timpenia individului.

Ca de obicei, Teodor Baconsky ma epateaza cu frazele lui -clare, inteligibile, si totusi nu usoare pentru  masa de semi intelecutali (printre care ma numar) . Exemplu :
“In prezent, centrul opozitiei fata de remanentele comunismului s-a deplasat dinspre elita de tip nicasian catre noile elite administrative si culturale ” si asa mai departe. De tip NICASIAN ? Iata o aluzie pe care trebuie sa o studiez…