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. // Preparo gli argomento da passare alla funzione.
  118. ArrayList args = new ArrayList ();
  119. args.Add (f);
  120. args.Add (tasks);
  121. args.Add (downloadFolder);
  122. Thread t = new Thread (new ParameterizedThreadStart(_Download));
  123. t.Start (args);
  124. this.threads.Add (t);
  125. }
  126.  
  127. protected void _Download(object args)
  128. {
  129. // Questi cast sono piuttosto brutali ma posso passare
  130. // solo un oggetto a Download e quindi è il meglio che
  131. // mi riesce di fare.
  132. File f = (File) ((ArrayList) args)[0];
  133. TaskTreeView tasks = (TaskTreeView) ((ArrayList) args)[1];
  134. string downloadFolder = (string) ((ArrayList) args)[2];
  135. Console.WriteLine (" => Download starting");
  136. FileTransfer transfer = new FileTransfer (f, ref tasks, this.user, this.password, downloadFolder);
  137. this.transfers.Add (transfer);
  138. }
  139.  
  140. }
  141.  
  142. public class SFTPConnection
  143. {
  144.  
  145. public Sftp sftp;
  146. public delegate void SFTPEvent (string src, string dest, int transferredBytes,
  147. int totalBytes, string message);
  148.  
  149. public event SFTPEvent TransferStarted;
  150. public event SFTPEvent TransferProgress;
  151. public event SFTPEvent TransferStopped;
  152.  
  153. public delegate void Del (string src, string dest,
  154. int transferredBytes, int totalBytes, string message);
  155.  
  156. public SFTPConnection (string user, string password)
  157. {
  158.  
  159. // Inizializziamo il protocollo
  160. this.sftp = new Sftp ("poisson.phc.unipi.it", user);
  161. this.sftp.Password = password;
  162.  
  163. this.sftp.OnTransferStart += new FileTransferEvent(this.TransferStartedHandler);
  164. this.sftp.OnTransferProgress += new FileTransferEvent(this.TransferProgressHandler);
  165. this.sftp.OnTransferEnd += new FileTransferEvent(this.TransferStoppedHandler);
  166.  
  167. }
  168.  
  169. private void TransferStartedHandler(string src, string dest, int transferredBytes,
  170. int totalBytes, string message)
  171. {
  172. Console.WriteLine (" => TransferStarted");
  173. TransferStarted(src, dest, transferredBytes, totalBytes, message);
  174. }
  175.  
  176. private void TransferProgressHandler(string src, string dest, int transferredBytes,
  177. int totalBytes, string message)
  178. {
  179. TransferProgress(src, dest, transferredBytes, totalBytes, message);
  180. }
  181.  
  182. private void TransferStoppedHandler(string src, string dest, int transferredBytes,
  183. int totalBytes, string message)
  184. {
  185. TransferStopped(src, dest, transferredBytes, totalBytes, message);
  186. }
  187.  
  188. public void Connect()
  189. {
  190. sftp.Connect (22);
  191. }
  192.  
  193. public ArrayList SearchFiles()
  194. {
  195. ArrayList matches = new ArrayList ();
  196. Console.WriteLine(" => Scan della nobackup");
  197. // ArrayList users = sftp.GetFileList ("/nobackup/");
  198. ArrayList users = new ArrayList();
  199. users.Add("robol");
  200. users.Add("bianchi");
  201. foreach(string folder in users)
  202. {
  203. if (folder == ".")
  204. continue;
  205. else if (folder == "..")
  206. continue;
  207. Console.WriteLine(" => Scan di {0}", folder);
  208. try { matches.AddRange (GetFolderContent(folder)); }
  209. catch(Exception e) { Console.WriteLine (e.Message); }
  210. }
  211. Console.WriteLine(" => Scan terminato");
  212. return matches;
  213. }
  214.  
  215. protected ArrayList GetFolderContent(string folder)
  216. {
  217. ArrayList matches, files;
  218. File f;
  219. string user;
  220. files = sftp.GetFileList("/nobackup/" + folder + "/");
  221. matches = new ArrayList ();
  222. foreach(string entry in files)
  223. {
  224. // Controllo che non sia una cartella. Evidentemente
  225. // questo metodo non è affidabile, ma per ora è il meglio
  226. // che SFTP ci permetta di fare.
  227. if(entry.IndexOf(".") == -1)
  228. matches.AddRange(GetFolderContent(folder + "/" + entry));
  229. else if(!entry.StartsWith("."))
  230. {
  231. user = folder;
  232. if(user.Contains("/"))
  233. user = user.Substring(0, user.IndexOf("/"));
  234. f = new File("/nobackup/" + folder + "/" + entry, user );
  235. matches.Add(f);
  236. }
  237. }
  238. return matches;
  239. }
  240.  
  241. public void Download(File f, string downloadFolder)
  242. {
  243. Console.WriteLine (" => Getting {0}", f.name);
  244. // try
  245. // {
  246. Console.WriteLine (f.path);
  247. this.sftp.Get (f.path, downloadFolder + Path.DirectorySeparatorChar + f.name);
  248. // }
  249. /* catch()
  250. {
  251. Console.WriteLine("Error in Get... ");
  252. Console.WriteLine(e.Message);
  253. } */
  254. }
  255.  
  256. public void Disconnect ()
  257. {
  258. sftp.Close ();
  259. }
  260. }
  261.  
  262. public class FileTransfer
  263. {
  264.  
  265. TaskTreeView tasks;
  266. File file;
  267. Gtk.TreeIter iter;
  268.  
  269. SFTPConnection sftp;
  270.  
  271. public delegate void Handler(string src, string dest, int transferredBytes,
  272. int totalBytes, string message);
  273.  
  274. public FileTransfer (File f, ref TaskTreeView tasks, string user, string password, string downloadFolder)
  275. {
  276. // Connessione al server
  277. this.sftp = new SFTPConnection (user, password);
  278. this.sftp.Connect ();
  279.  
  280. this.tasks = tasks;
  281. this.file = f;
  282.  
  283. sftp.TransferStarted += new SFTPConnection.SFTPEvent(OnTransferStarted);
  284. sftp.TransferProgress += new SFTPConnection.SFTPEvent(OnTransferProgress);
  285. sftp.TransferStopped += new SFTPConnection.SFTPEvent(OnTransferStopped);
  286.  
  287. Console.WriteLine(" => Starting sftp command");
  288. sftp.Download (this.file, downloadFolder);
  289. sftp.Disconnect ();
  290. }
  291.  
  292. public void Stop ()
  293. {
  294. this.sftp.Disconnect ();
  295. }
  296.  
  297. public void OnTransferStarted (string src, string dest, int transferredBytes,
  298. int totalBytes, string message)
  299. {
  300. Console.WriteLine(" => TransferStarted received");
  301. this.iter = this.tasks.AddTask(file.name, 0);
  302. }
  303.  
  304. public void OnTransferProgress(string src, string dest, int transferredBytes,
  305. int totalBytes, string message)
  306. {
  307. // if(message != "")
  308. // Console.WriteLine(message);
  309. int perc = transferredBytes / (totalBytes / 100);
  310. this.tasks.SetProgress(this.iter, perc);
  311. }
  312.  
  313. public void OnTransferStopped (string src, string dest, int transferredBytes,
  314. int totalBytes, string message)
  315. {
  316. this.tasks.DeleteRow (this.iter);
  317. }
  318. }
  319. }