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]

  1.  
  2. using System;
  3. using System.Collections;
  4. using System.Threading;
  5. using System.Text.RegularExpressions;
  6. using System.IO;
  7. using Tamir.SharpSsh;
  8.  
  9. namespace Dizzy
  10. {
  11.  
  12.  
  13. public class ProtocolException : ApplicationException
  14. {
  15. public ProtocolException () {}
  16. public ProtocolException (string Message) {}
  17. }
  18.  
  19. public class Protocol
  20. {
  21.  
  22. // I dati del nostro povero utente.
  23. string user, password;
  24.  
  25. // I transfer attivi
  26. ArrayList transfers = new ArrayList ();
  27.  
  28. public delegate void Del (string src, string dest,
  29. int transferredBytes, int totalBytes, string message);
  30.  
  31.  
  32. ArrayList fileList = new ArrayList ();
  33. ArrayList threads = new ArrayList ();
  34.  
  35. Thread updater;
  36. SFTPConnection sftpUpdater;
  37.  
  38. bool bootStrapped = false;
  39.  
  40. public Protocol (string user, string password)
  41. {
  42. this.user = user;
  43. this.password = password;
  44.  
  45. try
  46. {
  47. this.sftpUpdater = new SFTPConnection(this.user, this.password);
  48. this.sftpUpdater.Connect ();
  49. }
  50. catch(Exception e)
  51. {
  52. throw new ProtocolException("Impossibile connettersi a poisson.phc.unipi.it %% " + e.Message);
  53. }
  54.  
  55. this.updater = new Thread (new ThreadStart(this._UpdateFileList));
  56. this.updater.Start ();
  57.  
  58. }
  59.  
  60. public void Search(string keyword, ref FileTreeView f)
  61. {
  62. if (this.bootStrapped)
  63. {
  64. f.Clear ();
  65.  
  66. foreach(File entry in this.fileList)
  67. {
  68. Match m = Regex.Match(entry.name, keyword.Replace(" ", "|"), RegexOptions.IgnoreCase);
  69. if(m.Success)
  70. f.AddFile(entry);
  71. }
  72. }
  73. }
  74.  
  75. // Questa ricerca deve girare in un nuovo thread per non
  76. // disturbare l'interfaccia grafica.
  77. protected void _UpdateFileList ()
  78. {
  79. this.fileList = this.sftpUpdater.SearchFiles ();
  80. if(!this.bootStrapped)
  81. this.bootStrapped = true;
  82. }
  83.  
  84. public void UpdateFileList ()
  85. {
  86. if(this.updater.IsAlive)
  87. {
  88. Console.WriteLine (" > Update già in corso");
  89. return; // Non è il momento opportuno, l'update è in corso.
  90. }
  91. this.updater = new Thread (new ThreadStart(this._UpdateFileList));
  92. this.updater.Start ();
  93. }
  94.  
  95. public void Disconnect ()
  96. {
  97. foreach(FileTransfer t in this.transfers)
  98. {
  99. t.Stop ();
  100. }
  101. foreach(Thread t in this.threads)
  102. {
  103. if(t.IsAlive)
  104. t.Abort ();
  105. }
  106.  
  107. if (this.updater.IsAlive)
  108. {
  109. this.updater.Abort ();
  110. }
  111. this.sftpUpdater.Disconnect ();
  112. }
  113.  
  114.  
  115. public void Download(File f, ref TaskTreeView tasks, string downloadFolder)
  116. {
  117. ArrayList args = new ArrayList ();
  118. args.Add (f);
  119. args.Add (tasks);
  120. args.Add (downloadFolder);
  121. Thread t = new Thread (new ParameterizedThreadStart(_Download));
  122. t.Start (args);
  123. this.threads.Add (t);
  124. }
  125.  
  126. protected void _Download(object args)
  127. {
  128. // Questi cast sono piuttosto brutali ma posso passare
  129. // solo un oggetto a Download e quindi è il meglio che
  130. // mi riesce di fare.
  131. File f = (File) ((ArrayList) args)[0];
  132. TaskTreeView tasks = (TaskTreeView) ((ArrayList) args)[1];
  133. string downloadFolder = (string) ((ArrayList) args)[2];
  134. Console.WriteLine (" => Download starting");
  135. FileTransfer transfer = new FileTransfer (f, ref tasks, this.user, this.password, downloadFolder);
  136. this.transfers.Add (transfer);
  137. }
  138.  
  139. }
  140.  
  141. public class SFTPConnection
  142. {
  143.  
  144. public Sftp sftp;
  145. public delegate void SFTPEvent (string src, string dest, int transferredBytes,
  146. int totalBytes, string message);
  147.  
  148. public event SFTPEvent TransferStarted;
  149. public event SFTPEvent TransferProgress;
  150. public event SFTPEvent TransferStopped;
  151.  
  152. public delegate void Del (string src, string dest,
  153. int transferredBytes, int totalBytes, string message);
  154.  
  155. public SFTPConnection (string user, string password)
  156. {
  157.  
  158. // Inizializziamo il protocollo
  159. this.sftp = new Sftp ("poisson.phc.unipi.it", user);
  160. this.sftp.Password = password;
  161.  
  162. this.sftp.OnTransferStart += new FileTransferEvent(this.TransferStartedHandler);
  163. this.sftp.OnTransferProgress += new FileTransferEvent(this.TransferProgressHandler);
  164. this.sftp.OnTransferEnd += new FileTransferEvent(this.TransferStoppedHandler);
  165.  
  166. }
  167.  
  168. private void TransferStartedHandler(string src, string dest, int transferredBytes,
  169. int totalBytes, string message)
  170. {
  171. Console.WriteLine (" => TransferStarted");
  172. TransferStarted(src, dest, transferredBytes, totalBytes, message);
  173. }
  174.  
  175. private void TransferProgressHandler(string src, string dest, int transferredBytes,
  176. int totalBytes, string message)
  177. {
  178. TransferProgress(src, dest, transferredBytes, totalBytes, message);
  179. }
  180.  
  181. private void TransferStoppedHandler(string src, string dest, int transferredBytes,
  182. int totalBytes, string message)
  183. {
  184. TransferStopped(src, dest, transferredBytes, totalBytes, message);
  185. }
  186.  
  187. public void Connect()
  188. {
  189. sftp.Connect (22);
  190. }
  191.  
  192. public ArrayList SearchFiles()
  193. {
  194. ArrayList matches = new ArrayList ();
  195. Console.WriteLine(" => Scan della nobackup");
  196. // ArrayList users = sftp.GetFileList ("/nobackup/");
  197. ArrayList users = new ArrayList();
  198. users.Add("robol");
  199. users.Add("bianchi");
  200. foreach(string folder in users)
  201. {
  202. if (folder == ".")
  203. continue;
  204. else if (folder == "..")
  205. continue;
  206. Console.WriteLine(" => Scan di {0}", folder);
  207. try { matches.AddRange (GetFolderContent(folder)); }
  208. catch(Exception e) { Console.WriteLine (e.Message); }
  209. }
  210. Console.WriteLine(" => Scan terminato");
  211. return matches;
  212. }
  213.  
  214. protected ArrayList GetFolderContent(string folder)
  215. {
  216. ArrayList matches, files;
  217. File f;
  218. string user;
  219. files = sftp.GetFileList("/nobackup/" + folder + "/");
  220. matches = new ArrayList ();
  221. foreach(string entry in files)
  222. {
  223. // Controllo che non sia una cartella. Evidentemente
  224. // questo metodo non è affidabile, ma per ora è il meglio
  225. // che SFTP ci permetta di fare.
  226. if(entry.IndexOf(".") == -1)
  227. matches.AddRange(GetFolderContent(folder + "/" + entry));
  228. else if(!entry.StartsWith("."))
  229. {
  230. user = folder;
  231. if(user.Contains("/"))
  232. user = user.Substring(0, user.IndexOf("/"));
  233. f = new File("/nobackup/" + folder + "/" + entry, user );
  234. matches.Add(f);
  235. }
  236. }
  237. return matches;
  238. }
  239.  
  240. public void Download(File f, string downloadFolder)
  241. {
  242. Console.WriteLine (" => Getting {0}", f.name);
  243. try
  244. {
  245. Console.WriteLine (f.path);
  246. this.sftp.Get (f.path, downloadFolder + Path.DirectorySeparatorChar + f.name);
  247. }
  248. catch(Exception e)
  249. {
  250. Console.WriteLine("Error in Get... ");
  251. Console.WriteLine(e.Message);
  252. }
  253. }
  254.  
  255. public void Disconnect ()
  256. {
  257. sftp.Close ();
  258. }
  259. }
  260.  
  261. public class FileTransfer
  262. {
  263.  
  264. TaskTreeView tasks;
  265. File file;
  266. Gtk.TreeIter iter;
  267.  
  268. SFTPConnection sftp;
  269.  
  270. public delegate void Handler(string src, string dest, int transferredBytes,
  271. int totalBytes, string message);
  272.  
  273. public FileTransfer (File f, ref TaskTreeView tasks, string user, string password, string downloadFolder)
  274. {
  275. // Connessione al server
  276. this.sftp = new SFTPConnection (user, password);
  277. this.sftp.Connect ();
  278.  
  279. this.tasks = tasks;
  280. this.file = f;
  281.  
  282. sftp.TransferStarted += new SFTPConnection.SFTPEvent(OnTransferStarted);
  283. sftp.TransferProgress += new SFTPConnection.SFTPEvent(OnTransferProgress);
  284. sftp.TransferStopped += new SFTPConnection.SFTPEvent(OnTransferStopped);
  285.  
  286. Console.WriteLine(" => Starting sftp command");
  287. sftp.Download (this.file, downloadFolder);
  288. }
  289.  
  290. public void Stop ()
  291. {
  292. this.sftp.Disconnect ();
  293. }
  294.  
  295. public void OnTransferStarted (string src, string dest, int transferredBytes,
  296. int totalBytes, string message)
  297. {
  298. Console.WriteLine(" => TransferStarted received");
  299. this.iter = this.tasks.AddTask(file.name, 0);
  300. }
  301.  
  302. public void OnTransferProgress(string src, string dest, int transferredBytes,
  303. int totalBytes, string message)
  304. {
  305. // if(message != "")
  306. // Console.WriteLine(message);
  307. int perc = transferredBytes / (totalBytes / 100);
  308. this.tasks.SetProgress(this.iter, perc);
  309. }
  310.  
  311. public void OnTransferStopped (string src, string dest, int transferredBytes,
  312. int totalBytes, string message)
  313. {
  314. this.tasks.DeleteRow (this.iter);
  315. this.Stop ();
  316. }
  317. }
  318. }