Exemple #1
0
        public override void Send(Message message, MessagePriority priority)
        {
            Group receivers = message.Group != null ? message.Group : Group.AllParticipant;

            Chunk[] chunks;
            // Serialize the message and split it into chunks with the chunk encoder.
            // The encoder updates the current message- and chunk sequence numbers.
            using (Synchronizer.Lock(this)) {
                chunks = this.m_Encoder.MakeChunks(message, ref this.m_ChunkSequence);
            }
#if DEBUG
            string     caller = "";
            StackTrace st     = new StackTrace(false);
            if (st.GetFrame(2).GetMethod().IsConstructor)
            {
                MethodBase mb = st.GetFrame(2).GetMethod();
                string     n  = mb.ReflectedType.FullName;
                caller = n.Substring(n.LastIndexOf('.') + 1) + ".ctor";
            }
            else
            {
                caller = st.GetFrame(2).GetMethod().Name;
            }
            Trace.WriteLine("Message send caller=" + caller + " sequence=" + chunks[0].MessageSequence.ToString() +
                            " chunk count=" + chunks.Length.ToString() + " type=" + message.ToString() +
                            " priority=" + priority.ToString());
#endif
            if (message.Tags != null)
            {
                Trace.WriteLine("  " + message.Tags.ToString());
            }
            else
            {
                Trace.WriteLine("  NO TAGS");
                message.Tags = new MessageTags();
            }

            // Send each chunk asynchronously, with the requested priority.
            Array.ForEach(chunks, delegate(Chunk chunk) {
                this.Post(delegate() {
                    this.m_Sender.Send(chunk, receivers, message.Tags);
                }, priority);
            });
        }
Exemple #2
0
 public RequestMessageBody(string to                    = null, string[] registrationIds   = null, string condition = null,
                           string collapseKey           = null, MessagePriority priority   = MessagePriority.High, int ttl = MaxTimeToLive,
                           string restrictedPackageName = null, bool dryRun                = false,
                           IPayload data                = null, INotification notification = null)
 {
     if (to != null && registrationIds != null)
     {
         throw new ReceiverTypeAlreadySetExcepetion("Both 'to' and 'registrationIds' are set. You can set only one of them. It's either a single or bulk list.");
     }
     To = to;
     RegistrationIds       = registrationIds;
     Condition             = condition;
     CollapseKey           = collapseKey;
     Priority              = priority.ToString().ToLower();
     TimeToLive            = ttl;
     RestrictedPackageName = restrictedPackageName;
     DryRun       = dryRun;
     Data         = data;
     Notification = notification;
 }
Exemple #3
0
        private async Task <IFCMResponse> SendMessage <T>(string receiver, string id, string title, string type, T data, bool silent, MessagePriority priority)
            where T : class
        {
            if (!_isInitialized)
            {
                return(null);
            }

            var message = new Message()
            {
                To   = receiver,
                Data = (data != null
                                        ? new Dictionary <string, string>()
                {
                    {
                        "id", id
                    },
                    {
                        "title", title
                    },
                    {
                        "type", type
                    },
                    {
                        "data", JsonConvert.SerializeObject(data)
                    },
                    {
                        "silent", silent.ToString().ToLower()
                    },
                    {
                        "priority", priority.ToString()
                    }
                }
                                        : null),
                Priority = priority,
            };

            return(await _client.SendMessageAsync(message));
        }
        public static bool LogLine(string message, MessagePriority priority = MessagePriority.Infomation)
        {
            switch (priority)
            {
            case MessagePriority.Critical:
                break;

            case MessagePriority.Error:
                break;

            case MessagePriority.Warning:
                errorLogged?.Invoke(message);
                break;

            case MessagePriority.Infomation:
                break;

            default:
                break;
            }

            // ToDo fix this so that the log level check works.
            return(WriteLine(String.Format("{0} \t{1} \t{2}", DateTime.Now.ToString(), priority.ToString(""), message)));

            //    if (priority <= logLevel)
            //        return WriteLine(String.Format("{0} \t{1} \t{2}", DateTime.Now.ToString(), priority.ToString(""), message));
            //    else
            //        return false;
        }
        public override void Send(Message message, MessagePriority priority)
        {
            Group receivers = message.Group != null ? message.Group : Group.AllParticipant;

            Chunk[] chunks;
            // Serialize the message and split it into chunks with the chunk encoder.
            // The encoder updates the current message- and chunk sequence numbers.
            using(Synchronizer.Lock(this)) {
                chunks = this.m_Encoder.MakeChunks(message, ref this.m_ChunkSequence);
            }
            #if DEBUG
            string caller = "";
            StackTrace st = new StackTrace(false);
            if (st.GetFrame(2).GetMethod().IsConstructor) {
                MethodBase mb = st.GetFrame(2).GetMethod();
                string n = mb.ReflectedType.FullName;
                caller = n.Substring(n.LastIndexOf('.') + 1) + ".ctor";
            }
            else {
                caller = st.GetFrame(2).GetMethod().Name;
            }
            Trace.WriteLine("Message send caller=" + caller + " sequence=" + chunks[0].MessageSequence.ToString() +
                " chunk count=" + chunks.Length.ToString() + " type=" + message.ToString() +
                " priority=" + priority.ToString());
            #endif
            if (message.Tags != null) {
                Trace.WriteLine("  " + message.Tags.ToString());
            }
            else {
                Trace.WriteLine("  NO TAGS");
                message.Tags = new MessageTags();
            }

            // Send each chunk asynchronously, with the requested priority.
            Array.ForEach(chunks, delegate(Chunk chunk) {
                this.Post(delegate() {
                    this.m_Sender.Send(chunk, receivers, message.Tags);
                }, priority);
            });
        }
