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.Text.RegularExpressions; using System.IO; using Tamir.SharpSsh; namespace Dizzy { public class ProtocolException : ApplicationException { public ProtocolException () {} public ProtocolException (string Message) {} } public class Protocol { // I dati del nostro povero utente. string user, password; // I transfer attivi public delegate void Del (string src, string dest, int transferredBytes, int totalBytes, string message); Thread updater; SFTPConnection sftpUpdater; bool bootStrapped = false; public Protocol (ref GlobalConfig config) { this.user = config.GetValue("user"); this.password = config.password; try { this.sftpUpdater.Connect (); } catch(Exception e) { } this.updater.Start (); } public void Search(string keyword, ref FileTreeView f) { if (this.bootStrapped) { f.Clear (); foreach(File entry in this.fileList) { Match m = Regex.Match(entry.name, keyword.Replace(" ", "|"), RegexOptions.IgnoreCase); if(m.Success) f.AddFile(entry); } } } // Questa ricerca deve girare in un nuovo thread per non // disturbare l'interfaccia grafica. protected void _UpdateFileList () { this.fileList = this.sftpUpdater.SearchFiles (); if(!this.bootStrapped) this.bootStrapped = true; } public void UpdateFileList () { if(this.updater.IsAlive) { Console.WriteLine (" > Update già in corso"); return; // Non è il momento opportuno, l'update è in corso. } this.updater.Start (); } public void Disconnect () { foreach(FileTransfer t in this.transfers) { t.Stop (); } foreach(Thread t in this.threads) { if(t.IsAlive) t.Abort (); } if (this.updater.IsAlive) { this.updater.Abort (); } this.sftpUpdater.Disconnect (); } public void Download(File f, ref TaskTreeView tasks, string downloadFolder) { // Preparo gli argomento da passare alla funzione. args.Add (f); args.Add (tasks); 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]; TaskTreeView tasks = (TaskTreeView) ((ArrayList) args)[1]; string downloadFolder = (string) ((ArrayList) args)[2]; Console.WriteLine (" => Download starting"); this.transfers.Add (transfer); } } public class SFTPConnection { public Sftp sftp; 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.sftp.Password = password; } private void TransferStartedHandler(string src, string dest, int transferredBytes, int totalBytes, string message) { Console.WriteLine (" => TransferStarted"); TransferStarted(src, dest, transferredBytes, totalBytes, message); } private void TransferProgressHandler(string src, string dest, int transferredBytes, int totalBytes, string message) { TransferProgress(src, dest, transferredBytes, totalBytes, message); } private void TransferStoppedHandler(string src, string dest, int transferredBytes, int totalBytes, string message) { 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) { Console.WriteLine (" => Getting {0}", f.name); // try // { Console.WriteLine (f.path); this.sftp.Get (f.path, downloadFolder + Path.DirectorySeparatorChar + f.name); // } /* catch() { Console.WriteLine("Error in Get... "); Console.WriteLine(e.Message); } */ } public void Disconnect () { sftp.Close (); } } public class FileTransfer { TaskTreeView tasks; 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, ref TaskTreeView tasks, string user, string password, string downloadFolder) { // Connessione al server this.sftp.Connect (); this.tasks = tasks; this.file = f; Console.WriteLine(" => Starting sftp command"); 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) { Console.WriteLine(" => TransferStarted received"); this.iter = this.tasks.AddTask(file.name, 0); } public void OnTransferProgress(string src, string dest, int transferredBytes, int totalBytes, string message) { // if(message != "") // Console.WriteLine(message); int perc = transferredBytes / (totalBytes / 100); this.tasks.SetProgress(this.iter, perc); } public void OnTransferStopped (string src, string dest, int transferredBytes, int totalBytes, string message) { this.tasks.DeleteRow (this.iter); } } }