Beispiel #1
0
        /// <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>
        /// Send CRUD notifications for a StandardAppointment 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(StandardAppointmentsNotification crud)
        {
            ExecuteFaultHandledMethod(() =>
            {
                //Task.Delay(200).Wait();
                //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 StandardAppointment updates here using the info from the the crud
                //IStandardAppointmentRepository _repository = _DataRepositoryFactory.GetDataRepository<IStandardAppointmentRepository>();
                var _repository = _DataRepositoryFactory.GetDataRepository <IGenericEntityRepositoryBase <StandardAppointment, IDataContextNhJars> >();

                if (crud.Selector == SelectorTypes.store)
                {
                    IList <StandardAppointmentDto> storeApptList = _repository.Where(a => crud.Ids.Contains(a.Id), true).ToStandardAppointmentDtoList();
                    TrySendStoreNotificationToChannel(typeof(StandardAppointment).Name, storeApptList.ToJson());//, true);
                }

                if (crud.Selector == SelectorTypes.delete)
                {
                    TrySendDeleteNotificationToChannel(typeof(StandardAppointment).Name, crud.Ids.ConvertTo <List <string> >().ToArray());//, true);
                }
            });
        }
        /// <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));
                }
            });
        }
Beispiel #4
0
        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 NotifyResponse Post(NotifyUserIdRequest request)
        {
            Console.WriteLine("---------------------->Inside notifyUserIdReq \nUserId: " + request.ToUserAuthId);
            NotifyResponse res = new NotifyResponse();

            try
            {
                if (request.Selector == "cmd.onNotification")
                {
                    this.MessageProducer3.Publish(new NotificationToDBRequest()
                    {
                        SolnId         = request.SolnId,
                        UserId         = request.UserId,
                        NotifyUserId   = request.NotifyUserId,
                        Notification   = request.Msg,
                        NotificationId = request.NotificationId
                    });
                    Console.WriteLine("---------------------->After NotificationToDBRequest UserId: " + request.ToUserAuthId);
                }
                Console.WriteLine("request.Selector" + request.Selector + "------------No NotificationToDBRequest----------> UserId: " + request.ToUserAuthId);
                List <SubscriptionInfo> subscriptionInfos = ServerEvents.GetSubscriptionInfosByUserId(request.ToUserAuthId);

                foreach (SubscriptionInfo sub in subscriptionInfos)
                {
                    if (request.ToChannel == null)
                    {
                        ServerEvents.NotifySubscription(sub.SubscriptionId, request.Selector, request.Msg);
                    }
                    else
                    {
                        foreach (string channel in request.ToChannel)
                        {
                            ServerEvents.NotifySubscription(sub.SubscriptionId, request.Selector, request.Msg, channel);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message + e.StackTrace);
                res.ResponseStatus.Message = e.Message;
            }
            return(res);
        }