/// <summary>
        /// Event handler which is triggered when this page is navigated to
        /// </summary>
        /// <param name="e">Event arguments</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            DataContext = null; //important part, whenever you navigate, refreshes the ViewModel - no deletion, just resetting of the DataContext, so the page won't get stuck
            DataContext = App.ChatLogViewModel; //and finally the resetting

            currentPartner = (RemoteReference)PhoneApplicationService.Current.State["CurrentPartner"];
            myChatUser = (ChatUser)PhoneApplicationService.Current.State["MyChatUser"];

            ui_chatlogheader.Text = String.Format("Chatting with {0}", PhoneApplicationService.Current.State["PartnerNickname"] as String);
        }
示例#2
0
        public MainPage()
        {
            InitializeComponent();

            this.UIDispatcher = (DispatchedHandler a) => CoreWindow.GetForCurrentThread().Dispatcher.RunAsync(CoreDispatcherPriority.Normal, a);

            this.chatServiceTag = new TypeTag("chat");

            MyChatUsersViewModel = (ChatUsersViewModel)Resources["ChatUsersViewModel"];
            this.chatUsers = new Dictionary<Guid, RemoteReference>();

            // Set up our own name
            string nickname = "User" + new Random().Next(1, 99);
            ui_nickname.Text = nickname;
            ui_nickname.IsEnabled = false;

            // Set up our own user and all callbacks
            myChatUser = new ChatUser(nickname, this.Dispatcher);
            myChatUser.PartnerLeftChatEvent += PartnerLeftChat;
            myChatUser.InviteReceivedEvent += InviteReceivedFromUser;
            myChatUser.AcceptInviteEvent += AcceptInviteByUser;
            myChatUser.RejectInviteEvent += RejectInviteByUser;
            myChatUser.InviteAcceptedEvent += InviteAcceptedByUser;
            myChatUser.InviteRejectedEvent += InviteRejectedByUser;

            // Set up the listener callbacks for joining/leaving of users
            this.userListener = new ServiceListener<RemoteReference>();
            userListener.IsDiscovered += UserListener_IsDiscovered;
            userListener.IsDisconnected += UserListener_IsDisconnected;
            userListener.IsReconnected += UserListener_IsDiscovered;
            EventLoop.Instance.Whenever(chatServiceTag, userListener);

            // Export our service
            myServicePublication = EventLoop.Instance.Broadcast(chatServiceTag, myChatUser);

            // Go online on the network
            NetPOC.Network.NetworkControl.Network networkObj = EventLoop.Instance.GoOnline();
        }