• Nenhum resultado encontrado

9. Οδηγίες Εγκατάστασης

9.4 Οδηγίες για την ρύθμιση της MySQL Database

Μετά την εγκατάσταση του server, στον φάκελο SQL scripts θα βρούμε και το αρχείο με όνομα MYSqIScript.sql. Το αρχείο αυτό είναι το script το οποίο πρέπει να τρέξουμε για να δημιουργήσουμε την βάση δεδομένων στην περίπτωση που χρησιμοποιούμε MySQL.H διαδικασία είναι πολύ απλή. Βασική προϋπόθεση είναι μαζί με την MySQL να έχει εγκατασταθεί και το εργαλείο της MySQL Query Browser το οποίο μας επιτρέπει να χειριστούμε την βάση δεδομένων μέσα από γραφικό περιβάλλον. Το εργαλείο αυτό μπορούμε να το βρούμε πολύ εύκολα αν επισκεφτούμε την σελίδα της MySQL www.rπvsαl.corπ .

Για να τρέξουμε το script πρέπει να ανοίξουμε το MySQL query Browser πηγαίνοντας ΐναρξη - Ό λα τα προγράμματα - MySQL - MySQL Query Browser. Στην οθόνη του υπολογιστή θα εμφανκπεί ένα παράθυρο σύνδεσης, όπως αυτό της εικόνας που ακολουθεί. Εδώ πρέπει να συμπληρώσουμε τον κωδικό πρόσβασης που έχουμε ορίσει κατά την εγκατάσταση της MySQL και να πατήσουμε ΟΚ.

M y s q r

Query Browser

Ρ

Σύνδεση με το Instance το Αποθ/μένη Σύνδεση: |

SeiverHost [tocahost Όνομα Χρήστη: [ϊ^

--- 3 J

■ θύρα: [ 3 ^

Κωδικός:

|Γ~

Προεηιλ Σχήμα: [diploma

Λεπτομ.» | ΟΚ I Εκκαθάριση | Ακύρωση |

Στη συνέχεια εμφανίζεται το κύριο παράθυρο της εφαρμογής το οποίο αποτελείται από τρία βασικά κομμάτια. Στο πλαϊνό δεξιά κομμάτι μπορούμε να δούμε τα εγκατεστημένα σχήματα (βάσης) που υπάρχουν διαθέσιμες στην μηχανή διαχείρισης βάσεων της MySQL. Το μεγάλο κεντρικό κομμάτι, το οποίο είναι λευκό, είναι ο χώρος στον οποίο μπορούμε να γράψουμε οποιαδήποτε εντολή sql θέλουμε να εκτελέσουμε. Τα αποτελέσματα της εκτελέσιμης εντολής θα εμφανιστούν στο τρίτο κομμάτι του παραθύρου το οποίο βρίσκεται ιπο κάτω μέρος του.

Δημιουργία δυναμικής βιβλιοθήκης για την εξαγωγή και αποθήκευση ρυθμίσεων γραφικού περιβάλλοντος εφαρμογών

Για να τρέξουμε το script και να δημιουργήσουμε την βάση θα πρέπει να επιλέξουμε την εντολή Αρχείο - Ανοιγμα Script όπως φαίνεται στην εικόνα που ακολουθεί.

I την εξαγωγή και αποθήκευση ΐλλοντος εφαρμογών

ΐς που εμφανίζεται επιλέγουμε να :αι στον φάκελο SQL Scripts μέσα στον ίσιας. Για να εκτελέσουμε τον κώδικα

ΐς είναι έτοιμη προς χρηση.

Δημιουρνία δυναμικής βιβλιοθήκης y ia την εξανωνή και αποθήκευση ρυθμίσεων γραφικού περιβάλλοντος εφαρμογών

9.5 Οδηνίες για την ρύθμιση της Oracle lOg

ο server της πτυχιακής υποστηρίζει και την χρήση της βάσεως δεδομένων της Oracle, της πλέων επαγγελματικής λύσης την οποία χρησιμοποιούν οι μεγαλύτερες επιχειρήσεις και οργανισμοί, των οποίων τα δεδομένα χρίζουν ιδιαίτερης ασφάλειας και μεταχείρισης. Για τις ανάγκες της τττυχιακής χρησιμοποιήθηκαν δύο εκδόσεις, η 81 και lOg.

Ο τελικός έλεγχος έγινε στην έκδοση lOg αν και εκτιμάται ότι και η έκδσση 81 είναι πλήρως συμβατή λόγω της απλότητας για την οποία προορίζεται η χρήση της.

Και στην περίτττωση της Oracle, ένα script που βρίσκεται στον φάκελο SQL scripts με όνομα OracleScript.sql αναλαμβάνει όλη την δουλειά. Πριν τρέξουμε όμως το script θα πρέπει να δημιουργήσουμε την βάση χειροκίνητα. Η βάση θα μπορούσε να έχει δημιουργηθεί μέσω του script αλλά η πολυπλοκότητα του κώδικα κρίθηκε ανούσια, μιας και το εργαλείο δημιουργίας της βάσης είναι αρκετά εύκολα στη χρήση. Τα βήματα για την δημιουργία της βάσης δεδομένων είναι τα εξής:

1. Πηγαίνουμε "Εναρξη - Όλα τα Προγράμματα - Oracle-OraDblOg_home2 (μπορεί να διαφέρει ανάλογα με την έκδοση και των αριθμό των βάσεων που έχουν εγκατασταθεί κατά καιρούς στον υπολογιστή) - Configuration and Migration Tools και επιλέγουμε το πρόγραμμα Database Configuration Assistant. Στην οθόνη μας θα δούμε να εμφανίζεται το παράθυρο που φαίνεται στην παρακάτω εικόνα.

Welcome to Database ConAguratlon Assistant (Or Oracle database

Τμήμα Βιομηχανικής Πληροφορικής

Δημιουργία δυναμικής βιβλιοθήκης για την εξαγωγή και αποθήκευση ρυθμίσεων γραφικού περιβάλλοντος εφαρμογών

2. Στη Συνέχεια πατάμε επόμενο και επιλέγουμε την επιλογή Create Database και πατάμε επόμενο.

StKcl 111· optranon that you want to paifbrm;

• Create a OataPase ConPgure Database Options f Delete a Database r Manage Templates r Contlgure Automatic Storage Management

DponvoUpcyo | Επόμοο

3. Στην περίτττωσή μας δεν υπάρχει λόγος για δημιουργία κάποιας βάσης με συγκεκριμένες ιδιότητες οπότε αφήνουμε την επιλογή General Purpose και πατάμε επόμενο.

Δημιουργία δυναμικής βιβλιοθήκης για την εξαγωγή και αποθήκευση ρυθμίσεων γραφικού περιβάλλοντος εφαρμογών

Select a template ftom the tollowlng lilt to create a databaaa:

I Transaction Processing

Includes Datatliss

4. Εδώ πρέπει να δηλώσουμε το όνομα της βάσης δεδομένων και το SID της βάσης.

Κατά κανόνα αυτά τα δύο είναι ίδια και στην περσττωση της τττυχιακής το όνομα που πρέπει να δώσουμε είναι DIPLOMA.

An Oracle database Is uniquely Identified by a Global Database Name, typically of the tbrm "name Global Database Name: |diPLOMa|

__) ΒοήΒοσ j pporivotpeyo | Erriuevo ^ )

Τμήμα Βιομηχανικής Πληροφορικής

Δημιουρνία δυναμικής βιβλιοθήκης για την εξαγωγή και αποθήκευση ______________ ρυθμίσεων γραφικού περιβάλλοντος εφαρμογών_____________

. Στο επόμενο βήμα δεν αλλάζει τίποτα οπότε δεν υπάρχει λόγος αναφοράς σε αυτό.

Στο μεθεπόμενο θα πρέπει να ορίσουμε τον κωδικό πρόσβασης για τους βασικούς λογαριασμούς χρηστών που δημιουργούνται μαζί με την βάση. Ορίστε έναν κωδικό πρόσβασης και προχωρήστε πατώντας επόμενο.

DBSNMP

•S αροηνούμοΛ) |

Στο επόμενο και μέχρι το τελευταίο βήμα δεν υπάρχουν αλλαγές οπότε δεν θα αναφέρουμε λετττομέρειες. Απλά πατάμε επόμενο και προχωράμε μέχρι το τελευταίο παράθυρο στο οποίο πατάμε τέλος.

Δημιουρνία δυναμικής βιβλιοθήκης για την εξαγωγή και αποθήκευση ρυθμίσεων γραφικού περιβάλλοντος εφαρμογών_____________

Select the datebase creation options:

I? Create Database

- Γ Generate Database Creation Scric

_) ΒοήΒοα ) □ ponyoCpcvo I

