This topic has not yet been rated - Rate this topic

How to: Request and release control of shared resources

[This is preliminary documentation and is subject to change.]

Describes how to request control of a resource that is shared by another conversation participant. For an overview of resource sharing in Microsoft Lync 2013 Preview, see Resource Sharing in Lync.

The topic in this section builds on the sample application introduced in How Do I in Resource Sharing and continued in How to: Start resource sharing conversations. Figure 1 highlights the part of the sample Windows form that is discussed in this topic. The tasks in the following list are discussed in this topic and shown in the code samples.

  • Requesting control of a shared resource.

  • Displaying the local user’s sharing participation state as it changes.

  • Releasing control of a shared resource.

  • Stopping the shared resource view.

Figure 1. The Request, Release, and Stop Sharing resource sharing buttons

The Request Control and Release Control buttons

Before your application runs the logic in this topic, a resource sharing conversation must be active with one or more participants in addition to the local user. The local user participation state must be ParticipationState.Viewing, and another conversation participant must be sharing a resource in the conversation. For information about reaching this starting application state, see How to: Start resource sharing conversations.

A user can request control of a shared resource if their current participation state is ParticipationState.Viewing. This state is possible when another user is sharing their local resource and the local user is viewing the shared resource. When the local user makes a control request, their participation state changes to ParticipationState.RequestingControl. The user who is sharing a resource must accept the request before the local user’s participation state changes to ParticipationState.Controlling.

Important note Important

Only one user at a time can request control. If your application requests control and the local participant’s participation state is immediately set to ParticipationState.Viewing instead of ParticipationState.RequestingControl, another participant has a pending control request that the sharing participant has not responded to.

When a request for control of a resource is declined or canceled because there is a pending request from another user, the requesting user’s participation state change sequence is as follows:

  1. ParticipationState.Viewing

  2. ParticipationState.RequestingControl

  3. ParticipationState.Viewing

The ParticipationState.Controlling state is never set in this scenario.

Code example

The following example requests control of a resource shared by another user.

        /// <summary>
        ///Request control of a remotely owned resource and shared resource.
        ///The Request button is enabled when the _sharingModality_ActionAvailabilityChanged event handler is called
        ///with the event argument that specifies the ModalityAction.RequestSharingControl action is available.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Request_Button_Click(object sender, EventArgs e)
        {
            if (_LocalParticipantSharingModality != null && _LocalParticipantSharingModality.CanInvoke(ModalityAction.RequestSharingControl))
            {
                _LocalParticipantSharingModality.BeginRequestControl(SharingControlCallback, "request");
            }
        }

Important note Important

The previous example only requests control of a resource. The remote user must accept or decline. If the request is ignored by the other user, the requesting user participation status remains ParticipationState.RequestingControl until another presenter shares a resource and replaces the currently shared resource.

The following example is called on the platform thread when the request control operation is completed.

        /// <summary>
        /// Callback method for all asynchronous modality control methods.
        /// </summary>
        /// <param name="ar"></param>
        private void SharingControlCallback(System.IAsyncResult ar)
        {
            //Get the application sharing modality for the conversation participant to invoke controlling action on.
            ApplicationSharingModality sharingModality = (ApplicationSharingModality)_participantSharingModalities[_ResourceControllingContact.Uri];
 
            if (ar.IsCompleted == false)
            {
                MessageBox.Show(ar.AsyncState.ToString() +  " did not complete");
            }
            //Complete the asynchronous controlling action according to the asynchronous state string that indicates
            //which controlling action to complete.
            switch (ar.AsyncState.ToString().ToUpper())
            {
                case "ACCEPT":
                    sharingModality.EndAcceptControlRequest(ar);
                    break;
                case "DECLINE":
                    sharingModality.EndDeclineControlRequest(ar);
                    break;
                case "GRANT":
                    sharingModality.EndGrantControl(ar);
                    break;
                case "RELEASE":
                    sharingModality.EndReleaseControl(ar);
                    break;
                case "REQUEST":
                    sharingModality.EndRequestControl(ar);
                    break;
                case "REVOKE":
                    sharingModality.EndRevokeControl(ar);
                    break;
                case "DISCONNECT":
                    sharingModality.EndDisconnect(ar);
                    break;
            }
        }

