Пример #1
0
 public SlimNotificationOptions(ProtocolTypes enabledProtocols, bool isMandatory, ReceiverTypes enabledReceivers, string emailTemplateId)
 {
     EnabledProtocols = enabledProtocols;
     IsMandatory      = isMandatory;
     EnabledReceivers = enabledReceivers;
     EmailTemplateId  = emailTemplateId;
 }
Пример #2
0
        public ServerEventsClient RegisterNamedReceiver <T>(string receiverName)
            where T : IReceiver
        {
            ReceiverExec <T> .Reset();

            NamedReceivers[receiverName] = CreateReceiverHandler <T>;

            ReceiverTypes.Add(typeof(T));

            return(this);
        }
Пример #3
0
        public void FromXML(string xml)
        {
            XmlDocument dom = new XmlDocument();

            dom.LoadXml(xml);
            XmlNode xNode = dom.DocumentElement;

            if ((xNode.Name == RECEIVERS_ELEMENT) && (xNode.HasChildNodes))
            {
                foreach (XmlNode jNode in xNode.ChildNodes)
                {
                    if (jNode.Name == Receiver.RECEIVER_ELEMENT)
                    {
                        ReceiverTypes receiverType = ReceiverTypes.Unknown;
                        foreach (XmlAttribute jAttribute in jNode.Attributes)
                        {
                            if (jAttribute.Name == TYPE_ATTRIBUTE)
                            {
                                receiverType = (ReceiverTypes)Enum.Parse(typeof(ReceiverTypes), jAttribute.Value, true);
                            }
                        }
                        Receiver receiver = null;
#if (PocketPC)
                        if (receiverType == ReceiverTypes.HTCDiamond)
                        {
                            receiver = new HTCDiamondReceiver();
                        }
                        else
#endif
                        if (receiverType == ReceiverTypes.RFCOMM)
                        {
                            receiver = new RFCOMMReceiver();
                        }
                        else if (receiverType == ReceiverTypes.StandardCOM)
                        {
                            receiver = new StandardCOMReceiver();
                        }
                        else if (receiverType == ReceiverTypes.HTCDiamond)
                        {
                            receiver = new HTCDiamondReceiver();
                        }
                        receiver.FromXML(jNode.OuterXml);
                        this.Insert(receiver._ID, receiver);
                    }
                }
            }
        }
 public async Task <List <SlimNotification> > Get(ReceiverTypes receiver, int userId, int?agencyId, int skip, int top)
 => await _context.Notifications
 .Where(n => n.Receiver == receiver && n.UserId == userId && n.AgencyId == agencyId)
 .Skip(skip)
 .Take(top)
 .Select(n => new SlimNotification
 {
     Id            = n.Id,
     UserId        = n.UserId,
     AgencyId      = n.AgencyId,
     Message       = n.Message.ToJsonString(),
     Type          = n.Type,
     SendingStatus = n.SendingStatus,
     Created       = n.Created.DateTime,
     Received      = n.Received != null
                 ? n.Received.Value.DateTime
                 : null,
     Read = n.Read != null
                 ? n.Read.Value.DateTime
                 : null
 })
 .ToListAsync();
 private static string GetTemplateId(DefaultNotificationOptions options, ReceiverTypes receiver)
 => receiver switch
 {
 private async Task <Dictionary <NotificationTypes, SlimNotificationOptions> > GetDefaultOptions(ReceiverTypes receiver)
 => await _context.DefaultNotificationOptions
 .Where(o => o.EnabledReceivers.HasFlag(receiver))
 .ToDictionaryAsync(o => o.Type, o => new SlimNotificationOptions(o.EnabledProtocols, o.IsMandatory, o.EnabledReceivers, GetTemplateId(o, receiver)));
        private async Task <Dictionary <NotificationTypes, NotificationSettings> > GetMaterializedOptions(List <NotificationOptions> userOptions, ReceiverTypes receiver)
        {
            var defaultOptions = await GetDefaultOptions(receiver);

            var materializedSettings = new Dictionary <NotificationTypes, NotificationSettings>();

            foreach (var option in defaultOptions)
            {
                var userOption = userOptions.SingleOrDefault(no => no.Type == option.Key);

                var enabledProtocols = new Dictionary <ProtocolTypes, bool>();
                if (option.Value.EnabledProtocols.HasFlag(ProtocolTypes.Email))
                {
                    enabledProtocols.Add(ProtocolTypes.Email, userOption is null || option.Value.IsMandatory || userOption.EnabledProtocols.HasFlag(ProtocolTypes.Email));
                }
                if (option.Value.EnabledProtocols.HasFlag(ProtocolTypes.WebSocket))
                {
                    enabledProtocols.Add(ProtocolTypes.WebSocket, userOption is null || option.Value.IsMandatory || userOption.EnabledProtocols.HasFlag(ProtocolTypes.WebSocket));
                }

                materializedSettings.Add(option.Key, new NotificationSettings {
                    EnabledProtocols = enabledProtocols, IsMandatory = option.Value.IsMandatory
                });
            }

            return(materializedSettings);
        }