PutInfo() public method

Puts a value in the body
public PutInfo ( string header, string value ) : void
header string The header
value string The body
return void
Example #1
0
 public static void AddSong(this Client client, string song, string artist, string album, byte[] file)
 {
     IXPFile request = new IXPFile();
     request.NetworkFunction = "com.projectgame.music.music.addsong";
     request.PutInfo("name", song);
     request.PutInfo("artist", artist);
     request.PutInfo("album", album);
     request.PutInfo("file", Convert.ToBase64String(file));
     client.NoResponseRequest(request);
 }
Example #2
0
        public IXPFile NetworkGetTime()
        {
            IXPFile file = new IXPFile();
            file.NetworkFunction = "com.projectgame.clock.clock.gettime";

            file.PutInfo("hour", DateTime.Now.Hour.ToString());
            file.PutInfo("minute", DateTime.Now.Minute.ToString());
            file.PutInfo("second", DateTime.Now.Second.ToString());

            return file;
        }
Example #3
0
        public IXPFile NetworkGetDate()
        {
            IXPFile file = new IXPFile();
            file.NetworkFunction = "com.projectgame.clock.clock.getdate";

            file.PutInfo("day", DateTime.Now.Day.ToString());
            file.PutInfo("month", DateTime.Now.Month.ToString());
            file.PutInfo("year", DateTime.Now.Year.ToString());
            file.PutInfo("weekday", "" + (((int)DateTime.Now.DayOfWeek) - 1));

            return file;
        }
Example #4
0
        public IXPFile NetworkGetColor(string light_id)
        {
            IReadOnlyCollection<HueLight> lights = HueHub.Bridge.HueLights;
            HueLight light = lights.FirstOrDefault(l => l.Id.Equals(light_id));

            IXPFile res = new IXPFile();
            res.NetworkFunction = "com.projectgame.huelightning.hue.getcolor";
            res.PutInfo("bri", "" + light.Brightness);
            res.PutInfo("sat", "" + light.Saturation);
            res.PutInfo("hue", "" + light.Hue);

            return res;
        }
Example #5
0
        public IXPFile NetworkGetTimers()
        {
            IXPFile response = new IXPFile();
            response.NetworkFunction = "com.projectgame.clock.timer.gettimers";

            List<int> timers = TimerDbConnector.GetTimers();
            response.PutInfo("timer_count", "" + timers.Count);

            for(int i = 0; i < timers.Count; i++) {
                response.PutInfo("timer_" + i, "" + timers[i]);
            }

            return response;
        }
Example #6
0
        public IXPFile NetworkGetAlarms()
        {
            IXPFile response = new IXPFile();
            response.NetworkFunction = "com.projectgame.clock.alarm.getalarms";

            List<int> alarms = AlarmDbConnector.GetAlarms();
            response.PutInfo("alarm_count", "" + alarms.Count);

            for(int i = 0; i < alarms.Count; i++) {
                response.PutInfo("alarm_" + i, "" + alarms[i]);
            }

            return response;
        }
Example #7
0
        public IXPFile NetworkGetTimer(int timer_id)
        {
            IXPFile response = new IXPFile();
            response.NetworkFunction = "com.projectgame.clock.timer.gettimer";

            Timer timer = TimerDbConnector.GetTimer(timer_id);

            response.PutInfo("id", "" + timer.ID);
            response.PutInfo("name", "" + timer.Name);
            response.PutInfo("hours", "" + timer.Hours);
            response.PutInfo("minutes", "" + timer.Minutes);
            response.PutInfo("seconds", "" + timer.Seconds);

            return response;
        }
Example #8
0
 public static void DeleteAlarm(this Client client, Alarm alarm)
 {
     IXPFile file = new IXPFile();
     file.NetworkFunction = "com.projectgame.clock.alarm.unregisteralarm";
     file.PutInfo("alarm_id", "" + alarm.ID);
     client.NoResponseRequest(file);
 }
Example #9
0
 public static byte[] GetSongData(this Client client, int songId)
 {
     IXPFile request = new IXPFile();
     request.NetworkFunction = "com.projectgame.music.music.getsongdata";
     request.PutInfo("song_id", "" + songId);
     String response = client.SimpleRequest(request);
     return Convert.FromBase64String(response);
 }
