提交 497f8f76 编写于 作者: lwplvx's avatar lwplvx

初步测试

上级 28736b79
...@@ -6,6 +6,7 @@ using Aurora.Core.IService; ...@@ -6,6 +6,7 @@ using Aurora.Core.IService;
using Aurora.Core.IService.Dto; using Aurora.Core.IService.Dto;
using Aurora.Infrastructure.Response; using Aurora.Infrastructure.Response;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
namespace Aurora.Core.Api.Controllers namespace Aurora.Core.Api.Controllers
...@@ -16,12 +17,15 @@ namespace Aurora.Core.Api.Controllers ...@@ -16,12 +17,15 @@ namespace Aurora.Core.Api.Controllers
{ {
private readonly ILogger<TranslateController> _logger; private readonly ILogger<TranslateController> _logger;
private readonly IRocketService _rocketService; private readonly IRocketService _rocketService;
private readonly IHubContext<TranslateRocketHub> _hubContext;
public TranslateController(ILogger<TranslateController> logger, public TranslateController(ILogger<TranslateController> logger,
IRocketService rocketService) IRocketService rocketService,
IHubContext<TranslateRocketHub> hubContext)
{ {
_logger = logger; _logger = logger;
_rocketService = rocketService; _rocketService = rocketService;
_hubContext = hubContext;
} }
[HttpGet] [HttpGet]
...@@ -42,8 +46,21 @@ namespace Aurora.Core.Api.Controllers ...@@ -42,8 +46,21 @@ namespace Aurora.Core.Api.Controllers
/// <returns></returns> /// <returns></returns>
public async Task<ResponseModel<RocketDto>> Rocket(RocketDto model) public async Task<ResponseModel<RocketDto>> Rocket(RocketDto model)
{ {
var res = await _rocketService.Add(model); var res = await _rocketService.Rocket(model);
await _hubContext.Clients.All.SendAsync("rocketWord", model);
return res; return res;
} }
[HttpGet]
/// <summary>
/// biu word
/// </summary>
/// <returns></returns>
public async Task<ResponseModel<RocketDto>> Test()
{
await _hubContext.Clients.All.SendAsync("rocketWord", "model");
return new ResponseModel<RocketDto>(new RocketDto());
}
} }
} }
...@@ -28,6 +28,7 @@ namespace Aurora.Core.Api ...@@ -28,6 +28,7 @@ namespace Aurora.Core.Api
option.UseMySQL(configuration["ReadonlyConnectionStrings:MySql"])); option.UseMySQL(configuration["ReadonlyConnectionStrings:MySql"]));
services.AddTransient<ICategoryService, CategoryService>(); services.AddTransient<ICategoryService, CategoryService>();
services.AddTransient<IRocketService, RocketService>();
return services; return services;
} }
......
...@@ -41,6 +41,7 @@ namespace Aurora.Core.Api ...@@ -41,6 +41,7 @@ namespace Aurora.Core.Api
services.AddCommonService(); services.AddCommonService();
services.AddModuleCoreApi(Configuration); services.AddModuleCoreApi(Configuration);
services.AddSignalR();
} }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
...@@ -65,15 +66,23 @@ namespace Aurora.Core.Api ...@@ -65,15 +66,23 @@ namespace Aurora.Core.Api
endpoints.MapControllers(); endpoints.MapControllers();
}); });
// register this service // register this service
ServiceEntity serviceEntity = new ServiceEntity // ServiceEntity serviceEntity = new ServiceEntity
// {
// // IP = NetworkHelper.LocalIPAddress,
// Port = Convert.ToInt32(Configuration["Service:Port"]),
// ServiceName = Configuration["Service:Name"],
// ConsulIP = Configuration["Consul:IP"],
// ConsulPort = Convert.ToInt32(Configuration["Consul:Port"])
// };
// app.RegisterConsul(lifetime, serviceEntity);
app.UseEndpoints(endpoints =>
{ {
// IP = NetworkHelper.LocalIPAddress, endpoints.MapControllers();
Port = Convert.ToInt32(Configuration["Service:Port"]), endpoints.MapHub<TranslateRocketHub>("/hub/TranslateRocketHub");
ServiceName = Configuration["Service:Name"], });
ConsulIP = Configuration["Consul:IP"],
ConsulPort = Convert.ToInt32(Configuration["Consul:Port"])
};
app.RegisterConsul(lifetime, serviceEntity);
} }
} }
} }
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.Logging;
namespace Aurora.Core.Api
{
public class TranslateRocketHub : Hub
{
private readonly ILogger<TranslateRocketHub> _logger;
public TranslateRocketHub(ILogger<TranslateRocketHub> logger)
{
_logger = logger;
}
/// <summary>
/// 客户端连接
/// </summary>
/// <returns></returns>
public override async Task OnConnectedAsync()
{
await Groups.AddToGroupAsync(Context.ConnectionId, "SignalR Users");
await base.OnConnectedAsync();
}
public override async Task OnDisconnectedAsync(Exception exception)
{
await Groups.RemoveFromGroupAsync(Context.ConnectionId, "SignalR Users");
await base.OnDisconnectedAsync(exception);
}
public async Task SendMessage(string word)
{
await Clients.All.SendAsync("rocketWord", word);
}
}
}
\ No newline at end of file
...@@ -4,9 +4,9 @@ using System.Collections.Generic; ...@@ -4,9 +4,9 @@ using System.Collections.Generic;
namespace Aurora.Core.Domain.Entities namespace Aurora.Core.Domain.Entities
{ {
/// <summary> /// <summary>
/// 单词,我就用 Rocket 表示单词 /// 单词,我就用 Rocket 表示单词
/// </summary> /// </summary>
public class Rocket : TenantEntityBase public class RocketWord : TenantEntityBase
{ {
public int CategoryId { get; set; } public int CategoryId { get; set; }
public string Name { get; set; } public string Name { get; set; }
......
...@@ -34,6 +34,7 @@ namespace Aurora.Core.EntityFramework ...@@ -34,6 +34,7 @@ namespace Aurora.Core.EntityFramework
} }
public DbSet<Category> Categories { get; set; } public DbSet<Category> Categories { get; set; }
public DbSet<RocketWord> RocketWords { get; set; }
public DbSet<Subject> Subjects { get; set; } public DbSet<Subject> Subjects { get; set; }
public DbSet<Exampaper> Exampapers { get; set; } public DbSet<Exampaper> Exampapers { get; set; }
public DbSet<Question> Question { get; set; } public DbSet<Question> Question { get; set; }
......
...@@ -9,6 +9,6 @@ namespace Aurora.Core.IService ...@@ -9,6 +9,6 @@ namespace Aurora.Core.IService
public interface IRocketService public interface IRocketService
{ {
Task<ResponseModel<List<RocketDto>>> GetList(); Task<ResponseModel<List<RocketDto>>> GetList();
Task<ResponseModel<RocketDto>> Rocket(RocketDto model); Task<ResponseModel<RocketDto>> Rocket(RocketDto model);
} }
} }
...@@ -50,12 +50,23 @@ namespace Aurora.Core.Service ...@@ -50,12 +50,23 @@ namespace Aurora.Core.Service
public async Task<ResponseModel<RocketDto>> Rocket(RocketDto model) public async Task<ResponseModel<RocketDto>> Rocket(RocketDto model)
{ {
#region 保存到数据库
var entity = _mapper.Map<RocketWord>(model); var entity = _mapper.Map<RocketWord>(model);
_dbContext.Categories.Add(entity); _dbContext.RocketWords.Add(entity);
var num = await _dbContext.SaveChangesAsync(); var num = await _dbContext.SaveChangesAsync();
#endregion
#region 发送到移动端
// 按照用户发送
// 广播发送
#endregion
var dto = _mapper.Map<RocketDto>(entity); var dto = _mapper.Map<RocketDto>(entity);
var res = new ResponseModel<RocketDto>(dto); var res = new ResponseModel<RocketDto>(dto);
......
...@@ -26,15 +26,14 @@ function openUrlCurrentTab(url) { ...@@ -26,15 +26,14 @@ function openUrlCurrentTab(url) {
getCurrentTabId((tabId) => { getCurrentTabId((tabId) => {
chrome.tabs.update(tabId, { url: url }) chrome.tabs.update(tabId, { url: url })
}) })
} }
function handleStateChange() {} function handleStateChange() {}
chrome.contextMenus.create({ chrome.contextMenus.create({
title: '发射选择的单词:%s', // %s表示选中的文字 title: '发射选择的单词:%s', // %s表示选中的文字
contexts: ['selection'], // 只有当选中文字时才会出现此右键菜单 contexts: ['selection'], // 只有当选中文字时才会出现此右键菜单
onclick: function (params) { onclick: function (params) {
chrome.browserAction.setBadgeText({ text: 'new' }) chrome.browserAction.setBadgeText({ text: 'new' })
chrome.browserAction.setBadgeBackgroundColor({ color: [255, 0, 0, 255] }) chrome.browserAction.setBadgeBackgroundColor({ color: [255, 0, 0, 255] })
...@@ -43,10 +42,20 @@ chrome.contextMenus.create({ ...@@ -43,10 +42,20 @@ chrome.contextMenus.create({
xhr.open( xhr.open(
'GET', 'GET',
// chrome.extension.getURL('/config_resources/config.json'), // chrome.extension.getURL('/config_resources/config.json'),
'http://www.luoboit.cn/api/blog/post/query?Page=1&Limit=10', // 'http://www.luoboit.cn/api/blog/post/query?Page=1&Limit=10',
'http://localhost:8000/Translate/Test',
true, true,
) )
// prepare form data
// let data = new FormData(form)
let data = new FormData()
// set headers
// xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
// xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest')
// send request
// xhr.send(data)
//访问内部位于config_resources目录下的config.json文件 //访问内部位于config_resources目录下的config.json文件
xhr.send() xhr.send()
}, },
}) })
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册