Esempio n. 1
0
        public void GetPropertiesCallback(XRequestState requestState)
        {
            JObject query = JObject.Parse(requestState.ResponseData);

            if (query["result"].HasValues)
            {
                propResult = JsonConvert.DeserializeObject<Application.Properties.Result>(query["result"].ToString());
            }
            else { propResult = null; }

            if (requestState.UserCallback != null)
                requestState.UserCallback(propResult);
        }
Esempio n. 2
0
 /// <summary>
 /// Introspects the callback.
 /// </summary>
 /// <param name="requestState">State of the request.</param>
 private void IntrospectCallback(XRequestState requestState)
 {
     JObject query = JObject.Parse(requestState.ResponseData);
     if (XHelpers.CheckResponseForError(query, out mError))
     {
         //need exception handling in here
     }
     {
         if (requestState.UserCallback != null)
         {
             requestState.UserCallback(query);
         }
     }
 }
Esempio n. 3
0
        public void GetData(string method, object args, XClientResponseReceived internalCallback, XDataReceived userCallback)
        {
            var requestState = new XRequestState
            {
                InternalCallback = internalCallback,
                UserCallback     = userCallback,
                JsonRequest      = BuildJsonPost(method, args),
                Request          = (HttpWebRequest)WebRequest.Create(_Settings.XJsonInterfaceAddress)
            };

            requestState.Request.Credentials = new NetworkCredential(_Settings.UserName, _Settings.Password);
            requestState.Request.ContentType = "application/json";
            requestState.Request.Method      = "POST";
            requestState.Request.BeginGetRequestStream(ResponseStreamReceived, requestState);
        }
Esempio n. 4
0
        public void GetData(string method, object args, XClientResponseReceived internalCallback, XDataReceived userCallback)
        {
            var requestState = new XRequestState
                                   {
                                       InternalCallback = internalCallback,
                                       UserCallback = userCallback,
                                       JsonRequest = BuildJsonPost(method, args),
                                       Request = (HttpWebRequest) WebRequest.Create(mSettings.XJsonInterfaceAddress),
                                       RequestOperation = method
                                   };

            requestState.Request.Credentials = new NetworkCredential(mSettings.UserName, mSettings.Password);
            requestState.Request.ContentType = "application/json";
            requestState.Request.Method = "POST";
            requestState.Request.BeginGetRequestStream(ResponseStreamReceived, requestState);
        }
