Exemple #1
0
        // OnMyButtonClick routine handles all button click events
        // and displays IRibbonControl.Context in message box
        //public void OnMyButtonClick(Office.IRibbonControl control) 

        public void ButtonClicked(Office.IRibbonControl control)    
        {
            String ContactName = "";
            String numbers = "";
            Outlook.ContactItem contactItem = null;

            //int handle = Win32.FindWindow(null, appName);

            if (true) // handle != 0
            {
				try
				{
					if (control.Id == "outcallContacts")
					{
						Outlook.Explorer explorer = control.Context as Outlook.Explorer;
						Object item = explorer.Selection[1];
						contactItem = item as Outlook.ContactItem;
					}
					else if (control.Id == "outcallMenuContact")
					{
						Outlook.Selection selection = control.Context as Outlook.Selection;
						OutlookItem olItem = new OutlookItem(selection[1]);
						Object item = new Object();
						item = selection[1];
						contactItem = item as Outlook.ContactItem;
					}
					else if (control.Id == "outcallMenuMail" || control.Id == "outcallMail")
					{
						Outlook.MailItem mailItem = null;
						Object item = null;

                        List<string> accounts = new List<string>();

						if (control.Id == "outcallMail")
						{
							Outlook.Explorer explorer = control.Context as Outlook.Explorer;
							item = explorer.Selection[1];
						}
						else if (control.Id == "outcallMenuMail")
						{
							Outlook.Selection selection = control.Context as Outlook.Selection;
							OutlookItem olItem = new OutlookItem(selection[1]);
							item = new Object();
							item = selection[1];
						}

						mailItem = item as Outlook.MailItem;
						Outlook.Folder folder = mailItem.Parent as Outlook.Folder;
                        Outlook.Folder contacts = (Outlook.Folder)folder.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);

                        if (mailItem != null)
                        {
                            foreach (Outlook.Account account in folder.Session.Accounts)
                            {
                                accounts.Add(account.SmtpAddress);
                            }

                            bool isOut = false;

                            if (mailItem.Sender == null)
                            {
                                isOut = true;
                            }
                            else if (accounts.Contains(mailItem.Sender.Address))
                            {
                                isOut = true;
                            }

                            if (isOut)
                            {
                                Outlook.Recipients recipients = mailItem.Recipients;
                                foreach (Outlook.Recipient recipient in recipients)
                                {
                                    contactItem = recipient.AddressEntry.GetContact();

                                    if (contactItem != null)
                                        break;
                                }
                            }
                            else
                            {
                                contactItem = mailItem.Sender.GetContact();
                            }
                        }
					}
					else
					{
                        MessageBox.Show("The selected item is not supported. Please select a Contact or an Email.");
					}
				} catch (Exception e) {
                    MessageBox.Show("Please select a contact.");
					return;
				}

				if (contactItem != null)
				{
					ContactName = contactItem.FullName;
					/*if (ContactName != "")
					{
						ContactName = contactItem.FirstName + " | " + contactItem.MiddleName + " | " + contactItem.LastName;
					}
					else
					{
						ContactName = contactItem.CompanyName;
					}*/

					String strTemp = contactItem.AssistantTelephoneNumber;
					if (strTemp != null)
						numbers += "Assistant:" + strTemp + " | ";

					strTemp = contactItem.BusinessTelephoneNumber;
					if (strTemp != null)
						numbers += "Business:" + strTemp + " | ";

					strTemp = contactItem.Business2TelephoneNumber;
					if (strTemp != null)
						numbers += "Business2:" + strTemp + " | ";

					strTemp = contactItem.BusinessFaxNumber;
					if (strTemp != null)
						numbers += "Business Fax:" + strTemp + " | ";

					strTemp = contactItem.CallbackTelephoneNumber;
					if (strTemp != null)
						numbers += "Callback:" + strTemp + " | ";

					strTemp = contactItem.CarTelephoneNumber;
					if (strTemp != null)
						numbers += "Car:" + strTemp + " | ";

					strTemp = contactItem.CompanyMainTelephoneNumber;
					if (strTemp != null)
						numbers += "Company Main:" + strTemp + " | ";

					strTemp = contactItem.HomeTelephoneNumber;
					if (strTemp != null)
						numbers += "Home:" + strTemp + " | ";

					strTemp = contactItem.Home2TelephoneNumber;
					if (strTemp != null)
						numbers += "Home2:" + strTemp + " | ";

					strTemp = contactItem.HomeFaxNumber;
					if (strTemp != null)
						numbers += "Home Fax:" + strTemp + " | ";

					strTemp = contactItem.ISDNNumber;
					if (strTemp != null)
						numbers += "ISDN:" + strTemp + " | ";

					strTemp = contactItem.MobileTelephoneNumber;
					if (strTemp != null)
						numbers += "Mobile:" + strTemp + " | ";

					strTemp = contactItem.OtherTelephoneNumber;
					if (strTemp != null)
						numbers += "Other:" + strTemp + " | ";

					strTemp = contactItem.OtherFaxNumber;
					if (strTemp != null)
						numbers += "Other Fax:" + strTemp + " | ";

					strTemp = contactItem.PagerNumber;
					if (strTemp != null)
						numbers += "Pager:" + strTemp + " | ";

					strTemp = contactItem.PrimaryTelephoneNumber;
					if (strTemp != null)
						numbers += "Primary:" + strTemp + " | ";

					strTemp = contactItem.RadioTelephoneNumber;
					if (strTemp != null)
						numbers += "Radio:" + strTemp + " | ";

					strTemp = contactItem.TelexNumber;
					if (strTemp != null)
						numbers += "Telex:" + strTemp + " | ";

					strTemp = contactItem.TTYTDDTelephoneNumber;
					if (strTemp != null)
						numbers += "TTY/TDD:" + strTemp + " | ";
				}
				else
				{
					MessageBox.Show("Contact not found in your Address book.");
					return;
				}

				if (numbers == "")
				{
					MessageBox.Show("There are no phone numbers for the selected contact.");
					return;
				}

                String strDataToSend = "Dial#####" + ContactName + "#####" + numbers;

                strDataToSend = strDataToSend.Replace(" ", "&&&");

                /*Win32.COPYDATASTRUCT cpd;
                cpd.dwData = IntPtr.Zero;
                cpd.cbData = strDataToSend.Length;
                cpd.lpData = strDataToSend;

                Win32.SendMessage(handle, WM_COPYDATA, 0, ref cpd);*/

                RegistryKey key = Registry.CurrentUser.OpenSubKey("Software\\Bicom Systems\\OutCALL");

                string outcall_path = (string)key.GetValue("InstallDir");

                ProcessStartInfo startInfo = new ProcessStartInfo();
                startInfo.CreateNoWindow = false;
                startInfo.UseShellExecute = false;
                startInfo.FileName = outcall_path + "\\" + appBinary;
                startInfo.WindowStyle = ProcessWindowStyle.Normal;
                startInfo.Arguments = strDataToSend;

                try
                {
                    // Start the process with the info we specified.
                    // Call WaitForExit and then the using statement will close.
                    using (Process outcallProcess = Process.Start(startInfo))
                    {
                        outcallProcess.WaitForExit();
                    }
                }
                catch
                {
                    // Log error.

                    Debug.WriteLine("outcall execute error");
                }
            }
            else
            {
                /*RegistryKey key = Registry.LocalMachine.OpenSubKey("Software\\BicomSystems\\outcall");
                String applicationName = (string)key.GetValue("app_name");
                MessageBox.Show(applicationName + " is not running.");*/
                MessageBox.Show(appName + " is not running.");
            }
        }
