/// <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);
        }
        /// <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

            PageInformation info = e.Parameter as PageInformation;
            currentPartner = info.partner;
            myChatUser = info.myChatUser;

            ui_chatlogheader.Text = String.Format("Chatting with {0}", info.nickname);
        }
        public RemoteReference AddParameterReferencedObject(object obj)
        {
            TypeTag typeTag = new TypeTag("");
            Guid identifier = Guid.NewGuid();
            RemoteReference remoteReference = new RemoteReference(typeTag, identifier);
            // Change the typetag to something unique - to make sure it wouldn't be found as a service when looking up the object this remoteReference belongs to
            //remoteReference.serviceTag.tag = identifier.ToString();
            this.exportedObjects.Add(identifier, obj);
            this.remoteReferences.Add(identifier, remoteReference);

            return remoteReference;
        }
Exemplo n.º 4
0
 public PageInformation(RemoteReference partner, string nickname, ChatUser chatUser)
 {
     this.partner = partner;
     this.nickname = nickname;
     this.myChatUser = chatUser;
 }
Exemplo n.º 5
0
        /// <summary>
        /// Perform a remote method invocation on a remote object
        /// </summary>
        /// <param name="objectReference">The RemoteReference to the object on which to perform the remote method invocation</param>
        /// <param name="selector">Object containing the name of the method we wish to invoke, in string form, e.g. "GetName" and the due time</param>
        /// <param name="parameters">The array of parameters which are required by the to-be-invoked method</param>
        /// <returns>Returns a future, or a "future that we'll try to get you a return value at some point in the future"</returns>
        public Future RemoteMethodInvocation(RemoteReference objectReference, MessageSelector selector, object[] parameters)
        {
            System.Diagnostics.Debug.WriteLine(String.Format("PERFORMED RMI: {0}, {1}", selector, objectReference.sourceAddress));

            // Convert all parameters of type UObject to a RemoteReference (pass-by-reference for UObjects)
            for (int i = 0; i < parameters.Length; i++)
                if (parameters[i] is UObject)
                    parameters[i] = this.serviceManager.exportedServiceManager.AddParameterReferencedObject(parameters[i]);

            // Create a new future. We add a reference (the guid) of this future to the method invocation, so we know a return value belongs to this future
            Future future = new Future(objectReference.guid);
            // Create the data packet to send over the network
            NetworkRemoteMethodInvocation networkObject = new NetworkRemoteMethodInvocation(objectReference.guid, future.guid, selector.selector, parameters);
            // Enqueue it in the outgoing queue
            this.eventQueueOutgoing.Enqueue(objectReference.sourceAddress, networkObject, selector.due);

            return future;
        }
Exemplo n.º 6
0
 /// <summary>
 /// Invite a certain user to a personal chat
 /// </summary>
 /// <param name="user">The reference to the user with whom we want to chat</param>
 private void InviteUser(RemoteReference user)
 {
     System.Diagnostics.Debug.WriteLine("Inviting user");
     user.AsyncInvoke("Invite", this.myServicePublication.serviceIdentifier);
     this.UIDispatcher(() =>
         this.ShowMessageBox_OK(string.Format(this.inviteSuccessful_message, this.currentPartnerModel.nickname), this.inviteSuccessful_title));
 }
Exemplo n.º 7
0
        /// <summary>
        /// Join the chat with a certain user. Will change switch to the communication page.
        /// </summary>
        /// <param name="partner">Partner with whom we want to chat</param>
        /// <param name="partnerModel">The model of our current partner</param>
        /// 
        private void JoinChat(RemoteReference partner, ChatUserModel partnerModel)
        {
            this.currentPartner = partner;
            this.currentPartnerModel = partnerModel;

            partner.AsyncInvoke("EnteredChatNotification", this.myChatUser.GetName());
            Frame.Navigate(typeof(CommunicationPage), new PageInformation(partner, partnerModel.nickname, this.myChatUser));
        }
Exemplo n.º 8
0
        /// <summary>
        /// Event handler which is to be triggered when a chat user has disconnected from the network.
        /// This is not a partial failure, so we won't be seeing the user back for quite a while.
        /// </summary>
        /// <param name="userReference"></param>
        private void UserListener_IsDisconnected(RemoteReference userReference)
        {
            // Check if it is our current chat partner that has just disconnected. If yes, we should leave the chat.
            if (currentPartner.guid.Equals(userReference.guid))
                this.PartnerLeftChat();

            Guid userIdentifier = this.chatUsers.FirstOrDefault(x => x.Value.guid.Equals(userReference.guid)).Key;
            chatUsers.Remove(userIdentifier);
            this.UIDispatcher(() => this.MyChatUsersViewModel.RemoveChatUser(userIdentifier));
        }