Example #10
0
        public static Alarm GetAlarm(this Client client, int alarmId)
        {
            IXPFile file = new IXPFile();
            file.NetworkFunction = "com.projectgame.clock.alarm.getalarm";
            file.PutInfo("alarm_id", "" + alarmId);
            IXPFile response = client.IXPRequest(file);

            Alarm alarm = new Alarm();
            alarm.ID = int.Parse(response.GetInfoValue("id"));
            alarm.Name = response.GetInfoValue("name");
            alarm.Hours = int.Parse(response.GetInfoValue("hours"));
            alarm.Minutes = int.Parse(response.GetInfoValue("minutes"));
            alarm.Seconds = int.Parse(response.GetInfoValue("seconds"));
            alarm.Mon = response.GetInfoValue("mon").Equals("TRUE");
            alarm.Tue = response.GetInfoValue("tue").Equals("TRUE");
            alarm.Wed = response.GetInfoValue("wed").Equals("TRUE");
            alarm.Thu = response.GetInfoValue("thu").Equals("TRUE");
            alarm.Fri = response.GetInfoValue("fri").Equals("TRUE");
            alarm.Sat = response.GetInfoValue("sat").Equals("TRUE");
            alarm.Sun = response.GetInfoValue("sun").Equals("TRUE");
            alarm.Enabled = response.GetInfoValue("enabled").Equals("TRUE");

            return alarm;
        }
Example #11
0
        public IXPFile NetworkGetSongs()
        {
            IXPFile file = new IXPFile();
            file.NetworkFunction = "com.projectgame.music.music.getsongs";

            List<int> artists = MusicDbConnector.GetInterpreters();
            file.PutInfo("artist_count", "" + artists.Count);

            int ic = 0;
            foreach(int artist in artists) {
                file.PutInfo("artist_" + ic + "_id", "" + artist);
                file.PutInfo("artist_" + ic + "_name", MusicDbConnector.GetInterpreterName(artist));

                List<int> albums = MusicDbConnector.GetAlbums(artist);
                file.PutInfo("artist_" + ic + "_album_count", "" + albums.Count);
                int ac = 0;
                foreach(int album in albums) {
                    file.PutInfo("artist_" + ic + "_album_" + ac + "_id", "" + album);
                    file.PutInfo("artist_" + ic + "_album_" + ac + "_name", MusicDbConnector.GetAlbumName(album));

                    List<int> songs = MusicDbConnector.GetSongs(album);
                    file.PutInfo("artist_" + ic + "_album_" + ac + "_song_count", "" + songs.Count);
                    int sc = 0;
                    foreach(int song in songs) {
                        file.PutInfo("artist_" + ic + "_album_" + ac + "_song_" + sc + "_id", "" + song);
                        file.PutInfo("artist_" + ic + "_album_" + ac + "_song_" + sc + "_name", MusicDbConnector.GetSongName(song));

                        sc++;
                    }

                    ac++;
                }

                ic++;
            }

            return file;
        }
Example #12
0
 public static void UpdateAlarmEnabled(this Client client, Alarm alarm)
 {
     IXPFile file = new IXPFile();
     file.NetworkFunction = "com.projectgame.clock.alarm.setalarmenabled";
     file.PutInfo("alarm_id", "" + alarm.ID);
     file.PutInfo("enabled", alarm.Enabled ? "TRUE" : "FALSE");
     client.NoResponseRequest(file);
 }
Example #13
0
        public IXPFile NetworkGetLights()
        {
            IReadOnlyCollection<HueLight> lights = HueHub.Bridge.HueLights;
            IXPFile res = new IXPFile();
            res.NetworkFunction = "com.projectgame.huelightning.hue.getlights";
            res.PutInfo("Count", "" + lights.Count);

            for(int i = 0; i < lights.Count; i++) {
                res.PutInfo("" + i, lights.ElementAt(i).Id);
            }

            return res;
        }
Example #14
0
 public static void UpdateAlarmName(this Client client, Alarm alarm)
 {
     IXPFile file = new IXPFile();
     file.NetworkFunction = "com.projectgame.clock.alarm.setalarmname";
     file.PutInfo("alarm_id", "" + alarm.ID);
     file.PutInfo("name", alarm.Name);
     client.NoResponseRequest(file);
 }
