Skip to content

Commit

Permalink
MessageManager 项目调整,主要调整服务及UI
Browse files Browse the repository at this point in the history
  • Loading branch information
yuezhongxin committed Jul 16, 2014
1 parent ab66d59 commit fa5449f
Show file tree
Hide file tree
Showing 20 changed files with 172 additions and 80 deletions.
21 changes: 3 additions & 18 deletions MessageManager.Application.Tests/MessageApplicationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void ApplicationTest_SendMessage()
new MessageRepository(new EntityFrameworkRepositoryContext()),
new ContactRepository(),
new SendSiteMessageService());
Assert.True(messageService.SendMessage("title", "content", "senderLoginName", "receiverDisplayName").IsSuccess);
Assert.True(messageService.SendMessage("title", "content", "xiaocai", "大神").IsSuccess);
}

[Fact]
Expand All @@ -37,7 +37,8 @@ public void ApplicationTest_GetUnreadMessageList()
new MessageRepository(new EntityFrameworkRepositoryContext()),
new ContactRepository(),
new SendSiteMessageService());
foreach (MessageDTO message in messageService.GetUnreadMessageList("dashen").Data)
var messages = messageService.GetUnreadMessageList("dashen").Data;
foreach (MessageDTO message in messages)
{
Console.WriteLine("ID:" + message.ID);
Console.WriteLine("Title:" + message.Title);
Expand Down Expand Up @@ -65,21 +66,5 @@ public void ApplicationTest_ReadInbox()
Console.WriteLine("MessageState:" + message.State);
}
}

[Fact]
public void ApplicationTest_ReadMessageRecipient()
{
IMessageService messageService = new MessageServiceImpl(new EntityFrameworkRepositoryContext(),
new MessageRepository(new EntityFrameworkRepositoryContext()),
new ContactRepository(),
new SendSiteMessageService());
MessageDTO message = messageService.ReadMessageRecipient("1", "dashen").Data;
Console.WriteLine("ID:" + message.ID);
Console.WriteLine("Title:" + message.Title);
Console.WriteLine("Content:" + message.Content);
Console.WriteLine("Sender:" + message.Sender.DisplayName);
Console.WriteLine("Recipient:" + message.Recipient.DisplayName);
Console.WriteLine("MessageState:" + message.State);
}
}
}
2 changes: 1 addition & 1 deletion MessageManager.Application/IMessageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace MessageManager.Application
{
/// <summary>
/// Message管理应用层服务接口
/// Message管理应用层服务契约
/// </summary>
[ServiceContract(Name = "MessageService")]
public interface IMessageService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ public OperationResponse SendMessage(string title, string content, string sender
Message message = new Message(title, content, sender, receiver);
if (sendMessageService.SendMessage(message))
{
messageRepository.AddMessage(message);
return OperationResponse.Success("发送成功");
//messageRepository.Add(message);
//return Context.Commit();
}
else
Expand Down Expand Up @@ -189,8 +189,8 @@ public OperationResponse<MessageDTO> ReadMessageRecipient(string messageId, stri
{
return new OperationResponse<MessageDTO>(false, "未获取到阅读人信息");
}
message.Read(reader);
//messageRepository.Update(message);
message.SetState(reader);
messageRepository.UpdateMessage(message);
return new OperationResponse<MessageDTO>(true, "", Mapper.Map<Message, MessageDTO>(message));
}
#endregion
Expand Down
2 changes: 1 addition & 1 deletion MessageManager.Domain.Tests/MessageDomainTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public void DomainTest_ReadMessageRecipient()
{
Contact recipient = new Recipient("recipient");
Message message = new Message("title", "content", new Sender("sender"), recipient);
message.Read(recipient);
message.SetState(recipient);
Console.WriteLine("Title:" + message.Title);
Console.WriteLine("Content:" + message.Content);
Console.WriteLine("Sender:" + message.Sender.Name);
Expand Down
31 changes: 29 additions & 2 deletions MessageManager.Domain/Entity/Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,50 @@ public Message(string title, string content, Contact sender, Contact recipient)
this.Content = content;
this.SendTime = DateTime.Now;
this.State = MessageState.Unread;
this.DisplayType = MessageDisplayType.OutboxAndInbox;
this.Sender = sender;
this.Recipient = recipient;
}
public string ID { get; private set; }
public string Title { get; private set; }
public string Content { get; private set; }
public DateTime SendTime { get; private set; }
public MessageState State { get; set; }
public MessageState State { get; private set; }
public MessageDisplayType DisplayType { get; private set; }
public virtual Contact Sender { get; private set; }
public virtual Contact Recipient { get; private set; }

public void Read(Contact reader)
public void SetState(Contact reader)
{
if (this.Recipient.Name.Equals(reader.Name) && this.State == MessageState.Unread)
{
this.State = MessageState.Read;
}
}

public bool SetDisplayType(Contact reader)
{
// to do...
switch (this.DisplayType)
{
case MessageDisplayType.OutboxAndInbox:
if (this.Sender.Name.Equals(reader.Name))
{
this.DisplayType = MessageDisplayType.Inbox;
}
else
{
this.DisplayType = MessageDisplayType.Outbox;
}
return true;
case MessageDisplayType.Outbox:
break;
case MessageDisplayType.Inbox:
break;
default:
break;
}
return false;
}
}
}
1 change: 1 addition & 0 deletions MessageManager.Domain/MessageManager.Domain.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
<Compile Include="Specifications\OrSpecification.cs" />
<Compile Include="Specifications\ParameterRebinder.cs" />
<Compile Include="Specifications\Specification.cs" />
<Compile Include="ValueObject\MessageDisplayType.cs" />
<Compile Include="ValueObject\Sender.cs" />
<Compile Include="ValueObject\Contact.cs" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,11 @@ public interface IMessageRepository : IRepository<Message>
ICollection<Message> GetOutbox(Contact reader);

