private static void Startup() { //setup IPC channel Hashtable props = new Hashtable(); System.Runtime.Remoting.Channels.BinaryClientFormatterSinkProvider clientsink = new System.Runtime.Remoting.Channels.BinaryClientFormatterSinkProvider(); System.Runtime.Remoting.Channels.BinaryServerFormatterSinkProvider serversink = new System.Runtime.Remoting.Channels.BinaryServerFormatterSinkProvider(); serversink.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full; props["name"] = ""; props["portName"] = "REMOTING_IPC_CHANNEL_0x" + System.Diagnostics.Process.GetCurrentProcess().Id.ToString("X"); props["typeFilterLevel"] = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full; m_Channel = new System.Runtime.Remoting.Channels.Ipc.IpcChannel(props, clientsink, serversink); System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(m_Channel, false); }
private static void registerChannel(string name, string port) { System.Runtime.Remoting.Channels.BinaryServerFormatterSinkProvider serverProv = new System.Runtime.Remoting.Channels.BinaryServerFormatterSinkProvider(); serverProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full; System.Runtime.Remoting.Channels.BinaryClientFormatterSinkProvider clientProv = new System.Runtime.Remoting.Channels.BinaryClientFormatterSinkProvider(); System.Collections.IDictionary properties = new System.Collections.Hashtable(); properties["name"] = name; properties["priority"] = "20"; properties["portName"] = port; properties["secure"] = true; properties["tokenImpersonationLevel"] = System.Security.Principal.TokenImpersonationLevel.Impersonation; properties["includeVersions"] = false; properties["strictBinding"] = false; System.Security.Principal.SecurityIdentifier sidAdmin = new System.Security.Principal.SecurityIdentifier(System.Security.Principal.WellKnownSidType.InteractiveSid, null); System.Security.Principal.NTAccount nt = (System.Security.Principal.NTAccount)sidAdmin.Translate(typeof(System.Security.Principal.NTAccount)); progress("registerChannel: " + port + " with authorized group " + nt); properties["authorizedGroup"] = nt.Value; System.Runtime.Remoting.Channels.Ipc.IpcChannel ipcCh = new System.Runtime.Remoting.Channels.Ipc.IpcChannel(properties, clientProv, serverProv); System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(ipcCh, true); }
public static void Main() { string productName = "Daisy_Tobi"; string tobiAppRefProviderToken = "TobiAppRefProvider"; bool firstInstance; var theMutex = new Mutex(false, "Local\\" + productName, out firstInstance); try { string[] appParamters = null; bool clickOnce = ApplicationDeployment.IsNetworkDeployed; if (clickOnce) { appParamters = AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData; } else { appParamters = Environment.GetCommandLineArgs(); } bool hasParameters = appParamters != null && (clickOnce ? appParamters.Length > 0 : appParamters.Length > 1); string filePath = ""; if (hasParameters) { if (clickOnce) { try { filePath = new Uri(appParamters[0]).LocalPath; } catch { filePath = ""; MessageBox.Show("CANNOT PARSE URI: " + appParamters[0]); } } else { try { //Tobi.exe /verbose /debuglevel=3 var dict = CommandLineDictionary.FromArguments(appParamters.Skip(1), '/', '='); //bool verbose = d.ContainsKey("verbose"); //int testId = Int32.Parse(d["debuglevel"]); string open; dict.TryGetValue("open", out open); if (!string.IsNullOrEmpty(open)) { filePath = open; } } catch { filePath = appParamters[1]; } } } if (firstInstance) { IChannel theChannel = new System.Runtime.Remoting.Channels.Ipc.IpcChannel(productName); try { ChannelServices.RegisterChannel(theChannel, false); var app = new App(); app.InitializeComponent(); DebugFix.Assert(app == Application.Current); RemotingServices.Marshal(new AppRefProvider(app //, app.Dispatcher ), tobiAppRefProviderToken, typeof(AppRefProvider)); if (!string.IsNullOrEmpty(filePath)) { app.ParameterOpenFilePath = filePath; } app.Run(); } catch (SocketException ex) { MessageBox.Show(ex.Message); } finally { ChannelServices.UnregisterChannel(theChannel); } } else { if ( #if DEBUG true || #endif //DEBUG !string.IsNullOrEmpty(filePath)) { #if DEBUG MessageBox.Show("DEBUG: Tobi instance already running >> " + filePath); #endif //DEBUG try { AppRefProvider appRefProvider = (AppRefProvider)RemotingServices.Connect( typeof(AppRefProvider), "ipc://" + productName + "/" + tobiAppRefProviderToken); appRefProvider.TryOpenFile(filePath); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } } finally { theMutex.Close(); } }
private static void registerChannel(string name, string port) { System.Runtime.Remoting.Channels.BinaryServerFormatterSinkProvider serverProv = new System.Runtime.Remoting.Channels.BinaryServerFormatterSinkProvider(); serverProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full; System.Runtime.Remoting.Channels.BinaryClientFormatterSinkProvider clientProv = new System.Runtime.Remoting.Channels.BinaryClientFormatterSinkProvider(); System.Collections.IDictionary properties = new System.Collections.Hashtable(); properties["name"] = name; properties["priority"] = "20"; properties["portName"] = port; properties["secure"] = true; properties["tokenImpersonationLevel"] = System.Security.Principal.TokenImpersonationLevel.Impersonation; properties["includeVersions"] = false; properties["strictBinding"] = false; System.Security.Principal.SecurityIdentifier sidAdmin = new System.Security.Principal.SecurityIdentifier(System.Security.Principal.WellKnownSidType.InteractiveSid, null); System.Security.Principal.NTAccount nt = (System.Security.Principal.NTAccount) sidAdmin.Translate(typeof (System.Security.Principal.NTAccount)); progress("registerChannel: " + port + " with authorized group " + nt); properties["authorizedGroup"] = nt.Value; System.Runtime.Remoting.Channels.Ipc.IpcChannel ipcCh = new System.Runtime.Remoting.Channels.Ipc.IpcChannel(properties, clientProv, serverProv); System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(ipcCh, true); }