Example #15
0
        public IXPFile NetworkGetFullAlarms()
        {
            IXPFile response = new IXPFile();
            response.NetworkFunction = "com.projectgame.clock.alarm.getfullalarms";

            List<int> alarmIDs = AlarmDbConnector.GetAlarms();

            response.PutInfo("alarm_count", "" + alarmIDs.Count);

            for(int i = 0; i < alarmIDs.Count; i++){
                Alarm alarm = AlarmDbConnector.GetAlarm(alarmIDs[i]);

                response.PutInfo("alarm_" + i + "_id", "" + alarm.ID);
                response.PutInfo("alarm_" + i + "_name", "" + alarm.Name);
                response.PutInfo("alarm_" + i + "_hours", "" + alarm.Hours);
                response.PutInfo("alarm_" + i + "_minutes", "" + alarm.Minutes);
                response.PutInfo("alarm_" + i + "_seconds", "" + alarm.Seconds);
                response.PutInfo("alarm_" + i + "_mon", alarm.Mon ? "TRUE" : "FALSE");
                response.PutInfo("alarm_" + i + "_tue", alarm.Tue ? "TRUE" : "FALSE");
                response.PutInfo("alarm_" + i + "_wed", alarm.Wed ? "TRUE" : "FALSE");
                response.PutInfo("alarm_" + i + "_thu", alarm.Thu ? "TRUE" : "FALSE");
                response.PutInfo("alarm_" + i + "_fri", alarm.Fri ? "TRUE" : "FALSE");
                response.PutInfo("alarm_" + i + "_sat", alarm.Sat ? "TRUE" : "FALSE");
                response.PutInfo("alarm_" + i + "_sun", alarm.Sun ? "TRUE" : "FALSE");
                response.PutInfo("alarm_" + i + "_enabled", alarm.Enabled ? "TRUE" : "FALSE");
            }

            return response;
        }
Example #16
0
 public static Alarm AddAlarm(this Client client, Alarm alarm)
 {
     IXPFile file = new IXPFile();
     file.NetworkFunction = "com.projectgame.clock.alarm.registeralarm";
     file.PutInfo("name", alarm.Name);
     file.PutInfo("hours", "" + alarm.Hours);
     file.PutInfo("minutes", "" + alarm.Minutes);
     file.PutInfo("seconds", "" + alarm.Seconds);
     file.PutInfo("mon", alarm.Mon ? "TRUE" : "FALSE");
     file.PutInfo("tue", alarm.Tue ? "TRUE" : "FALSE");
     file.PutInfo("wed", alarm.Wed ? "TRUE" : "FALSE");
     file.PutInfo("thu", alarm.Thu ? "TRUE" : "FALSE");
     file.PutInfo("fri", alarm.Fri ? "TRUE" : "FALSE");
     file.PutInfo("sat", alarm.Sat ? "TRUE" : "FALSE");
     file.PutInfo("sun", alarm.Sun ? "TRUE" : "FALSE");
     file.PutInfo("enabled", alarm.Enabled ? "TRUE" : "FALSE");
     int id = int.Parse(client.SimpleRequest(file));
     alarm.ID = id;
     return alarm;
 }
Example #17
0
        private static void Work()
        {
            while (_running) {
                Thread.Sleep(1000); ;

                _timerSemaphore.Enqueue();

                DateTime now = DateTime.Now;

                foreach(Timer timer in _timers.Keys) {
                    if(timer == null) {
                        Debug.Log(_debugChannel, "Timer is null. This should not happen");
                        continue;
                    }

                    _timers [timer].Subtract (new TimeSpan (0, 0, 1));

                    foreach(ServerInstance instance in _clients.Keys){
                        IXPFile file = new IXPFile();
                        file.NetworkFunction = _clients[instance][Function.UPDATED];
                        file.PutInfo("timer_id", "" + timer.ID);
                        file.PutInfo("name", "" + timer.Name);
                        file.PutInfo ("hours", "" + _timers[timer].Hours);
                        file.PutInfo ("minutes", "" + _timers[timer].Minutes);
                        file.PutInfo ("seconds", "" + _timers[timer].Seconds);

                        instance.Send(Encoding.UTF8.GetBytes(file.XML));
                    }

                    CallTimer(timer);
                }

                _timerSemaphore.Dequeue();
            }
        }
Example #18
0
        public static void StopTimer(Timer timer)
        {
            _timers.Remove (timer);

            foreach(ServerInstance instance in _clients.Keys){
                IXPFile file = new IXPFile();
                file.NetworkFunction = _clients[instance][Function.STOPPED];
                file.PutInfo("timer_id", "" + timer.ID);
                file.PutInfo("name", "" + timer.Name);

                instance.Send(Encoding.UTF8.GetBytes(file.XML));
            }
        }
