protected void Page_Load(object sender, EventArgs e) { if (Request.HttpMethod == "POST") { //不要调用UrlDecodeMessage,直接拆分请求字串,进行验签 // 获取异步通知请求字串 string requestString = Request.Form.ToString(); // 分割请求字串 string[] EncryptBody = requestString.Split('&'); //分割后的请求字串转换通信报文实体 MessageWorker.trafficMessage message = new MessageWorker.trafficMessage(); for (int i = 0; i < EncryptBody.Length; i++) { string[] tmp = EncryptBody[i].Split('='); switch (tmp[0]) { //需要添加引用System.Web,用于url转码,处理base64产生的+/= case "charset": message.charset = EncryptBody[i].Replace("charset=", "").Trim('"'); break; case "signType": message.signType = EncryptBody[i].Replace("signType=", "").Trim('"'); break; case "data": message.data = EncryptBody[i].Replace("data=", "").Trim('"'); break; case "sign": message.sign = EncryptBody[i].Replace("sign=", "").Trim('"'); break; case "extend": message.extend = EncryptBody[i].Replace("extend=", "").Trim('"'); break; } } //验签,验签结果会提现在sign字段,以true或false方式提现 MessageWorker worker = new MessageWorker(); worker.CheckSignMessageAfterResponse(message); } }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req, [SendGrid(ApiKey = "CustomSendGridKeyAppSettingName")] IAsyncCollector <SendGridMessage> messageCollector, ILogger log) { log.LogInformation("C# HTTP trigger function processed a request."); var options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true, }; var requestBody = await new StreamReader(req.Body).ReadToEndAsync(); var meeting = JsonSerializer.Deserialize <DeaconMeeting>(requestBody, options); try { var message = new SendGridMessage(); var worker = new MessageWorker(message); meeting.Email = Environment.GetEnvironmentVariable("DeaconMeetingEmail"); meeting.Name = Environment.GetEnvironmentVariable("DeaconMeetingName"); meeting.FromEmail = Environment.GetEnvironmentVariable("DeaconMeetingFromEmail"); meeting.FromName = Environment.GetEnvironmentVariable("DeaconMeetingFromName"); meeting.Copy = Environment.GetEnvironmentVariable("DeaconMeetingCopy"); await messageCollector.AddAsync(worker.PrepareDiaconateMeetingEmail(meeting)); } catch (Exception e) { log.LogInformation(e.ToString()); return(new BadRequestResult()); } return(new OkResult()); }
public async Task <ReadOnlyCollection <Uri>[]> GetWebsitesLinksAsync(string[] urls) { var messageWorker = new MessageWorker(); var absoluteLinkParser = new AbsoluteLinkParserCore(); var hrefLinkParserCore = new HrefLinkParserCore(); var linkParsers = new List <IParserLinkCore>() { absoluteLinkParser, hrefLinkParserCore }; List <SiteParser> siteParsers = new List <SiteParser>(); Dictionary <SiteParser, Uri> dictionary = new Dictionary <SiteParser, Uri>(); foreach (var site in urls) { var siteParser = new SiteParser(messageWorker); siteParsers.Add(siteParser); dictionary.Add(siteParser, new Uri(site)); } var tasks = siteParsers.Select(i => { return(i.GetUrlTreeAsync(linkParsers, dictionary[i])); }); var parsedLinks = await Task.WhenAll(tasks); Console.WriteLine("All site are parsed."); return(parsedLinks); }
public void StartClient() { if (messageWorker != null) { messageWorker.Stop(); } clients.Init(); messageWorker = new MessageWorker(user.username); }
public static async Task RunAsync([TimerTrigger("0 0 15 * * THU")] TimerInfo myTimer, [SendGrid(ApiKey = "CustomSendGridKeyAppSettingName")] IAsyncCollector <SendGridMessage> messageCollector, ILogger log) { log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}"); var connection = Environment.GetEnvironmentVariable("CosmosDBConnection"); try { var cosmosClient = new CosmosClient(connection); const string databaseId = "ministries"; var database = await cosmosClient.CreateDatabaseIfNotExistsAsync(databaseId); var deacon = new DeaconDuty { Month = DateTime.Now.AddMonths(1).ToString("MMMM") }; var meeting = new DeaconMeeting(); await GetCurrentDeacon(database.Database, deacon, meeting); if (string.IsNullOrEmpty(deacon.AttendeeId)) { log.LogInformation("Deacon not found"); } await GetDeaconInformation(database.Database, deacon); if (string.IsNullOrEmpty(deacon.AttendeeId)) { log.LogInformation("Attendee not found"); } var message = new SendGridMessage(); var worker = new MessageWorker(message); deacon.FromEmail = Environment.GetEnvironmentVariable("DeaconDutyFromEmail"); deacon.FromName = Environment.GetEnvironmentVariable("DeaconDutyFromName"); deacon.Copy = Environment.GetEnvironmentVariable("DeaconDutyCopy"); await messageCollector.AddAsync(worker.PrepareDiaconateEmail(deacon)); if (!string.IsNullOrEmpty(meeting.DeaconDate)) { meeting.Email = Environment.GetEnvironmentVariable("DeaconMeetingEmail"); meeting.Name = Environment.GetEnvironmentVariable("DeaconMeetingName"); meeting.FromEmail = Environment.GetEnvironmentVariable("DeaconMeetingFromEmail"); meeting.FromName = Environment.GetEnvironmentVariable("DeaconMeetingFromName"); meeting.Copy = Environment.GetEnvironmentVariable("DeaconMeetingCopy"); await messageCollector.AddAsync(worker.PrepareDiaconateReminderEmail(meeting)); } } catch (Exception e) { log.LogInformation(e.ToString()); } }
public void PostInvalid() { var data = _fixture.CreateMany <Message>().ToList(); var count = data.Count; _mock.Setup(x => x.PutNewMessage(It.IsAny <Message>())).Callback((Message m) => data.Add(m)); MessageWorker.Initialize(_mock.Object); MessageWorker.PutNewMessage(-1, null, null, null); }
public void BuildEmailTo_email_no_name() { var toEmail = "*****@*****.**"; var toName = string.Empty; _worker = new MessageWorker(_message); _worker.BuildEmailTo(toEmail, toName); Assert.Equal(toEmail, _message.Personalizations[0].Tos[0].Email); }
public void BuildEmailTo_email_and_name() { var toEmail = "*****@*****.**"; var toName = "Peter Parker"; _worker = new MessageWorker(_message); _worker.BuildEmailTo(toEmail, toName); Assert.Equal(toEmail, _message.Personalizations[0].Tos[0].Email); Assert.Equal(toName, _message.Personalizations[0].Tos[0].Name); }
public void GetAll() { var data = _fixture.CreateMany <Message>().ToList(); _mock.Setup(x => x.GetAll()).Returns(data); MessageWorker.Initialize(_mock.Object); Assert.IsNotNull(MessageWorker.GetAllMessages()); Assert.IsTrue(MessageWorker.GetAllMessages().Any()); }
public void BuildEmailCopyTest_no_copy() { _worker = new MessageWorker(_message); var toEmail = "*****@*****.**"; var toName = "Peter Parker"; _message.AddTo(toEmail, toName); var ccEmail = string.Empty; _worker.BuildEmailCopy(ccEmail); Assert.Null(_message.Personalizations[0].Ccs); }
public void BuildEmailCopyTest_1_email() { _worker = new MessageWorker(_message); var toEmail = "*****@*****.**"; var toName = "Peter Parker"; _message.AddTo(toEmail, toName); var ccEmail = "*****@*****.**"; _worker.BuildEmailCopy(ccEmail); Assert.Equal(ccEmail, _message.Personalizations[0].Ccs[0].Email); }
public void BuildFromTest_no_email() { var fromEmail = string.Empty; var fromName = string.Empty; const string defaultEmail = "*****@*****.**"; const string defaultName = "Crossroads Deacons"; _worker = new MessageWorker(_message); _worker.BuildEmailFrom(fromEmail, fromName); Assert.Equal(defaultEmail, _message.From.Email); Assert.Equal(defaultName, _message.From.Name); }
public void BuildFromTest_email_and_name() { var fromEmail = "*****@*****.**"; var fromName = "Peter Parker"; const string defaultEmail = "*****@*****.**"; const string defaultName = "Crossroads Deacons"; _worker = new MessageWorker(_message); _worker.BuildEmailFrom(fromEmail, fromName); Assert.Equal(fromEmail, _message.From.Email); Assert.Equal(fromName, _message.From.Name); }
public RecalculateHoursOfUserTests() { _options = new DbContextOptionsBuilder <AppDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).Options; using (var context = new AppDbContext(_options)) { } _bus = Substitute.For <IBus>(); _serviceProvider = new ServiceCollection().AddScoped(_ => new AppDbContext(_options)).BuildServiceProvider(); _worker = new MessageWorker(_bus, _serviceProvider, Substitute.For <ILogger <MessageWorker> >()); }
public void GetMessagesMessageIdValid() { var data = _fixture.CreateMany <Message>().ToList(); var ids = data.Select(x => x.MessageId).ToList(); _mock.Setup(x => x.GetByMessageId(ids[0])).Returns(data.Where(y => y.MessageId.Equals(ids[0]))); _mock.Setup(x => x.GetByMessageId(It.IsNotIn(ids.Select(y => y)))).Returns((IEnumerable <Message>)null); MessageWorker.Initialize(_mock.Object); Assert.IsNotNull(MessageWorker.GetMessageById(ids.First())); Assert.IsTrue(MessageWorker.GetMessageById(ids.First()).Any()); }
public void GetMessagesMessageIdInvalid() { var data = _fixture.CreateMany <Message>().ToList(); var ids = data.Select(x => x.MessageId); _mock.Setup(x => x.GetByMessageId(It.IsIn(ids))).Returns(data); _mock.Setup(x => x.GetByMessageId(It.IsNotIn(ids))).Returns((IEnumerable <Message>)null); MessageWorker.Initialize(_mock.Object); Assert.IsNull(MessageWorker.GetMessageById("badmessageid")); Assert.IsNull(MessageWorker.GetMessageById("")); }
public void BuildEmailCopyTest_2_email_1_name() { _worker = new MessageWorker(_message); var toEmail = "*****@*****.**"; var toName = "Peter Parker"; _message.AddTo(toEmail, toName); var ccEmail = "[email protected];;[email protected];Tony Stark"; _worker.BuildEmailCopy(ccEmail); Assert.Equal("*****@*****.**", _message.Personalizations[0].Ccs[0].Email); Assert.Equal("*****@*****.**", _message.Personalizations[0].Ccs[1].Email); Assert.Equal("Tony Stark", _message.Personalizations[0].Ccs[1].Name); }
public void GetMessagesDateTimeValid() { var data = _fixture.CreateMany <Message>(10).ToList(); var subSet = data.OrderBy(x => x.TimeStamp).Take(5).ToList(); var validDateTime = subSet.Last().TimeStamp; _mock.Setup(x => x.GetAfterTime(validDateTime)).Returns(subSet); _mock.Setup(x => x.GetAfterTime(It.IsNotIn(subSet.Select(t => t.TimeStamp)))).Returns((IEnumerable <Message>)null); MessageWorker.Initialize(_mock.Object); Assert.IsNotNull(MessageWorker.GetMessageAfterTime(validDateTime)); Assert.IsFalse(MessageWorker.GetMessageAfterTime(validDateTime).Any(x => x.TimeStamp > validDateTime)); }
public void GetMessageUserIdValid() { var data = _fixture.CreateMany <Message>().ToList(); var ids = data.Select(x => x.UserId); _mock.Setup(x => x.GetByUserId(It.IsIn(ids))).Returns(data); _mock.Setup(x => x.GetByUserId(It.IsNotIn(ids))).Returns((IEnumerable <Message>)null); MessageWorker.Initialize(_mock.Object); var idList = ids.ToList(); Assert.IsNotNull(MessageWorker.GetMessageByUser(idList.First())); Assert.IsTrue(MessageWorker.GetMessageByUser(idList.First()).Any()); }
private void button2_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(this.tbMsg.Text)) { MessageBox.Show("请输入报文"); return; } MessageWorker worker = new MessageWorker(); worker.CerFile = this.tbCerPath.Text; MessageWorker.trafficMessage msg = worker.UrlDecodeMessage(this.tbMsg.Text); msg = worker.CheckSignMessageAfterResponse(msg); lbcheck.Text = msg.sign; MessageBox.Show(msg.sign); }
public void GetMessagesQuery() { const string searchVar = "word"; var data = _fixture.CreateMany <Message>().ToList(); var data2 = _fixture.CreateMany <Message>().ToList(); data2.ForEach(x => x.Body += searchVar); data.AddRange(data2); _mock.Setup(x => x.GetMessagesContaining(searchVar)).Returns(data.Where(x => x.Body.Contains(searchVar))); MessageWorker.Initialize(_mock.Object); Assert.IsTrue(MessageWorker.GetMessagesContainingString("word").ToList().Any(x => data.Contains(x))); }
public void TestConcurrencyLevelIsRespected(int concurrencyLevel, int nMessages, int processingTime) { var evt = new ManualResetEvent(false); // TODO: this test isn't testing any behaviour so far.. // just ensuring the worker can cope with high number of messages var receiver = SetupReceiver(nMessages); var dispatcher = SetupDispatcher(nMessages, processingTime, evt); using (var processor = new MessageWorker(receiver, dispatcher, new NullLoggerFactory(), concurrencyLevel)) { processor.Start(); Task.Delay(TimeSpan.FromMinutes(15)).ContinueWith(t => evt.Set()); evt.WaitOne(); } }
protected void Page_Load(object sender, EventArgs e) { if (Request.HttpMethod == "POST") { string asyncNotice = Request.Form.ToString(); MessageWorker worker = new MessageWorker(); worker.PFXFile = pfxFilePath; //商户pfx证书路径 worker.PFXPassword = pfxPassword; //商户pfx证书密码 worker.CerFile = cerFilePath; //杉德cer证书路径 //验签 MessageWorker.trafficMessage asyncMessage = worker.CheckSignMessageAfterResponse(worker.UrlDecodeMessage(asyncNotice)); log.Debug("验签结果:" + asyncMessage.sign); log.Debug("反馈报文:" + asyncMessage.data); Response.Write("resp=000000"); } }
public void Send(string message) { if (message == "") { return; } var msg = new Message { User = "******", UserId = 1, Body = message, TimeStamp = DateTime.Now, Channel = "#general", MessageId = Guid.NewGuid().ToString() }; Clients.All.addNewMessage(msg.ToString()); MessageWorker.Initialize(new MessageDatabaseModel()); MessageWorker.PutNewMessage(1, null, null, message); }
public void PostValid() { var data = _fixture.CreateMany <Message>().ToList(); var count = data.Count; _mock.Setup(x => x.PutNewMessage(It.IsAny <Message>())).Callback((Message m) => data.Add(m)); MessageWorker.Initialize(_mock.Object); MessageWorker.PutNewMessage(1, "user", "#reactive", "Improptu comments are hard to think of."); Assert.IsTrue(data.Count == ++count); MessageWorker.PutNewMessage(1, "user", "#reactive", "Improptu comments are hard to think of."); Assert.IsTrue(data.Count == ++count); MessageWorker.PutNewMessage(2, null, "#reactive", "Improptu comments are hard to think of."); Assert.IsTrue(data.Count == ++count); MessageWorker.PutNewMessage(3, "user", null, "Improptu comments are hard to think of."); Assert.IsTrue(data.Count == ++count); MessageWorker.PutNewMessage(3, "user", "#reactive", null); Assert.IsTrue(data.Count == ++count); MessageWorker.PutNewMessage(4, null, null, null); Assert.IsTrue(data.Count == ++count); }
public void GetMessagesChannelValid() { var validChannels = new [] { "#general", "#random", "#important" }; var data = _fixture.CreateMany <Message>().ToList(); data.ForEach(x => x.Channel = validChannels[0]); var data2 = _fixture.CreateMany <Message>().ToList(); data2.ForEach(x => x.Channel = validChannels[1]); var data3 = _fixture.CreateMany <Message>().ToList(); data3.ForEach(x => x.Channel = validChannels[2]); data.AddRange(data2); data.AddRange(data3); _mock.Setup(x => x.GetByChannel("#general")).Returns(data.Where(x => x.Channel.Equals("#general"))); _mock.Setup(x => x.GetByMessageId(It.IsNotIn(validChannels))).Returns((IEnumerable <Message>)null); MessageWorker.Initialize(_mock.Object); Assert.IsNotNull(MessageWorker.GetMessagesByChannel("#general")); Assert.IsTrue(MessageWorker.GetMessagesByChannel("#general").ToList().Any(x => data.Contains(x))); }
private void SendMessage_Worker(object o) { messageWorker = new MessageWorker(); messageWorker.MessageRecieved += MessageWorker_MessageRecieved; messageWorker.SendMessage((WCF_Functions.MessageData)o); }
public IEnumerable <Message> GetByMessage(string messageId) { return(MessageWorker.GetMessageById(messageId)); }
public void Post(string username, int id, string channel, string strVal) { MessageWorker.PutNewMessage(id, username, channel, strVal); }
public RouteWorker() { m_worker = new MessageWorker(); m_rnodes = new Dictionary <Int32, RNode>(); m_worker.NodeRegistered += OnNodeAdded; }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req, [SendGrid(ApiKey = "CustomSendGridKeyAppSettingName")] IAsyncCollector <SendGridMessage> messageCollector, ILogger log) { log.LogInformation("C# HTTP trigger function processed a request."); var connection = Environment.GetEnvironmentVariable("CosmosDBConnection"); try { var cosmosClient = new CosmosClient(connection); const string databaseId = "ministries"; var database = await cosmosClient.CreateDatabaseIfNotExistsAsync(databaseId); var deacon = new DeaconDuty { Month = DateTime.Now.AddMonths(1).ToString("MMMM") }; var meeting = new DeaconMeeting(); await GetCurrentDeacon(database.Database, deacon, meeting); if (string.IsNullOrEmpty(deacon.AttendeeId)) { log.LogInformation("Deacon not found"); return(new BadRequestResult()); } await GetDeaconInformation(database.Database, deacon); if (string.IsNullOrEmpty(deacon.AttendeeId)) { log.LogInformation("Deacon not found"); return(new BadRequestResult()); } var message = new SendGridMessage(); var worker = new MessageWorker(message); deacon.FromEmail = Environment.GetEnvironmentVariable("DeaconDutyFromEmail"); deacon.FromName = Environment.GetEnvironmentVariable("DeaconDutyFromName"); deacon.Copy = Environment.GetEnvironmentVariable("DeaconDutyCopy"); await messageCollector.AddAsync(worker.PrepareDiaconateEmail(deacon)); if (!string.IsNullOrEmpty(meeting.DeaconDate)) { meeting.Email = Environment.GetEnvironmentVariable("DeaconMeetingEmail"); meeting.Name = Environment.GetEnvironmentVariable("DeaconMeetingName"); meeting.FromEmail = Environment.GetEnvironmentVariable("DeaconMeetingFromEmail"); meeting.FromName = Environment.GetEnvironmentVariable("DeaconMeetingFromName"); meeting.Copy = Environment.GetEnvironmentVariable("DeaconMeetingCopy"); await messageCollector.AddAsync(worker.PrepareDiaconateReminderEmail(meeting)); } } catch (Exception e) { log.LogInformation(e.ToString()); return(new BadRequestResult()); } return(new OkResult()); }