public void CreateChannel(bool isMaster, string channelName) { if (isMaster) { _receiver = new LocalMessageReceiver(channelName, ReceiverNameScope.Global, LocalMessageReceiver.AnyDomain); _receiver.DisableSenderTrustCheck = true; _receiver.MessageReceived += new EventHandler <MessageReceivedEventArgs>(_receiver_MessageReceived); _receiver.Listen(); } else { string guid = Guid.NewGuid().ToString(); if (_receiver != null) { guid = _receiver.ReceiverName; } _sender = new LocalMessageSender(channelName, LocalMessageSender.Global); _sender.SendCompleted += new EventHandler <SendCompletedEventArgs>(_sender_SendCompleted); _sender.SendAsync(string.Format("createchannel|{0}", guid)); if (_receiver == null) { _receiver = new LocalMessageReceiver(guid, ReceiverNameScope.Global, LocalMessageReceiver.AnyDomain); _receiver.DisableSenderTrustCheck = true; _receiver.MessageReceived += new EventHandler <MessageReceivedEventArgs>(_receiver_MessageReceived); _receiver.Listen(); } } }
public void DisableSenderTrustCheck() { LocalMessageReceiver lmr = new LocalMessageReceiver("x"); Assert.IsFalse(lmr.DisableSenderTrustCheck, "DisableSenderTrustCheck/Default"); lmr.DisableSenderTrustCheck = true; Assert.IsTrue(lmr.DisableSenderTrustCheck, "DisableSenderTrustCheck/Change"); lmr.Listen(); Assert.Throws <InvalidOperationException> (delegate { // throw, even if setting the actual value lmr.DisableSenderTrustCheck = true; }, "Listen/InvalidOperationException"); lmr.Dispose(); Assert.Throws <ObjectDisposedException> (delegate { // throw, even if setting the actual value lmr.DisableSenderTrustCheck = true; }, "Dispose/ObjectDisposedException"); // other properties are still available after dispose Assert.IsNull(lmr.AllowedSenderDomains, "AllowedSenderDomains"); Assert.AreEqual(ReceiverNameScope.Domain, lmr.NameScope, "NameScope"); Assert.AreEqual("x", lmr.ReceiverName, "ReceiverName"); }
public void AllowedSenderDomains_Immutable() { string [] list = new string [] { "xxx" }; LocalMessageReceiver lmr = new LocalMessageReceiver(String.Empty, ReceiverNameScope.Domain, list); list [0] = "yyy"; // original list can be modified but it won't affect the LocalMessageReceiver CheckForSingleValue(lmr.AllowedSenderDomains, "xxx"); }
public MainPage() { InitializeComponent(); _uploadInfo = new UploadInfo(); this.DataContext = _uploadInfo; //Subscribe to update messages _receiver = new LocalMessageReceiver("SLMFU"); _receiver.MessageReceived += new EventHandler <MessageReceivedEventArgs>(_receiver_MessageReceived); _receiver.Listen(); }
public LocalInstanceMessenger() { _receiver = new LocalMessageReceiver("FacetedWorlds.ThoughtCloud"); try { _receiver.Listen(); _singleInstance = true; } catch (ListenFailedException x) { _singleInstance = false; } }
private void Application_Startup(object sender, StartupEventArgs e) { try { LocalMessageReceiver receiver = new LocalMessageReceiver("singleinstance"); receiver.Listen(); this.RootVisual = new LoginPage(); } catch (ListenFailedException) { MessageBox.Show("Can't run two instance's at a same time.", "Error", MessageBoxButton.OK); Application.Current.MainWindow.Close(); } }
public void Dispose() { timer.Stop(); timer.Tick -= new EventHandler(timer_Tick); if (_sender != null) { _sender.SendCompleted -= new EventHandler <SendCompletedEventArgs>(_sender_SendCompleted); _sender = null; } if (_receiver != null) { _receiver.MessageReceived -= new EventHandler <MessageReceivedEventArgs>(_receiver_MessageReceived); _receiver = null; } }
public Receiver() { InitializeComponent(); LocalMessageReceiver messageReceiver = new LocalMessageReceiver("receiver", ReceiverNameScope.Global, LocalMessageReceiver.AnyDomain); messageReceiver.MessageReceived += messageReceiver_MessageReceived; try { messageReceiver.Listen(); } catch (ListenFailedException) { output.Text = "Cannot receive messages." + Environment.NewLine + "There is already a receiver with the name 'receiver'."; } }
public MainPage() { InitializeComponent(); _jsonserializer = new DataContractJsonSerializer(inkP.Strokes.GetType()); // First try. // Create receiver with one preset name. _localreceiver = new LocalMessageReceiver(clientnames[clientid]); _localreceiver.MessageReceived += localreceiver_MessageReceived; try { _localreceiver.Listen(); } catch (Exception e) { // Second try. // Create receiver with another preset name. _localreceiver.MessageReceived -= localreceiver_MessageReceived; clientid = 1; _localreceiver = new LocalMessageReceiver(clientnames[clientid]); _localreceiver.MessageReceived += localreceiver_MessageReceived; try { _localreceiver.Listen(); } catch (Exception e1) { // Already has two apllication instance. // Pop messagebox, disable drawing area. MessageBox.Show("Only allow 2 clients."); disablegrid.Visibility = Visibility.Visible; return; } } // Create sender targeting to another application's receiver _localsender = new LocalMessageSender(clientnames[(clientid + 1) % 2]); _localsender.SendCompleted += localsender_SendCompleted; drawbr.Background = new SolidColorBrush(colors[clientid]); }
public void Ctor_StringReceiverNameScopeIEnumerable() { List <string> list = new List <string> (); Assert.Throws <ArgumentNullException> (delegate { new LocalMessageReceiver(null, ReceiverNameScope.Domain, list); }, "Name/null"); Assert.Throws <ArgumentException> (delegate { new LocalMessageReceiver(TooLongName, ReceiverNameScope.Domain, list); }, "Name/TooLongName"); Assert.Throws <ArgumentNullException> (delegate { new LocalMessageReceiver(String.Empty, ReceiverNameScope.Domain, null); }, "AllowedSenderDomains/null"); Assert.Throws <ArgumentNullException> (delegate { string[] null_entry = new string[] { "a", null, "b" }; new LocalMessageReceiver(LongName, ReceiverNameScope.Domain, null_entry); }, "AllowedSenderDomains/null-entry"); Assert.Throws <ArgumentException> (delegate { string [] bad_entry = new string [] { "a", InvalidNameComma, "b" }; new LocalMessageReceiver(LongName, ReceiverNameScope.Domain, bad_entry); }, "AllowedSenderDomains/bad-entry/comma"); Assert.Throws <ArgumentException> (delegate { string [] bad_entry = new string [] { "a", InvalidNameColon, "b" }; new LocalMessageReceiver(LongName, ReceiverNameScope.Domain, bad_entry); }, "AllowedSenderDomains/bad-entry/colon"); LocalMessageReceiver lmr = new LocalMessageReceiver(String.Empty, (ReceiverNameScope)Int32.MinValue, list); Assert.AreEqual((ReceiverNameScope)Int32.MinValue, lmr.NameScope, "NameScope/Bad"); lmr = new LocalMessageReceiver("name", ReceiverNameScope.Global, list); Assert.IsFalse(Object.ReferenceEquals(list, lmr.AllowedSenderDomains), "AllowedSenderDomains"); Assert.AreEqual(typeof(ReadOnlyCollection <string>), lmr.AllowedSenderDomains.GetType(), "AllowedSenderDomains/Type"); Assert.IsFalse(lmr.DisableSenderTrustCheck, "DisableSenderTrustCheck"); Assert.AreEqual(ReceiverNameScope.Global, lmr.NameScope, "NameScope"); Assert.AreEqual("name", lmr.ReceiverName, "ReceiverName"); lmr = new LocalMessageReceiver(LongName, ReceiverNameScope.Domain, LocalMessageReceiver.AnyDomain); Assert.IsNotNull(lmr.AllowedSenderDomains, "AllowedSenderDomains/AnyDomain"); Assert.AreEqual(LongName, lmr.ReceiverName, "ReceiverName/LongName"); }
public void Ctor_String() { Assert.Throws <ArgumentNullException> (delegate { new LocalMessageReceiver(null); }, "null"); Assert.Throws <ArgumentException> (delegate { new LocalMessageReceiver(TooLongName); }, "TooLongName"); LocalMessageReceiver lmr = new LocalMessageReceiver(String.Empty); Assert.IsNull(lmr.AllowedSenderDomains, "AllowedSenderDomains"); Assert.IsFalse(lmr.DisableSenderTrustCheck, "DisableSenderTrustCheck"); Assert.AreEqual(ReceiverNameScope.Domain, lmr.NameScope, "NameScope"); Assert.AreEqual(String.Empty, lmr.ReceiverName, "ReceiverName"); lmr = new LocalMessageReceiver(InvalidNameComma); Assert.AreEqual(InvalidNameComma, lmr.ReceiverName, "ReceiverName/InvalidNameComma"); lmr = new LocalMessageReceiver(InvalidNameColon); Assert.AreEqual(InvalidNameColon, lmr.ReceiverName, "ReceiverName/InvalidNameColon"); }
public void Listen_Empty() { LocalMessageReceiver lmr = new LocalMessageReceiver(String.Empty); lmr.Listen(); }