Example #19
0
 public static void UpdateAlarmWeekdays(this Client client, Alarm alarm)
 {
     IXPFile file = new IXPFile();
     file.NetworkFunction = "com.projectgame.clock.alarm.setalarmweekdays";
     file.PutInfo("alarm_id", "" + alarm.ID);
     file.PutInfo("mon", alarm.Mon ? "TRUE" : "FALSE");
     file.PutInfo("tue", alarm.Tue ? "TRUE" : "FALSE");
     file.PutInfo("wed", alarm.Wed ? "TRUE" : "FALSE");
     file.PutInfo("thu", alarm.Thu ? "TRUE" : "FALSE");
     file.PutInfo("fri", alarm.Fri ? "TRUE" : "FALSE");
     file.PutInfo("sat", alarm.Sat ? "TRUE" : "FALSE");
     file.PutInfo("sun", alarm.Sun ? "TRUE" : "FALSE");
     client.NoResponseRequest(file);
 }
Example #20
0
        private static void Work()
        {
            while (_running) {
                Thread.Sleep(1000);

                _semaphore.Enqueue();

                foreach(ServerInstance client in _clients.Keys) {
                    IXPFile file = new IXPFile();
                    file.NetworkFunction = _clients[client];
                    file.PutInfo("hours", "" + DateTime.Now.Hour);
                    file.PutInfo("minutes", "" + DateTime.Now.Minute);
                    file.PutInfo("seconds", "" + DateTime.Now.Second);

                    client.Send(Encoding.UTF8.GetBytes(file.XML));
                }

                _semaphore.Dequeue();
            }
        }
Example #21
0
 public static void RegisterToAlarmService(this Client client, string function)
 {
     IXPFile file = new IXPFile();
     file.NetworkFunction = "com.projectgame.clock.alarm.registertoalarmservice";
     file.PutInfo("function", function);
     client.NoResponseRequest(file);
 }
Example #22
0
        private void button1_Click(object sender, EventArgs e)
        {
            IXPFile file = new IXPFile();
            file.NetworkFunction = "com.projectgame.clock.alarm.registeralarm";
            file.PutInfo("name", "This is my test alarm");
            file.PutInfo("hours", "17");
            file.PutInfo("minutes", "45");
            file.PutInfo("seconds", "00");
            file.PutInfo("mon", "TRUE");
            file.PutInfo("tue", "FALSE");
            file.PutInfo("wed", "FALSE");
            file.PutInfo("thu", "FALSE");
            file.PutInfo("fri", "TRUE");
            file.PutInfo("sat", "FALSE");
            file.PutInfo("sun", "TRUE");
            file.PutInfo("enabled", "TRUE");

            IXPRequest request = new IXPRequest(_client, file, AddAlarm_Response);
        }
Example #23
0
        private static void HandleMessage(ServerInstance arg1, string message)
        {
            IXPFile ixp = new IXPFile(message);

            FunctionInfo nfunc = _networkFunctions.FirstOrDefault(nf => nf.Name.Equals(ixp.NetworkFunction));

            if (nfunc != null)
                Debug.Log(_debugChannel, "Function: " + ixp.NetworkFunction);
            else {
                Debug.Log(_debugChannel, "Function: Unknown");
                return;
            }

            Dictionary<string, object> dicParams = new Dictionary<string, object>();
            foreach (string param in nfunc.Parameters) {
                if (ixp.GetInfoValue(param) == null && nfunc.GetParameterType(param) != typeof(ServerInstance)) {
                    Debug.Log(_debugChannel, "Missing parameter: " + param);
                    return;
                }

                object paramVal = null;
                Type t = nfunc.GetParameterType(param);
                if (t == typeof(ServerInstance)) {
                    paramVal = arg1;
                } else {
                    string strVal = ixp.GetInfoValue(param);

                    if (t == typeof(string)) {
                        paramVal = strVal;
                    } else if (t == typeof(int)) {
                        int i = -1;
                        bool s = int.TryParse(strVal, out i);
                        if (s)
                            paramVal = i;
                    } else if(t == typeof(byte)) {
                        byte b = 0;
                        bool s = byte.TryParse(strVal, out b);
                        if (s)
                            paramVal = b;
                    } else if(t == typeof(ushort)){
                        ushort us = 0;
                        bool s = ushort.TryParse(strVal, out us);
                        if (s)
                            paramVal = us;
                    } else if (t == typeof(bool)) {
                        if (strVal.Equals("TRUE"))
                            paramVal = true;
                        else if (strVal.Equals("FALSE"))
                            paramVal = false;
                    }

                    if (paramVal == null) {
                        Debug.Log(_debugChannel, "Invalid type for param " + param + ". Expected " + t.ToString() + ". Got Value: " + strVal);
                        return;
                    }
                }

                dicParams.Add(param, paramVal);
            }

            if (nfunc.ReturnType == typeof(void))
                nfunc.Invoke(dicParams);
            else if (nfunc.ReturnType == typeof(IXPFile)) {
                IXPFile file = (IXPFile)nfunc.Invoke(dicParams);
                arg1.Send(Encoding.UTF8.GetBytes(file.XML));
            } else {
                object response = nfunc.Invoke(dicParams);
                IXPFile iresponse = new IXPFile();
                iresponse.NetworkFunction = ixp.NetworkFunction;
                iresponse.PutInfo("Response", response.ToString());
                arg1.Send(Encoding.UTF8.GetBytes(iresponse.XML));
            }
        }
