void ConversationManager_ConversationAdded(object sender, ConversationManagerEventArgs e) { this.Dispatcher.BeginInvoke(new Action(() => { StatusTextBlock.Text = "A conversation is added"; }), null); if (_conversation != null && e.Conversation.GetHashCode() == _conversation.GetHashCode()) { _sharingModality = (ApplicationSharingModality)_conversation.Modalities[ModalityTypes.ApplicationSharing]; _sharingModality.ModalityStateChanged += sharingModality_ModalityStateChanged; _conversation.AddParticipant(_remoteContact); } // populate the ShareableListBox with ShareableResources this.Dispatcher.BeginInvoke(new Action(() => { StatusTextBlock.Text = "Populating shareable resources..."; ShareableResourcesListBox.Items.Clear(); for (int i = 0; i < _sharingModality.ShareableResources.Count; i++) { SharingResource sr = _sharingModality.ShareableResources[i]; ShareableResourcesListBox.Items.Add(sr.Name); } ShareableResourcesListBox.SelectedIndex = 0; StatusTextBlock.Text = "Shareable resources are populated."; }), null); }
internal SharingResource_Wrapper(SharingResource sharingResource) { if (sharingResource == null) { throw new ArgumentNullException(); } _SharingResource = sharingResource; }
/// <summary> /// Shares the resource selected by the user. /// </summary> private void ShareSelectedResource(SharingResourceType selectedResourceType) { //If there is no active conversation to share this resource in, return from handler if (Conversation == null) { return; } _log.Debug("StartSharingResource"); //If there is no sharing modality stored locally on the active conversation, get it from the active conversation and store it. if (_sharingModality == null) { _sharingModality = Conversation.Modalities[ModalityTypes.ApplicationSharing] as ApplicationSharingModality; } SharingResource sharingResource = null; if (_sharingModality.ShareableResources == null) { _log.Debug("ShareableResources is null"); return; } //foreach (SharingResource s in _sharingModality.ShareableResources) //{ // //if (s.Id == selectedResource.ResourceId) // //{ // // //Get the type of resource selected by the user // // selectedResourceType = s.Type; // // sharingResource = s; // // break; // //} //} CanShareDetail sharingDetail; if (!_sharingModality.CanShare(selectedResourceType, out sharingDetail)) { _log.Debug("sharingDetail:{0}", sharingDetail); switch (sharingDetail) { case CanShareDetail.DisabledByOrganizerPolicy: MessageBox.Show("The conversation organizer has disallowed sharing"); break; case CanShareDetail.DisabledByPolicy: MessageBox.Show("Sharing resources is not allowed "); break; case CanShareDetail.DisabledByRole: MessageBox.Show("Conference attendees cannot share resources"); break; } return; } _log.Debug("selectedResourceType: {0}", selectedResourceType.ToString()); if (selectedResourceType == SharingResourceType.Desktop) { _sharingModality.BeginShareDesktop((ar) => { _sharingModality.EndShareDesktop(ar); } , null); } else if (selectedResourceType == SharingResourceType.Monitor) { _sharingModality.BeginShareResources(sharingResource, (ar) => { _sharingModality.EndShareResources(ar); }, null); } else { _sharingModality.BeginShareResources(sharingResource, (ar) => { try { _sharingModality.EndShareResources(ar); } catch (OperationException oe) { throw oe; } catch (LyncClientException lce) { throw lce; } } , null); } }
/// <summary> /// Start application sharing with the remote participant /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void StartSharingButton_Click(object sender, RoutedEventArgs e) { if (_conversation != null && _sharingModality != null) { SharingResource sr = _sharingModality.ShareableResources[ShareableResourcesListBox.SelectedIndex]; switch (sr.Type) { case SharingResourceType.Desktop: this.Dispatcher.Invoke(new Action(() => { _appsharingHighlighters = new Highlighter[Screen.AllScreens.Length]; for (int i = 0; i < Screen.AllScreens.Length; i++) { _appsharingHighlighters[i] = new Highlighter(HighLighterMode.Screen, i); } }), null); _sharingModality.BeginShareDesktop((ar) => { _sharingModality.EndShareDesktop(ar); }, null); break; case SharingResourceType.Monitor: this.Dispatcher.Invoke(new Action(() => { _appsharingHighlighters = new Highlighter[1]; _appsharingHighlighters[0] = new Highlighter(HighLighterMode.Screen, sr.Id - 1); }), null); _sharingModality.BeginShareResources(sr, (ar) => { _sharingModality.EndShareResources(ar); }, null); break; case SharingResourceType.Process: this.Dispatcher.Invoke(new Action(() => { _appsharingHighlighters = new Highlighter[1]; _appsharingHighlighters[0] = new Highlighter(HighLighterMode.Process, sr.Id); }), null); _sharingModality.BeginShareResources(sr, (ar) => { _sharingModality.EndShareResources(ar); }, null); break; case SharingResourceType.Window: this.Dispatcher.Invoke(new Action(() => { _appsharingHighlighters = new Highlighter[1]; _appsharingHighlighters[0] = new Highlighter(HighLighterMode.Window, sr.Id); }), null); _sharingModality.BeginShareResources(sr, (ar) => { _sharingModality.EndShareResources(ar); }, null); break; default: break; } } }
public void ShareAndSync(IntPtr intptr, ApplicationSharingModality shareModality, SharingResource item) { try { //共享程序置顶 Win32API.SetWindowPos(intptr, -1, 615, 110, 0, 0, 1 | 2); //开始共享该程序 shareModality.BeginShareResources(item, null, null); //同步页面 Conference.MainWindow.MainPageInstance.ChairView.SyncPageHelper(ConferenceCommon.EnumHelper.ViewSelectedItemEnum.Resource); } catch (Exception ex) { LogManage.WriteLog(this.GetType(), ex); } finally { } }
/// <summary> /// Shows the shared resouce "chrome" around the shared process /// </summary> /// <param name="selectedResourceObject"></param> internal void ShowProcessChrome(SharingResource selectedResourceObject) { Process[] processes = Process.GetProcesses(); Process currentProcess = null; foreach (Process process in processes) { //In the case of Outlook, the main outlook window MainWindowHandle is the Id of the process. if (selectedResourceObject.Id == (Int32)process.MainWindowHandle || selectedResourceObject.Id == process.Id) { currentProcess = process; break; } } if (currentProcess == null) { return; } //activate the selected application and bring to foreground IntPtr currentProcessHandle = currentProcess.MainWindowHandle; SetForegroundWindow(currentProcessHandle); //Get the visual state of the shared application WINDOWPLACEMENT placement = new WINDOWPLACEMENT(); placement.length = Marshal.SizeOf(placement); GetWindowPlacement(currentProcessHandle, out placement); if (placement.showCmd == SW_MINIMIZE) { ShowWindow(currentProcessHandle, SW_RESTORE); } //Get the location and rectangle of the selected application RECT processWindowSize = new RECT(); GetWindowRect(currentProcessHandle, ref processWindowSize); Size size = new Size(); size = new Size(processWindowSize.Height - processWindowSize.X, processWindowSize.Width - processWindowSize.Y); Rectangle processWindow = new Rectangle(new Point(processWindowSize.X, processWindowSize.Y), size); Rectangle currentProcessWindow = processWindow; //set the size of the Chrome window based on the visual state of the //shared application currentChrome = new Chrome(); if (placement.showCmd == SW_MAXIMIZE) { int taskBarSize = Screen.PrimaryScreen.Bounds.Height - Screen.PrimaryScreen.WorkingArea.Height; processWindow.X = 0; processWindow.Y = 0; processWindow.Height = (processWindowSize.Width - borderWith * 2) + 2; processWindow.Width = processWindowSize.Height + processWindowSize.X; currentChrome.Highlight(processWindow, true, borderWith); } else { currentChrome.Highlight(processWindow, false, borderWith); } }
/// <summary> /// 共享并同步 /// </summary> /// <param name="intptr"></param> /// <param name="shareModality"></param> /// <param name="item"></param> public void ShareAndSync(IntPtr intptr, ApplicationSharingModality shareModality, SharingResource item) { try { //共享程序置顶 Win32API.SetWindowPos(intptr, -1, 615, 110, 0, 0, 1 | 2); //开始共享该程序 shareModality.BeginShareResources(item, null, null); if (this.ShareAndSyncCallBack != null) { this.ShareAndSyncCallBack(); } } catch (Exception ex) { LogManage.WriteLog(this.GetType(), ex); } finally { } }