private static void Main() { try { Message message = new Message("Hi, Message!"); InviteMessage inviteMessage = new InviteMessage("Hi, InviteMessage"); message.Send(); inviteMessage.Send(); } catch (Exception ex) { Console.WriteLine(ex.Message); } Console.ReadLine(); }
/// <summary> /// Finds a message type to handle the message. /// </summary> public ReceivableMessage Process() { // Named messages. if (NickMessage.CanProcess(this)) { return(new NickMessage(this)); } if (QuitMessage.CanProcess(this)) { return(new QuitMessage(this)); } if (JoinMessage.CanProcess(this)) { return(new JoinMessage(this)); } if (PartMessage.CanProcess(this)) { return(new PartMessage(this)); } if (PrivateMessage.CanProcess(this)) { return(new PrivateMessage(this)); } if (PingMessage.CanProcess(this)) { return(new PingMessage(this)); } if (NoticeMessage.CanProcess(this)) { return(new NoticeMessage(this)); } if (UserModeMessage.CanProcess(this)) { return(new UserModeMessage(this)); } if (ChannelModeMessage.CanProcess(this)) { return(new ChannelModeMessage(this)); } if (KickMessage.CanProcess(this)) { return(new KickMessage(this)); } if (InviteMessage.CanProcess(this)) { return(new InviteMessage(this)); } if (OperwallMessage.CanProcess(this)) { return(new OperwallMessage(this)); } if (Receive.TopicMessage.CanProcess(this)) { return(new Receive.TopicMessage(this)); } // IRCv3 messages. if (Receive.v3.CapabilityMessage.CanProcess(this)) { return(new Receive.v3.CapabilityMessage(this)); } if (Receive.v3.AwayMessage.CanProcess(this)) { return(new Receive.v3.AwayMessage(this)); } // Numerics. if (NumericMessage.CanProcess(this)) { // Pass all numeric messages to NumericMessage so an event can be fired, then pass it to more specific instances. // ReSharper disable once ObjectCreationAsStatement new NumericMessage(this); if (WelcomeMessage.CanProcess(this)) { return(new WelcomeMessage(this)); } if (YourHostMessage.CanProcess(this)) { return(new YourHostMessage(this)); } if (CreatedMessage.CanProcess(this)) { return(new CreatedMessage(this)); } if (MyInfoMessage.CanProcess(this)) { return(new MyInfoMessage(this)); } if (SupportMessage.CanProcess(this)) { return(new SupportMessage(this)); } if (BounceMessage.CanProcess(this)) { return(new BounceMessage(this)); } if (MOTDEndMessage.CanProcess(this)) { return(new MOTDEndMessage(this)); } if (MOTDStartMessage.CanProcess(this)) { return(new MOTDStartMessage(this)); } if (MOTDMessage.CanProcess(this)) { return(new MOTDMessage(this)); } if (LUserMessage.CanProcess(this)) { return(new LUserMessage(this)); } if (NamesMessage.CanProcess(this)) { return(new NamesMessage(this)); } if (EndOfNamesMessage.CanProcess(this)) { return(new EndOfNamesMessage(this)); } if (TopicMessage.CanProcess(this)) { return(new TopicMessage(this)); } if (TopicWhoTimeMessage.CanProcess(this)) { return(new TopicWhoTimeMessage(this)); } if (ListMessage.CanProcess(this)) { return(new ListMessage(this)); } if (ListEndMessage.CanProcess(this)) { return(new ListEndMessage(this)); } if (YoureOperMessage.CanProcess(this)) { return(new YoureOperMessage(this)); } if (AwayMessage.CanProcess(this)) { return(new AwayMessage(this)); } if (UnAwayMessage.CanProcess(this)) { return(new UnAwayMessage(this)); } if (NowAwayMessage.CanProcess(this)) { return(new NowAwayMessage(this)); } if (ChannelModeIsMessage.CanProcess(this)) { return(new ChannelModeIsMessage(this)); } if (UModeIsMessage.CanProcess(this)) { return(new UModeIsMessage(this)); } if (VersionMessage.CanProcess(this)) { return(new VersionMessage(this)); } if (TimeMessage.CanProcess(this)) { return(new TimeMessage(this)); } if (WhoMessage.CanProcess(this)) { return(new WhoMessage(this)); } if (WhoisMessage.CanProcess(this)) { return(new WhoisMessage(this)); } if (EndOfWhoMessage.CanProcess(this)) { return(new EndOfWhoMessage(this)); } if (EndOfWhoisMessage.CanProcess(this)) { return(new EndOfWhoisMessage(this)); } if (BanListMessage.CanProcess(this)) { return(new BanListMessage(this)); } if (EndOfBanListMessage.CanProcess(this)) { return(new EndOfBanListMessage(this)); } if (InviteListMessage.CanProcess(this)) { return(new InviteListMessage(this)); } if (EndOfInviteListMessage.CanProcess(this)) { return(new EndOfInviteListMessage(this)); } if (ExceptListMessage.CanProcess(this)) { return(new ExceptListMessage(this)); } if (EndOfExceptListMessage.CanProcess(this)) { return(new EndOfExceptListMessage(this)); } if (IsOnMessage.CanProcess(this)) { return(new IsOnMessage(this)); } // Catch all for unhandled error messages. if (ErrorMessage.CanProcess(this)) { return(new ErrorMessage(this)); } } Console.WriteLine("Message handler for \"" + Text + "\" not found."); return(null); }
public void DeserializeInviteMessageWithIsupAndSdp(bool includeIsup, bool includeSdp) { MediaGateway.RegisterCodec(MediaGateway.AudioCodec.G711Alaw, () => new AlawMediaCodec(null, null)); const string CallId = "ABC"; const string LocalIp = "127.0.0.1"; Contact to = "[email protected]:5060;user=phone"; var @from = new Contact( "[email protected]:5060", null, new[] { new KeyValuePair <string, string>("user", "phone") }); Contact callerContact = "[email protected]:5060"; var invite = new InviteMessage(CallId, to, @from, @from); var port = MediaGateway.GetNextPort(); if (includeSdp) { invite.SdpData = new Sdp(); invite.SdpData.AddParameter("o", string.Format("- {0} 0 IN IP4 {1}", 10, LocalIp)) .AddParameter("s", "-") .AddParameter("c", "IN IP4 " + LocalIp) .AddParameter("t", "0 0") .AddParameter("m", string.Format("audio {0} RTP/AVP 8 101", port)) .AddParameter("a", "rtpmap:8 PCMA/8000") .AddParameter("a", "rtpmap:101 telephone-event/8000") .AddParameter("a", "fmtp:101 0-15").AddParameter("a", "sendrecv"); } if (includeIsup) { var isup = new IsupInitialAddress(); invite.IsupData = isup; isup.ForwardCallIndicator.LoadParameterData(new byte[] { 0x20, 0x01 }); isup.CallingPartyCategory.CategoryFlags = CallingPartyCategory.Category.Unknown; isup.NatureOfConnectionIndicator.EchoControlIncluded = false; isup.NatureOfConnectionIndicator.ContinuityCheckIndicator = NatureOfConnection.ContinuityCheckIndicatorFlags.NotRequired; isup.NatureOfConnectionIndicator.SatelliteIndicator = NatureOfConnection.SatelliteIndicatorFlags.One; isup.CalledNumber.Number = new string(invite.To.Address.TakeWhile(a => a != '@').ToArray()); isup.CalledNumber.NumberingFlags = NAIFlags.RoutingNotAllowed | NAIFlags.Isdn; isup.CalledNumber.Flags = PhoneFlags.NAINationalNumber; var callingNumber = invite.IsupData.AddOptionalParameter(new IsupPhoneNumberParameter(IsupParameterType.CallingPartyNumber) { Number = invite.From.Address.Split('@').FirstOrDefault() }); callingNumber.NumberingFlags |= NAIFlags.ScreeningVerifiedAndPassed | NAIFlags.NetworProvided; isup.AddOptionalParameter(new IsupPhoneNumberParameter(IsupParameterType.OriginalCalledNumber) { Number = callerContact.Address.Split('@').FirstOrDefault(), Flags = callingNumber.Flags, NumberingFlags = NAIFlags.PresentationRestricted | NAIFlags.Isdn }); isup.AddOptionalParameter(new IsupPhoneNumberParameter(IsupParameterType.RedirectingNumber) { Number = callerContact.Address.Split('@').FirstOrDefault(), Flags = callingNumber.Flags, NumberingFlags = NAIFlags.PresentationRestricted | NAIFlags.Isdn }); isup.AddOptionalParameter(new RedirectInfo { RedirectReason = RedirReason.NoReply, RedirectCounter = 1, RedirectIndicatorFlags = RedirectInfo.RedirectIndicator.CallDiverted }); } if (includeSdp) { invite.Headers["Via"] = string.Format("SIP/2.0/UDP {0}:5060;branch=z9hG4bK7fe{1}", LocalIp, DateTime.Now.Ticks.ToString("X8").ToLowerInvariant()); } var bytes = invite.Serialize(); var deserialized = SipMessage.Parse(bytes) as InviteMessage; Assert.IsNotNull(deserialized, "message isn't an invite"); Assert.That(invite.Contact, Is.EqualTo(deserialized.Contact)); Assert.AreEqual(invite.Contact.ToString(), deserialized.Contact.ToString()); Assert.AreEqual(invite.From, deserialized.From); Assert.AreEqual(invite.To, deserialized.To); if (includeSdp) { Assert.AreEqual(invite.SdpData.ContentText, deserialized.SdpData.ContentText); } if (includeIsup) { Assert.AreEqual(invite.IsupData.GetByteArray().ToHex().ToUpper(), deserialized.IsupData.GetByteArray().ToHex().ToUpper()); } Assert.AreEqual(invite.Method, deserialized.Method); }