NodeStatus.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Xml.Serialization;
  6. using System.IO;
  7. using System.Runtime.Serialization.Formatters.Binary;
  8. namespace SuperSocket.SocketBase
  9. {
  10. /// <summary>
  11. /// The status of one SuperSocket node (one installation or deployment)
  12. /// </summary>
  13. [Serializable]
  14. public class NodeStatus
  15. {
  16. /// <summary>
  17. /// Gets or sets the bootstrap status.
  18. /// </summary>
  19. /// <value>
  20. /// The bootstrap status.
  21. /// </value>
  22. public StatusInfoCollection BootstrapStatus { get; set; }
  23. /// <summary>
  24. /// Gets or sets the status of all server instances running in this node.
  25. /// </summary>
  26. /// <value>
  27. /// The instances status.
  28. /// </value>
  29. public StatusInfoCollection[] InstancesStatus { get; set; }
  30. /// <summary>
  31. /// Saves the specified file path.
  32. /// </summary>
  33. /// <param name="filePath">The file path.</param>
  34. public void Save(string filePath)
  35. {
  36. var serializer = new BinaryFormatter();
  37. using (var stream = File.Create(filePath))
  38. {
  39. serializer.Serialize(stream, this);
  40. stream.Flush();
  41. stream.Close();
  42. }
  43. }
  44. /// <summary>
  45. /// Loads a NodeStatus instance from a file.
  46. /// </summary>
  47. /// <param name="filePath">The file path.</param>
  48. /// <returns></returns>
  49. public static NodeStatus LoadFrom(string filePath)
  50. {
  51. var serializer = new BinaryFormatter();
  52. using (var stream = File.Open(filePath, FileMode.Open, FileAccess.Read))
  53. {
  54. var status = serializer.Deserialize(stream) as NodeStatus;
  55. stream.Close();
  56. return status;
  57. }
  58. }
  59. }
  60. }