public MainWindow() { InitializeComponent(); try { //Start the conversation automation = LyncClient.GetAutomation(); client = LyncClient.GetClient(); } catch (LyncClientException lyncClientException) { MessageBox.Show("Failed to connect to Lync."); Console.Out.WriteLine(lyncClientException); } catch (SystemException systemException) { if (IsLyncException(systemException)) { // Log the exception thrown by the Lync Model API. MessageBox.Show("Failed to connect to Lync."); Console.WriteLine("Error: " + systemException); } else { // Rethrow the SystemException which did not come from the Lync Model API. throw; } } }
void sendFileItem_Click(object sender, RoutedEventArgs e) { IItem item = ((MenuItem)e.Source).Tag as IItem; string contacts = Environment.GetCommandLineArgs()[2]; contacts = contacts.Substring(contacts.IndexOf("<") + 1).TrimEnd(new char[] { '>' }); _LyncClient = Microsoft.Lync.Model.LyncClient.GetClient(); List <string> c = new List <string>(); c.Add(contacts); Microsoft.Lync.Model.Extensibility.Automation automation = Microsoft.Lync.Model.LyncClient.GetAutomation(); Dictionary <AutomationModalitySettings, object> _ModalitySettings = new Dictionary <AutomationModalitySettings, object>(); _ModalitySettings.Add(AutomationModalitySettings.FirstInstantMessage, "Hi Serkant, please have a look at this:"); _ModalitySettings.Add(AutomationModalitySettings.Subject, "Sharing File"); _ModalitySettings.Add(AutomationModalitySettings.SendFirstInstantMessageImmediately, true); //_ModalitySettings.Add(AutomationModalitySettings.FilePathToTransfer, @"c:\temp\test.txt"); _ModalitySettings.Add(AutomationModalitySettings.FilePathToTransfer, item.URL); IAsyncResult res = automation.BeginStartConversation(AutomationModalities.InstantMessage | AutomationModalities.FileTransfer, c, _ModalitySettings, null, null); automation.EndStartConversation(res); }
//send message private void button1_Click(object sender, RoutedEventArgs e) { try { string contacts = Environment.GetCommandLineArgs()[2]; contacts = contacts.Substring(contacts.IndexOf("<") + 1).TrimEnd(new char[] { '>' }); _LyncClient = Microsoft.Lync.Model.LyncClient.GetClient(); List <string> c = new List <string>(); c.Add(contacts); Microsoft.Lync.Model.Extensibility.Automation automation = Microsoft.Lync.Model.LyncClient.GetAutomation(); IAsyncResult res = automation.BeginStartConversation(Microsoft.Lync.Model.Extensibility.AutomationModalities.InstantMessage, c, null, SendContextDataCallback, automation); } catch (Exception ex) { MessageBox.Show("Err:" + ex.Message); } }
//share browser private void button4_Click(object sender, RoutedEventArgs e) { string browser = GetDefaultBrowserPath(); Process process = new Process(); process.StartInfo.FileName = "iexplore.exe"; process.StartInfo.Arguments = "-nomerge http://www.google.com"; process.Start(); while (process.MainWindowHandle == IntPtr.Zero) { System.Threading.Thread.Sleep(100); } string contacts = Environment.GetCommandLineArgs()[2]; contacts = contacts.Substring(contacts.IndexOf("<") + 1).TrimEnd(new char[] { '>' }); _LyncClient = Microsoft.Lync.Model.LyncClient.GetClient(); List <string> c = new List <string>(); c.Add(contacts); Microsoft.Lync.Model.Extensibility.Automation automation = Microsoft.Lync.Model.LyncClient.GetAutomation(); AutomationModalities _ChosenMode = AutomationModalities.ApplicationSharing | AutomationModalities.InstantMessage; Dictionary <AutomationModalitySettings, object> _ModalitySettings = new Dictionary <AutomationModalitySettings, object>(); // Add the process Id to the modality settings for the conversation. _ModalitySettings.Add(AutomationModalitySettings.SharedProcess, process.Id); // Add the main window handle to the modality settings for the conversation. _ModalitySettings.Add(AutomationModalitySettings.SharedWindow, process.MainWindowHandle); // Adds text to toast and local user IMWindow text-entry control. _ModalitySettings.Add(AutomationModalitySettings.FirstInstantMessage, "Hello Serkant. I would like to share my first running process with you."); _ModalitySettings.Add(AutomationModalitySettings.SendFirstInstantMessageImmediately, true); IAsyncResult res = automation.BeginStartConversation(_ChosenMode, c, _ModalitySettings, StartConversationCallback2, null); //automation.EndStartConversation(res); }
public MessageSender() { try { automation = LyncClient.GetAutomation(); } catch (LyncClientException lyncClientException) { Console.Out.WriteLine(lyncClientException); } catch (SystemException systemException) { if (IsLyncException(systemException)) { // Log the exception thrown by the Lync Model API. Console.WriteLine("Error: " + systemException); } else { // Rethrow the SystemException which did not come from the Lync Model API. throw; } } }
void shareFileItem_Click(object sender, RoutedEventArgs e) { IItem item = ((MenuItem)e.Source).Tag as IItem; string extension = item.URL.Substring(item.URL.LastIndexOf('.') + 1); Process process = new Process(); switch (extension.ToLower()) { case "dotx": process.StartInfo.FileName = "winword.exe"; process.StartInfo.Arguments = "/t " + item.URL; break; case "doc": case "docx": process.StartInfo.FileName = "winword.exe"; process.StartInfo.Arguments = item.URL; break; case "xls": case "csv": process.StartInfo.FileName = "excel.exe"; process.StartInfo.Arguments = "/r" + item.URL; break; default: process.StartInfo.FileName = "iexplore.exe"; process.StartInfo.Arguments = "-nomerge " + item.URL; break; } process.StartInfo.WindowStyle = ProcessWindowStyle.Maximized; process.Start(); while (process.MainWindowHandle == IntPtr.Zero) { System.Threading.Thread.Sleep(100); } string contacts = Environment.GetCommandLineArgs()[2]; contacts = contacts.Substring(contacts.IndexOf("<") + 1).TrimEnd(new char[] { '>' }); _LyncClient = Microsoft.Lync.Model.LyncClient.GetClient(); List <string> c = new List <string>(); c.Add(contacts); Microsoft.Lync.Model.Extensibility.Automation automation = Microsoft.Lync.Model.LyncClient.GetAutomation(); AutomationModalities _ChosenMode = AutomationModalities.ApplicationSharing | AutomationModalities.InstantMessage; Dictionary <AutomationModalitySettings, object> _ModalitySettings = new Dictionary <AutomationModalitySettings, object>(); // Add the process Id to the modality settings for the conversation. _ModalitySettings.Add(AutomationModalitySettings.SharedProcess, process.Id); // Add the main window handle to the modality settings for the conversation. _ModalitySettings.Add(AutomationModalitySettings.SharedWindow, process.MainWindowHandle); // Adds text to toast and local user IMWindow text-entry control. _ModalitySettings.Add(AutomationModalitySettings.FirstInstantMessage, "Hello Serkant. I would like to share my first running process with you."); _ModalitySettings.Add(AutomationModalitySettings.SendFirstInstantMessageImmediately, true); IAsyncResult res = automation.BeginStartConversation(_ChosenMode, c, _ModalitySettings, null, null); automation.EndStartConversation(res); }