Exemple #2
0
        // OnMyButtonClick routine handles all button click events
        // and displays IRibbonControl.Context in message box
        //public void OnMyButtonClick(Office.IRibbonControl control)

        public void ButtonClicked(Office.IRibbonControl control)
        {
            String ContactName = "";
            String numbers     = "";

            Outlook.ContactItem contactItem = null;

            //int handle = Win32.FindWindow(null, appName);

            if (true) // handle != 0
            {
                try
                {
                    if (control.Id == "outcallContacts")
                    {
                        Outlook.Explorer explorer = control.Context as Outlook.Explorer;
                        Object           item     = explorer.Selection[1];
                        contactItem = item as Outlook.ContactItem;
                    }
                    else if (control.Id == "outcallMenuContact")
                    {
                        Outlook.Selection selection = control.Context as Outlook.Selection;
                        OutlookItem       olItem    = new OutlookItem(selection[1]);
                        Object            item      = new Object();
                        item        = selection[1];
                        contactItem = item as Outlook.ContactItem;
                    }
                    else if (control.Id == "outcallMenuMail" || control.Id == "outcallMail")
                    {
                        Outlook.MailItem mailItem = null;
                        Object           item     = null;

                        List <string> accounts = new List <string>();

                        if (control.Id == "outcallMail")
                        {
                            Outlook.Explorer explorer = control.Context as Outlook.Explorer;
                            item = explorer.Selection[1];
                        }
                        else if (control.Id == "outcallMenuMail")
                        {
                            Outlook.Selection selection = control.Context as Outlook.Selection;
                            OutlookItem       olItem    = new OutlookItem(selection[1]);
                            item = new Object();
                            item = selection[1];
                        }

                        mailItem = item as Outlook.MailItem;
                        Outlook.Folder folder   = mailItem.Parent as Outlook.Folder;
                        Outlook.Folder contacts = (Outlook.Folder)folder.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);

                        if (mailItem != null)
                        {
                            foreach (Outlook.Account account in folder.Session.Accounts)
                            {
                                accounts.Add(account.SmtpAddress);
                            }

                            bool isOut = false;

                            if (mailItem.Sender == null)
                            {
                                isOut = true;
                            }
                            else if (accounts.Contains(mailItem.Sender.Address))
                            {
                                isOut = true;
                            }

                            if (isOut)
                            {
                                Outlook.Recipients recipients = mailItem.Recipients;
                                foreach (Outlook.Recipient recipient in recipients)
                                {
                                    contactItem = recipient.AddressEntry.GetContact();

                                    if (contactItem != null)
                                    {
                                        break;
                                    }
                                }
                            }
                            else
                            {
                                contactItem = mailItem.Sender.GetContact();
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("The selected item is not supported. Please select a Contact or an Email.");
                    }
                } catch (Exception e) {
                    MessageBox.Show("Please select a contact.");
                    return;
                }

                if (contactItem != null)
                {
                    ContactName = contactItem.FullName;

                    /*if (ContactName != "")
                     * {
                     *      ContactName = contactItem.FirstName + " | " + contactItem.MiddleName + " | " + contactItem.LastName;
                     * }
                     * else
                     * {
                     *      ContactName = contactItem.CompanyName;
                     * }*/

                    String strTemp = contactItem.AssistantTelephoneNumber;
                    if (strTemp != null)
                    {
                        numbers += "Assistant:" + strTemp + " | ";
                    }

                    strTemp = contactItem.BusinessTelephoneNumber;
                    if (strTemp != null)
                    {
                        numbers += "Business:" + strTemp + " | ";
                    }

                    strTemp = contactItem.Business2TelephoneNumber;
                    if (strTemp != null)
                    {
                        numbers += "Business2:" + strTemp + " | ";
                    }

                    strTemp = contactItem.BusinessFaxNumber;
                    if (strTemp != null)
                    {
                        numbers += "Business Fax:" + strTemp + " | ";
                    }

                    strTemp = contactItem.CallbackTelephoneNumber;
                    if (strTemp != null)
                    {
                        numbers += "Callback:" + strTemp + " | ";
                    }

                    strTemp = contactItem.CarTelephoneNumber;
                    if (strTemp != null)
                    {
                        numbers += "Car:" + strTemp + " | ";
                    }

                    strTemp = contactItem.CompanyMainTelephoneNumber;
                    if (strTemp != null)
                    {
                        numbers += "Company Main:" + strTemp + " | ";
                    }

                    strTemp = contactItem.HomeTelephoneNumber;
                    if (strTemp != null)
                    {
                        numbers += "Home:" + strTemp + " | ";
                    }

                    strTemp = contactItem.Home2TelephoneNumber;
                    if (strTemp != null)
                    {
                        numbers += "Home2:" + strTemp + " | ";
                    }

                    strTemp = contactItem.HomeFaxNumber;
                    if (strTemp != null)
                    {
                        numbers += "Home Fax:" + strTemp + " | ";
                    }

                    strTemp = contactItem.ISDNNumber;
                    if (strTemp != null)
                    {
                        numbers += "ISDN:" + strTemp + " | ";
                    }

                    strTemp = contactItem.MobileTelephoneNumber;
                    if (strTemp != null)
                    {
                        numbers += "Mobile:" + strTemp + " | ";
                    }

                    strTemp = contactItem.OtherTelephoneNumber;
                    if (strTemp != null)
                    {
                        numbers += "Other:" + strTemp + " | ";
                    }

                    strTemp = contactItem.OtherFaxNumber;
                    if (strTemp != null)
                    {
                        numbers += "Other Fax:" + strTemp + " | ";
                    }

                    strTemp = contactItem.PagerNumber;
                    if (strTemp != null)
                    {
                        numbers += "Pager:" + strTemp + " | ";
                    }

                    strTemp = contactItem.PrimaryTelephoneNumber;
                    if (strTemp != null)
                    {
                        numbers += "Primary:" + strTemp + " | ";
                    }

                    strTemp = contactItem.RadioTelephoneNumber;
                    if (strTemp != null)
                    {
                        numbers += "Radio:" + strTemp + " | ";
                    }

                    strTemp = contactItem.TelexNumber;
                    if (strTemp != null)
                    {
                        numbers += "Telex:" + strTemp + " | ";
                    }

                    strTemp = contactItem.TTYTDDTelephoneNumber;
                    if (strTemp != null)
                    {
                        numbers += "TTY/TDD:" + strTemp + " | ";
                    }
                }
                else
                {
                    MessageBox.Show("Contact not found in your Address book.");
                    return;
                }

                if (numbers == "")
                {
                    MessageBox.Show("There are no phone numbers for the selected contact.");
                    return;
                }

                String strDataToSend = "Dial#####" + ContactName + "#####" + numbers;

                strDataToSend = strDataToSend.Replace(" ", "&&&");

                /*Win32.COPYDATASTRUCT cpd;
                 * cpd.dwData = IntPtr.Zero;
                 * cpd.cbData = strDataToSend.Length;
                 * cpd.lpData = strDataToSend;
                 *
                 * Win32.SendMessage(handle, WM_COPYDATA, 0, ref cpd);*/

                RegistryKey key = Registry.CurrentUser.OpenSubKey("Software\\Bicom Systems\\OutCALL");

                string outcall_path = (string)key.GetValue("InstallDir");

                ProcessStartInfo startInfo = new ProcessStartInfo();
                startInfo.CreateNoWindow  = false;
                startInfo.UseShellExecute = false;
                startInfo.FileName        = outcall_path + "\\" + appBinary;
                startInfo.WindowStyle     = ProcessWindowStyle.Normal;
                startInfo.Arguments       = strDataToSend;

                try
                {
                    // Start the process with the info we specified.
                    // Call WaitForExit and then the using statement will close.
                    using (Process outcallProcess = Process.Start(startInfo))
                    {
                        outcallProcess.WaitForExit();
                    }
                }
                catch
                {
                    // Log error.

                    Debug.WriteLine("outcall execute error");
                }
            }
            else
            {
                /*RegistryKey key = Registry.LocalMachine.OpenSubKey("Software\\BicomSystems\\outcall");
                 * String applicationName = (string)key.GetValue("app_name");
                 * MessageBox.Show(applicationName + " is not running.");*/
                MessageBox.Show(appName + " is not running.");
            }
        }