7. Μόλις πατήσουμε το κουμπί «Τέλος» εμφανίζεται ένα συγκεντρωτικό παράθυρο με όλες τις ρυθμίσεις της βάσης μας. Πατώντας ΟΚ η βάση αρχίζει να δημιουργείται. Η διαδικασία μπορεί να διαρκέσει μερικά λεπτά. Μετά το τέλος της διαδικασίας η βάση είναι έτοιμη για να εγκαταστήσουμε οποιονδήποτε πίνακα.

8. Το επόμενο βήμα είναι να τρέξουμε το script το οποίο θα δημιουργήσει τους κατάλληλους χρήστες και πίνακες. Για να γίνει αυτό πρέπει να ανοίξουμε το εργαλείο sqiplus της Oracle. Από εκεί, μέσω της εντολής Αρχείο - Ανοιγμα, μπορούμε να εντοπίσουμε το script και να το εκτελέσουμε. Μετά την εκτέλεσή του η βάση είναι έτοιμη να χρησιμοποιηθεί από την εφαρμογή.

Τμήμα Βιομηχανικής Πληροφορικής

Δημιουργία δυναμικής βιβλιοθήκης για την εξαγωγή και αποθήκευση ______________ρυθμίσεων γραφικού περιβάλλοντος εφαρμογών_____________

10. ο κώδικας της βιβλιοθήκης

Λίγο πριν τελειώσουμε με αυτήν την παρουσίαση, θα ήταν καλό να παραθέσουμε και λίγο χώρο για την παρουσίαση τσυ πηγαίου κώδικα για τον οποίο κοπιάσαμε τόσο πολύ και ήμαστε υπερήφανοι. Στις επόμενες σελίδες θα μπορέσετε να μελετήσετε λεπτομερώς όλα τα κομμάτια που συζητήθηκαν παραπάνω, καθώς και κομμάτια που παραλείψαμε λόγω του βοηθητικού τους ρόλου.

using System;

using System.Collections.Generic;

using System.Text;

using System.Data;

using Systera.Windows.Forms;

using System.Drawing;

using System.10;

using System.Xml;

using System.Net.Sockets;

using System.Threading;

using MySql.Data.MySqlClient;

using System.Data.OracleClient;

using System.Data.SqlClient;

