示例#1
0
        private static void Main(string[] args)
        {
            using (var client = new MessagingClient())
                client.SendMessage("test message");

            Console.WriteLine("Message sent.  Press <ENTER> to exit.");
            Console.ReadLine();
        }
示例#2
0
 protected override async Task OnJoinAsync(JoinEvent ev)
 {
     Log.WriteInfo($"SourceType:{ev.Source.Type}, SourceId:{ev.Source.Id}");
     await MessagingClient.ReplyMessageAsync(ev.ReplyToken, $"Thank you for letting me join your {ev.Source.Type.ToString().ToLower()}!");
 }
示例#3
0
 private Task EchoAsync(string replyToken, string userMessage)
 {
     return(MessagingClient.ReplyMessageAsync(replyToken, userMessage));
 }
 public Ping()
 {
     MessagingClient.SendMessageAsync <PingRequest, PingResponse>(null)
     .ReturnsForAnyArgs(GetCompletedTask(ExpectedResponse));
 }
        protected override async Task OnMessageAsync(MessageEvent ev)
        {
            var msg = ev.Message as TextEventMessage;

            if (msg == null)
            {
                return;
            }

            switch (msg.Text)
            {
            case "Rectangle-Cover":
                await ReplyButtonsTemplateMessageAsync(ImageAspectRatioType.Rectangle, ImageSizeType.Cover);

                break;

            case "Square-Contain":
                await ReplyButtonsTemplateMessageAsync(ImageAspectRatioType.Square, ImageSizeType.Contain);

                break;

            case "Square-Cover":
                await ReplyButtonsTemplateMessageAsync(ImageAspectRatioType.Square, ImageSizeType.Cover);

                break;

            case "Rectangle-Contein":
            default:
                await ReplyButtonsTemplateMessageAsync(ImageAspectRatioType.Rectangle, ImageSizeType.Contain);

                break;
            }

            async Task ReplyButtonsTemplateMessageAsync(ImageAspectRatioType imageAspectRatio, ImageSizeType imageSize)
            {
                var imageUri = BlobStorage.ListBlobUri(blobDirectoryName).FirstOrDefault(uri => uri.ToString().EndsWith(imageName));

                if (imageUri == null)
                {
                    imageUri = await BlobStorage.UploadImageAsync(Properties.Resources.sample_image, blobDirectoryName, imageName);
                }

                var actions = new[]
                {
                    new MessageTemplateAction("Rectangle-Contain", "Rectangle-Contain"),
                    new MessageTemplateAction("Rectangle-Cover", "Rectangle-Cover"),
                    new MessageTemplateAction("Square-Contain", "Square-Contain"),
                    new MessageTemplateAction("Square-Cover", "Square-Cover")
                };
                var templateMessage = new TemplateMessage("ButtonsTemplate",
                                                          new ButtonsTemplate(
                                                              imageAspectRatio.ToString() + "-" + imageSize.ToString(),
                                                              imageUri.ToString(),
                                                              "Test of thumbnail image settings",
                                                              actions,
                                                              imageAspectRatio,
                                                              imageSize,
                                                              imageBackgroundColor: "#FF0000",
                                                              defaultAction: new MessageTemplateAction("Default-Action", "Default-Action")));
                await MessagingClient.ReplyMessageAsync(ev.ReplyToken, new[] { templateMessage });
            }
        }
示例#6
0
        public void MessagingClient_DefaultCerificateStoreIsWindowsCerificateStore()
        {
            MessagingClient messagingClient = new MessagingClient(Settings, LoggerFactory, CollaborationRegistry, AddressRegistry);

            Assert.IsInstanceOfType(messagingClient.CertificateStore, typeof(WindowsCertificateStore));
        }
示例#7
0
 public void Asynchronous_ProcessingTasks_NotSet()
 {
     Settings.ServiceBus.Asynchronous.ProcessingTasks = 0;
     Client = new MessagingClient(Settings, LoggerFactory, CollaborationRegistry, AddressRegistry, CertificateStore);
 }
示例#8
0
 public void Error_ReadTimeout_NotSet()
 {
     Settings.ServiceBus.Error.ReadTimeout = TimeSpan.Zero;
     Client = new MessagingClient(Settings, CollaborationRegistry, AddressRegistry);
 }