Exemplo n.º 9
0
 /// <summary>
 /// Event handler which is to be triggered when a chat user has been discovered on the network
 /// </summary>
 /// <param name="userReference">The identifier of the chat user</param>
 private void UserListener_IsDiscovered(RemoteReference userReference)
 {
     FutureListener<string> nameListener = new FutureListener<string>();
     // Get his name and store it locally - this is very useful for further operations (otherwise we'd have to ask him every time -> network delays)
     nameListener.IsResovled +=
         (string name) =>
         {
             this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => MyChatUsersViewModel.AddChatUser(userReference.guid, name));
             this.chatUsers.Add(userReference.guid, userReference);
         };
     Future future = userReference.AsyncInvoke("GetName");
     future.When(nameListener);
 }
Exemplo n.º 10
0
 /// <summary>
 /// Event handler which is triggered when the user selection in the UI changes
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void ui_UserList_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     ChatUserModel selectedUser = e.AddedItems[0] as ChatUserModel;
     if (selectedUser == null)
         System.Diagnostics.Debug.WriteLine("Couldn't cast eventargs to UserModel");
     else
     {
         RemoteReference userReference;
         if (this.chatUsers.TryGetValue(selectedUser.guid, out userReference))
         {
             currentPartner = userReference;
             currentPartnerModel = selectedUser;
         }
         else
             System.Diagnostics.Debug.WriteLine("Couldn't find selected user " + selectedUser.guid.ToString());
     }
 }
Exemplo n.º 11
0
        /// <summary>
        /// Join the chat with a certain user. Will change switch to the communication page.
        /// </summary>
        /// <param name="partner">Partner with whom we want to chat</param>
        /// <param name="partnerModel">The model of our current partner</param>
        private void JoinChat(RemoteReference partner, ChatUserModel partnerModel)
        {
            this.currentPartner = partner;
            this.currentPartnerModel = partnerModel;
            PhoneApplicationService.Current.State["CurrentPartner"] = partner;
            PhoneApplicationService.Current.State["PartnerNickname"] = partnerModel.nickname;
            PhoneApplicationService.Current.State["MyChatUser"] = this.myChatUser;

            partner.AsyncInvoke("EnteredChatNotification", this.myChatUser.GetName());
            NavigationService.Navigate(communicationPageURI);
        }
        /// <summary>
        /// Export a certain service. This service will link the given serviceImplementation to the provided TypeTag.
        /// When the ServiceImplementation implements the UObject interface, a RemoteReference will be returned.
        /// Otherwise the ServiceImplementation itself will be returned.
        /// When the same object is exported twice, it will be handled as a new service. The instance will be stored as if it was new.
        /// This will also generate a new RemoteReference.
        /// </summary>
        /// <param name="tag">TypeTag which identifies the service which needs to be exported</param>
        /// <param name="serviceImplementation">Service implementation to export (make available on the network)</param>
        /// <param name="identifier">Output parameter which will give you the identifier associated with the service implementation</param>
        /// <returns>Returns an object which can be used to transmit to other devices (either the ServiceImplementation itself or a RemoteReference)</returns>
        public object ExportService(TypeTag tag, object serviceImplementation, out Guid identifier)
        {
            // Check if the typetag already has exported service implementations
            identifier = Guid.NewGuid();
            if (!services.ContainsKey(tag))
                services.Add(tag, new List<Guid>() { identifier });
            else
            {
                // If an implementation already exists - add a new implementation to the existing list
                List<Guid> _services;
                if (services.TryGetValue(tag, out _services))
                    _services.Add(identifier);
            }

            // Now add the service implementation to the list of exported services
            this.exportedObjects.Add(identifier, serviceImplementation);

            // If the service is a UObject, we should refer to it with a remote reference. Store this too! (and return a RemoteReference)
            if (serviceImplementation is UObject)
            {
                RemoteReference remoteReference = new RemoteReference(tag, identifier);
                this.AddRemoteReference(identifier, remoteReference);
                // Returns the RemoteReference as "exportable object"
                return remoteReference;
            }
            // Otherwise just return the implementation itself
            return serviceImplementation;
        }
 /// <summary>
 /// Add a new RemoteReference for a certain service identified per TypeTag
 /// </summary>
 /// <param name="tag">TypeTag which identifies the service</param>
 /// <param name="remoteReference">RemoteReference to link to this particular service</param>
 private void AddRemoteReference(Guid identifier, RemoteReference remoteReference)
 {
     remoteReferences.Add(identifier, remoteReference);
 }
 /// <summary>
 /// Try to get an already existing RemoteReference for a given identifier
 /// </summary>
 /// <param name="identifier">Guid to get the RemoteReference for</param>
 /// <param name="remoteReference">Output parameter where the RemoteReference will be stored</param>
 /// <returns>Returns whether an existing RemoteReference could be found or not (which will tell you if the output parameter is useful or not)</returns>
 public Boolean TryGetRemoteReference(Guid identifier, out RemoteReference remoteReference)
 {
     return remoteReferences.TryGetValue(identifier, out remoteReference);
 }
 public Boolean TryGetParameterReferencedObject(RemoteReference remoteReference, out Object obj)
 {
     return this.exportedObjects.TryGetValue(remoteReference.guid, out obj);
 }