Ejemplo n.º 1
0
        public static void parseConfiguration()
        {
            Console.WriteLine("Parsing XML");

            StringBuilder op = new StringBuilder();


            string readText = File.ReadAllText(path);
            // Create an XmlReader
            XmlDocument doc = new XmlDocument();

            doc.Load(path);

            XmlNode isEnabledNode    = doc.DocumentElement.SelectSingleNode("/notificationConfiguration/isEnabled");
            XmlNode smsEnabledNode   = doc.DocumentElement.SelectSingleNode("/notificationConfiguration/smsEnabled");
            XmlNode callEnabledNode  = doc.DocumentElement.SelectSingleNode("/notificationConfiguration/callEnabled");
            XmlNode otherEnabledNode = doc.DocumentElement.SelectSingleNode("/notificationConfiguration/otherEnabled");


            bool configIsEnabled    = bool.Parse(isEnabledNode.InnerText);
            bool configSmsEnabled   = bool.Parse(smsEnabledNode.InnerText);
            bool configCallEnabled  = bool.Parse(callEnabledNode.InnerText);
            bool configOtherEnabled = bool.Parse(otherEnabledNode.InnerText);

            NotificationConfiguration.getInstance().IsEnabled    = configIsEnabled;
            NotificationConfiguration.getInstance().SmsEnabled   = configSmsEnabled;
            NotificationConfiguration.getInstance().CallEnabled  = configCallEnabled;
            NotificationConfiguration.getInstance().OtherEnabled = configOtherEnabled;
        }
Ejemplo n.º 2
0
        public static void persistConfiguration()
        {
            Console.WriteLine("Persisting");

            StringBuilder op = new StringBuilder();


            string readText = File.ReadAllText(path);
            // Create an XmlReader
            XmlDocument doc = new XmlDocument();

            doc.Load(path);

            XmlNode isEnabledNode    = doc.DocumentElement.SelectSingleNode("/notificationConfiguration/isEnabled");
            XmlNode smsEnabledNode   = doc.DocumentElement.SelectSingleNode("/notificationConfiguration/smsEnabled");
            XmlNode callEnabledNode  = doc.DocumentElement.SelectSingleNode("/notificationConfiguration/callEnabled");
            XmlNode otherEnabledNode = doc.DocumentElement.SelectSingleNode("/notificationConfiguration/otherEnabled");

            isEnabledNode.InnerText    = NotificationConfiguration.getInstance().IsEnabled.ToString();
            smsEnabledNode.InnerText   = NotificationConfiguration.getInstance().SmsEnabled.ToString();
            callEnabledNode.InnerText  = NotificationConfiguration.getInstance().CallEnabled.ToString();
            otherEnabledNode.InnerText = NotificationConfiguration.getInstance().OtherEnabled.ToString();

            doc.Save(path);
        }
Ejemplo n.º 3
0
        public Boolean isMessageDisplayAuthorised(Notification notification)
        {
            Boolean addMessage          = true;
            Boolean notificationHandled = false;

            if ((notification.Application.Equals("com.android.sms") || notification.Application.Equals("com.android.mms") || notification.Application.Equals("com.samsung.android.messaging")))
            {
                if (NotificationConfiguration.getInstance().SmsEnabled)
                {
                    Console.WriteLine("SMS reçu et traité");
                }
                else
                {
                    addMessage = false;
                    Console.WriteLine("Sms reçu et non traité");
                }
                notificationHandled = true;
            }
            if (notificationHandled == false)
            {
                if (notification.Application.Equals("com.android.server.telecom") || notification.Application.Equals("com.android.incallui"))
                {
                    if (NotificationConfiguration.getInstance().CallEnabled)
                    {
                        Console.WriteLine("Appel reçu et traité");
                    }
                    else
                    {
                        addMessage = false;
                        Console.WriteLine("Appel reçu et non traité");
                    }
                    notificationHandled = true;
                }
            }
            if (notificationHandled == false)
            {
                if (NotificationConfiguration.getInstance().OtherEnabled)
                {
                    Console.WriteLine("Autre reçu et traité");
                }
                else
                {
                    addMessage = false;
                    Console.WriteLine("Autre reçu et non traité");
                }
                notificationHandled = true;
            }
            return(addMessage);
        }
