Ejemplo n.º 1
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);
 }
Ejemplo n.º 2
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);
 }
Ejemplo n.º 3
0
 public IXPRequest(Networking.Client client, IXPFile request, Action<string> responseDelegate)
 {
     _request = request;
     _responseDelegate = responseDelegate;
     _client = client;
     Thread thread = new Thread(new ThreadStart(Work));
     thread.Start();
 }
Ejemplo n.º 4
0
        private static void IXPRequest_Client_MessageReceived(byte[] obj)
        {
            IXPFile file = new IXPFile(Encoding.UTF8.GetString(obj));

            if (!file.NetworkFunction.Equals(_ixpRequestRequest))
                return;

            _ixpRequestResponse = file;
        }
Ejemplo n.º 5
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);
 }
Ejemplo n.º 6
0
        private void _client_MessageReceived(byte[] obj)
        {
            IXPFile ixp = new IXPFile(Encoding.UTF8.GetString(obj));
            if (!ixp.NetworkFunction.Equals(_request.NetworkFunction))
                return;

            _received = true;

            _responseDelegate(ixp.GetInfoValue("Response"));
        }
Ejemplo n.º 7
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;
        }
Ejemplo n.º 8
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;
        }
Ejemplo n.º 9
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;
        }
Ejemplo n.º 10
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;
        }
Ejemplo n.º 11
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;
        }
Ejemplo n.º 12
0
        public static List<Alarm> GetAlarms(this Client client)
        {
            IXPFile file = new IXPFile();
            file.NetworkFunction = "com.projectgame.clock.alarm.getalarms";
            IXPFile response = client.IXPRequest(file);

            List<Alarm> alarms = new List<Alarm>();
            int count = int.Parse(response.GetInfoValue("alarm_count"));
            for(int i = 0; i < count; i++) {
                int id = int.Parse(response.GetInfoValue("alarm_" + i));
                alarms.Add(client.GetAlarm(id));
            }

            return alarms;
        }
Ejemplo n.º 13
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;
        }
Ejemplo n.º 14
0
        /// <summary>
        /// A Request that gives back a single string
        /// </summary>
        /// <param name="file">The file to send</param>
        /// <returns>The servers response</returns>
        public static string SimpleRequest(this Client client, IXPFile file)
        {
            _simpleRequestRequest = file.NetworkFunction;
            client.MessageReceived += SimpleRequest_Client_MessageReceived;
            client.Send(Encoding.UTF8.GetBytes(file.XML));

            while (_simpleRequestResponse == null)
                Thread.Sleep(200);

            client.MessageReceived -= SimpleRequest_Client_MessageReceived;

            string response = _simpleRequestResponse;
            _simpleRequestResponse = null;
            return response;
        }
Ejemplo n.º 15
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);
        }
Ejemplo n.º 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;
 }
Ejemplo n.º 17
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;
        }
Ejemplo n.º 18
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;
        }
Ejemplo n.º 19
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;
        }
Ejemplo n.º 20
0
        public static MusicCollection GetSongs(this Client client)
        {
            IXPFile request = new IXPFile();
            request.NetworkFunction = "com.projectgame.music.music.getsongs";
            IXPFile response = client.IXPRequest(request);

            MusicCollection musicCollection = new MusicCollection();
            int artistCount = int.Parse(response.GetInfoValue("artist_count"));

            for(int currentArtistIndex = 0; currentArtistIndex < artistCount; currentArtistIndex++) {
                int artistID = int.Parse(response.GetInfoValue("artist_" + currentArtistIndex + "_id"));
                string artistName = response.GetInfoValue("artist_" + currentArtistIndex + "_name");
                Artist artist = new Artist(artistID, artistName);
                musicCollection.Artists.Add(artist);

                int albumCount = int.Parse(response.GetInfoValue("artist_" + currentArtistIndex + "_album_count"));

                for(int currentAlbumIndex = 0; currentAlbumIndex < albumCount; currentAlbumIndex++) {
                    int albumID = int.Parse(response.GetInfoValue("artist_" + currentArtistIndex + "_album_" + currentAlbumIndex + "_id"));
                    string albumName = response.GetInfoValue("artist_" + currentArtistIndex + "_album_" + currentAlbumIndex + "_name");
                    Album album = new Album(albumID, albumName);
                    artist.Albums.Add(album);

                    int songCount = int.Parse(response.GetInfoValue("artist_" + currentArtistIndex + "_album_" + currentAlbumIndex + "_song_count"));

                    for(int currentSongIndex = 0; currentSongIndex  < songCount; currentSongIndex++) {
                        int songID = int.Parse(response.GetInfoValue("artist_" + currentArtistIndex + "_album_" + currentAlbumIndex + "_song_" + currentSongIndex + "_id"));
                        string songName = response.GetInfoValue("artist_" + currentArtistIndex + "_album_" + currentAlbumIndex + "_song_" + currentSongIndex + "_name");
                        Song song = new Song(songID, songName);
                        album.Songs.Add(song);
                    }
                }
            }

            return musicCollection;
        }
Ejemplo n.º 21
0
 private void UpdarteTime(IXPFile file)
 {
     Invoke((MethodInvoker)delegate { lblCurTime.Text = String.Format("{0:00}:{1:00}:{2:00}", int.Parse(file.GetInfoValue("hours")), int.Parse(file.GetInfoValue("minutes")), int.Parse(file.GetInfoValue("seconds"))); });
 }
Ejemplo n.º 22
0
        private void HandleMessage(string message)
        {
            System.Diagnostics.Debug.WriteLine(message);
            IXPFile file = new IXPFile(message);

            if (file.NetworkFunction.Equals(ALARM_SERVICE_FUNCTION))
                CallAlarm(file);

            if (file.NetworkFunction.Equals(TIME_SERVICE_FUNCTION))
                UpdarteTime(file);
        }
Ejemplo n.º 23
0
        private void CallAlarm(IXPFile file)
        {
            int id = int.Parse(file.GetInfoValue("alarm_id"));
            Alarm a = _alarms.FirstOrDefault(al => al.ID == id);

            MessageBox.Show("ALARM: " + a.Name);
        }
Ejemplo n.º 24
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));
            }
        }
Ejemplo n.º 25
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();
            }
        }
Ejemplo n.º 26
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();
        }
Ejemplo n.º 27
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));
            }
        }
Ejemplo n.º 28
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));
            }
        }
Ejemplo n.º 29
0
 private void btnGetTimt_Click(object sender, EventArgs e)
 {
     IXPFile file = new IXPFile();
     file.NetworkFunction = "com.projectgame.clock.clock.gettime";
     IXPRequest request = new IXPRequest(_client, file, GetTime_Response);
 }
Ejemplo n.º 30
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;
        }