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

初步测试

上级 28736b79
......@@ -6,6 +6,7 @@ using Aurora.Core.IService;
using Aurora.Core.IService.Dto;
using Aurora.Infrastructure.Response;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.Logging;
namespace Aurora.Core.Api.Controllers
......@@ -16,12 +17,15 @@ namespace Aurora.Core.Api.Controllers
{
private readonly ILogger<TranslateController> _logger;
private readonly IRocketService _rocketService;
private readonly IHubContext<TranslateRocketHub> _hubContext;
public TranslateController(ILogger<TranslateController> logger,
IRocketService rocketService)
IRocketService rocketService,
IHubContext<TranslateRocketHub> hubContext)
{
_logger = logger;
_rocketService = rocketService;
_hubContext = hubContext;
}
[HttpGet]
......@@ -42,8 +46,21 @@ namespace Aurora.Core.Api.Controllers
/// <returns></returns>
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;
}
[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
option.UseMySQL(configuration["ReadonlyConnectionStrings:MySql"]));
services.AddTransient<ICategoryService, CategoryService>();
services.AddTransient<IRocketService, RocketService>();
return services;
}
......
......@@ -41,6 +41,7 @@ namespace Aurora.Core.Api
services.AddCommonService();
services.AddModuleCoreApi(Configuration);
services.AddSignalR();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
......@@ -65,15 +66,23 @@ namespace Aurora.Core.Api
endpoints.MapControllers();
});
// 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,
Port = Convert.ToInt32(Configuration["Service:Port"]),
ServiceName = Configuration["Service:Name"],
ConsulIP = Configuration["Consul:IP"],
ConsulPort = Convert.ToInt32(Configuration["Consul:Port"])
};
app.RegisterConsul(lifetime, serviceEntity);
endpoints.MapControllers();
endpoints.MapHub<TranslateRocketHub>("/hub/TranslateRocketHub");
});
}
}
}
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;
namespace Aurora.Core.Domain.Entities
{
/// <summary>
/// 单词,我就用 Rocket 表示单词
/// 单词,我就用 Rocket 表示单词
/// </summary>
public class Rocket : TenantEntityBase
public class RocketWord : TenantEntityBase
{
public int CategoryId { get; set; }
public string Name { get; set; }
......
......@@ -34,6 +34,7 @@ namespace Aurora.Core.EntityFramework
}
public DbSet<Category> Categories { get; set; }
public DbSet<RocketWord> RocketWords { get; set; }
public DbSet<Subject> Subjects { get; set; }
public DbSet<Exampaper> Exampapers { get; set; }
public DbSet<Question> Question { get; set; }
......
......@@ -9,6 +9,6 @@ namespace Aurora.Core.IService
public interface IRocketService
{
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
public async Task<ResponseModel<RocketDto>> Rocket(RocketDto model)
{
#region 保存到数据库
var entity = _mapper.Map<RocketWord>(model);
_dbContext.Categories.Add(entity);
_dbContext.RocketWords.Add(entity);
var num = await _dbContext.SaveChangesAsync();
#endregion
#region 发送到移动端
// 按照用户发送
// 广播发送
#endregion
var dto = _mapper.Map<RocketDto>(entity);
var res = new ResponseModel<RocketDto>(dto);
......
......@@ -26,15 +26,14 @@ function openUrlCurrentTab(url) {
getCurrentTabId((tabId) => {
chrome.tabs.update(tabId, { url: url })
})
}
}
function handleStateChange() {}
chrome.contextMenus.create({
title: '发射选择的单词:%s', // %s表示选中的文字
contexts: ['selection'], // 只有当选中文字时才会出现此右键菜单
onclick: function (params) {
onclick: function (params) {
chrome.browserAction.setBadgeText({ text: 'new' })
chrome.browserAction.setBadgeBackgroundColor({ color: [255, 0, 0, 255] })
......@@ -43,10 +42,20 @@ chrome.contextMenus.create({
xhr.open(
'GET',
// 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,
)
// 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文件
xhr.send()
xhr.send()
},
})
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册