Example #24
0
 public static void UpdateAlarmTime(this Client client, Alarm alarm)
 {
     IXPFile file = new IXPFile();
     file.NetworkFunction = "com.projectgame.clock.alarm.setalarmtime";
     file.PutInfo("alarm_id", "" + alarm.ID);
     file.PutInfo("hours", "" + alarm.Hours);
     file.PutInfo("minutes", "" + alarm.Minutes);
     file.PutInfo("seconds", "" + alarm.Seconds);
     client.NoResponseRequest(file);
 }
Example #25
0
        private static void CallTimer(Timer timer)
        {
            _clientSemaphore.Enqueue();

            Debug.Log(_debugChannel, "Calling timer " + timer.Name);

            foreach(ServerInstance instance in _clients.Keys){
                IXPFile file = new IXPFile();
                file.NetworkFunction = _clients[instance][Function.CALLED];
                file.PutInfo("timer_id", "" + timer.ID);
                file.PutInfo("name", "" + timer.Name);

                instance.Send(Encoding.UTF8.GetBytes(file.XML));
            }

            _clientSemaphore.Dequeue();
        }
Example #26
0
        private static void CallAlarm(Alarm alarm)
        {
            _clientSemaphore.Enqueue();

            Debug.Log(_debugChannel, "Calling alarm " + alarm.Name);

            foreach(ServerInstance client in _clients.Keys) {
                IXPFile file = new IXPFile();
                file.NetworkFunction = _clients[client];
                file.PutInfo("alarm_id", "" + alarm.ID);
                file.PutInfo("name", "" + alarm.Name);

                client.Send(Encoding.UTF8.GetBytes(file.XML));
            }

            _clientSemaphore.Dequeue();
        }
Example #27
0
        public static void StartTimer(Timer timer)
        {
            _timers.Add (timer, new TimeSpan(timer.Hours, timer.Minutes, timer.Seconds));

            foreach(ServerInstance instance in _clients.Keys){
                IXPFile file = new IXPFile();
                file.NetworkFunction = _clients[instance][Function.STARTED];
                file.PutInfo("timer_id", "" + timer.ID);
                file.PutInfo("name", "" + timer.Name);

                instance.Send(Encoding.UTF8.GetBytes(file.XML));
            }
        }
Example #28
0
        public IXPFile NetworkGetAlarm(int alarm_id)
        {
            IXPFile response = new IXPFile();
            response.NetworkFunction = "com.projectgame.clock.alarm.getalarm";

            Alarm alarm = AlarmDbConnector.GetAlarm(alarm_id);

            response.PutInfo("id", "" + alarm.ID);
            response.PutInfo("name", "" + alarm.Name);
            response.PutInfo("hours", "" + alarm.Hours);
            response.PutInfo("minutes", "" + alarm.Minutes);
            response.PutInfo("seconds", "" + alarm.Seconds);
            response.PutInfo("mon", alarm.Mon ? "TRUE" : "FALSE");
            response.PutInfo("tue", alarm.Tue ? "TRUE" : "FALSE");
            response.PutInfo("wed", alarm.Wed ? "TRUE" : "FALSE");
            response.PutInfo("thu", alarm.Thu ? "TRUE" : "FALSE");
            response.PutInfo("fri", alarm.Fri ? "TRUE" : "FALSE");
            response.PutInfo("sat", alarm.Sat ? "TRUE" : "FALSE");
            response.PutInfo("sun", alarm.Sun ? "TRUE" : "FALSE");
            response.PutInfo("enabled", alarm.Enabled ? "TRUE" : "FALSE");

            return response;
        }