namespace myLibrary {

public class EnviromentSettings {

private int ServerPort;

public string DatabaseName;

public string DBMS;

public int SQLPort;

public string SQLIP_A;

public string SQLIP_B;

public string SQLIP_C;

public string SQLIP_D;

public EnviromentSettings() i

StreamReader rd = new

StreamReader(Application.StartupPath.ToStringO + " W s e t t i n g s .conf");

//StreamReader rd = new

StreamReader ("C: WServerDirectoryWsettings . conf ") ; StreamReader rd2 = new

StreamReader(Application.StartupPath.ToStringO + " W port.conf”);

//StreamReader rd2 = new StreamReader ("C: W S e r v e r D i rectoryWport. conf") ;

SQLIP_A = rd.ReadLine0 ; SQLIP_B = rd.ReadLine0 ; SQLIP_C = rd.ReadLine0 ; SQLIP_D = rd.ReadLine0 ; SQLPort = int.Parse(rd.ReadLine0);

DatabaseName = rd.ReadLine();

DBMS = r d .ReadLine();

Τμήμα Βιομηχανικής Πληροφορικής

Δημιουρνία δυναμικής βιβλιοθήκης y ia την εξαγωνή και αποθήκευση ______________ ρυθμίσεων νραφικού περιβάλλοντος εφαρμογών

ServerPort = rd2.Close 0 ;

it. Parse (rd2.ReadLine() ) ;

public class ImportExport {

struct myObject public public public public public public public

string type;

Point point;

int colorRed;

int colorGreen;

int colorBlue;

string text;

Size size;

bool visible;

public void ExportToXml(Form a, string serial) {

XmlTextWriter writer = new

XmlTextWriter(Application.StartupPath.ToStringO + "\\E:

serial + ".xml", null);

//XmlTextWriter writer = new

XmlTextWriter ("C: WClientD i r e c t o r y W E x p o r t s W " + serial

".xml",null);

writer.Formatting = Formatting.Indented;

writer.WriteStartDocument{);

writer.WriteComment("this is my comment");

writer.WriteStartElement("root");

a.Controls.Count; i++)

writer.WriteStartElement("Object");

writer.WriteStartElement("Type");

writer.WriteString(a.Controls[i].ToString());

writer.WriteEndElement();

writer.WriteStartElement("Name");

writer.WriteString(a.Controls[i].Name.ToString());

writer.WriteEndElement();

Δημιουρνία δυναμικής βιβλιοθήκης y ia την εξανωγή και αποθήκευση ______________ρυθμίσεων γραφικού περιβάλλοντος εφαρμονών_____________

writer.WriteStartElement("Υ”);

writer.WriteString(a.Controls[i].Location.Y.ToString{));

writer.WriteEndElement() ; writer.WriteEndElementO;

writer.WriteStartElement("Green") ;

writer.WriteStartElement("Blue");

writer.WriteString (a.Controls [i] .BaclcColor. B. ToString () ) ; writer.WriteEndElement() ; writer.WriteEndElement() ; writer.WriteStartElement("Text") ;

writer.WriteString(a.Controls[i].Text.ToString()) ; writer.WriteEndElement();

writer.WriteStartElement("Height");

writer.WriteString(a.Controls[i].Height.ToString());

writer.WriteEndElement();

writer.WriteStartElement("Width");

writer.WriteString(a.Controls[i].Width.ToString());

writer.WriteEndElement();

writer.WriteStartElement("Visible");

writer.WriteString(a .Controls[i ].Visible.ToString());

writer.WriteEndElement();

writer.WriteEndElement();

writer.WriteEndElement();

writer.WriteEndDocument();

writer.Close();

public void ImportFromXml(Form a, string serial) i

XmlTextReader reader = new

XmlTextReader (Application.StartupPath.ToString() + " W D o w n l o a d s W " + serial + ".xml");

//XmlTextReader reader = new

XmlTextReader("C:\\ClientDirectory\\Downloads\\" + serial + ".xml");

myObj ect mo = new myObj e c t ();

reader.WhitespaceHandling = WhitespaceHandling.None;

Τμήμα Βιομηχανικής Πληροφορικής

Δημιουρνία δυναμικής βιβλιοθήκης y ia την εξανωνή και αποθήκευση ______________ ρυθμίσεων γραφικού περιβάλλοντος εφαρμογών_____________

while (reader.Read()) {

if (reader.NodeType == XmlNodeType.Element ) ί

if (reader.Name.ToStringO == "Object") {

reader.ReadToFollowing("Type");

reader.Read();

mo.type = r e a d e r . V a l u e . S p l i t [0];

reader.ReadToFollowing{"Name");

reader.Read 0 ;

mo. name = reader.Value.ToStringO;

reader.ReadToFollowing("X");

reader.Read 0 ; mo.point.X = int.Parse(reader.Value.ToStringO);

reader.ReadToFollowing("Y");

reader.Read 0 ; int.Parse(reader.Value.ToString());

reader.ReadToFollowing("Red");

reader.Rea d ();

mo.colorRed = int.Parse(reader.Value.ToStringO);

reader.ReadToFollowing("Green");

reader.Read 0 ; mo.colorGreen = int.Parse(reader.Value.ToStringO);

reader.ReadToFollowing("Blue");

reader.Read();

mo.colorBlue = int.Parse(reader.Value.ToString());

reader.ReadToFollowing("Text");

reader.Read();

the text element node the next node

if (reader.NodeType ==

XmlNodeType.Element)//if this node is an element, means that i value is assigned

//find

reader.Read();

mo.size.Height = it. Par se (reader. Value. ToString () ) ;

= reader.Value.ToStringO;

Δημιουρνία δυναμικής βιβλιοθήκης για την εξαγωγή και αποθήκευση ρυθμίσεων γραφικού περιβάλλοντος εφαρμογών_____________

mo.size.Height = int.Parse(reader.Value.ToStringO) ;

}

reader.ReadToFollowing("Width”);

reader.Read 0 ; mo.size.Width = int.Parse(reader.Value.ToString());

reader.ReadToFollowing("Visible");

reader.Rea d ();

mo.visible = bool.Parse(reader.Value.ToStringO);

for (int i = 0; : a .Controls.Count; i++)

(a.Controls [i] .ToStringO .SplitC, ' ) [0] ==

a.Controls[i].Name == mo.name)

Color.FromArgb(mo.colorRed,

} }//for }//if }//if }//while

a.Controls[i].Location = mo.point;

a.Controls[i].Size = mo.size;

a.Controls[i].BackColor = ).colorGreen, m o .colorBlue);

a.Controls[i].Text = mo.text;

a.Controls[i].Visible = mo.visible;

brea)c;

public class Client public string ConnectToIP;

public int ConnectToPort;

public Client() {

StreamReader reader = new

StreamReader(Application.StartupPath.ToStringO + " W s e t t i n g s .conf");

//StreamReader reader = new StreamReader ("C: WClientDirectoryWsettings. conf") ;

ConnectToIP = reader.ReadLine0 +

ConnectToIP = ConnectToIP + reader.ReadLine() + ConnectToIP “ ConnectToIP + reader.ReadLine() + ConnectToIP = ConnectToIP + reader.ReadLine();

ConnectToPort = int.Parse(reader.ReadLine());

)

public void Upload(string serialNum, string IP, int port) {

try

Τμήμα Βιομηχανικής Πληροφορικής

Δημιουρνία δυναμικής βιβλιοθήκης για την εξαγωγή και αποθήκευση ______________ ρυθμίσεων γραφικού περιβάλλοντος εφαρμογών_____________

TcpClient tcpclient = new TcpClient(IP, port);//create tcp client for SendFileLine method

Networ)cStream networkstream = tcpclient.GetStream();

SendRead sendread = new SendReadO;

FileManager filemanager = new FileManager();

string line, s = Application.StartupPath.ToString() h

" W E x p o r t s W " ;

//string line, s = "C:\\ClientDirectory\\Exports\\";

sendread. SendLine ("upload", tcpclient, networkstream); //send upload signal

Console.ReadLine();

sendread.SendLine(serialNum, tcpclient, networkstream); //send clients serial number

Console.ReadLine();

int linesNum = filemanager.CountFileLines(s + serialNum + ".xml"); //count the lines of the file

sendread.SendLine(linesNum.ToString0 , tcpclient, networkstream); //send the lines of the file

FileStream fstrm = new FileStream(s + serialNum +

".xml", FileMode.Open, FileAccess.Read);

StreamReader rw = new StreamReader(fstrm);

while ((line = rw.ReadLine()) != null)

networkstream);

sendread.SendLine(line, tcpclient, //send every line of the file

Console.ReadLine();

catch (Exception e) {

MessageBox.Show(e.Message.ToStringO);

} )//Upload

public void Download(string serialNum, string IP, : port ) string temp;

int NumOfLines = 0;

string path = Application.StartupPath.ToString() +

" W t m p W " ;

//string path = "C: W C l i e n t D i r e c t o r y W t m p W " ; string repository = Application.StartupPath.ToString() +

"\\Downloads\\";

//string repository = "C: WClientDireo t o r y W D o w n l o a d s W " ; string data;

try

Δημιουργία δυναμικής βιβλιοθήκης για την εξαγωγή και αποθήκευση ______________ρυθμίσεων γραφικού περιβάλλοντος εφαρμογών_____________

TcpClient tcpclient = new TcpClient(IP, port);//create tcp client for SendFileLine method

NetworkStream networkstream = tcpclient.GetStream();

SendRead sendread = new SendReadO;

FileManager filemanager = new FileManager();

sendread.SendLine("download", tcpclient, networkstream); //send download signal

sendread.SendLine(serialNum, tcpclient, networkstream); //send serial number

networkstream)

temp = sendread.ReadLine(tcpclient, networkstream);

NumOfLines = int.Parse(temp);

for (int i = 0; i < NumOfLines; i++) //read every {

data = sendread.ReadLine(tcpclient,

filemanager.AddLine(path + serialNum + ".xml".

}

System.10.File.Copy(path + serialNum + "

repository + serialNum + ".xml", true);

System.10.File.Delete(path + serialNum ^ }

catch (Exception e) {

MessageBox.Show(e.Message.ToStringO);

public string login(string username, string password, string IP, int port)

{

string serial = "-1";

try {

Tcpclient tcpclient = new TcpClient(IP, port);//create tcp client for SendFileLine method

Networkstream networkstream = tcpclient.GetStream();

SendRead sendread = new SendRead();

FileManager filemanager = new FileManager();

sendread.SendLine("login", tcpclient, networkstream);

//send login s

networkstream)

sendread.SendLine(username, tcpclient.

Τμήμα Βιομηχανικής Πληροφορικής

Δημιουργία δυναμικής βιβλιοθήκης για την εξαγωγή και αποθήκευση ρυθμίσεων γραφικού περιβάλλοντος εφαρμογών

networkstream);

sendread.SendLine(password, tcpclient,

serial = sendread.ReadLine(tcpclient, networkstream);

}

catch (Exception e) {

MessageBox.Show(e.Message.ToStringO);

} return serial;

}//login

public class ThreadedTcpSrvr (

private TcpListener client;

private Thread myTCPserver;

public ThreadedTcpSrvr() {

int result = 0;

StreamReader reader = new

StreamReader(Application.StartupPath.ToString() + " W p o r t .conf");

//StreamReader reader = new StreamReader("C:WServerDirectoryWport.conf");

if (int.TryParse(reader.ReadLine0 , out result)) {

if (result != 0) (

client = new TcpListener(result);

} }

client = new TcpListener(1800);

reader.Close 0 ;

public void TCPserverLoop() {

client.Start();

while ('client. PendingO)

Δημιουρνία δυναμικής βιβλιοθήκης για την εξαγωγή και ατιοθήκευση ______________ρυθμίσεων γραφικού περιβάλλοντος εφαρμογών_____________

Thread.Sleep(1000);

ConnectionThread newconnection = new ConnectionThread();

newconnection.threadListener = this.client;

Thread newthread = new Thread(new

public void TerminateTCPserver() {

this.myTCPserver.Abort 0 ; }

public void StartTCPserver() {

this.myTCPserver.Start();

public class ConnectionThread {

public TcpListener threadListener;

//private static int connections = 0;

public void ServeUpload(TcpClient tc, NetworkStream ns) {

string serial;

string temp;

string path = Application.StartupPath.ToString() +

" W t m p W " ;

//string path = "C: W S e r v e r D i r e c t o r y W t m p W " ; string repository = Application.StartupPath.ToString() ■

"WReposi t o r y W " ;

//string repository =

"C: W ServerDirectoryWRepositoryW" ; int NumOfLines = 0 ;

SQLRelated sqlrelated = new SQLRelated();

SQLRelated.SQLstruct sqlstruct = new SQLRelated.SQLstruct();

EnviromentSettings envset = new EnviromentSettings();

FileManager filemanager = new FileManager();

SendRead sendread = new SendRead();

try i

switch (envset.DBMS) {

case "ORACLE":

sqlstruct =

sqlrelated.CheckUserExistanceOracle(int.Parse(serial), envset);

break;

case "MySQL":

Τμήμα Βιομηχανικής Πληροφορικής

Δημιουρνία δυναμικής βιβλιοθήκης yia την εξαγωνή και αποθήκευση ρυθμίσεων νραφικού περιβάλλσντος εφαρμονών

sqlstruct =

sqlrelated.CheckDserExistanceMySQL(int.Parse(serial), envset);

break;

case "MSSQLServer":

sqlstruct =

sqlrelated.CheckUserExistanceMSSQLServer(int.Parse(serial), envset);

if (sqlstruct.password.Length != 0 &&

sqlstruct.username.Length != 0) {

temp = sendread.ReadLine(tc, ns);

if (int.TryParse(temp, out NumOfLines)) //check if the signal is a number

NumOfLines = int.Parse(temp);

System.10.File.Copy((path + serial + ".xml"), (repository + serial + ".xml"), true);

System.10.File.Delete(path + serial + ".xml");

) }

catch (Exception e) {

Console.WriteLine(e.Message) ;

public void ServeDownload(TcpClient tc, NetworkStream ns) (

string temp;

string line;

int serial = 0;

int counter = 0;

string path = Application.StartupPath.ToString() +

"WRepos i t o r y W " ;

//string path = "C: WServerDirectoryWRepositoryW";

SQLRelated sqlrelated = new SQLRelated();

SQLRelated.SQLstruct sqlstruct = new SQLRelated.SQLstruct 0 ;

EnviromentSettings envset = new EnviromentSettings();

SendRead sendread = new SendReadO;

FileManager filemanager = new FileManager();

Δημιουρνία δυναμικής βιβλιοθήκης για την εξαγωγή και αποθήκευση ______________ρυθμίσεων γραφικού περιβάλλοντος εφαρμογών_____________

try {

temp = sendread.ReadLine(to, ns); //read the serial number of the client

if (int.TryParse {temp, out serial)) //checlc if the signal is a number

i

serial = int.Parse(temp);

switch (envset.DBMS) {

case "ORACLE":

sqlstruct = sqlrelated.CheclcUserExistanceOracle (serial, envset) ;

brealc;

case "MySQL":

sqlstruct = sqlrelated. Chec)iUserExistanceMySQL (serial, envset) ;

break;

case "MSSQLServer":

sqlstruct =

sqlrelated.CheckUserExistanceMSSQLServer(serial, envset);

if (sqlstruct.password.Length != 0 &&

sqlstruct.username.Length != 0)

counter = filemanager.CountFileLines(path H sendread.SendLine(counter.ToString(), tc.

■s);

FileStream fstrm = new FileStream(path + temp + ".xml", FileMode.Open, FileAccess.Read, FileShare.Read);

StreamReader rw = new StreamReader(fstrm);

while {(line = rw.ReadLine{)) != null) {

sendread.SendLine(line, tc, ns); //send every line of the file

catch (Exception e) {

Console.WriteLine(e.ToString{));

} }//ServeDownload

public void ServeLogin(TcpClient tc, NetworkStr<

(

string username;

string password;

string serial = "-1";

Τμήμα Βιομηχανικής Πληροφορικής

Δημιουργία δυναμικής βιβλιοθήκης για την εξαγωγή και αποθήκευση ______________ ρυθμίσεων γραφυιού περιβάλλοντος εφαρμογών

int temp = 0 ;

SQLRelated sqlrelated = new SQLRelated();

EnviromentSettings envset = new EnviromentSettings();

SendRead sendread = new SendRead();

username = sendread.ReadLine{tc, ns);

password = sendread.ReadLine(tc, ns);

switch (envset.DBMS) {

case "ORACLE":

temp =

sqlrelated.RetrieveSerialOracle(username, password, envset);

brea)c;

case "MySQL":

temp =

sqlrelated.RetrieveSerialMySQL(username, password, envset);

b r e a k ; case "MSSQLServer":

temp =

sqlrelated.RetrieveSerialMSSQLServer(username, password, envset);

break;

)

/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / //check if the user exists in the database and return the serial

/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / if (temp != 0)

{

sendread.SendLine(temp.ToString(), tc, ns);

} {

//store the serial into the serial string sendread.SendLine(serial, tc, ns);

} }

catch (Exception e) {

Console.WriteLine( e .ToString());

) }//Servelogin

public void HandleConnection() {

string responseData;

byte[] data = new byte[1024];

Δημιουργία δυναμικής βιβλιοθήκης για την εξαγωγή και αποθήκευση ______________ρυθμίσεων γραφικού περιβάλλοντος εφαρμογών_____________

connections",

SendRead sendobj = new SendRead();

TcpClient client = threadListener.AcceptTcpClient();

NetworkStream ns = client.GetStream();

/ / c o n n e c tio n s + + ;

//Console.WriteLine("New client accepted: {0} active connections);

while (true) {

responseData = sendobj.ReadLine(client, ns);

if (responseData == "upload") {

this.ServeUpload(client, ns);

)

else if (responseData == "download") (

this.ServeDownload(client, ns);

}

else if (responseData == "login") {

this.ServeLogin(client, ns);

) { )

connections", ns.CloseO ; client.Close();

//connections— ;

//Console.WriteLine("Client disconnected: (0) active connections 1;

public class SendRead

public string ReadLine(TcpClient tc, NetworkStream ns)

byte[] data = new b y t e [1024];

if (ns.CanRead && ns.CanWrite)

Τμήμα Βιομηχανικής Πληροφορικής T.E .I. Καβάλας

Δημιουρνία δυναμικής βιβλιοθήκης y ia την εξαγωνή και αποθήκευση ______________ ρυθμίσεων νραφικού περιβάλλοντος εφαρμονών

5.Read(data, 0, data.Length);

.3.Write(data, 0, recv) ;

this stream");

if (ins.CanRead) {

Console.WriteLine("cannot write data to this tc.Close();

} {

if (Ins.CanWrite) {

Console.WriteLine("cannot read data from tc.CloseO ;

}

catch (Exception e) i

Console.WriteLine(e);

public void SendLine(string content, TcpClient tc, NetworJcStream ns) //Give the content of the file in order transmit it

byte[] data = new b yt e [1024];

if (ns.CanWrite && ns.CanRead) {

data = new byte[1024];

data = Encoding.ASCII.GetBytes(content);

ns.Write(data, 0, data.Length);

ns.Read(data, 0, data.Length);

String returndata = Encoding.ASCII.GetString(data) ;

Console.WriteLine("Host returned:

returndata);

Δημιουργία δυναμικής βιβλιοθήκης για την εξαγωγή και αποθήκευση ρυθμίσεων γραφικού περιβάλλοντος εφαρμογών

this stream");

if (Ins.CanRead) ί

Console.WriteLine("cannot write data to this tc.Close();

) {

if {Ins.CanWrite) ί

Console.WriteLine("cannot read data from tc.Close 0 ;

}

public class FileManager {

public void AddLine(string filename, string data) {

FileStream fstrm = new FileStream(filename, FileMode.Append, FileAccess.Write);

StreamWriter wr = new StreamWriter(fstrm);

if (fstrm.CanWrite) {

wr.WriteLine(data);

public int CountFileLines(string path) {

int NumOfLines = 0;

string line;

try {

FileStream fstrm = : FileMode.Open, FileAccess.Read);

StreamReader rw = n if (fstrm.CanRead) {

while ((line = rw {

NumOfLines++;

iw FileStream (path, I StreamReader(fstrm) ;

j.ReadLineO ) != null)

fstrm.Close 0 ;

Τμήμα Βιομηχανικής Πληροφορικής

Δημιουρνία δυναμικής βιβλιοθήκης yia την εξανωνή και αποθήκευση ______________ ρυθμίσεων γραφικού περιβάλλοντος εφαρμονών___________

Check the path");

)

fstrm.Close();

rw.CloseO;

Console.WriteLine("Cannot read from this file.

catch (Exception e) {

Console.WriteLine(e.ToString());

}

return NumOfLines;

public class SQLRelated (

public struct SQLstruct public string username;

public string password;

public int RetrieveSerialMySQL(string username, string pwd, EnviromentSettings env)

(

string query = "SELECT id FROM users WHERE username = + username + "' AND pwd = '" + pwd +

string connectionstringMySQL = "datasource=" + env.SQLIP_A + + env.SQLIP_B + + env.SQLIP_C + "." + env.SQLIP_D + ";username=antigoni;password=tasos;database=diploma;";

//string connectionstringMySQL =

"datasource=localhost;username=antigoni;password=tasos;database=diplo

IDbConnection dbcon = new MySqlConnection(connectionstringMySQL);

IDbCommand dbcmd = dbcon.CreateCommand();

dbcon.Open();

while (reader.ReadO ) (

result = (int)reader["id"];

reader.Close();

reader = null;

dbcmd.Dispose();

Δημιουργία δυναμικής βιβλιοθήκης για την εξαγωγή και αποθήκευση ______________ρυθμίσεων γραφικού περιβάλλοντος εφαρμογών_____________

dbcmd = null;

dbcon.CloseO ; dbcon = null;

)

catch (Exception e) {

MessageBox.Show(e.ToString());

return result;

}

pxoblic int RetrieveSerialOracle (string username, string pwd, EnviromentSettings env)

{

int result = 0;

try ί

string query = "SELECT id FROM users WHERE username = '" + username + "' AND pwd = '" + pwd + " ;

//string connectionstringOracle = "Data Source=" + env.SQLIP_A + + env.SQLIP_B + + env.SQLIP_C + + env.SQLIP_D + ";User ID=antigoni;Password=tasos";

string connectionstringOracle = "Data Source=diploma;User ID=antigoni;Password=tasos";

IDbConnection dbcon = new

OracleConnection(connectionstringOracle); //Oracle connection

= dbcon.CreateCommandO;

while (reader.Read 0) {

result = int.Parse(reader["id"].ToStringO);

) reader.Close 0 ; reader = null;

dbcmd.CommandText = query;

dbcmd.ExecuteNonQuery();

dbcmd.Dispose();

dbcmd = null;

dbcon.Close();

dbcon = null;

}

catch (Exception e) {

MessageBox.Show(e.ToStringO);

) return result;

)

public int RetrieveSerialMSSQLServer(string username, string pwd, EnviromentSettings env)

Τμήμα Βιομηχανικής Πληροφορικής

Δημιουρνία δυναμικής βιβλιοθήκης yia την εξαγωνή και αποθήκευση ______________ ρυθμίσεων νραφικού περιβάλλοντος εφαρμονών

try (

string query = "SELECT id FROM users WHERE username = + username + AND pwd = '" + pwd +

//string connectionstringMSSQLServer = "Server =" + env.SQLIP_A + + env.SQLIP_B + + env.SQLIP C + + env.SQLIP_D + Database = diploma; User ID = antigoni; Password = tasos";

//string connectionstringMSSQLServer = "Server

“localhost; Database = diploma; User ID = tasos; Password = antigoni";

//string connectionstringMSSQLServer = "Server

=localhost; Database = diploma; User ID = antigoni; Password = tasos";

//string connectionstringMSSQLServer = "Data Source="

+ env.SQLIP_A + "." + env.SQLIP_B + + env.SQLIP_C + "." + env.SQLIP_D + ",1433;Network Library=DBMSSOCN;Initial Catalog=diploma;User ID=antigoni;Password=tasos;";

//string connectionstringMSSQLServer = "Server

=laptop\\sqlexpress; Database = diploma; User ID = antigoni; Password

= tasos";

string connectionstringMSSQLServer = "Server =" + env.DatabaseName + "; Database = diploma; User ID = antigoni;

Password = tasos";

IDbConnection dbcon = new

SqlConnection(connectionstringMSSQLServer); //MSSQL Server connection

IDbCommand dbcmd = dbcon.CreateCommand{);

dbcon.Open();

dbcmd.CommandText = query;

IDataReader reader = dbcmd.ExecuteReader();

while (reader.Read0) (

result = (int)reader["id"];

}

reader.CloseO ; reader = null;

dbcmd.Dispose();

dbcmd = null;

dbcon.Close();

dbcon = null;

)

catch (Exception e) {

MessageBox.Show(e.ToString());

} return result;

public SQLstruct CheckUserExistanceMySQL(int serial, EnviromentSettings env)

SQLstruct mystruct = r try

Δημιουργία δυναμικής βιβλιοθήκης για την εξαγωγή και αποθήκευση ρυθμίσεων γραφικού περιβάλλοντος εφαρμογών

string query = "SELECT username, pwd FROM users WHERE id = '" + serial + "';";

string connectionstringMySQL = "datasource=" + env.SQLIP_A + + env.SQLIP_B + + env.SQLIP_C + + env.SQLIP_D + ";username=antigoni;password=tasos;database=diploma;

//string connectionstringMySQL =

"datasource=localhost;username=antigoni;password=tasos;database=diplo

IDbConnection dbcon = new

MySqlConnection(connectionstringMySQL); //Default connection is MySQL;

IDbCoiranand dbcmd = dbcon.CreateCommand() ; dbcon.Open{);

while (reader.Read())

mystruct.username = reader["username"].ToStringO;

mystruct.password = reader["pwd"].ToString();

)

reader.Close 0 ; reader = null;

db cmd.Dispose();

dbcmd = null;

dbcon.Close();

dbcon = null;

}

catch (Exception e) (

MessageBox.Show(e.ToStringO);

}

return mystruct;

SQLstruct mystruct = new SQLstruct();

try ί

string query = "SELECT username, pwd FROM users WHERE id = '" + serial + "'";

//string connectionstringOracle = "Data Source=" + env.SQLIP_A + "." + env.SQLIPB + "." + env.SQLIP_C + "." + env.SQLIP_D + ";User ID=antigoni;Password=tasos";

string connectionstringOracle = "Data Source=diploma;Dser ID=antigoni;Password=tasos";

IDbConnection dbcon = new

OracleConnection(connectionstringOracle); //Oracle connection IDbCommand dbcmd = dbcon.CreateCommand();

dbcon.Open();

Τμήμα Βιομηχανικής Πληροφορικής

Δημιουρνία δυναμικής βιβλιοθήκης yia την εξανωνή και αποθήκευση ______________ ρυθμίσεων γραφικού περιβάλλοντος εφαρμονών

dbcmd.ConimandText = query;

IDataReader reader = dbcmd.ExecuteReader();

while (reader.ReadO ) {

mystruct.username = reader["username"].ToStringO;

^ mystruct.password = reader["pwd"].ToString();

reader.CloseO ; reader = null;

dbcmd.CommandText = query;

dbcmd.ExecuteNonQueryO;

dbcmd.Dispose();

dbcmd = null;

dbcon.Close{);

dbcon = null;

catch (Exception e) {

MessageBox.Show(e.ToString());

return mystruct;

)

public SQLstruct CheckUserExistanceMSSQLServer(int serial

EnviromentSettings env) '

i

SQLstruct mystruct = new SQLstruct();

try {

string query = "SELECT username, pwd FROM users WHERE id = '

//string connectionstringMSSQLServer =

’." + env.SQLIPB + "." + env.SQLIP_C +

’; Database = diploma; User ID = antigoni; Password = env.SQLIP_A

env.SQLIP_D tasos";

//string connectionstringMSSQLServer = "Server

=localhost; Database = diploma; User ID = tasos; Password = antigoni";

//string connectionstringMSSQLServer = "Server

=localhost; Database = diploma; User ID = antigoni; Password = tasos";

//string connectionstringMSSQLServer = "Data Source="

+ env.SQLIP_A + "." + env.SQLIP_B + "." + env.SQLIP_C + "." + env.SQLIP_D + ",1433;Network Library=DBMSSOCN;Initial Catalog=diploma;User ID=antigoni;Password=tasos;";

//string connectionstringMSSQLServer = "Server

=laptop\\sqlexpress; Database - diploma; User ID = antigoni; Password string connectionstringMSSQLServer = "Server =" + env.DatabaseName + "; Database = diploma; User ID = antigoni;

Password = tasos";

Δημιουρνία δυναμικής βιβλιοθήκης yia την εξανωγή και αποθήκευση ρυθμίσεων γραφικού περιβάλλοντος εφαρμογών

IDbConnection dbcon = new SqlConnection(connectionstringMSSQLServer);

IDbCommand dbcmd = dbcon.CreateCoiranand();

dbcon.O p e n ();

while (reader.Read()) mystruct

.1

reader["username"].ToString();

mystruct.password = reader["pwd"].ToString();

)

reader.Close();

reader = null;

dbcmd.Dispose();

dbcmd = null;

dbcon.Close () ; dbcon = null;

}

catch (Exception e) {

MessageBox.Show(e.ToString());

}

return mystruct;

try {

string query = "INSERT INTO diploma.users(username, pwd, first_name, last_name, birthdate) VALUES ('" + usr + "' , + pwi + "■, '" + first_name + "','" + last_name + "', ·" + birthdate + "');"

string connectionstringMySQL = "datasource=" + env.SQLIP_A + "." + env.SQLIP_B + + env.SQLIP_C + "." + env.SQLIP_D + ";username=antigoni;password=tasos;database=diploma;";

IDbConnection dbcon = new MySqlConnection(connectionstringMySQL);

IDbCommand dbcmd = dbcon.CreateCommand();

dbcon.Open();

MessageBox.Show("User Created!");

dbcmd.Dispose();

dbcmd = null;

dbcon.Close();

dbcon = null;

Τμήμα Βιομηχανικής Πληροφορικής

Δημιουρνία δυναμικής βιβλιοθήκης για την εξανωνή και αποθήκευση ρυθμίσεων νραφικού περιβάλλοντος εφαρμονών

}

catch (Exceptit

public bool CreateAccountOracle(string usr, string pwd, string first_name, string last_name, string birthdate, EnviromentSettings env)

{ try (

//string query = "INSERT INTO users(username, pwd, first_name, last_name, birthdate) VALUES ('" + usr + + pwd +

+ first_name + + last_name + "', + birthdate + string query = "INSERT INTO users(username, pwd, first_name, last_name, birthdate) VALUES ("' + usr + + pwd +

+ first_name + + last_name + to_date(" + birthdate H

",’YYYYMMDD'))";

//string connectionstringOracle = "Data Source=" + env. S Q L I P A + "." + e n v.SQLIPB + "." + env.SQ L I P C + "." + env.SQ L I P D + ";User ID=antigoni;Password=tasos";

string connectionstringOracle = "Data Source=diploma;User ID=antigoni;Password=tasos";

IDbConnection dbcon = new OracleConnection(connectionstringOracle);

dbcmd.CommandText = query;

dbcmd.ExecuteScalar0 ; MessageBox.Show("User Created!");

dbcmd.Dispose();

dbcmd = null;

dbcon.Close 0 ; dbcon = null;

}

catch (Exception e)

public bool CreateAccountMSSQLServer(string usr, string pwd, string first_name, string last_name, string birthdate,

EnviromentSettings env)

Δημιουργία δυναμικής βιβλιοθήκης για την εξαγωγή και ατχοθήκευση ρυθμίσεων γραφικού περιβάλλοντος εφαρμογών

string query = "INSERT INTO users(username, pwd, first_name, last_name, birthdate) VALUES ('" + usr + + pwd +

+ first_name + + last_name + + birthdate + //string connectionstringMSSQLServer = "Server =" + env.SQLIP_A + + env.SQLIP_B + "." + env.SQLIP_C + + env.SQLIP_D + Database = diploma; User ID = antigoni; Password =

//string connectionstringMSSQLServer = "Server

=localhost; Database = diploma; User ID = tasos; Password = antigoni";

//string connectionstringMSSQLServer = "Server

=localhost; Database = diploma; User ID = antigoni; Password = //string connectionstringMSSQLServer = "Data Source="

+ env.SQLIP_A + "." + env.SQLIP_B + + env.SQLIP_C + + env.SQLIP D + ", 1433;Network Library=DBMSSOCN;Initial Catalog=diploma;User ID=antigoni;Password=tasos;";

//string connectionstringMSSQLServer = "Server

=laptop\\sqlexpress; Database = diploma; User ID = antigoni; Password string connectionstringMSSQLServer = "Server =" + env.DatabaseName + "; Database = diploma; User ID = antigoni;

Password = tasos";

IDbConnection dbcon = new SqlConnection(connectionstringMSSQLServer) ;

IDbCommand dbcmd = dbcon.CreateCommand();

dbcon.Ope n ();

MessageBox.Show("User Created!");

dbcmd.Dispose();

dbcmd = null;

dbcon.Close();

dbcon = null;

return true;

)

catch (Exception e)

public bool DeleteAccountMySQL(string usr, string pwd, string lame, string last_name, string birthdate, EnviromentSettings

string query = usr + "' AND pwd = '" + pwd H ' AND last_name = "' + last_n;

’DELETE FROM users WHERE username = '"

"' AND first_ncime = '" + first_name + t\e + "' AND birthdate = '" + birthdate

Τμήμα Βιομηχανικής Πληροφορικής

Δημιουρνία δυναμικής βιβλιοθήκης yia την εξανωνή και αποθήκευση ρυθμίσεων νραφικσύ περιβάλλοντος εφαρμογών

string connectionstringMySQL = "datasource=" + env.SQLIP_A + + env.SQLIP_B + + env.SQLIP_C + + env.SQLIP_D + ";username=antigoni;password=tasos;database=diploma;'

IDbConnection dbcon = new MySqlConnection(connectionstringMySQL);

IDbConunand dbcmd = dbcon.CreateCommand() ; dbcon.Ope n () ;

MessageBox.Sh o w ("User Deleted!");

dbcmd.Dispose{) ; dbcmd = null;

dbcon.Close();

dbcon = null;

return true;

}

catch (Exception e) {

MessageBox.Show(e.Message);

return false;

public bool DeleteAccountOracle(string usr, string pwd, string first_name, string last_name, string birthdate, EnviromentSettings env)

{ try {

string query = "DELETE FROM users WHERE username = + usr + "' AND pwd = '" + pwd + "' AND f irst_name = '" + first_naii AND last_name = "' + last_name + AND birthdate = to_date(" H birthdate + ",'YYYYMMDD')";

//string connectionstringOracle = "Data Source=" h env.SQLIP_A + + env.SQLIP_B + + env.SQLIP_C + + env.SQLIP_D + ";Oser ID=antigoni;Password=tasos";

string connectionstringOracle = "Data Source=diploma;User ID=antigoni;Password=tasos";

IDbConnection dbcon = new OracleConnection(connectionstringOracle);

IDbCommand dbcmd = dbcon.CreateCommand();

dbcon.Open();

MessageBox.Show("User Deleted!");

dbcmd.Dispose();

dbcmd = null;

dbcon.Close 0 ; dbcon = null;

return true;

Τμήμα Βιομηχανικής Πληροφορικής

Documentos relacionados