Ejemplo n.º 4
0
        public void CallBackAfterAnalysis(String name, String message)
        {
            //Création des objets vides
            Notification      notification  = new Notification("", "");
            ConnectionRequest connectionReq = new ConnectionRequest("", "");
            Device            deviceWaitingToBeConnected = null;
            //Conversion et traitement et parsing d'un JSON
            JObject jsonMessage = JSONHandler.stringToJson(message);

            string[] parsedJson          = JSONHandler.interpretation(jsonMessage);
            string   messageReceivedType = parsedJson[0].ToLower();
            Device   device     = new Device();
            Boolean  addMessage = false;

            //Interprétation du JSON parsé

            // Je suis baptiste et je commit de la merde

            //Demande de connexion
            if (messageReceivedType == "connection")
            {
                connectionReq.Appareil = parsedJson[1];
                connectionReq.Autor    = parsedJson[2];
                var pairaineKey = parsedJson[2].Split(':');
                var connexionId = pairaineKey[0] + ":" + pairaineKey[1] + "@" + pairaineKey[2];


                deviceWaitingToBeConnected             = getDeviceWaitingToBeConnected(name);
                deviceWaitingToBeConnected.ConnexionId = connexionId;
                if (isTestClient(connectionReq) || (int.Parse(pairaineKey[2]) == CommunicationService.getInstance().randomSecretNumberAccess))
                {
                    //device = Devices.Devices.FirstOrDefault(o => o.Name == name);
                    notification.Application = parsedJson[1];
                    notification.Message     = "demande de connexion";
                    Console.WriteLine("Successfuly connexion !");
                    deviceWaitingToBeConnected.DeviceType = connectionReq.Appareil;
                    this.DisplayNotif("connexion", "L'appareil " + connectionReq.Appareil + " tente de se connecter", "connexion", "appel", this.callBackYesOnConnexion, this.callBackNoOnConnexion, deviceWaitingToBeConnected);
                }
                else
                {
                    deviceWaitingToBeConnected.sendMessage(JSONHandler.creationRefuseConnexionRequest(deviceWaitingToBeConnected.ConnexionId, "Server"));
                    this.DisplayNotif("connexion", "Echec de connexion avec l'appareil " + connectionReq.Appareil + ". La clé temporaire n'est plus correcte, veuillez réessayer.", "Message", "appel", null, null, null);
                }
                addMessage = true;
            }
            //Demande de deconnexion
            else if (messageReceivedType == "disconnection")
            {
                device = Devices.Devices.FirstOrDefault(o => o.Name == name);
                CallBackAfterDeconnexion(device);
                //--Envoi du message

                //--Deconnexion de l'appareil--

                // Notifaction des vues
                CommunicationViewModel communicationViewModel = (CommunicationViewModel)PageViewModels.FirstOrDefault(o => o.Name == "Communication");
                communicationViewModel.OnPropertyChanged("ListDevices");
                SmsViewModel smsViewModel = (SmsViewModel)PageViewModels.FirstOrDefault(o => o.Name == "Sms View");
                if (smsViewModel != null)
                {
                    smsViewModel.OnPropertyChanged("ListDevices");
                }
            }
            //Reception d'un message
            else if (messageReceivedType == "notification")
            {
                notification.Application = parsedJson[1];

                addMessage = true;
                var config = NotificationConfiguration.getInstance();
                if (NotificationConfiguration.getInstance().IsEnabled)
                {
                    addMessage = isMessageDisplayAuthorised(notification);
                }

                notification.Message = parsedJson[3];

                if (addMessage)
                {
                    RetrieveSms(parsedJson[3], parsedJson[4], name);
                    this.DisplayNotif("Message", notification.Message, "Notification", null, null, null, null);
                }
            }
            else if (messageReceivedType == "batterystate")
            {
                handleBatteryState(name, parsedJson);
            }


            if (messageReceivedType != "connection")
            {
                if (addMessage)
                {
                    handleMessageAdded(name, notification, message);
                }
            }
        }