Exemple #1
0
        /*creates an alarm object from JSON*/
        public SNSAlarm parseAlarmJSON(string json)
        {
            int startIndex, stopIndex;

            string[] rawAttributes;
            string[] editedAttributes;

            SNSAlarm myAlarm;


            /* json = Regex.Replace(json, @"{", "");
             * json = Regex.Replace(json, @"\s+", "");
             * json = Regex.Replace(json, @"}", "");
             */

            //parse incoming json into usable alarm info
            rawAttributes    = json.Split(',');
            editedAttributes = new string[rawAttributes.Length];

            for (int i = 0; i < rawAttributes.Length; i++)
            {
                startIndex          = rawAttributes[i].LastIndexOf("\" : \"");
                stopIndex           = rawAttributes[i].LastIndexOf("\"");
                editedAttributes[i] = rawAttributes[i].Substring(startIndex + 5, stopIndex - startIndex - 5);
            }

            myAlarm = new SNSAlarm(editedAttributes[0], editedAttributes[1], editedAttributes[2], editedAttributes[3], editedAttributes[4], editedAttributes[5]);

            return(myAlarm);
        }
Exemple #2
0
        /*creates alarm actions and logs info into database*/
        public void createActions(SNSAlarm myAlarm)
        {
            SNS_Alarm_Action myAlarmAction;
            SNS_Action       mySNSAction;

            // Settings mySettings;



            //create a new alarm action
            myAlarmAction = new SNS_Alarm_Action(myAlarm.Name, myAlarm.Type, myAlarm.Subject);

            //figure out what to do for that action
            mySNSAction = new SNS_Action(myAlarmAction.name, myAlarmAction.subject, myAlarmAction.type);



            //set that action for SNS_Alarm_Action
            myAlarmAction.typeSNSAction = mySNSAction;

            //add alarm action to database


            //log alarm
            Event alarmEvent = new Event("source", myAlarm, myAlarmAction, mySNSAction);



            //add to database
            using (AWS_SNS_API_Context myDbContext = new AWS_SNS_API_Context())
            {
                myDbContext.Alarms.Add(myAlarm);
                myDbContext.SNSAlarmActions.Add(myAlarmAction);
                myDbContext.SNSActions.Add(mySNSAction);
                myDbContext.EventLog.Add(alarmEvent);
                myDbContext.SaveChanges();
            }

            performAction(myAlarmAction);
        }