public static ConversationDC ConversationToConversationDC(Conversation conv)
 {
     ConversationDC convDC = null;
     using (var db = new BomberDbContext())
     {
         var q = (from co in db.Conversations
                   where co.ConversationId == conv.ConversationId
                   select co).ToList();
         if (q.Count > 0)
         {
             var c = q.ElementAt(0);
             convDC = new ConversationDC()
             {
                 ConversationId = c.ConversationId,
                 ConversationLog = c.ConversationLog,
                 Host = PlayerToPlayerDC(c.Host),
                 Participants = PlayersToPlayerDCs(c.Players)
             };
         }
     }
     return convDC;
 }
Beispiel #2
0
     private void FixupConversation(Conversation previousValue)
     {
         if (previousValue != null && ReferenceEquals(previousValue.CurrentGame, this))
         {
             previousValue.CurrentGame = null;
         }
 
         if (Conversation != null)
         {
             Conversation.CurrentGame = this;
         }
     }
 public void CreateConversation(ConversationDC newConv)
 {
     using (var db = new BomberDbContext())
     {
         var q = (from p in db.Players
                  where p.PlayerId == newConv.Host.PlayerId
                  select p).ToList();
         var convMembersIds = from i in newConv.Participants
                              select i.PlayerId;
         var convMembers = (from p in db.Players
                            where convMembersIds.Contains(p.PlayerId)
                            select p);
         if (q.Count > 0)
         {
             var host = q.ElementAt(0);
             Conversation c = new Conversation()
             {
                 Host = host,
                 ConversationLog = ""
             };
             // discussion : add the host to c.Players or not? let's say no, for now...
             foreach (var p in convMembers)
             {
                 if (!c.Players.Contains(p))
                     c.Players.Add(p);
             }
             db.Conversations.AddObject(c);
             db.SaveChanges();
             var convDC = EntityContractTranslator.ConversationToConversationDC(c);
             var cm = new ConversationManager(convDC);
             Conversations.Add(convDC.ConversationId, cm);
             if (Sessions.Keys.Contains(host.PlayerId))
             {
                 var s = Sessions[host.PlayerId];
                 cm.EndOfConvEvent += s.EndOfConvEventHandler;
                 cm.JoinEvent += s.JoinConvEventHandler;
                 cm.KickEvent += s.KickFromConvEventHandler;
                 cm.LeaveEvent += s.LeaveConvEventHandler;
                 cm.MessageEvent += s.ConvMessageEventHandler;
                 s.Callback.InitializeConversation(convDC);
             }
             foreach (var p in convMembers)
             {
                 if (Sessions.Keys.Contains(p.PlayerId))
                 {
                     var s = Sessions[p.PlayerId];
                     cm.EndOfConvEvent += s.EndOfConvEventHandler;
                     cm.JoinEvent += s.JoinConvEventHandler;
                     cm.KickEvent += s.KickFromConvEventHandler;
                     cm.LeaveEvent += s.LeaveConvEventHandler;
                     cm.MessageEvent += s.ConvMessageEventHandler;
                     s.Callback.InitializeConversation(convDC);
                 }
             }
         }
     }
 }