/// <summary> /// Send CRUD notifications for a ActivityLog Entity or Entities /// Note! : /// This Method is a special method used by the service when ServerEvents are being used.(serviceStack). /// If the service does not implement serverEvents this will throw an error. /// This will send a notification to all subscribed clients (including the client the request originated from) where the chanel name is the name of the entity type. /// This will only process SelectorTypes.store and SelectorTypes.delete notifications. /// The notification sent to subscribers will be a ServerEventMessage (serviceStack) where the data(json) is set as ServerEventMessageData (Jars) object. /// </summary> /// <param name="crud">The notification request indicating a store or delete event that will be sent to other subscribers.</param> public virtual void Any(ActivityLogsNotification crud) { ExecuteFaultHandledMethod(() => { SubscriptionInfo subscriber = ServerEvents.GetSubscriptionInfo(crud.FromUserName); if (subscriber == null) { throw HttpError.NotFound($"Subscriber {crud.FromUserName} does not exist."); } //do some job updates here using the info from the the crud //IActivityLogRepository _repository = _DataRepositoryFactory.GetDataRepository<IActivityLogRepository>(); var _repository = _DataRepositoryFactory.GetDataRepository <IGenericEntityRepositoryBase <ActivityLog, IDataContextNhJars> >(); if (crud.Selector == SelectorTypes.store) { crud.Logs = _repository.CreateUpdateList(crud.Logs.ConvertAllTo <ActivityLog>().ToList(), crud.FromUserName).ConvertAllTo <ActivityLogDto>().ToList(); ServerEvents.NotifyChannel(typeof(ActivityLog).Name, crud.Selector, crud.Logs);//.ConvertToJarsSyncStoreEvent()); } if (crud.Selector == SelectorTypes.delete) { _repository.DeleteList(crud.Logs.ConvertAllTo <ActivityLog>().ToList()); ServerEvents.NotifyChannel(typeof(ActivityLog).Name, crud.Selector, crud.Logs.Select(l => l.Id)); } }); }
public void Any(PostRawToChannel request) { if (!IsAuthenticated && AppSettings.Get("LimitRemoteControlToAuthenticatedUsers", false)) { throw new HttpError(HttpStatusCode.Forbidden, "You must be authenticated to use remote control."); } // Ensure the subscription sending this notification is still active var sub = ServerEvents.GetSubscriptionInfo(request.From); if (sub == null) { throw HttpError.NotFound("Subscription {0} does not exist".Fmt(request.From)); } // Check to see if this is a private message to a specific user if (request.ToUserId != null) { // Only notify that specific user ServerEvents.NotifyUserId(request.ToUserId, request.Selector, request.Message); } else { // Notify everyone in the channel for public messages ServerEvents.NotifyChannel(request.Channel, request.Selector, request.Message); } }
public async Task <object> Any(PostChatToChannel request) { // Ensure the subscription sending this notification is still active var sub = ServerEvents.GetSubscriptionInfo(request.From); if (sub == null) { throw HttpError.NotFound("Subscription {0} does not exist".Fmt(request.From)); } var channel = request.Channel; var chatMessage = request.Message.IndexOf("{{", StringComparison.Ordinal) >= 0 ? await HostContext.AppHost.ScriptContext.RenderScriptAsync(request.Message, new Dictionary <string, object> { [nameof(Request)] = Request }) : request.Message; // Create a DTO ChatMessage to hold all required info about this message var msg = new ChatMessage { Id = ChatHistory.GetNextMessageId(channel), Channel = request.Channel, FromUserId = sub.UserId, FromName = sub.DisplayName, Message = chatMessage.HtmlEncode(), }; // Check to see if this is a private message to a specific user if (request.ToUserId != null) { // Mark the message as private so it can be displayed differently in Chat msg.Private = true; // Send the message to the specific user Id await ServerEvents.NotifyUserIdAsync(request.ToUserId, request.Selector, msg); // Also provide UI feedback to the user sending the private message so they // can see what was sent. Relay it to all senders active subscriptions var toSubs = ServerEvents.GetSubscriptionInfosByUserId(request.ToUserId); foreach (var toSub in toSubs) { // Change the message format to contain who the private message was sent to msg.Message = $"@{toSub.DisplayName}: {msg.Message}"; await ServerEvents.NotifySubscriptionAsync(request.From, request.Selector, msg); } } else { // Notify everyone in the channel for public messages await ServerEvents.NotifyChannelAsync(request.Channel, request.Selector, msg); } if (!msg.Private) { ChatHistory.Log(channel, msg); } return(msg); }
public object Any(PostChatToChannel request) { // Ensure the subscription sending this notification is still active var sub = ServerEvents.GetSubscriptionInfo(request.From); if (sub == null) { throw HttpError.NotFound("Subscription {0} does not exist".Fmt(request.From)); } var channel = request.Channel; // Create a DTO ChatMessage to hold all required info about this message var msg = new ChatMessage { Id = ChatHistory.GetNextMessageId(channel), Channel = request.Channel, FromUserId = sub.UserId, FromName = sub.DisplayName, Message = request.Message, }; // Check to see if this is a private message to a specific user if (request.ToUserId != null) { // Mark the message as private so it can be displayed differently in Chat msg.Private = true; // Send the message to the specific user Id ServerEvents.NotifyUserId(request.ToUserId, request.Selector, msg); // Also provide UI feedback to the user sending the private message so they // can see what was sent. Relay it to all senders active subscriptions var toSubs = ServerEvents.GetSubscriptionInfosByUserId(request.ToUserId); foreach (var toSub in toSubs) { // Change the message format to contain who the private message was sent to msg.Message = "@{0}: {1}".Fmt(toSub.DisplayName, msg.Message); ServerEvents.NotifySubscription(request.From, request.Selector, msg); } } else { // Notify everyone in the channel for public messages ServerEvents.NotifyChannel(request.Channel, request.Selector, msg); } if (!msg.Private) { ChatHistory.Log(channel, msg); } return(msg); }
public GetSubscriptionId_InfoResponse Post(GetSubscriptionId_InfoRequest request) { GetSubscriptionId_InfoResponse res = new GetSubscriptionId_InfoResponse(); SubscriptionInfo SubInfos = ServerEvents.GetSubscriptionInfo(request.ToSubscriptionId); res.AuthId = SubInfos.UserId; if (SubInfos.UserId.Length > 0) { string[] Values = SubInfos.UserId.Split(':'); res.SolnId = Values[0]; res.UserId = Values[1]; res.Wc = Values[2]; } return(res); }
public NotifyResponse Post(NotifySubscriptionRequest request) { NotifyResponse res = new NotifyResponse(); try { Console.WriteLine("Reached in NotifySubscriptionRequest"); SubscriptionInfo subscriptionInfos = ServerEvents.GetSubscriptionInfo(request.ToSubscriptionId); if (subscriptionInfos != null) { if (!String.IsNullOrEmpty(subscriptionInfos.SubscriptionId)) { Console.WriteLine("SubscriptionId :" + subscriptionInfos.SubscriptionId); if (request.ToChannel == null) { ServerEvents.NotifySubscription(subscriptionInfos.SubscriptionId, request.Selector, request.Msg); } else { foreach (string channel in request.ToChannel) { ServerEvents.NotifySubscription(subscriptionInfos.SubscriptionId, request.Selector, request.Msg, channel); } } } else { Console.WriteLine("SubscriptionId doesn't Exist"); res.ResponseStatus.Message = "SubscriptionId doesn't Exist"; } } else { Console.WriteLine("subscriptionInfos Is Null"); res.ResponseStatus.Message = "subscriptionInfos Is Null"; } } catch (Exception e) { Console.WriteLine(e.Message + e.StackTrace); res.ResponseStatus.Message = e.Message; } return(res); }
/// <summary> /// Send CRUD notifications for a JarsUserRole Entity or Entities /// Note! : /// This Method is a special method used by the service when ServerEvents are being used.(serviceStack). /// If the service does not implement serverEvents this will throw an error. /// This will send a notification to all subscribed clients (including the client the request originated from) where the chanel name is the name of the entity type. /// This will only process SelectorTypes.store and SelectorTypes.delete notifications. /// The notification sent to subscribers will also be a JarsSyncEventStore or JarsSyncEventStore Dto object. /// </summary> /// <param name="crud">The notification request indicating a store or delete event that will be sent to other subscribers.</param> public virtual void Any(JarsUserRolesCrudNotification crud) { ExecuteFaultHandledMethod(() => { //check that the sender has subscribed to the service SubscriptionInfo subscriber = ServerEvents.GetSubscriptionInfo(crud.FromSubscriptionId); if (subscriber == null) { throw HttpError.NotFound($"Subscriber {crud.FromUserId} does not exist."); } //do some job updates here using the info from the the crud IJarsUserRoleRepository _repository = _DataRepositoryFactory.GetDataRepository <IJarsUserRoleRepository>(); if (crud.Selector == SelectorTypes.store) { if (crud.Role != null) { crud.Role = _repository.CreateUpdate(crud.Role, crud.FromUserId); ServerEvents.NotifyChannel(crud.Channel, crud.Selector, crud.Role.ConvertToJarsSyncEventStore()); } else { crud.Roles = _repository.CreateUpdateList(crud.Roles, crud.FromUserId).ToList(); ServerEvents.NotifyChannel(crud.Channel, crud.Selector, crud.Roles.ConvertToJarsSyncEventStore()); } } if (crud.Selector == SelectorTypes.delete) { if (crud.Role != null) { _repository.Delete(crud.Role); ServerEvents.NotifyChannel(crud.Channel, crud.Selector, crud.Role.ConvertToJarsSyncEventDelete()); } else { _repository.DeleteList(crud.Roles); ServerEvents.NotifyChannel(crud.Channel, crud.Selector, crud.Roles.ConvertToJarsSyncEventDelete()); } } }); }
public object Any(SSETestRequest request) { var response = new SSETestResponse { EchoMessage = request.Message }; var sub = ServerEvents.GetSubscriptionInfo(request.From); if (sub == null) { throw HttpError.NotFound("Subscription {0} does not exist".Fmt(request.From)); } // Notify everyone in the channel for public messages ServerEvents.NotifyChannel(request.Channel, request.Selector, request.Message); return(response); }