I've registered the shoppingCartHub on the same site as ChatHub: localhost:6240/signalr. It's successful registered as console.log("shoppingCartHub", shoppingCartHub ) returns me the hub object at client side and I could see a message in the console: SignalR: Triggering client hub event 'sendEventData' on hub 'AbpCommonHub'. But not sure why the callback function was not get called. Could you help me take a look where I did incorrectly?
Server Side. Is it correct to use AbpCommonHub instead of ShoppingCartHandler in the return type of _hubContext ? _hubContext = GlobalHost.ConnectionManager.GetHubContext<AbpCommonHub>();?
[HubName("shoppingCartHub")]
public class ShoppingCartHandler : AbpCommonHub, IEventHandler<EventData>
{
private IHubContext _hubContext;
public ShoppingCartHandler(IOnlineClientManager onlineClientManager, IClientInfoProvider clientInfoProvider) : base(onlineClientManager, clientInfoProvider)
{
_hubContext = GlobalHost.ConnectionManager.GetHubContext<AbpCommonHub>();
}
public void HandleEvent(EventData eventData)
{
_hubContext.Clients.All.sendEventData(eventData.Entry);
}
}
Client Side:
$.connection.hub.url = abp.signalr.url || '/signalr';
$.connection.hub.logging = true;
var shoppingCartHub = $.connection.shoppingCartHub;
console.log("shoppingCartHub", shoppingCartHub ); //this line could run.
shoppingCartHub.on("sendEventData", function (message) { console.log("called inside event", message);})
$.connection.hub.start().done(function () {
console.log('ShoppingCart Hub has started'); //this line could run.
});
$.connection.hub.error(function (err) {
console.log("ShoppingCart Hub ERROR : " + err);
});
Autogenerated proxy: Seems it's only contains handleEvent method.
proxies['shoppingCartHub'] = this.createHubProxy('shoppingCartHub');
proxies['shoppingCartHub'].client = { };
proxies['shoppingCartHub'].server = {
handleEvent function (eventData) {
return proxies['shoppingCartHub'].invoke.apply(proxies['shoppingCartHub'], $.merge(["HandleEvent"], $.makeArray(arguments)));
},
register: function () {
return proxies['shoppingCartHub'].invoke.apply(proxies['shoppingCartHub'], $.merge(["Register"], $.makeArray(arguments)));
}
};
<cite>aaron: </cite> You need to login with your GitHub account to access the private repo. You can invite yourself here: <a class="postlink" href="https://aspnetzero.com/LicenseManagement">https://aspnetzero.com/LicenseManagement</a>
Gotcha, thank you!
<cite>ismcagdas: </cite> Hi @OriAssurant ,
- Yes, you can but you need to reference Microsoft.AspNet.SignalR in the Application project. Yes, you need to register it.
I couldn't understand the other two questions, sorry. Why don't you use a similar way we did for Chat feature. You can define a ShoppingCartHub similar to <a class="postlink" href="https://github.com/aspnetzero/aspnet-zero-core/blob/dev/aspnet-core/src/MyCompanyName.AbpZeroTemplate.Web.Core/Chat/SignalR/ChatHub.cs">https://github.com/aspnetzero/aspnet-ze ... ChatHub.cs</a>.
On the client side, when a user adds an item to cart, instead of calling the app service, you need to communicate with the ShoppingCartHub. Then it will notify all open browsers (including the one which users is shopping on) to add this new item to user's cart.
You can take a look at how we send chat message to another user.
Thank you very much, ismcagdas. Let me try with the ChatHub way:)
This is awesome. Let me try it now! Thank you so much Aaron.
I'm using MVC5.* and AngularJS for our project. I have a shopping cart module for user to add items into it . I'm trying to archive that an item could be added to all opened windows if user add one item in one of opened windows. I have couple questions on the way of using AbpCommonHub to implement signalr hub.
(1) Can I use AbpCommonHub in Application project (instead of Web Project)? If I can, do I still need to register in Start_Up.cs in the web project? (2) If could, could I add AbpCommonHub as a property in one of my Services?
public class ShoppingCartService : MyProjectAppServiceBase, IShoppingCartService{
private static IHubContext CommonHub
{
get
{
return GlobalHost.ConnectionManager.GetHubContext<AbpCommonHub>();
}
}
public void BroadCastAddItem(IReadOnlyList<IOnlineClient> clients)
{
foreach (var client in clients)
{
var signalRClient = CommonHub.Clients.Client(client.ConnectionId);
if (signalRClient == null)
{
Logger.Debug("Can not get user " + client.UserId + " from SignalR hub!");
continue;
}
signalRClient.getAddItemMessage("A new Item added to Shopping Cart!"));
}
}
}
*:Because I already inherit base class MyProjectAppServiceBase, I could not add AbpCommonHub as base class. Is it okay to add AbpCommonHub as a private field?
(3) Could I use localhost:6240/signalr to connect to the server?
Any hint would be greatly appreciated! Thank you in advance.
I tried to set up constants in AbpSettings, created customprovider(inheriting from SettingsProvider) in WebApi project, configured it in APiModule as below:
Configuration.Settings.Providers.Add<MySettingProvider>();
However, the values are not being pulled from the database.
The following is how I am trying to pull the values: SettingManager.GetSettingValue(AppSettings.TenantManagement.URL);
Please let me know if I am missing anything.
Thank you for your help in advance.
Thanks for your help, we figured it out:
_context.DisableAllFilters();
Sure, thank you Aaron. Here is the configuration.cs for tenant databases:
namespace x.y.PortalDBOneMigrations
{
public sealed class Configuration : DbMigrationsConfiguration<EntityFramework.PortalDbOneContext>, IMultiTenantSeed
{
public AbpTenantBase Tenant { get; set; }
public Configuration()
{
}
protected override void Seed(PortalDbOneContext context)
{
context.EntityChangeEventHelper = NullEntityChangeEventHelper.Instance;
context.EventBus = NullEventBus.Instance;
//seeding data for tenant id 2
new UserRolePermissionTenantCreator(context, 2).CreateUserRolePermission();
}
}
}
Hmm.. sorry forgot to mention I'm using MVC5.* + AngularJS. Seems IgnoreQueryFilters is not available in this version? I got this error:
IDbSet<User>' does not contain a definition for 'IgnoreQueryFilters' and no extension method 'IgnoreQueryFilters' accepting a first argument of type 'IDbSet<User>' could be found (are you missing a using directive or an assembly reference?)
I separate host and tenant databases and inherit AbpDbContext for tenant databases.
When seeding data, I'm using var user1 = _dbcontext.Users().Any(u=>u.UserName = ***) to identify if a user exists.
But I could not get any result from _dbcontext.Users().Any() even though there are records in the database. This causes duplicate data to be seeded if I run migrator multiple times.
I've tried set current unitofwork to either disable tenant filter or settenant to the target tenant's Id but still couldn't make it work:
_context.CurrentUnitOfWorkProvider.Current.DisableFilter(AbpDataFilters.MayHaveTenant);
_context.CurrentUnitOfWorkProvider.Current.Settenant(2);
Any idea why the normal Linq query doesn't work in this case?
Thank you,