private void buttonStopPresenting_Click(object sender, RoutedEventArgs e) { ShareableContent selectedContent = (ShareableContent)listBoxContentBin.SelectedItem; if (selectedContent != null) { int reason; // if can invoke returns false, you can get the reason from here. if (selectedContent.CanInvoke(ShareableContentAction.StopPresenting, out reason)) { selectedContent.StopPresenting(); } } else { Log("Select a content from Content Bin first"); } }
private void buttonCreatePPT_Click(object sender, RoutedEventArgs e) { // title of each content should be different title = textBoxTitle.Text; try { if (_contentModality.CanInvoke(ModalityAction.CreateShareablePowerPointContent)) { // This way of calling will block the app until Content is created. To create a more responsive app you can // use an AsyncCallback Delegate to end this asynchoronous opertation. More information about this C# concept // can be found on MSDN IAsyncResult result = _contentModality.BeginCreateContentFromFile(ShareableContentType.PowerPoint, title, textBoxPPTFilePath.Text, true, null, null); ShareableContent pptContent = _contentModality.EndCreateContentFromFile(result); // The newly created content is only present on local computer. Lets upload it to conference // where other users can also see the content listed in their content bin. int reason; // if can invoke returns false, you can get the reason from here. if (pptContent.CanInvoke(ShareableContentAction.Upload, out reason)) { pptContent.Upload(); // above call will start uploading the content to conference. Once the content is ready its // state will change from Offline to Online thats when Present() can be called. } } } catch (NullReferenceException) { Log("Null Reference Exception: Did you create the conversation first? If yes, try restarting the sample."); } catch (ContentTitleExistException) { Log("Content Title Exists Exception: Please enter a unique title and try again."); } catch (LyncClientException) { Log("Enter a valid path to the PowerPoint presentation."); } catch (Exception excep) { Log(excep.ToString()); } }
private void buttonShareWhiteBoard_Click(object sender, RoutedEventArgs e) { // title of each content should be different title = textBoxTitle.Text; try { if (_contentModality.CanInvoke(ModalityAction.CreateShareableWhiteboardContent)) { // This way of calling will block the app until Content is created. To create a more responsive app you can // use an AsyncCallback Delegate to end this asynchoronous opertation. More information about this C# concept // can be found on MSDN IAsyncResult result = _contentModality.BeginCreateContent(ShareableContentType.Whiteboard, title, null, null); whiteBoardContent = _contentModality.EndCreateContent(result); whiteBoardContent.StateChanged += new EventHandler <ShareableContentStateChangedEventArgs>(whiteBoardContent_StateChanged); // The newly created content is only present on local computer. Lets upload it to conference // where other users can also see the content listed in their content bin. int reason; // if can invoke returns false, you can get the reason from here. if (whiteBoardContent.CanInvoke(ShareableContentAction.Upload, out reason)) { whiteBoardContent.Upload(); // above call will start uploading the content to conference. Once the content is ready its // state will change from Offline to Online thats when Present() can be called. } } } catch (ContentTitleExistException) { Log("Title already exists. Please enter a unique title and try again."); } catch (NullReferenceException) { Log("Null Reference Exception: Did you create the conversation first? If yes, you can try restarting the sample."); } }
/// <summary> /// 共享电子白板 /// </summary> public static void ShareWhiteboard(ConversationWindow conversationWindow, string selfName, Action callBack) { try { if (conversationWindow != null) { DispatcherTimer timer1 = null; TimerJob.StartRun(new Action(() => { if (conversationWindow.Conversation == null) { timer1.Stop(); return; } //获取电子白板启动模型实例 ContentSharingModality contentShareingModality = (ContentSharingModality)conversationWindow.Conversation.Modalities[ModalityTypes.ContentSharing]; DispatcherTimer timer2 = null; //查看是否可以共享白板 var canShareWhiteboard = contentShareingModality.CanInvoke(ModalityAction.CreateShareableWhiteboardContent); if (canShareWhiteboard) { if (contentShareingModality.CanInvoke(ModalityAction.Connect)) { contentShareingModality.BeginConnect(null, null); } //获取共享白板的名称 string whiteShareName = GetWhiteShareName(selfName, whiteBoardShareName); if (contentShareingModality.CanInvoke(ModalityAction.CreateShareableWhiteboardContent)) { //创建一个默认的电子白板 IAsyncResult result = contentShareingModality.BeginCreateContent(ShareableContentType.Whiteboard, whiteShareName, null, null); //结束提交 ShareableContent whiteBoardContent = contentShareingModality.EndCreateContent(result); TimerJob.StartRun(new Action(() => { int reason; //【在此可监控异常】 if (whiteBoardContent.CanInvoke(ShareableContentAction.Upload, out reason)) { //电子白板上传 whiteBoardContent.Upload(); } if (whiteBoardContent.State == ShareableContentState.Online) { timer2.Stop(); //当前呈现(电子白板) whiteBoardContent.Present(); if (callBack != null) { callBack(); } } }), 10, out timer2); timer1.Stop(); } } }), 400, out timer1); } else { MessageBox.Show("使用电子白板共享之前先选择一个会话", "操作提示", MessageBoxButton.OK, MessageBoxImage.Information); } } catch (Exception ex) { LogManage.WriteLog(typeof(LyncHelper), ex); } }