VinnoApplication.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using System.IO;
  2. namespace fis.Vid
  3. {
  4. public class VinnoApplication
  5. {
  6. /// <summary>
  7. /// Gets the application's ID
  8. /// </summary>
  9. public string ApplicationId { get; }
  10. /// <summary>
  11. /// Gets the OriginalId of the applciation.
  12. /// </summary>
  13. public string ApplicationOriginalId { get; }
  14. /// <summary>
  15. /// Gets the application's name.
  16. /// </summary>
  17. public string ApplicationName { get; }
  18. /// <summary>
  19. /// Gets the applciation's category name.
  20. /// </summary>
  21. public string ApplicationCategoryName { get; }
  22. /// <summary>
  23. /// Gets if is user defined.
  24. /// </summary>
  25. public bool IsUserDefined { get; }
  26. public VinnoApplication(string applicationId, string applicationOriginalId, string applicationName, string applicationCategoryName, bool isUserDefined)
  27. {
  28. ApplicationId = applicationId;
  29. ApplicationOriginalId = applicationOriginalId;
  30. ApplicationName = applicationName;
  31. ApplicationCategoryName = applicationCategoryName;
  32. IsUserDefined = isUserDefined;
  33. }
  34. public byte[] ToBytes()
  35. {
  36. byte[] result;
  37. using (var stream = new MemoryStream())
  38. {
  39. var writer = new VinnoStreamWriter(stream);
  40. writer.WriteString(ApplicationId);
  41. writer.WriteString(ApplicationOriginalId);
  42. writer.WriteString(ApplicationName);
  43. writer.WriteString(ApplicationCategoryName);
  44. writer.WriteBool(IsUserDefined);
  45. result = stream.ToArray();
  46. }
  47. return result;
  48. }
  49. public static VinnoApplication FromBytes(byte[] bytes)
  50. {
  51. VinnoApplication result;
  52. using (var stream = new MemoryStream(bytes))
  53. {
  54. stream.Position = 0;
  55. var reader = new VinnoStreamReader(stream);
  56. var applicationId = reader.ReadString();
  57. var applicationOriginalId = reader.ReadString();
  58. var applicationName = reader.ReadString();
  59. var applicationCategoryName = reader.ReadString();
  60. var isUserDefined = reader.ReadBool();
  61. result = new VinnoApplication(applicationId,applicationOriginalId,applicationName,applicationCategoryName,isUserDefined);
  62. }
  63. return result;
  64. }
  65. }
  66. }