Exemple #6
0
        public string Serialize()
        {
            StringBuilder configXML = new StringBuilder("<?xml version=\"1.0\" encoding=\"utf-8\"?>");

            configXML.Append("\r\n");
            configXML.Append("<EventMessage>");
            configXML.Append("\r\n");
            configXML.Append('\t');
            configXML.Append(GetXMLNodeString("ID", _id));
            configXML.Append("\r\n");
            configXML.Append('\t');
            configXML.Append(GetXMLNodeString("Priority", _priority.ToString()));
            configXML.Append("\r\n");
            configXML.Append('\t');
            configXML.Append(GetXMLNodeString("ProcessorType", _processorType));
            configXML.Append("\r\n");
            configXML.Append('\t');
            configXML.Append(GetXMLNodeString("Body", _body));
            configXML.Append("\r\n");
            configXML.Append('\t');
            configXML.Append(GetXMLNodeString("Sender", _sender));
            configXML.Append("\r\n");
            configXML.Append('\t');
            configXML.Append(GetXMLNodeString("Subscribers", _subscribers));
            configXML.Append("\r\n");
            configXML.Append('\t');
            configXML.Append(GetXMLNodeString("AuthorizedRoles", _authorizedRoles));
            configXML.Append("\r\n");
            configXML.Append('\t');
            configXML.Append(GetXMLNodeString("ExceptionMessage", _exceptionMessage));
            configXML.Append("\r\n");
            configXML.Append('\t');
            configXML.Append(GetXMLNodeString("SentDate", _sentDate.ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ", CultureInfo.InvariantCulture)));
            configXML.Append("\r\n");
            configXML.Append('\t');
            configXML.Append(GetXMLNodeString("ExpirationDate", _expirationDate.ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ", CultureInfo.InvariantCulture)));
            configXML.Append("\r\n");
            configXML.Append('\t');
            configXML.Append("<Attributes>");
            foreach (string key in this.Attributes.Keys)
            {
                configXML.Append("\r\n");
                configXML.Append('\t', 2);
                configXML.Append("<Attribute>");
                configXML.Append("\r\n");
                configXML.Append('\t', 3);
                configXML.Append(GetXMLNodeString("Name", key));
                configXML.Append("\r\n");
                configXML.Append('\t', 3);
                configXML.Append(GetXMLNodeString("Value", this.Attributes[key]));
                configXML.Append("\r\n");
                configXML.Append('\t', 2);
                configXML.Append("</Attribute>");
            }
            configXML.Append("\r\n");
            configXML.Append('\t');
            configXML.Append("</Attributes>");
            configXML.Append("\r\n");
            configXML.Append("</EventMessage>");
            return(configXML.ToString());
        }