Message GetMessageById(string id);

void AddMessage(Message message);

void UpdateMessage(Message message);

void DeleteMessage(Message message);
}
}
14 changes: 14 additions & 0 deletions MessageManager.Domain/ValueObject/MessageDisplayType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* author:xishuai
* address:https://www.github.com/yuezhongxin/MessageManager
**/

namespace MessageManager.Domain.ValueObject
{
public enum MessageDisplayType
{
OutboxAndInbox,
Outbox,
Inbox
}
}
2 changes: 1 addition & 1 deletion MessageManager.Repositories.Tests/ContactRepositoryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class ContactRepositoryTest
public void RepositoryTest_GetContactByLoginName()
{
IContactRepository contactRepository = new ContactRepository();
Contact contact = contactRepository.GetContactByLoginName("1");
Contact contact = contactRepository.GetContactByLoginName("xiaocai");
Console.WriteLine("Name:" + contact.Name);
Console.WriteLine("LoginName:" + contact.LoginName);
Console.WriteLine("DisplayName:" + contact.DisplayName);
Expand Down
18 changes: 16 additions & 2 deletions MessageManager.Repositories/ContactRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,26 @@ public class ContactRepository : IContactRepository
#region ContactRepository Members
public Contact GetContactByLoginName(string loginName)
{
return new Contact("1", "xiaocai", "小菜");
if (loginName.Equals("xiaocai"))
{
return new Contact("1", "xiaocai", "小菜");
}
else
{
return new Contact("2", "dashen", "大神");
}
}

public Contact GetContactByDisplayName(string displayName)
{
return new Contact("2", "dashen", "大神");
if (displayName.Equals("大神"))
{
return new Contact("2", "dashen", "大神");
}
else
{
return new Contact("1", "xiaocai", "小菜");
}
}
#endregion
}
Expand Down
30 changes: 24 additions & 6 deletions MessageManager.Repositories/MessageRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,59 @@
using MessageManager.Domain.ValueObject;
using MessageManager.Repositories.EntityFramework;
using System.Collections.Generic;
using System.Linq;

namespace MessageManager.Repositories
{
public class MessageRepository : EntityFrameworkRepository<Message>, IMessageRepository
{
private static List<Message> messages = new List<Message>() { new Message("title", "content ", new Sender("2", "dashen", "大神"), new Recipient("1", "xiaocai", "小菜")) };
public MessageRepository(IRepositoryContext context)
: base(context)
{ }

#region IMessageRepository Members
public ICollection<Message> GetUnreadMessageList(Contact reader)
{
return new List<Message>() { new Message("title", "content", new Sender("1", "xiaocai", "小菜"), new Recipient("2", "dashen", "大神")) };
return messages.Where(m => m.Recipient.Name == reader.Name).ToList();
}

public int GetUnreadMessageCount(Contact reader)
{
return 1;
return messages.Where(m => m.Recipient.Name == reader.Name).Count();
}

public ICollection<Message> GetInbox(Contact reader)
{
return new List<Message>() { new Message("title", "content", new Sender("1", "xiaocai", "小菜"), new Recipient("2", "dashen", "大神")) };
return messages.Where(m => m.Recipient.Name == reader.Name).ToList();
}

public ICollection<Message> GetOutbox(Contact reader)
{
return new List<Message>() { new Message("title", "content", new Sender("1", "xiaocai", "小菜"), new Recipient("2", "dashen", "大神")) };
return messages.Where(m => m.Sender.Name == reader.Name).ToList();
}

public Message GetMessageById(string id)
{
//return new Message("title", "content", new Sender("1", "xiaocai", "小菜"), new Recipient("2", "dashen", "大神"));
return new Message("title", "content", new Sender("2", "dashen", "大神"), new Recipient("1", "xiaocai", "小菜"));
return messages.Find(m => m.ID == id);
}

public void AddMessage(Message message)
{
messages.Add(message);
}

public void UpdateMessage(Message message)
{
messages.Remove(messages.Find(m => m.ID == message.ID));
messages.Add(message);
}

public void DeleteMessage(Message message)
{
messages.Remove(messages.Find(m => m.ID == message.ID));
}
#endregion

}
}
19 changes: 10 additions & 9 deletions MessageManager.Services/MessageService.svc.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using MessageManager.Application;
using MessageManager.Application.DTO;
using MessageManager.Infrastructure;
using System;
using System.Collections.Generic;

