/WcfChat/IChatService.cs

http://wcfsimplechat.codeplex.com · C# · 108 lines · 75 code · 8 blank · 25 comment · 0 complexity · 9d4e9d92ee329c817e831d1745bfaa3e MD5 · raw file

  1. /*
  2. * IChatService.cs
  3. *
  4. * Copyright 2012 Isaac Ojeda <isaacoq(at)gmail(dot)com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This progam is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program.
  18. *
  19. */
  20. using System;
  21. using System.Collections.Generic;
  22. using System.Linq;
  23. using System.Runtime.Serialization;
  24. using System.ServiceModel;
  25. using System.Text;
  26. namespace WcfChat
  27. {
  28. [ServiceContract(SessionMode = SessionMode.Allowed)]
  29. public interface IChatService
  30. {
  31. [OperationContract]
  32. ChatUser ClientConnect(string userName);
  33. [OperationContract]
  34. List<ChatMessage> GetNewMessages(ChatUser user);
  35. [OperationContract]
  36. void SendNewMessage(ChatMessage newMessage);
  37. [OperationContract]
  38. List<ChatUser> GetAllUsers();
  39. [OperationContract]
  40. void RemoveUser(ChatUser user);
  41. }
  42. /// <summary>
  43. ///
  44. /// </summary>
  45. [DataContract]
  46. public class ChatMessage
  47. {
  48. private ChatUser user;
  49. [DataMember]
  50. public ChatUser User
  51. {
  52. get { return user; }
  53. set { user = value; }
  54. }
  55. private string message;
  56. [DataMember]
  57. public string Message
  58. {
  59. get { return message; }
  60. set { message = value; }
  61. }
  62. private DateTime date;
  63. [DataMember]
  64. public DateTime Date
  65. {
  66. get { return date; }
  67. set { date = value; }
  68. }
  69. }
  70. /// <summary>
  71. ///
  72. /// </summary>
  73. [DataContract]
  74. public class ChatUser
  75. {
  76. private string userName, ipAddress, hostName;
  77. [DataMember]
  78. public string UserName
  79. {
  80. get { return userName; }
  81. set { userName = value; }
  82. }
  83. [DataMember]
  84. public string IpAddress
  85. {
  86. get { return ipAddress; }
  87. set { ipAddress = value; }
  88. }
  89. [DataMember]
  90. public string HostName
  91. {
  92. get { return hostName; }
  93. set { hostName = value; }
  94. }
  95. public override string ToString()
  96. {
  97. return this.UserName;
  98. }
  99. }
  100. }