/// <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 object Any(EchoRequest request) { ServerEvents.NotifyChannel("default-channel", "cmd.echo", request.ToEcho); return(new EchoResponse { Echoed = request.ToEcho }); }
/// <summary> /// Send CRUD notifications for a JarsJob 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(JarsJobsNotification crud) { //ExecuteFaultHandledMethod(() => //{ //check that the sender has subscribed to the service //SubscriptionInfo subscriber = ServerEvents.GetSubscriptionInfo(crud.From); List <SubscriptionInfo> subscriber = ServerEvents.GetSubscriptionInfosByUserId(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 IJarsJobRepository _repository = _DataRepositoryFactory.GetDataRepository <IJarsJobRepository>(); //first determine if the Dto objects are full or not, if they are then fill the counterpart objects if (crud.Selector == SelectorTypes.store) { crud.Jobs = _repository.CreateUpdateList(crud.Jobs.ConvertAllTo <JarsJob>().ToList(), crud.FromUserName).ConvertAllTo <JarsJobDto>().ToList(); ServerEvents.NotifyChannel(typeof(JarsJob).Name, crud.Selector, crud.Jobs); } if (crud.Selector == SelectorTypes.delete) { _repository.DeleteList(crud.Jobs.ConvertAllTo <JarsJob>().ToList()); ServerEvents.NotifyChannel(typeof(JarsJob).Name, crud.Selector, crud.Jobs.Select(j => j.Id)); } //}); }
/// <summary> /// Process environment commands. /// </summary> /// <param name="request">The request.</param> public void Post(EnvironmentCommand request) { switch (request.Command) { case EnvironmentCommands.Start: GameController.Start(); break; case EnvironmentCommands.Reset: GameController.Reset(); break; } var status = GameController.GetEnvironmentStatus(); switch (status.Item1) { case EnvironmentStatus.Registering: ServerEvents.NotifyAll(new GetReadyMessage { Dragons = status.Item3 }); break; case EnvironmentStatus.Active: ServerEvents.NotifyChannel("player", new EnvironmentStatusMessage { Status = status.Item1, Dragons = status.Item3 }); break; } ServerEvents.NotifyAll(new EnvironmentStatusMessage { Status = status.Item1, Dragons = status.Item3 }); }
/// <summary> /// Send CRUD notifications for a StandardAppointmentException 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(StandardAppointmentExceptionsCrudNotification crud) { ExecuteFaultHandledMethod(() => { //check that the sender has subscribed to the service //SubscriptionInfo subscriber = ServerEvents.GetSubscriptionInfo(crud.From); List <SubscriptionInfo> subscriber = ServerEvents.GetSubscriptionInfosByUserId(crud.FromUserName); if (subscriber == null) { throw HttpError.NotFound($"Subscriber {crud.FromUserName} does not exist."); } //do some StandardAppointmentException updates here using the info from the the crud //IStandardAppointmentExceptionRepository _repository = _DataRepositoryFactory.GetDataRepository<IStandardAppointmentExceptionRepository>(); var _repository = _DataRepositoryFactory.GetDataRepository <IGenericEntityRepositoryBase <StandardAppointmentException, IDataContextNhJars> >(); if (crud.Selector == SelectorTypes.store) { IList <StandardAppointmentException> exList = crud.AppointmentExceptions.ToList().ConvertAll(x => x.ConvertTo <StandardAppointmentException>()); exList = _repository.CreateUpdateList(exList, crud.FromUserName).ToList(); crud.AppointmentExceptions = exList.ToList().ConvertAll(x => x.ConvertTo <StandardAppointmentExceptionDto>()); ServerEvents.NotifyChannel(typeof(StandardAppointmentException).Name, crud.AppointmentExceptions);//.ConvertToJarsSyncStoreEvent()); } if (crud.Selector == SelectorTypes.delete) { IList <StandardAppointmentException> exList = crud.AppointmentExceptions.ToList().ConvertAll(x => x.ConvertTo <StandardAppointmentException>()); _repository.DeleteList(exList); ServerEvents.NotifyChannel(typeof(StandardAppointmentException).Name, crud.AppointmentExceptions.Select(a => a.Id)); } }); }
public void Any(PostObjectToChannel request) { if (request.ToUserId != null) { if (request.CustomType != null) { ServerEvents.NotifyUserId(request.ToUserId, request.Selector ?? Selector.Id <CustomType>(), request.CustomType); } if (request.SetterType != null) { ServerEvents.NotifyUserId(request.ToUserId, request.Selector ?? Selector.Id <SetterType>(), request.SetterType); } } else { if (request.CustomType != null) { ServerEvents.NotifyChannel(request.Channel, request.Selector ?? Selector.Id <CustomType>(), request.CustomType); } if (request.SetterType != null) { ServerEvents.NotifyChannel(request.Channel, request.Selector ?? Selector.Id <SetterType>(), request.SetterType); } } }
public NotifyResponse Post(NotifyChannelRequest request) { NotifyResponse res = new NotifyResponse(); try { //var subscriptionInfos = ServerEvents.GetSubscriptionsDetails(request.ToChannel); //if (subscriptionInfos != null) //{ foreach (string channel in request.ToChannel) { ServerEvents.NotifyChannel(channel, request.Selector, request.Msg); } //} // else // { // Console.WriteLine("No one listening in the Channel: " + request.ToChannel.ToJson()); //} } catch (Exception e) { Console.WriteLine(e.ToJson()); res.ResponseStatus.Message = e.Message; } return(res); }
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); }
/// <summary> /// Remove player's registration (deregister). /// </summary> /// <param name="request">The request.</param> /// <returns>The <see cref="object"/>.</returns> public object Delete(RegistrationCommand request) { var result = GameController.Deregister(request.Slug); if (result) { ServerEvents.NotifyChannel("spectator", new SpectatorMessage { MessageType = MessageTypes.Player, Name = request.Name, Avatar = request.Hash, Message = $"`@{request.Slug}` has left the demo" }); } return(new HttpResult(HttpStatusCode.NoContent)); }
/// <summary> /// Register a player. /// </summary> /// <param name="request">The request.</param> /// <returns>The <see cref="object"/>.</returns> public object Post(RegistrationCommand request) { var result = GameController.Register(request.Slug, request.Hash, request.Name); if (!result) { throw new HttpError(HttpStatusCode.NotAcceptable, "DuplicatePlayerID"); } ServerEvents.NotifyChannel("spectator", new SpectatorMessage { MessageType = MessageTypes.Player, Name = request.Name, Avatar = request.Hash, Message = $"`@{request.Slug}` has joined the demo" }); return(new HttpResult(HttpStatusCode.Created)); }
/// <summary> /// Process player's actions. /// </summary> /// <param name="request">The request.</param> public void Post(ActionCommand request) { var user = Request.Cookies["hero"].Value; var name = Request.Cookies["hero_name"].Value; var hash = Request.Cookies["hero_hash"].Value; switch (request.Command) { case ActionCommands.Attack: GameController.Attack(user, request.Target); ServerEvents.NotifyChannel("spectator", new SpectatorMessage { MessageType = MessageTypes.Player, Name = name, Avatar = hash, Message = $"`@{user}` attacks `{request.Target}` the dragon" }); break; } }
/// <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); }
public object Any(SSETestRemoteControlRequest request) { ServerEvents.NotifyChannel(request.Channel, request.Selector, request.Message); return(null); }
/// <summary> /// Push environment messages. /// </summary> /// <param name="request">The request.</param> public void Post(EnvironmentMessage request) { ServerEvents.NotifyChannel("spectator", new SpectatorMessage { MessageType = request.MessageType, Name = request.Name, Message = request.Message }); }