namespace MessageManager.Services
Expand All @@ -14,49 +13,51 @@ public class MessageService : IMessageService
private readonly IMessageService messageServiceImpl = ServiceLocator.Instance.GetService<IMessageService>();
#endregion

/// <returns></returns>
public OperationResponse SendMessage(string title, string content, string senderLoginName, string receiverDisplayName)
{
//to do 异常处理,日志记录
return messageServiceImpl.SendMessage(title, content, senderLoginName, receiverDisplayName);
}

public OperationResponse ReplyMessage(string messageId, string title, string content, string replierLoginName)
{
throw new NotImplementedException();
return messageServiceImpl.ReplyMessage(messageId, title, content, replierLoginName);
}

public OperationResponse ForwardMessage(string messageId, string title, string content, string senderLoginName, string receiverDisplayName)
{
throw new NotImplementedException();
return messageServiceImpl.ForwardMessage(messageId, title, content, senderLoginName, receiverDisplayName);
}

public OperationResponse<ICollection<MessageDTO>> GetUnreadMessageList(string readerLoginName)
{
throw new NotImplementedException();
return messageServiceImpl.GetUnreadMessageList(readerLoginName);
}

public OperationResponse<int> GetUnreadMessageCount(string readerLoginName)
{
throw new NotImplementedException();
return messageServiceImpl.GetUnreadMessageCount(readerLoginName);
}

public OperationResponse<ICollection<MessageDTO>> ReadInbox(string readerLoginName)
{
throw new NotImplementedException();
return messageServiceImpl.ReadInbox(readerLoginName);
}

public OperationResponse<ICollection<MessageDTO>> ReadOutbox(string readerLoginName)
{
throw new NotImplementedException();
return messageServiceImpl.ReadOutbox(readerLoginName);
}

public OperationResponse<MessageDTO> ReadMessageSender(string messageId, string readerLoginName)
{
throw new NotImplementedException();
return messageServiceImpl.ReadMessageSender(messageId, readerLoginName);
}

public OperationResponse<MessageDTO> ReadMessageRecipient(string messageId, string readerLoginName)
{
throw new NotImplementedException();
return messageServiceImpl.ReadMessageRecipient(messageId, readerLoginName);
}
}
}
14 changes: 7 additions & 7 deletions MessageManager.Web/App_Start/RouteConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

routes.MapRoute(
"ShowMessageRoute",
"Message/Show/{id}",
new { controller = "Message", action = "Show", id = UrlParameter.Optional }
);
//routes.MapRoute(
// "ShowMessageRoute",
// "Message/ReadMessageSender/{id}",
// new { controller = "Message", action = "Show", id = UrlParameter.Optional }
// );

routes.MapRoute(
name: "Default",
url: "{controller}/{action}",
defaults: new { controller = "Message", action = "Compose" }
url: "{controller}/{action}/{id}",
defaults: new { controller = "Message", action = "Compose", id = UrlParameter.Optional }
);

//routes.MapRoute(
Expand Down
5 changes: 4 additions & 1 deletion MessageManager.Web/Controllers/AccountController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Web.Mvc;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;

namespace MessageManager.Web.Controllers
Expand All @@ -10,6 +11,8 @@ public class AccountController : Controller
public void LogOn()
{
FormsAuthentication.SetAuthCookie("xiaocai", false);
Response.Cookies.Add(new HttpCookie("DisplayName", HttpUtility.UrlEncode("小菜")));


//HttpCookie cookie = FormsAuthentication.GetAuthCookie("xiaocai2", false);
//FormsAuthenticationTicket oldTicket = FormsAuthentication.Decrypt(cookie.Value);
Expand Down
Loading

0 comments on commit fa5449f

Please sign in to comment.