Esempio n. 5
0
        /// <summary>
        /// Callback for GetVolume.
        /// </summary>
        /// <param name="requestState"></param>
        private void GetVolumeCallback(XRequestState requestState)
        {
            var query = JObject.Parse(requestState.ResponseData);

            if (query["error"] == null)
            {
                var result = (JObject)query["result"];

                var currentVolume = Convert.ToDouble(result["result"].Value <JValue>().Value);

                if (requestState.UserCallback != null)
                {
                    requestState.UserCallback(currentVolume);
                }
            }
        }
        /// <summary>
        /// Scans the callback.
        /// </summary>
        /// <param name="requestState">State of the request.</param>
        private void ScanCallback(XRequestState requestState)
        {
            var query = JObject.Parse(requestState.ResponseData);
            var result = (JValue)query["result"];

            if (requestState.UserCallback != null)
            {
                requestState.UserCallback(result.Value.ToString());
            }
        }
        /// <summary>
        /// Gets the songs callback.
        /// </summary>
        /// <param name="requestState">State of the request.</param>
        private void GetSongsCallback(XRequestState requestState)
        {
            var songs = new Songs();

            var query = JObject.Parse(requestState.ResponseData);

            if (XHelpers.CheckResponseForError(query, out mError))
            {
                //error handling needed here
            }
            else
            {
                var result = (JObject)query["result"];

                songs.LoadFromJsonObject(result);

                if (requestState.UserCallback != null)
                    requestState.UserCallback(songs);
            }
        }
        /// <summary>
        /// Gets the artists callback.
        /// </summary>
        /// <param name="requestState">State of the request.</param>
        private void GetArtistsCallback(XRequestState requestState)
        {
            var artists = new Artists();

            var query = JObject.Parse(requestState.ResponseData);

            if(XHelpers.CheckResponseForError(query,out mError))
            {

            }
            else
            {

                var result = (JObject) query["result"];

                artists.LoadFromJsonObject(result, false);

                if (requestState.UserCallback != null)
                    requestState.UserCallback(artists);
            }
        }
        /// <summary>
        /// Gets the artist details callback.
        /// </summary>
        /// <param name="requestState">State of the request.</param>
        private void GetArtistDetailsCallback(XRequestState requestState)
        {
            JObject query = JObject.Parse(requestState.ResponseData);

            if (XHelpers.CheckResponseForError(query, out mError))
            {
                //error handling needed here
            }
            else
            {

                var result = (JObject)query["result"];

                Artist artist = null;

                if (result["artistdetails"] != null)
                {
                    JObject item = (JObject)result["artistdetails"];
                    artist = Artist.FromJsonObject(item, false);

                }
                if (requestState.UserCallback != null)
                {
                    requestState.UserCallback(artist);
                }
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Callback for GetTime
        /// </summary>
        /// <param name="requestState"></param>
        private void GetTimeCallback(XRequestState requestState)
        {
            string timeFormatted = "";

             var query = JObject.Parse(requestState.ResponseData);

             if (query["error"] == null)
             {
            var result = (JObject)query["result"];

            var timePlayed = Convert.ToInt32(result["time"].Value<JValue>().Value);
            var timeTotal = Convert.ToInt32(result["total"].Value<JValue>().Value);

            timeFormatted = String.Format("{0}:{1} / {2}:{3}", String.Format("{0:00}", (timePlayed / 60)), String.Format("{0:00}", (timePlayed % 60)), String.Format("{0:00}", (timeTotal / 60)), String.Format("{0:00}", (timeTotal % 60)));
             }

             if (requestState.UserCallback != null)
            requestState.UserCallback(timeFormatted);
        }
Esempio n. 11
0
        /// <summary>
        /// Videoes the library callback manager.
        /// </summary>
        /// <param name="requestState">State of the request.</param>
        private void VideoLibraryCallbackManager(XRequestState requestState)
        {
            object returnObject = null;

            VideoLibrary operation = GetMethod(requestState.RequestOperation);

            var query = JObject.Parse(requestState.ResponseData);
            JObject result = (JObject)query["result"];

            switch (operation)
            {
                case VideoLibrary.Clean:
                    returnObject = result.Values(0).ToString();
                    break;

                case VideoLibrary.Export:
                    break;

                case VideoLibrary.GetEpisodeDetails:
                    Episode episode = null;
                    if (result["episodedetails"] != null)
                    {
                        JObject item = (JObject)result["episodedetails"];
                        episode = Episode.FromJsonObject(item);

                    }
                    returnObject = episode;
                    break;

                case VideoLibrary.GetEpisodes:
                case VideoLibrary.GetRecentlyAddedEpisodes:
                    var episodes = new Episodes();
                    episodes.LoadFromJsonObject(result);
                    returnObject = episodes;
                    break;

                case VideoLibrary.GetGenres:
                    var genres = new Genres();
                    genres.LoadFromJsonObject(result);
                    returnObject = genres;
                    break;

                case VideoLibrary.GetMovieDetails:
                    Movie movie = null;
                    if (result["moviedetails"] != null)
                    {
                        JObject item = (JObject)result["moviedetails"];
                        movie = Movie.FromJsonObject(item);
                    }
                    returnObject = movie;
                    break;

                case VideoLibrary.GetMovies:
                case VideoLibrary.GetRecentlyAddedMovies:
                    var movies = new Movies();
                    movies.LoadFromJsonObject(result);
                    returnObject = movies;
                    break;

                case VideoLibrary.GetMovieSetDetails:
                    MovieSetExtended movieSet = null;
                    if (result["setdetails"] != null)
                    {
                        JObject item = (JObject)result["setdetails"];
                        movieSet = MovieSetExtended.FromJsonObject(item);
                    }
                    returnObject = movieSet;
                    break;

                case VideoLibrary.GetMovieSets:
                    var movieSets = new MovieSets();
                    movieSets.LoadFromJsonObject(result);
                    returnObject = movieSets;
                    break;

                case VideoLibrary.GetMusicVideoDetails:
                    MusicVideo musicVideo = null;
                    if (result["musicvideodetails"] != null)
                    {
                        JObject item = (JObject)result["musicvideodetails"];
                        musicVideo = MusicVideo.FromJsonObject(item);
                    }
                    returnObject = musicVideo;
                    break;

                case VideoLibrary.GetMusicVideos:
                case VideoLibrary.GetRecentlyAddedMusicVideos:
                    var musicVideos = new MusicVideos();
                    musicVideos.LoadFromJsonObject(result);
                    returnObject = musicVideos;
                    break;

                case VideoLibrary.GetSeasons:
                    var seasons = new Seasons();
                    seasons.LoadFromJsonObject(result);
                    returnObject = seasons;
                    break;

                case VideoLibrary.GetTVShowDetails:
                    TvShow tvShow = null;
                    if (result["tvshowdetails"] != null)
                    {
                        JObject item = (JObject)result["tvshowdetails"];
                        tvShow = TvShow.FromJsonObject(item);
                    }
                    returnObject = tvShow;
                    break;

                case VideoLibrary.GetTVShows:
                    var tvShows = new TvShows();
                    tvShows.LoadFromJsonObject(result);
                    returnObject = tvShows;
                    break;

                case VideoLibrary.Scan:
                    returnObject = result.Values(0).ToString();
                    break;
            }

            if (requestState.UserCallback != null)
                requestState.UserCallback(returnObject);
        }
Esempio n. 12
0
        /// <summary>
        /// Notifies the callback.
        /// </summary>
        /// <param name="requestState">State of the request.</param>
        private void NotifyCallback(XRequestState requestState)
        {
            JObject query = JObject.Parse(requestState.ResponseData);

            if (XHelpers.CheckResponseForError(query, out mError))
            {
                //need exception handling in here
            }
            {
                var result = (JValue)query["result"];
                if (requestState.UserCallback != null)
                {
                    requestState.UserCallback(result.ToString());
                }
            }
        }
Esempio n. 13
0
        /// <summary>
        /// Callback for GetVolume.
        /// </summary>
        /// <param name="requestState"></param>
        private void GetVolumeCallback(XRequestState requestState)
        {
            var query = JObject.Parse(requestState.ResponseData);

             if (query["error"] == null)
             {
            var result = (JObject)query["result"];

            var currentVolume = Convert.ToDouble(result["result"].Value<JValue>().Value);

            if (requestState.UserCallback != null)
               requestState.UserCallback(currentVolume);
             }
        }
Esempio n. 14
0
        private void GetActivePlayersCallback(XRequestState requestState)
        {
            JObject query = JObject.Parse(requestState.ResponseData);
              JObject player = null;
              //error checking if (query["error"] == null)
              if (query["result"].HasValues)
              {
              player = JObject.Parse(query["result"].First.ToString());

              PlayerId = Convert.ToInt32(player["playerid"].Value<JValue>().Value.ToString());
              //need to get the player type here
              }
              else { player = null; }

              if (requestState.UserCallback != null)
              requestState.UserCallback(player);
        }
Esempio n. 15
0
        private void UpdateCurrentSpeed(XRequestState requestState)
        {
            JObject query = JObject.Parse(requestState.ResponseData);

              JObject result = JObject.Parse(query["result"].ToString());

              CurrentSpeed = Convert.ToInt32(result["speed"].Value<JValue>().Value.ToString());
        }
Esempio n. 16
0
        /// <summary>
        /// Callback for SeekTime.
        /// </summary>
        /// <param name="requestState"></param>
        private void SeekTimeCallback(XRequestState requestState)
        {
            var query = JObject.Parse(requestState.ResponseData);

             if (query["error"] == null)
             {
            if (requestState.UserCallback != null)
               requestState.UserCallback(true);
             }
             else
             {
            if (requestState.UserCallback != null)
               requestState.UserCallback(false);
             }
        }
Esempio n. 17
0
        /// <summary>
        /// Exports the callback.
        /// </summary>
        /// <param name="requestState">State of the request.</param>
        private void ExportCallback(XRequestState requestState)
        {
            var query = JObject.Parse(requestState.ResponseData);

            if (XHelpers.CheckResponseForError(query, out mError))
            {

            }
            if (requestState.UserCallback != null)
            {
                requestState.UserCallback(query);
                //var result = (JObject)query["result"];
            }
        }
Esempio n. 18
0
        /// <summary>
        /// Gets the album details callback.
        /// </summary>
        /// <param name="requestState">State of the request.</param>
        private void GetAlbumDetailsCallback(XRequestState requestState)
        {
            JObject query = JObject.Parse(requestState.ResponseData);
            var result = (JObject)query["result"];

            Album album = null;

            if (result["albumdetails"] != null)
            {
                JObject item = (JObject)result["albumdetails"];
                album = Album.FromJsonObject(item);

            }
            if (requestState.UserCallback != null)
            {
                requestState.UserCallback(album);
            }
        }
Esempio n. 19
0
        /// <summary>
        /// Gets the albums callback.
        /// </summary>
        /// <param name="requestState">State of the request.</param>
        private void GetAlbumsCallback(XRequestState requestState)
        {
            var albums = new Albums();//new List<Album>();

            JObject query = JObject.Parse(requestState.ResponseData);
            var result = (JObject)query["result"];

            albums.LoadFromJsonObject(result);

            if (requestState.UserCallback != null)
                requestState.UserCallback(albums);
        }
Esempio n. 20
0
        /// <summary>
        /// Callback for GetPercentage.
        /// </summary>
        /// <param name="requestState"></param>
        private void GetPercentageCallback(XRequestState requestState)
        {
            double percentagePlayed = 0;
             var query = JObject.Parse(requestState.ResponseData);

             if (query["error"] == null)
             {
            var result = (JObject)query["result"];
            percentagePlayed = Convert.ToDouble(result["Percentage"].Value<JValue>().Value);
             }

             if (requestState.UserCallback != null)
            requestState.UserCallback(percentagePlayed);
        }