private RegistryKey OpenBaseKey() { NSOutlook.NameSpace session = _item.Session; try { return(OutlookRegistryUtils.OpenProfileOutlookKey(session.CurrentProfileName)); } finally { ComRelease.Release(session); } }
public void Restart() { // Use the current command line, with a profile command if not specified string commandLine = Environment.CommandLine; // This selects both /profile and /profiles. In that case we don't specify the profile, otherwise // we specify the current profile // It seems to be impossible to escape a profile name with a quote, so in that case ignore it if (!commandLine.ToLower().Contains("/profile") && !_addIn.ProfileName.Contains("\"")) { commandLine += " /profile " + Util.QuoteCommandLine(_addIn.ProfileName); } // Custom command line foreach (ZPushAccount account in _resyncAccounts) { string path = account.Account.BackingFilePath; if (!string.IsNullOrEmpty(path) && System.IO.Path.GetExtension(path) == ".ost") { commandLine += " /cleankoe " + Util.QuoteCommandLine(path); } } foreach (KeyValuePair <ZPushAccount, GABUser> share in _shares) { using (RegistryKey key = OutlookRegistryUtils.OpenProfileOutlookKey(_addIn.ProfileName, RegistryKeyPermissionCheck.ReadWriteSubTree)) { int accountId = (int)key.GetValue(OutlookConstants.REG_VAL_NEXT_ACCOUNT_ID); using (RegistryKey accountKey = key.CreateSubKey(string.Format("{0:X8}", accountId))) { accountKey.SetValue(OutlookConstants.REG_VAL_ACCOUNTNAME, share.Value.UserName + " through " + share.Key.DisplayName); accountKey.SetValue(OutlookConstants.REG_VAL_DISPLAYNAME, "Share for " + share.Value.DisplayName); accountKey.SetValue(OutlookConstants.REG_VAL_EMAIL, "test" + share.Key.Account.SmtpAddress); accountKey.SetValue(OutlookConstants.REG_VAL_EAS_SERVER, share.Key.Account.ServerURL); accountKey.SetValue(OutlookConstants.REG_VAL_EAS_USERNAME, share.Key.Account.UserName + ".share." + share.Value.UserName); accountKey.SetValue(OutlookConstants.REG_VAL_EAS_PASSWORD, share.Key.Account.EncryptedPassword); //accountKey.SetValue(OutlookConstants.REG_VAL_EAS_DEVICEID, share.Key.Account.DeviceId); accountKey.SetValue("clsid", "{ED475415-B0D6-11D2-8C3B-00104B2A6676}"); } key.SetValue(OutlookConstants.REG_VAL_NEXT_ACCOUNT_ID, accountId + 1); } } // Run that Process process = new Process(); process.StartInfo = new ProcessStartInfo(RestarterPath, Process.GetCurrentProcess().Id + " " + commandLine); process.Start(); // And close us and any other windows _addIn.Quit(CloseWindows); }
private void Worker() { Port = DEFAULT_PORT; // Register URL using (RegistryKey key = OutlookRegistryUtils.OpenOutlookKey(REG_KEY, Microsoft.Win32.RegistryKeyPermissionCheck.ReadWriteSubTree)) { if (key != null) { // Set only if empty or already our URL string oldURL = key.GetValueString(REG_VALUE); if (string.IsNullOrWhiteSpace(oldURL) || oldURL.Contains("/" + URL_IDENTIFIER + "/")) { key.SetValue(REG_VALUE, string.Format(URL, Port)); } } } FreeBusyServer server = new FreeBusyServer(this); // Run TcpListener listener = new TcpListener(IPAddress.Loopback, Port); listener.Start(); for (;;) { Interlocked.Increment(ref _iterationCount); try { for (;;) { // Wait for a connection TcpClient client = listener.AcceptTcpClient(); Interlocked.Increment(ref _requestCount); // And handle it in the UI thread to allow GAB access Tasks.Task(null, this, "FreeBusyHandler", () => server.HandleRequest(client)); } } catch (Exception e) { Logger.Instance.Error(this, "Error in FreeBusy server: {0}", e); } } }
private void Worker() { Port = DEFAULT_PORT; // Check the URL to reuse the port number if possible try { using (RegistryKey key = OutlookRegistryUtils.OpenOutlookKey(REG_KEY)) { if (key != null) { string oldURL = key.GetValueString(REG_VALUE); if (oldURL.StartsWith(URL_BASE)) { string rest = oldURL.Substring(URL_BASE.Length); int sep = rest.IndexOf('/'); if (sep >= 0) { rest = rest.Substring(0, sep); } int port = int.Parse(rest); if (port > 0 && port < 65536) { Port = port; } } } } } catch (Exception) { Port = DEFAULT_PORT; } TcpListener listener; listener = new TcpListener(IPAddress.Loopback, Port); try { listener.Start(); } catch (SocketException) { // Error opening port, try with a default one listener = new TcpListener(IPAddress.Loopback, 0); listener.Start(); Port = ((IPEndPoint)listener.LocalEndpoint).Port; } // Register URL using (RegistryKey key = OutlookRegistryUtils.OpenOutlookKey(REG_KEY, Microsoft.Win32.RegistryKeyPermissionCheck.ReadWriteSubTree)) { if (key != null) { // Set only if empty or already our URL string oldURL = key.GetValueString(REG_VALUE); if (string.IsNullOrWhiteSpace(oldURL) || oldURL.Contains("/" + URL_IDENTIFIER + "/")) { key.SetValue(REG_VALUE, string.Format(URL, Port)); } } } FreeBusyServer server = new FreeBusyServer(this); // Run for (;;) { Interlocked.Increment(ref _iterationCount); try { for (;;) { // Wait for a connection TcpClient client = listener.AcceptTcpClient(); Interlocked.Increment(ref _requestCount); // And handle it in the UI thread to allow GAB access Tasks.Task(null, this, "FreeBusyHandler", () => server.HandleRequest(client)); } } catch (Exception e) { Logger.Instance.Error(this, "Error in FreeBusy server: {0}", e); } } }