Inheritance: INativeDependencyObjectWrapper, IDisposable
		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();
				}
			}
		}
Example #2
0
        public MainPage()
        {
            InitializeComponent();

            LocalMessageReceiver msgReceiver = new LocalMessageReceiver(SenderAppName);
            msgReceiver.MessageReceived += (object sender, MessageReceivedEventArgs e) =>
            {
                switch (e.Message)
                {
                    case "Red":
                        {
                            rect.Fill = new SolidColorBrush(Colors.Red);
                            break;
                        }

                    case "Green":
                        {
                            rect.Fill = new SolidColorBrush(Colors.Green);
                            break;
                        }
                    case "Blue":
                        {
                            rect.Fill = new SolidColorBrush(Colors.Blue);
                            break;
                        }

                }
            };
            msgReceiver.Listen();
        }
        public LocalInstanceMessenger()
        {
            _receiver = new LocalMessageReceiver("FacetedWorlds.ThoughtCloud");

            try
            {
                _receiver.Listen();
                _singleInstance = true;
            }
            catch (ListenFailedException x)
            {
                _singleInstance = false;
            }
        }
Example #4
0
        public AlertsIpc(Guid receiver, ViewModel vm)
        {
            _receiverId = receiver;

            _messageReceiver = new LocalMessageReceiver(
                    _receiverId.ToString (), 
                    ReceiverNameScope.Global, LocalMessageReceiver.AnyDomain);
            _messageReceiver.MessageReceived += messageReceiver_MessageReceived;
            _messageReceiver.DisableSenderTrustCheck = true;
            _vmodel = vm;
            try
            {
                _messageReceiver.Listen();
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Example #5
0
		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");
		}
Example #6
0
		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");
		}
Example #7
0
		public void Listen_Empty ()
		{
			LocalMessageReceiver lmr = new LocalMessageReceiver (String.Empty);
			lmr.Listen ();
		}
Example #8
0
		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");
		}
Example #9
0
		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");
		}
Example #10
0
 void MainPage_Loaded(object sender, RoutedEventArgs e)
 {
     LocalMessageReceiver msgRec = new LocalMessageReceiver("fengyun");
     msgRec.MessageReceived +=new EventHandler<MessageReceivedEventArgs> ( msgRec_MessageReceived);
     msgRec.Listen();
 }
		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;
			}
		}