Ejemplo n.º 1
0
        //writes json to file
        public static void serializeToFile(Message msg)
        {
            //serilze message object into json
            string jason = JsonConvert.SerializeObject(msg);
            //open file stream
            System.IO.StreamWriter file = new System.IO.StreamWriter("messageJson.txt", true);
            //append json string to file
            file.WriteLine(jason);

            //close file writer
            file.Close();
        }
Ejemplo n.º 2
0
        //takes in head/body and creates create message instance
        public void analyzeMessage(String head, String body)
        {
            //set inouts as varibles
            _basicHeader = head;
            _basicBody = body;
            //regex check valid id
            Match match = idPtrn.Match(_basicHeader);
            if (!match.Success)
            {
                throw new System.ArgumentOutOfRangeException("Message Header", "Message Header is invalid.\nMust be a Charcter and Nine digits.");
            }
            else
            {
                //set id to first char from header
                Char id = _basicHeader[0];
                //remove id from header
                if (id.Equals('S'))
                {
                    //create new sms
                    Sms newMsg = new Sms(_basicHeader, _basicBody);
                    //anaylze sms
                    newMsg.anaylizeMessage();
                    //set as final message
                    _finalMessage = newMsg;
                    //add to message list
                    MESSAGE_LIST.Add(_finalMessage);
                }
                else if (id.Equals('E'))
                {
                    //create new email
                    Email newMsg = new Email(_basicHeader, _basicBody);
                    //analyize message
                    newMsg.anaylizeMessage();
                    //set as final message
                    _finalMessage = newMsg;
                    //check if valid sir message
                    if (SirEmail.checkIfSir(newMsg))
                    {
                        //read inincidnet list
                        SirEmail.fillIncidents();
                        //create new sir email(pass old one as argument)
                        SirEmail sir = new SirEmail(newMsg);
                        //analyize sir
                        sir.anaylizeMessage();
                        //set as final
                        _finalMessage = sir;
                        //add to message list
                        MESSAGE_LIST.Add(_finalMessage);

                    }
                    else
                    {
                        MESSAGE_LIST.Add(_finalMessage);
                    }
                }
                else if (id.Equals('T'))
                {
                    //create new Tweet
                    Tweet newMsg = new Tweet(_basicHeader, _basicBody);
                    //analylze tweet
                    newMsg.anaylizeMessage();
                    //set as final message
                    _finalMessage = newMsg;
                    //add to list
                    MESSAGE_LIST.Add(_finalMessage);
                }
                else
                {
                    throw new System.ArgumentOutOfRangeException("Message Header", "Invalid Message ID.\nID not reconized.");
                }
            }
            //serilze message
            Serializer.serializeToFile(_finalMessage);
        }
Ejemplo n.º 3
0
 //returns message as json string
 public static string serializeMessage(Message msg)
 {
     return (JsonConvert.SerializeObject(msg));
 }