A user’s participation state is their current resource sharing-related activity. A user can be sharing a resource, viewing a resource shared by another user, requesting control of a resource, or controlling a resource. It is important that the local user is notified of any changes to this state. The Lync 2013 Preview client gives visual clues such as the gold chrome frame that encloses the shared resource and conversation window text that shows the participation state. Your application should also show the participation state of the local user, primarily because a user may have closed the sharing stage of the conversation window or minimized the window. In that case, the user must rely on your application to disclose the current participation state.

Note Note

Once a user has started sharing a local resource, hiding the sharing stage of the conversation window or minimizing the window does not stop the resource sharing.

Handling the ParticipationStateChanged event

When a conversation is started and no participant has shared a resource yet, every participant’s participation state is ParticipationState.None. After a participant starts sharing a resource, all participants who accept the sharing invitation have a participation state of ParticipationState.Viewing. The sharing participant has a participation state of ParticipationState.Sharing. If you have registered an event callback method for the ApplicationSharingModality.ParticipationStateChanged event on the Microsoft.Lync.Model.Conversation.Sharing.ApplicationSharingModality object of the Microsoft.Lync.Model.Conversation.Conversation, you can update your UI with the new participation state of the local user.

Code example

The following example updates the text of a label on the UI with the current participation state of the local user.

        /// <summary>
        /// Handles the event raised when a participant participation state changes.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void _sharingModality_ParticipationStateChanged(object sender, ParticipationStateChangedEventArgs e)
        {
            if (((ApplicationSharingModality)sender) == _sharingModality)
            {
                if (e.NewState.ToString() == "None")
                {
                    this.Invoke(new UpdateSharingStateDelegate(UpdateSharingState), new object[] { "not sharing" });
                }
                else
                {
                    this.Invoke(new UpdateSharingStateDelegate(UpdateSharingState), new object[] { e.NewState.ToString() });
                }
                ApplicationSharingModality participantModality = (ApplicationSharingModality)sender;
                string userName = participantModality.Controller.Contact.GetContactInformation(ContactInformationType.DisplayName).ToString();
                this.Invoke(new ChangeLabelTextDelegate(ChangeLabelText), new object[] { SharedResource_Label, userName });
            }
        }

A user can release control of a shared resource if their current participation state is ParticipationState.Controlling. This state is possible when another user is sharing their local resource and the local user is controlling the shared resource. When the local user releases control of a shared resource, their participation state changes to ParticipationState.Viewing.

Code example

The following example releases control of the shared resource after confirming that the local user can release control of the resource.

        /// <summary>
        ///Release control of a remotely owned resource and shared resource.
        ///The Release button is enabled when the _sharingModality_ActionAvailabilityChanged event handler is
        ///called with the event argument that specifies the ModalityAction.ReleaseSharingControl action is available.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Release_Button_Click(object sender, EventArgs e)
        {
            if (_LocalParticipantSharingModality != null && _LocalParticipantSharingModality.CanInvoke(ModalityAction.ReleaseSharingControl))
            {
                _LocalParticipantSharingModality.BeginReleaseControl(SharingControlCallback, "release");
            }
        }

If you want to stop sharing a local resource, switch to a different local resource, or stop viewing a remote resource, you disconnect from the conversation application sharing modality. When you share a different local resource, you are automatically re-connected to the sharing modality.

Code example

The following example disconnects the conversation application sharing modality but leaves the conversation active.

        /// <summary>
        /// Disconnects the conversation application sharing modality so that the user
        /// is no longer sharing or viewing a resource.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Disconnect_Button_Click(object sender, EventArgs e)
        {
            if (_sharingModality != null && _sharingModality.CanInvoke(ModalityAction.Disconnect))
            {
                _sharingModality.BeginDisconnect(ModalityDisconnectReason.None, SharingControlCallback, "disconnect");
 
            }
        }

When your application has requested and released control of a shared resource, the resource is shown on the content stage of all participants and the local user is not in control. In addition, the ModalityAction.RequestSharingControl action is available. You can now request sharing control of the shared resource again. If the local user is a presenter in the conversation, a local resource can be shared.

Community Additions

Show:
© 2014 Microsoft. All rights reserved.