viewgit/index.php:465 Only variables should be passed by reference [2048]
viewgit/index.php:466 Non-static method GeSHi::get_language_name_from_extension() should not be called statically [2048]
using System; using System.Collections; using System.Threading; using System.IO.Compression; using System.Text.RegularExpressions; using System.IO; using Tamir.SharpSsh; using System.Data.SQLite; using Dizzy; namespace Dizzy { public class ProtocolException : ApplicationException { public ProtocolException () {} public ProtocolException (string Message) {} } public class Protocol { // I transfer attivi public delegate void Del (string src, string dest, int transferredBytes, int totalBytes, string message); Thread finder; // Dati letti dal thread che cerca per capire cosa cercare string keyword, user, type; GlobalConfig config; public delegate void ProtocolEvent (); // Questo evento sembra non dare problemi perché ogni volta che // è emesso aspettiamo che l'utente inserisca i dati necessari // con while(!this.config.authenticated) {} public event ProtocolEvent AuthenticationRequired; public Protocol (ref GlobalConfig config) { this.config = config; // this.UpdateFileList (); } public void Search(string keyword, string user, string type) { if (this.finder != null && this.finder.IsAlive) { Log.Info ("Ricerca in corso"); return; } if (!System.IO.File.Exists(this.config.ListFileName ())) { // Dovremmo notificare l'utente che non c'è la lista Log.Warning ("La lista non è presente, chiedo di scaricarla"); this.UpdateFileList (); } else { Log.Info ("Avvio la ricerca nel database"); this.keyword = keyword; this.user = user; this.type = type; this.finder.Start (); } } protected File ReadFile(StreamReader file) { string path = file.ReadLine(); string user = file.ReadLine (); int size = System.Convert.ToInt32(file.ReadLine (), 10); } protected void _Search() { // Questa funzione viene chiamata quando qualcuno richiede // una ricerca. Inoltre abbiamo la quasi certezza che ne venga // chiamata solo un'istanza nello stesso momento. ArrayList files; try { files = list.Search (this.keyword, this.type, this.user); } catch (Exception e) { // Probabilmente stiamo solamente scaricando il database, // ma tant'è. Log.Error ("Impossibile effettuare la ricerca nel database: " + e.Message); } // this.fileTreeView.Clear (); EventManager.FileTreeViewClear (); foreach(File f in files) { // this.fileTreeView.AddFile (f); EventManager.FileTreeViewAddFile (f); } EventManager.SearchFinished (); if (files.Count == 0) EventManager.ErrorMessage ("Nessun risultato trovato!"); } public void UpdateFileList () { /*if(this.listUpdater != null && this.listUpdater.IsAlive) { Log.Warning ("La lista è già in fase di aggiornamento, non faccio nulla"); return; } this.listUpdater = new Thread (new ThreadStart (this._UpdateFileList)); this.listUpdater.Start (); */ _UpdateFileList (); } protected void _UpdateFileList () { // SFTPConnection s; Sftp s; if (!this.config.authenticated) { Log.Info ("I dati di autenticazione non sono presenti"); this.AuthenticationRequired (); // Aspetto che l'utente abbia fatto. while(!this.config.authenticated) {} Log.Info ("Ho acquisito utente e password"); } EventManager.ListUpdateStarted (); // Inizializziamo la connessione con i dati che supponiamo // di avere. // s = new SFTPConnection (this.config.GetValue("user"), // this.config.password); this.config.password); try { s.Connect (); } catch (Exception e) { Log.Error ("Autenticazione errata (" + e.Message + ")"); this.config.authenticated = false; } if(!this.config.authenticated) { EventManager.ErrorMessage ("Autenticazione fallita"); } else { Log.Info ("Aggiornamento della lista avviato"); // s.Download (new File("/nobackup/robol/index.db", "robol"), // this.config.ConfigDir ()); s.Get("/nobackup/robol/index.db", this.config.ConfigDir() + System.IO.Path.DirectorySeparatorChar + "index.db"); Log.Info ("Lista Aggiornata"); s.Close (); } EventManager.ListUpdateFinished (); } public void Disconnect () { foreach(FileTransfer t in this.transfers) { t.Stop (); } foreach(Thread t in this.threads) { if(t.IsAlive) t.Abort (); } if(this.finder != null && this.finder.IsAlive) { this.finder.Abort (); } } public void Download(File f, string downloadFolder) { // Preparo gli argomento da passare alla funzione. if (!this.config.authenticated) this.AuthenticationRequired (); while(!this.config.authenticated) {} args.Add (f); args.Add (downloadFolder); t.Start (args); this.threads.Add (t); } protected void _Download(object args) { // Questi cast sono piuttosto brutali ma posso passare // solo un oggetto a Download e quindi è il meglio che // mi riesce di fare. File f = (File) ((ArrayList) args)[0]; string downloadFolder = (string) ((ArrayList) args)[1]; Log.Info ("Avvio il download di " + f.name); try { FileTransfer transfer = new FileTransfer (f, this.config.GetValue("user"), this.config.password, downloadFolder); this.transfers.Add (transfer); } catch (Exception e) { Log.Error (e.Message); this.config.authenticated = false; this.Download (f, downloadFolder); } } public void Upload(string f) { // Preparo gli argomento da passare alla funzione. if (!this.config.authenticated) this.AuthenticationRequired (); while(!this.config.authenticated) {} args.Add (f); t.Start (args); this.threads.Add (t); } protected void _Upload(object args) { // Questi cast sono piuttosto brutali ma posso passare // solo un oggetto a Download e quindi è il meglio che // mi riesce di fare. string f = (string) ((ArrayList) args)[0]; Log.Info ("Avvio l'upload di " + f); try { this.transfers.Add (transfer); } catch (Exception e) { Log.Error (e.Message); this.config.authenticated = false; this.Upload (f); } } } public class SFTPConnection { public Sftp sftp; string user; public delegate void SFTPEvent (string src, string dest, int transferredBytes, int totalBytes, string message); public event SFTPEvent TransferStarted; public event SFTPEvent TransferProgress; public event SFTPEvent TransferStopped; public delegate void Del (string src, string dest, int transferredBytes, int totalBytes, string message); public SFTPConnection (string user, string password) { // Inizializziamo il protocollo this.user = user; this.sftp.Password = password; } private void TransferStartedHandler(string src, string dest, int transferredBytes, int totalBytes, string message) { if(TransferStarted != null) TransferStarted(src, dest, transferredBytes, totalBytes, message); } private void TransferProgressHandler(string src, string dest, int transferredBytes, int totalBytes, string message) { if (TransferProgress != null) TransferProgress(src, dest, transferredBytes, totalBytes, message); } private void TransferStoppedHandler(string src, string dest, int transferredBytes, int totalBytes, string message) { if (TransferStopped != null) TransferStopped(src, dest, transferredBytes, totalBytes, message); } public void Connect() { sftp.Connect (22); } public ArrayList SearchFiles() { Console.WriteLine(" => Scan della nobackup"); // ArrayList users = sftp.GetFileList ("/nobackup/"); users.Add("robol"); users.Add("bianchi"); foreach(string folder in users) { if (folder == ".") continue; else if (folder == "..") continue; Console.WriteLine(" => Scan di {0}", folder); try { matches.AddRange (GetFolderContent(folder)); } catch(Exception e) { Console.WriteLine (e.Message); } } Console.WriteLine(" => Scan terminato"); return matches; } protected ArrayList GetFolderContent(string folder) { ArrayList matches, files; File f; string user; files = sftp.GetFileList("/nobackup/" + folder + "/"); foreach(string entry in files) { // Controllo che non sia una cartella. Evidentemente // questo metodo non è affidabile, ma per ora è il meglio // che SFTP ci permetta di fare. if(entry.IndexOf(".") == -1) matches.AddRange(GetFolderContent(folder + "/" + entry)); else if(!entry.StartsWith(".")) { user = folder; if(user.Contains("/")) user = user.Substring(0, user.IndexOf("/")); matches.Add(f); } } return matches; } public void Download(File f, string downloadFolder) { this.sftp.Get (f.path, downloadFolder + Path.DirectorySeparatorChar + f.name); } public void Upload(string filename) { this.sftp.Put(filename, "/nobackup/" + this.user + "/"); } public void Disconnect () { sftp.Close (); } } public class FileTransfer { File file; Gtk.TreeIter iter; SFTPConnection sftp; public delegate void Handler(string src, string dest, int transferredBytes, int totalBytes, string message); public FileTransfer (File f, string user, string password, string downloadFolder) { // Connessione al server this.sftp.Connect (); this.file = f; sftp.Download (this.file, downloadFolder); sftp.Disconnect (); } public void Stop () { this.sftp.Disconnect (); } public void OnTransferStarted (string src, string dest, int transferredBytes, int totalBytes, string message) { EventManager.TaskTreeViewAddTask (file.name, 0); this.iter = EventManager.GetIter (file.name); } public void OnTransferProgress(string src, string dest, int transferredBytes, int totalBytes, string message) { int perc = transferredBytes / (totalBytes / 100); EventManager.TaskTreeViewSetProgress (this.iter, perc); } public void OnTransferStopped (string src, string dest, int transferredBytes, int totalBytes, string message) { EventManager.TaskTreeViewRemove (iter); } } public class FileUpload { string filename; Gtk.TreeIter iter; SFTPConnection sftp; public delegate void Handler(string src, string dest, int transferredBytes, int totalBytes, string message); public FileUpload (string filename, string user, string password) { // Connessione al server this.sftp.Connect (); this.filename = filename; sftp.Upload (this.filename); sftp.Disconnect (); } public void Stop () { this.sftp.Disconnect (); } public void OnTransferStarted (string src, string dest, int transferredBytes, int totalBytes, string message) { EventManager.TaskTreeViewAddTask (filename, 0); this.iter = EventManager.GetIter (filename); } public void OnTransferProgress(string src, string dest, int transferredBytes, int totalBytes, string message) { int perc = transferredBytes / (totalBytes / 100); EventManager.TaskTreeViewSetProgress (iter, perc); } public void OnTransferStopped (string src, string dest, int transferredBytes, int totalBytes, string message) { EventManager.TaskTreeViewRemove (iter); } } public class FileList { GlobalConfig config; SQLiteConnection connection; public FileList(ref GlobalConfig config) { this.config = config; string connectionString = "Data Source=" + this.config.ListFileName () + ";Version=3"; } public ArrayList Search(string keyword, string type, string user) { this.connection.Open (); // Eseguiamo la query SQLiteCommand sqlCmd = this.connection.CreateCommand (); sqlCmd.CommandText = "SELECT * from files WHERE name LIKE '%" + keyword + "%'"; SQLiteDataReader reader = sqlCmd.ExecuteReader (); File tmp; while(reader.Read()) { reader.GetString(2), // User reader.GetString(1), // Name reader.GetInt32(3)); // Size if ( (type == "Qualsiasi" || tmp.type.Name() == type) && (user == "" || user == tmp.user) ) { matches.Add (tmp); } } this.connection.Close (); return matches; } } }