PageRenderTime 45ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/source/samples/ObviousCode.Interlace.BitTunnel/Knock/KnockServer/ServerActivities/ServerLists.cs

https://bitbucket.org/VahidN/interlace
C# | 95 lines | 74 code | 21 blank | 0 comment | 6 complexity | 47b6f45b2440761e65419cd2da69a8bc MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using ObviousCode.Interlace.BitTunnel.Connectivity;
  6. using ObviousCode.Interlace.BitTunnelLibrary.File;
  7. using ObviousCode.Interlace.BitTunnelLibrary.Events;
  8. using KnockServer.Mounting;
  9. using System.Threading;
  10. namespace KnockServer.ServerActivities
  11. {
  12. public class ServerLists : ConsoleCommand
  13. {
  14. public ServerLists() : base(10, true, "list", "listf")
  15. {
  16. }
  17. #region ICommand Members
  18. public override bool HandleCommand(CommandContext context)
  19. {
  20. bool listed = false;
  21. string command = context.Command;
  22. if (HasArguments && Arguments == "all")
  23. {
  24. DirectoryMounter mounter = new DirectoryMounter();
  25. CommandContext context2 = context.Clone();
  26. context2.Command = "listd";
  27. mounter.HandlesCommand(context2);
  28. mounter.HandleCommand(context2);
  29. }
  30. EventHandler<FileListEventArgs> handler = delegate(object sender, ObviousCode.Interlace.BitTunnelLibrary.Events.FileListEventArgs e)
  31. {
  32. FullFileListReceived(e.FileList);
  33. listed = true;
  34. };
  35. context.LocalClient.FullFileListReceived += new EventHandler<FileListEventArgs>(handler);
  36. context.LocalClient.RequestFullFileList();
  37. while (!listed)
  38. {
  39. Thread.Sleep(100);
  40. }
  41. context.LocalClient.FullFileListReceived -= new EventHandler<FileListEventArgs>(handler);
  42. return true;
  43. }
  44. public int Priority
  45. {
  46. get { return 10; }
  47. }
  48. #endregion
  49. void FullFileListReceived(IList<FileDescriptor> list)
  50. {
  51. if (list.Count == 0)
  52. {
  53. Console.WriteLine("No Files Prepared");
  54. }
  55. else
  56. {
  57. List<FileDescriptor> files = new List<FileDescriptor>(list);
  58. files.Sort(
  59. delegate(FileDescriptor lhs, FileDescriptor rhs)
  60. {
  61. return lhs.FileFullName.CompareTo(rhs.FileFullName);
  62. });
  63. Console.WriteLine();
  64. Console.WriteLine("Available Files");
  65. Console.WriteLine("---------------");
  66. foreach (FileDescriptor file in files)
  67. {
  68. Console.WriteLine(file.FileFullName);
  69. }
  70. Console.WriteLine();
  71. }
  72. }
  73. }
  74. }