Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="message">Текст сообщения</param>
        /// <param name="AccountId1">Отправитель</param>
        /// <param name="AccountId2">Получатель</param>
        /// <returns></returns>
        public bool Send(string message, int AccountId1, int AccountId2)
        {
            using (ForumContainer container = new ForumContainer())
            {
                ConversationSet conversation = container.ConversationSet.SingleOrDefault(x =>
                                                                                         (x.AccountSet_Recipient.AccountId == AccountId1 && x.AccountSet_Sender.AccountId == AccountId2) ||
                                                                                         (x.AccountSet_Recipient.AccountId == AccountId2 && x.AccountSet_Sender.AccountId == AccountId1)
                                                                                         );


                if (conversation == null)
                {
                    ConversationSet newConversation = new ConversationSet()
                    {
                        RecipientId = AccountId2,
                        SenderId    = AccountId1
                    };
                    container.ConversationSet.Add(newConversation);
                    container.SaveChanges();

                    FormConversation = newConversation;
                }
                else
                {
                    FormConversation = conversation;
                    // next code
                }
            }


            if (message != string.Empty || message.Length < 5)
            {
                using (ForumContainer container = new ForumContainer())
                {
                    MessageSet messageSet = new MessageSet()
                    {
                        Date           = DateTime.Now,
                        MessageText    = message,
                        ConversationId = FormConversation.ConversationId,
                        SenderId       = AccountId2
                    };
                    container.MessageSet.Add(messageSet);
                    container.SaveChanges();
                }
                // this code post query in server and get await

                return(true);
            }
            else
            {
                errorMessage = "Вы не ввели сообщение, либо оно слишком короткое!";
                return(false);
            }
        }
Ejemplo n.º 2
0
        private void SendMessageButton_Click(object sender, EventArgs e)
        {
            if (selectedUser == null)
            {
                MessageBox.Show("Вы не выбрали получателя");
                return;
            }

            ForumContainer Scontainer = new ForumContainer();

            var converstation = new ConversationSet()
            {
                SenderId             = Client.AccountId,
                RecipientId          = selectedUser.AccountId,
                AccountSet_Recipient = Scontainer.AccountSet.SingleOrDefault(x => x.AccountId == selectedUser.AccountId),
                AccountSet_Sender    = Scontainer.AccountSet.SingleOrDefault(x => x.AccountId == Client.AccountId)
            };

            void handlerClickerChat(object SenderK, EventArgs args)
            {
                MessageSendForm messageForm = new MessageSendForm(Client, converstation.AccountSet_Recipient);

                messageForm.Show();
            };

            Scontainer.ConversationSet.Add(converstation);
            Scontainer.SaveChanges();

            Chat.Chat newChat = new Chat.Chat(converstation.AccountSet_Recipient.Login, handlerClickerChat); // с кем беседа
            pmFlowLoyoutPanel.Controls.Add(newChat);

            if (Message.Text != string.Empty || Message.Text.Length < 5)
            {
                MessageSet message = new MessageSet()
                {
                    Date           = DateTime.Now,
                    MessageText    = Message.Text,
                    ConversationId = converstation.ConversationId,
                    SenderId       = Client.AccountId
                };
                Scontainer.MessageSet.Add(message);
                Scontainer.SaveChanges();

                Message.Text = "";
                // this code post query in server and get await
            }
            else
            {
                MessageBox.Show("Вы не ввели сообщение, либо оно слишком короткое!");
                return;
            }
            Close();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// init = Получатель, send = Отправитель
        /// </summary>
        /// <param name="init">Получатель</param>
        /// <param name="send">Отправитель</param>
        private void GetMessages(AccountSet init, AccountSet send)
        {
            using (ForumContainer container = new ForumContainer())
            {
                ConversationSet conversation = container.ConversationSet.SingleOrDefault(x =>
                                                                                         (x.AccountSet_Recipient.AccountId == init.AccountId && x.AccountSet_Sender.AccountId == send.AccountId) ||
                                                                                         (x.AccountSet_Recipient.AccountId == send.AccountId && x.AccountSet_Sender.AccountId == init.AccountId)
                                                                                         );


                if (conversation == null)
                {
                    ConversationSet newConversation = new ConversationSet()
                    {
                        RecipientId = init.AccountId,
                        SenderId    = send.AccountId
                    };

                    FormConversation = newConversation;

                    container.ConversationSet.Add(newConversation);
                    container.SaveChanges();

                    return;
                }
                else
                {
                    FormConversation = conversation;

                    var MessageList = container.MessageSet.Where(x => x.ConversationSet.ConversationId == FormConversation.ConversationId).ToList();
                    if (MessageList.Count > 0)
                    {
                        foreach (MessageSet message in MessageList)
                        {
                            AddNewMessageContainer(message);
                        }
                    }

                    return;
                }
            }
        }
    /*
    <ConversationSet Key="ConversationLevel9_1_ColonyAdama">
        <Conversation>
            <Potrait Name="PotraitRight" Texture="Conversation/Conversation_WilliamAdama" />
            <TalkStr Index="10001" />
            <TalkStr Index="10002" />
            <TalkStr Index="10003" />
            <TalkStr Index="10004" />
            <TalkStr Index="10005" />
        </Conversation>
    </ConversationSet>
     */
    public static bool ParseConversationSet( XmlNode _ConversationSetNode , 
										  out ConversationSet _ConversationSet )
    {
        _ConversationSet = null ;
        if( "ConversationSet" == _ConversationSetNode.Name )
        {

            _ConversationSet = new ConversationSet() ;
            _ConversationSet.m_Key = _ConversationSetNode.Attributes[ "Key" ].Value ;
            for( int i = 0 ; i < _ConversationSetNode.ChildNodes.Count ; ++i )
            {
                Conversation conversation = null ;
                if( true == ParseConversation( _ConversationSetNode.ChildNodes[ i ] , out conversation ) )
                {
                    _ConversationSet.m_Conversations.Add( conversation ) ;
                }
            }
        }
        return ( _ConversationSet != null &&
                 _ConversationSet.m_Conversations.Count > 0 ) ;
    }
    private void PlayNext()
    {
        // 播放下一個 字串 對話 或是對話集
        // Debug.Log( "PlayNext() " ) ;

        if( null == m_CurrentConversation ||
            ( null != m_CurrentConversation &&
              true == m_CurrentConversation.IsFinished() )
            )
        {
            m_CurrentConversation = m_WaitingConversationSets.Dequeue() ;
            // Debug.Log( "PlayNext() m_CurrentConversation = m_WaitingConversationSets.Dequeue" ) ;
        }

        if( null == m_CurrentConversation )
        {
            Debug.Log( "PlayNext() null == m_CurrentConversation" ) ;
            return ;
        }

        if( false == m_CurrentConversation.IsFinished() )
        {
            EnableAllDialog( true ) ;
            m_CurrentConversation.PlayNext() ;
            if( null != m_Audio )
            {
                this.gameObject.audio.PlayOneShot( m_Audio ) ;
            }
        }
    }
 public ConversationSet( ConversationSet _src )
 {
     m_Key = _src.m_Key ;
     m_Conversations = _src.m_Conversations ;
     m_CurrentIndex = _src.m_CurrentIndex ;
 }