示例#9
0
 public void AddressRegistry_NotSet()
 {
     Client = new MessagingClient(Settings, CollaborationRegistry, null);
 }
示例#10
0
 public void Error_ProcessingTasks_NotSet()
 {
     Settings.ServiceBus.Error.ProcessingTasks = 0;
     Client = new MessagingClient(Settings, CollaborationRegistry, AddressRegistry);
 }
示例#11
0
 public void Error_TimeToLive_NotSet()
 {
     Settings.ServiceBus.Error.TimeToLive = TimeSpan.Zero;
     Client = new MessagingClient(Settings, CollaborationRegistry, AddressRegistry);
 }
示例#12
0
 public void Options_NotSet()
 {
     Client = new MessagingClient(null, CollaborationRegistry, AddressRegistry);
 }
示例#13
0
 public void Asynchronous_ProcessingTasks_NotSet()
 {
     Settings.ServiceBus.Asynchronous.ProcessingTasks = 0;
     Client = new MessagingClient(Settings, CollaborationRegistry, AddressRegistry);
 }
示例#14
0
        internal void SetupInternal(int otherHerId)
        {
            var addressRegistrySettings = new AddressRegistrySettings()
            {
                UserName         = "******",
                Password         = "******",
                EndpointName     = "SomeEndpointName",
                WcfConfiguration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None),
                CachingInterval  = TimeSpan.FromSeconds(5)
            };
            var collaborationRegistrySettings = new CollaborationProtocolRegistrySettings()
            {
                UserName         = "******",
                Password         = "******",
                EndpointName     = "SomeEndpointName",
                WcfConfiguration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None),
                CachingInterval  = TimeSpan.FromSeconds(5)
            };

            LoggerFactory = new LoggerFactory();

            MockLoggerProvider = new MockLoggerProvider(null);
            LoggerFactory.AddProvider(MockLoggerProvider);
            Logger = LoggerFactory.CreateLogger <BaseTest>();

            var distributedCache = DistributedCacheFactory.Create();

            AddressRegistry = new AddressRegistryMock(addressRegistrySettings, distributedCache);
            AddressRegistry.SetupFindCommunicationPartyDetails(i =>
            {
                var file = Path.Combine("Files", $"CommunicationDetails_{i}.xml");
                return(File.Exists(file) == false ? null : XElement.Load(file));
            });
            AddressRegistry.SetupGetCertificateDetailsForEncryption(i =>
            {
                var path = Path.Combine("Files", $"GetCertificateDetailsForEncryption_{i}.xml");
                return(File.Exists(path) == false ? null : XElement.Load(path));
            });
            AddressRegistry.SetupGetCertificateDetailsForValidatingSignature(i =>
            {
                var path = Path.Combine("Files", $"GetCertificateDetailsForValidatingSignature_{i}.xml");
                return(File.Exists(path) == false ? null : XElement.Load(path));
            });

            CollaborationRegistry = new CollaborationProtocolRegistryMock(collaborationRegistrySettings, distributedCache, AddressRegistry);
            CollaborationRegistry.SetupFindProtocolForCounterparty(i =>
            {
                var file = Path.Combine("Files", $"CPP_{i}.xml");
                return(File.Exists(file) == false ? null : File.ReadAllText(file));
            });
            CollaborationRegistry.SetupFindAgreementForCounterparty(i =>
            {
                var file = Path.Combine("Files", $"CPA_{i}.xml");
                return(File.Exists(file) == false ? null : File.ReadAllText(file));
            });
            CollaborationRegistry.SetupFindAgreementById(i =>
            {
                var file = Path.Combine("Files", $"CPA_{i:D}.xml");
                return(File.Exists(file) == false ? null : File.ReadAllText(file));
            });

            Settings = new MessagingSettings()
            {
                MyHerId            = MockFactory.HelsenorgeHerId,
                SigningCertificate = new CertificateSettings()
                {
                    StoreName     = StoreName.My,
                    StoreLocation = StoreLocation.LocalMachine,
                    Thumbprint    = TestCertificates.HelsenorgeSigntatureThumbprint
                },
                DecryptionCertificate = new CertificateSettings()
                {
                    StoreName     = StoreName.My,
                    StoreLocation = StoreLocation.LocalMachine,
                    Thumbprint    = TestCertificates.HelsenorgeEncryptionThumbprint
                }
            };

            Settings.ServiceBus.ConnectionString = "connection string";
            Settings.ServiceBus.Synchronous.ReplyQueueMapping.Add(Environment.MachineName.ToLower(), "RepliesGoHere");
            // make things easier by only having one processing task per queue
            Settings.ServiceBus.Asynchronous.ProcessingTasks = 1;
            Settings.ServiceBus.Synchronous.ProcessingTasks  = 1;
            Settings.ServiceBus.Error.ProcessingTasks        = 1;

            MockFactory          = new MockFactory(otherHerId);
            CertificateValidator = new MockCertificateValidator();
            CertificateStore     = new MockCertificateStore();
            var signingCertificate    = CertificateStore.GetCertificate(TestCertificates.HelsenorgeSigntatureThumbprint);
            var encryptionCertificate = CertificateStore.GetCertificate(TestCertificates.HelsenorgeEncryptionThumbprint);

            MessageProtection = new MockMessageProtection(signingCertificate, encryptionCertificate);

            Client = new MessagingClient(
                Settings,
                CollaborationRegistry,
                AddressRegistry,
                CertificateStore,
                CertificateValidator,
                MessageProtection
                );
            Client.ServiceBus.RegisterAlternateMessagingFactory(MockFactory);

            Server = new MessagingServer(
                Settings,
                Logger,
                LoggerFactory,
                CollaborationRegistry,
                AddressRegistry,
                CertificateStore,
                CertificateValidator,
                MessageProtection
                );
            Server.ServiceBus.RegisterAlternateMessagingFactory(MockFactory);
        }
