ChannelParameter.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using System.Collections.Generic;
  2. using WingServerCommon.Log;
  3. using WingServerCommon.Utilities;
  4. namespace WingRtmpService.ChannelManagers
  5. {
  6. class ChannelConstant
  7. {
  8. public const string CreateChannelKey = "CreateChannelKey";
  9. public const string DeleteChannelKey = "DeleteChannelKey";
  10. public const string GetChannelListKey = "GetChannelListKey";
  11. }
  12. class ChannelParameter
  13. {
  14. private readonly Dictionary<string, string> _parameter;
  15. public ChannelParameter()
  16. {
  17. _parameter = new Dictionary<string, string>();
  18. }
  19. public Dictionary<string, string> Parameter => _parameter;
  20. public void SetCreateParameter(string channelName)
  21. {
  22. if (!_parameter.ContainsKey(ChannelConstant.CreateChannelKey))
  23. {
  24. _parameter.Add(ChannelConstant.CreateChannelKey,
  25. GetChannelName(channelName));
  26. }
  27. else
  28. {
  29. _parameter[ChannelConstant.CreateChannelKey] = GetChannelName(channelName);
  30. }
  31. }
  32. public void SetDeleteParameter(string cid)
  33. {
  34. if (string.IsNullOrEmpty(cid))
  35. {
  36. Logger.WriteLineError("Channel cid is empty.");
  37. return;
  38. }
  39. if (!_parameter.ContainsKey(ChannelConstant.DeleteChannelKey))
  40. {
  41. _parameter.Add(ChannelConstant.DeleteChannelKey, cid);
  42. }
  43. else
  44. {
  45. _parameter[ChannelConstant.DeleteChannelKey] = cid;
  46. }
  47. }
  48. public void SetGetChannelListParameter(int maxRecordsCount)
  49. {
  50. if (maxRecordsCount > 0)
  51. {
  52. if (!_parameter.ContainsKey(ChannelConstant.GetChannelListKey))
  53. {
  54. _parameter.Add(ChannelConstant.GetChannelListKey, maxRecordsCount.ToString());
  55. }
  56. else
  57. {
  58. _parameter[ChannelConstant.GetChannelListKey] = maxRecordsCount.ToString();
  59. }
  60. }
  61. }
  62. private static string GetChannelName(string channelName)
  63. {
  64. return !string.IsNullOrEmpty(channelName) ? channelName : IdHelper.Generate<string>();
  65. }
  66. }
  67. }