示例#15
0
 public void Synchronous_ProcessingTasksEqualsZero_IsAllowed()
 {
     Settings.ServiceBus.Synchronous.ProcessingTasks = 0;
     Client = new MessagingClient(Settings, LoggerFactory, CollaborationRegistry, AddressRegistry, CertificateStore);
 }
示例#16
0
 public void MyHerId_NotSet()
 {
     Settings.MyHerId = 0;
     Client           = new MessagingClient(Settings, CollaborationRegistry, AddressRegistry);
 }
示例#17
0
 public void Syncrhonous_CallTimeout_NotSet()
 {
     Settings.ServiceBus.Synchronous.CallTimeout = TimeSpan.Zero;
     Client = new MessagingClient(Settings, LoggerFactory, CollaborationRegistry, AddressRegistry);
 }
示例#18
0
 public void SigningCertificate_NotSet()
 {
     Settings.SigningCertificate = null;
     Client = new MessagingClient(Settings, CollaborationRegistry, AddressRegistry);
 }
示例#19
0
 public void Syncrhonous_ReplyQueue_NotSet()
 {
     Settings.ServiceBus.Synchronous.ReplyQueueMapping = new Dictionary <string, string>();
     Client = new MessagingClient(Settings, LoggerFactory, CollaborationRegistry, AddressRegistry);
 }
示例#20
0
 public void ConnectionString_NotSet()
 {
     Settings.ServiceBus.ConnectionString = null;
     Client = new MessagingClient(Settings, CollaborationRegistry, AddressRegistry);
 }
示例#21
0
 public void Asynchronous_TimeToLive_NotSet()
 {
     Settings.ServiceBus.Asynchronous.TimeToLive = TimeSpan.Zero;
     Client = new MessagingClient(Settings, LoggerFactory, CollaborationRegistry, AddressRegistry, CertificateStore);
 }
示例#22
0
 public void Syncrhonous_TimeToLive_NotSet()
 {
     Settings.ServiceBus.Synchronous.TimeToLive = TimeSpan.Zero;
     Client = new MessagingClient(Settings, CollaborationRegistry, AddressRegistry);
 }
 /// <summary>
 /// Initializes a new instance of the MessagingClientManager class.
 /// </summary>
 public MessagingClientManager()
 {
     this.messagingClient = new MessagingClient(new Guid(ApplicationId), true, new TimeSpan(TimerIntervalHours, TimerIntervalMinutes, TimerIntervalSeconds));
     this.messagingClient.Start();
     this.messagingClient.MessageReceived += new EventHandler<DeCurtis.Messaging.Common.MessageReceivedEventArgs>(this.MessagingClient_MessageReceived);
 }
示例#24
0
 public bool Connected()
 {
     return(MessagingClient.CanPing());
 }