Esempio n. 1
0
        private async Task GetReDataAsync()
        {
            if (this._groups.Count != 0)
                return;

            Uri dataUri = new Uri("ms-appx:///DataModel/ReData.json");

            StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(dataUri);
            string jsonText = await FileIO.ReadTextAsync(file);
            JsonObject jsonObject = JsonObject.Parse(jsonText);
            JsonArray jsonArray = jsonObject["Groups"].GetArray();
            
            foreach (JsonValue groupValue in jsonArray)
            {
                JsonObject groupObject = groupValue.GetObject();
                ReDataGroup group = new ReDataGroup(groupObject["UniqueId"].GetString(),
                                                            groupObject["Title"].GetString());
                int index = 0;
                foreach (JsonValue itemValue in groupObject["Items"].GetArray())
                {                    
                    JsonObject itemObject = itemValue.GetObject();

                    string uniqueIdTmp = itemObject["UniqueId"].GetString();
                    string titleTmp = itemObject["Title"].GetString();
                    string subTitleTmp = itemObject["Subtitle"].GetString();
                    string imagePathTmp = itemObject["ImagePath"].GetString();
                    string descriptionTmp = itemObject["Description"].GetString();
                    string playUrlTmp = itemObject["PlayUrl"].GetString();
                    ReDataItem ri = new ReDataItem(index, uniqueIdTmp);
                    group.Items.Add(ri);
                    index++;
                }
                this.Groups.Add(group);
            }
        }
Esempio n. 2
0
        private async Task GetWebServiceRelatedDataAsync(ReDataGroup group)
        {
            try
            {
                if ((group == null) && (group.UniqueId.Equals(string.Empty)))
                {
                    return;
                }

                string requestUrl = "http://replatform.cloudapp.net:8000/getrelated/?id={0}&uuid={1}&type={2}&from={3}&to={4}";
                //string requestUrl = "http://192.168.1.215:9999/getrelated/?id={0}";
                requestUrl = String.Format(requestUrl, group.UniqueId, App.gDeviceName, App.gDeviceType, App.NavigationRoadmap.GetFrom(), App.NavigationRoadmap.GetTo());

                HttpBaseProtocolFilter filter = new HttpBaseProtocolFilter();
                filter.AutomaticDecompression = true;
                HttpClient httpClient       = new HttpClient(filter);
                CancellationTokenSource cts = new CancellationTokenSource();

                filter.CacheControl.ReadBehavior  = HttpCacheReadBehavior.Default;
                filter.CacheControl.WriteBehavior = HttpCacheWriteBehavior.Default;

                Uri resourceUri;
                if (!Uri.TryCreate(requestUrl.Trim(), UriKind.Absolute, out resourceUri))
                {
                    return;
                }

                HttpResponseMessage response = await httpClient.GetAsync(resourceUri).AsTask(cts.Token);

                string jsonText = await Helpers.GetResultAsync(response, cts.Token);

                if (filter != null)
                {
                    filter.Dispose();
                    filter = null;
                }

                if (httpClient != null)
                {
                    httpClient.Dispose();
                    httpClient = null;
                }

                if (cts != null)
                {
                    cts.Dispose();
                    cts = null;
                }

                GetRelatedResultJsonData(group, jsonText);
            }
            catch (Exception e)
            {
                String ex = e.Message;
            }
        }
Esempio n. 3
0
        private void GetSearchResultJsonData(string jsonData)
        {
            if (string.IsNullOrEmpty(jsonData))
            {
                return;
            }

            if (jsonData.Equals("null"))
            {
                return;
            }

            _groups = new ObservableCollection <ReDataGroup>();

            string      groupId    = "search";
            string      groupTitle = "search";
            ReDataGroup group      = new ReDataGroup(groupId, groupTitle);

            JsonArray groupJsonArray = JsonArray.Parse(jsonData);
            int       indexInGroup   = 0;

            foreach (JsonValue groupValue in groupJsonArray)
            {
                JsonObject jsonObject = groupValue.GetObject();

                string    playUrl   = "";
                JsonArray jsonArray = jsonObject["playlist"].GetArray();

                foreach (JsonValue itemValue in jsonArray)
                {
                    JsonObject itemObject        = itemValue.GetObject();
                    JsonArray  playlistJsonArray = itemObject["list"].GetArray();

                    foreach (JsonValue playUrlValue in playlistJsonArray)
                    {
                        JsonObject playUrlObject = playUrlValue.GetObject();
                        playUrl = playUrlObject.ContainsKey("url") ? playUrlObject["url"].GetString() : "";
                        break;
                    }
                }

                string uniqueId    = jsonObject.ContainsKey("_id") ? jsonObject["_id"].GetString() : "";
                string title       = jsonObject.ContainsKey("title") ? jsonObject["title"].GetString() : "";
                string actor       = jsonObject.ContainsKey("actor") ? jsonObject["actor"].GetString() : "";
                string director    = jsonObject.ContainsKey("director") ? jsonObject["director"].GetString() : "";
                string cate        = jsonObject.ContainsKey("cate") ? jsonObject["cate"].GetString() : "";
                string imagePath   = jsonObject.ContainsKey("img") ? jsonObject["img"].GetString() : "";
                string description = jsonObject.ContainsKey("info") ? jsonObject["info"].GetString() : "";
                group.Items.Add(new ReDataItem(indexInGroup, uniqueId, title, actor, director, imagePath, description, playUrl));

                indexInGroup++;
            }
            this._groups.Add(group);
        }
Esempio n. 4
0
        // add related medias to group's items
        private void GetRelatedResultJsonData(ReDataGroup group, string jsonData)
        {
            if (string.IsNullOrEmpty(jsonData))
            {
                this._groups.Add(group);
                return;
            }

            if (jsonData.Equals("null"))
            {
                this._groups.Add(group);
                return;
            }

            JsonArray groupJsonArray = JsonArray.Parse(jsonData);
            int       indexInGroup   = 0;

            foreach (JsonValue groupValue in groupJsonArray)
            {
                JsonObject jsonObject = groupValue.GetObject();

                string    playUrl   = "";
                JsonArray jsonArray = jsonObject["playlist"].GetArray();

                foreach (JsonValue itemValue in jsonArray)
                {
                    JsonObject itemObject        = itemValue.GetObject();
                    JsonArray  playlistJsonArray = itemObject["list"].GetArray();

                    foreach (JsonValue playUrlValue in playlistJsonArray)
                    {
                        JsonObject playUrlObject = playUrlValue.GetObject();
                        playUrl = playUrlObject.ContainsKey("url") ? playUrlObject["url"].GetString() : "";
                        break;
                    }
                }

                string uniqueId    = Helpers.GetJosnObjectStringValue(jsonObject, "_id");      //jsonObject.ContainsKey("_id") ? jsonObject["_id"].GetString() : "";
                string title       = Helpers.GetJosnObjectStringValue(jsonObject, "title");    //jsonObject.ContainsKey("title") ? jsonObject["title"].GetString() : "";
                string actor       = Helpers.GetJosnObjectStringValue(jsonObject, "actor");    //jsonObject.ContainsKey("actor") ? jsonObject["actor"].GetString() : "";
                string director    = Helpers.GetJosnObjectStringValue(jsonObject, "director"); //jsonObject.ContainsKey("director") ? jsonObject["director"].GetString() : "";
                string cate        = Helpers.GetJosnObjectStringValue(jsonObject, "cate");     //jsonObject.ContainsKey("cate") ? jsonObject["cate"].GetString() : "";
                string imagePath   = Helpers.GetJosnObjectStringValue(jsonObject, "img");      //jsonObject.ContainsKey("img") ? jsonObject["img"].GetString() : "";
                string description = Helpers.GetJosnObjectStringValue(jsonObject, "info");     //jsonObject.ContainsKey("info") ? jsonObject["info"].GetString() : "";
                group.Items.Add(new ReDataItem(indexInGroup, uniqueId, title, actor, director, imagePath, description, playUrl));

                indexInGroup++;
            }
            this._groups.Add(group);
        }
Esempio n. 5
0
        private void GetResultJsonData(string jsonData)
        {
            if (string.IsNullOrEmpty(jsonData))
            {
                return;
            }

            if (jsonData.Equals("null"))
            {
                return;
            }

            _groups = new ObservableCollection <ReDataGroup>();

            JsonObject originalJsonObject = JsonObject.Parse(jsonData);
            JsonArray  groupJsonArray     = originalJsonObject["data"].GetArray();

            int groupIndex = 0;

            foreach (JsonValue groupValue in groupJsonArray)
            {
                JsonObject jsonObject = groupValue.GetObject();

                string      groupId     = Helpers.GetJosnObjectStringValue(jsonObject, "_id");
                string      groupTitle  = Helpers.GetJosnObjectStringValue(jsonObject, "name");
                string      description = Helpers.GetJosnObjectIntegerValue(jsonObject, "count");
                string      imagePath   = Helpers.GetJosnObjectStringValue(jsonObject, "img");
                ReDataGroup group       = new ReDataGroup(groupId, groupTitle, imagePath, description);

                JsonArray collectionJsonArray = jsonObject["cor"].GetArray();
                int       indexInGroup        = 0;
                foreach (JsonValue collectionValue in collectionJsonArray)
                {
                    JsonObject collectionObject = collectionValue.GetObject();
                    string     uniqueId         = Helpers.GetJosnObjectStringValue(collectionObject, "id");
                    string     itemTitle        = Helpers.GetJosnObjectStringValue(collectionObject, "name");
                    string     itemDescription  = Helpers.GetJosnObjectIntegerValue(collectionObject, "count");
                    string     itemImagePath    = Helpers.GetJosnObjectStringValue(collectionObject, "img");
                    group.Items.Add(new ReDataItem(indexInGroup, uniqueId, itemTitle, itemImagePath, itemDescription));
                    indexInGroup++;
                }

                this._groups.Add(group);
                groupIndex++;
            }
        }
Esempio n. 6
0
        // create media detail group
        private async Task GetDetailResultJsonData(string jsonData)
        {
            if ((jsonData == null) || (jsonData.Equals(String.Empty)))
            {
                return;
            }

            ReDataGroup group = null;

            JsonArray groupJsonArray = JsonArray.Parse(jsonData);

            foreach (JsonValue groupValue in groupJsonArray)
            {
                JsonObject jsonObject = groupValue.GetObject();

                string    playUrl   = "";
                JsonArray jsonArray = jsonObject["playlist"].GetArray();

                foreach (JsonValue itemValue in jsonArray)
                {
                    JsonObject itemObject        = itemValue.GetObject();
                    JsonArray  playlistJsonArray = itemObject["list"].GetArray();

                    foreach (JsonValue playUrlValue in playlistJsonArray)
                    {
                        JsonObject playUrlObject = playUrlValue.GetObject();
                        playUrl = playUrlObject.ContainsKey("url") ? playUrlObject["url"].GetString() : "";
                        break;
                    }
                }

                string uniqueId    = Helpers.GetJosnObjectStringValue(jsonObject, "_id");      //jsonObject.ContainsKey("_id") ? jsonObject["_id"].GetString() : "";
                string title       = Helpers.GetJosnObjectStringValue(jsonObject, "title");    //jsonObject.ContainsKey("title") ? jsonObject["title"].GetString() : "";
                string actor       = Helpers.GetJosnObjectStringValue(jsonObject, "actor");    //jsonObject.ContainsKey("actor") ? jsonObject["actor"].GetString() : "";
                string director    = Helpers.GetJosnObjectStringValue(jsonObject, "director"); //jsonObject.ContainsKey("director") ? jsonObject["director"].GetString() : "";
                string cate        = Helpers.GetJosnObjectStringValue(jsonObject, "cate");     //jsonObject.ContainsKey("cate") ? jsonObject["cate"].GetString() : "";
                string imagePath   = Helpers.GetJosnObjectStringValue(jsonObject, "img");      //jsonObject.ContainsKey("img") ? jsonObject["img"].GetString() : "";
                string description = Helpers.GetJosnObjectStringValue(jsonObject, "info");     //jsonObject.ContainsKey("info") ? jsonObject["info"].GetString() : "";
                group = new ReDataGroup(uniqueId, title, actor, director, imagePath, description, playUrl);
            }
            if (group != null)
            {
                await _reDetailDataSource.GetWebServiceRelatedDataAsync(group);
            }
        }
Esempio n. 7
0
        private async Task GetReDataAsync()
        {
            if (this._groups.Count != 0)
            {
                return;
            }

            Uri dataUri = new Uri("ms-appx:///DataModel/ReData.json");

            StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(dataUri);

            string jsonText = await FileIO.ReadTextAsync(file);

            JsonObject jsonObject = JsonObject.Parse(jsonText);
            JsonArray  jsonArray  = jsonObject["Groups"].GetArray();

            foreach (JsonValue groupValue in jsonArray)
            {
                JsonObject  groupObject = groupValue.GetObject();
                ReDataGroup group       = new ReDataGroup(groupObject["UniqueId"].GetString(),
                                                          groupObject["Title"].GetString());
                int index = 0;
                foreach (JsonValue itemValue in groupObject["Items"].GetArray())
                {
                    JsonObject itemObject = itemValue.GetObject();

                    string     uniqueIdTmp    = itemObject["UniqueId"].GetString();
                    string     titleTmp       = itemObject["Title"].GetString();
                    string     subTitleTmp    = itemObject["Subtitle"].GetString();
                    string     imagePathTmp   = itemObject["ImagePath"].GetString();
                    string     descriptionTmp = itemObject["Description"].GetString();
                    string     playUrlTmp     = itemObject["PlayUrl"].GetString();
                    ReDataItem ri             = new ReDataItem(index, uniqueIdTmp);
                    group.Items.Add(ri);
                    index++;
                }
                this.Groups.Add(group);
            }
        }
Esempio n. 8
0
        // add related medias to group's items
        private void GetRelatedResultJsonData(ReDataGroup group, string jsonData)
        {
            if (string.IsNullOrEmpty(jsonData))
            {
                this._groups.Add(group);
                return;
            }

            if (jsonData.Equals("null"))
            {
                this._groups.Add(group);
                return;
            }

            JsonArray groupJsonArray = JsonArray.Parse(jsonData);
            int indexInGroup = 0;
            foreach (JsonValue groupValue in groupJsonArray)
            {
                JsonObject jsonObject = groupValue.GetObject();

                string playUrl = "";
                JsonArray jsonArray = jsonObject["playlist"].GetArray();

                foreach (JsonValue itemValue in jsonArray)
                {
                    JsonObject itemObject = itemValue.GetObject();
                    JsonArray playlistJsonArray = itemObject["list"].GetArray();

                    foreach (JsonValue playUrlValue in playlistJsonArray)
                    {
                        JsonObject playUrlObject = playUrlValue.GetObject();
                        playUrl = playUrlObject.ContainsKey("url") ? playUrlObject["url"].GetString() : "";
                        break;
                    }
                }

                string uniqueId = Helpers.GetJosnObjectStringValue(jsonObject, "_id");//jsonObject.ContainsKey("_id") ? jsonObject["_id"].GetString() : "";
                string title = Helpers.GetJosnObjectStringValue(jsonObject, "title");//jsonObject.ContainsKey("title") ? jsonObject["title"].GetString() : "";
                string actor = Helpers.GetJosnObjectStringValue(jsonObject, "actor");//jsonObject.ContainsKey("actor") ? jsonObject["actor"].GetString() : "";
                string director = Helpers.GetJosnObjectStringValue(jsonObject, "director");//jsonObject.ContainsKey("director") ? jsonObject["director"].GetString() : "";
                string cate = Helpers.GetJosnObjectStringValue(jsonObject, "cate");//jsonObject.ContainsKey("cate") ? jsonObject["cate"].GetString() : "";
                string imagePath = Helpers.GetJosnObjectStringValue(jsonObject, "img");//jsonObject.ContainsKey("img") ? jsonObject["img"].GetString() : "";
                string description = Helpers.GetJosnObjectStringValue(jsonObject, "info");//jsonObject.ContainsKey("info") ? jsonObject["info"].GetString() : "";
                group.Items.Add(new ReDataItem(indexInGroup, uniqueId, title, actor, director, imagePath, description, playUrl));

                indexInGroup++;
            }
            this._groups.Add(group);
        }
Esempio n. 9
0
        private async Task GetWebServiceRelatedDataAsync(ReDataGroup group)
        {
            try
            {
                if ((group == null) && (group.UniqueId.Equals(string.Empty)))
                {
                    return;
                }

                string requestUrl = "http://replatform.cloudapp.net:8000/getrelated/?id={0}&uuid={1}&type={2}&from={3}&to={4}";
                //string requestUrl = "http://192.168.1.215:9999/getrelated/?id={0}";
                requestUrl = String.Format(requestUrl, group.UniqueId, App.gDeviceName, App.gDeviceType, App.NavigationRoadmap.GetFrom(), App.NavigationRoadmap.GetTo());

                HttpBaseProtocolFilter filter = new HttpBaseProtocolFilter();
                filter.AutomaticDecompression = true;
                HttpClient httpClient = new HttpClient(filter);
                CancellationTokenSource cts = new CancellationTokenSource();

                filter.CacheControl.ReadBehavior = HttpCacheReadBehavior.Default;
                filter.CacheControl.WriteBehavior = HttpCacheWriteBehavior.Default;

                Uri resourceUri;
                if (!Uri.TryCreate(requestUrl.Trim(), UriKind.Absolute, out resourceUri))
                {
                    return;
                }

                HttpResponseMessage response = await httpClient.GetAsync(resourceUri).AsTask(cts.Token);
                string jsonText = await Helpers.GetResultAsync(response, cts.Token);

                if (filter != null)
                {
                    filter.Dispose();
                    filter = null;
                }

                if (httpClient != null)
                {
                    httpClient.Dispose();
                    httpClient = null;
                }

                if (cts != null)
                {
                    cts.Dispose();
                    cts = null;
                }

                GetRelatedResultJsonData(group, jsonText);                
            }
            catch (Exception e) 
            {
                String ex = e.Message;
            }
        }
Esempio n. 10
0
        // create media detail group
        private async Task GetDetailResultJsonData(string jsonData)
        {
            if ((jsonData == null) || (jsonData.Equals(String.Empty)))
            {
                return;
            }

            ReDataGroup group = null;

            JsonArray groupJsonArray = JsonArray.Parse(jsonData);
            foreach (JsonValue groupValue in groupJsonArray)
            {
                JsonObject jsonObject = groupValue.GetObject();

                string playUrl = "";
                JsonArray jsonArray = jsonObject["playlist"].GetArray();

                foreach (JsonValue itemValue in jsonArray)
                {
                    JsonObject itemObject = itemValue.GetObject();
                    JsonArray playlistJsonArray = itemObject["list"].GetArray();

                    foreach (JsonValue playUrlValue in playlistJsonArray)
                    {
                        JsonObject playUrlObject = playUrlValue.GetObject();
                        playUrl = playUrlObject.ContainsKey("url") ? playUrlObject["url"].GetString() : "";
                        break;
                    }
                }

                string uniqueId = Helpers.GetJosnObjectStringValue(jsonObject, "_id");//jsonObject.ContainsKey("_id") ? jsonObject["_id"].GetString() : "";
                string title = Helpers.GetJosnObjectStringValue(jsonObject, "title");//jsonObject.ContainsKey("title") ? jsonObject["title"].GetString() : "";
                string actor = Helpers.GetJosnObjectStringValue(jsonObject, "actor");//jsonObject.ContainsKey("actor") ? jsonObject["actor"].GetString() : "";
                string director = Helpers.GetJosnObjectStringValue(jsonObject, "director");//jsonObject.ContainsKey("director") ? jsonObject["director"].GetString() : "";
                string cate = Helpers.GetJosnObjectStringValue(jsonObject, "cate");//jsonObject.ContainsKey("cate") ? jsonObject["cate"].GetString() : "";
                string imagePath = Helpers.GetJosnObjectStringValue(jsonObject, "img");//jsonObject.ContainsKey("img") ? jsonObject["img"].GetString() : "";
                string description = Helpers.GetJosnObjectStringValue(jsonObject, "info");//jsonObject.ContainsKey("info") ? jsonObject["info"].GetString() : "";
                group = new ReDataGroup(uniqueId, title, actor, director, imagePath, description, playUrl);
            }
            if (group != null)
            {
                await _reDetailDataSource.GetWebServiceRelatedDataAsync(group);
            }
        }
Esempio n. 11
0
        private void GetResultJsonData(string jsonData)
        {
            if (string.IsNullOrEmpty(jsonData))
            {
                return;
            }

            if (jsonData.Equals("null"))
            {
                return;
            }

            _groups = new ObservableCollection <ReDataGroup>();

            string      groupId    = "Guess";
            string      groupTitle = "Guess";
            ReDataGroup group      = new ReDataGroup(groupId, groupTitle);

            JsonArray groupJsonArray = JsonArray.Parse(jsonData);
            int       indexInGroup   = 0;

            foreach (JsonValue groupValue in groupJsonArray)
            {
                JsonObject jsonObject = groupValue.GetObject();

                string    playUrl   = "";
                JsonArray jsonArray = jsonObject["playlist"].GetArray();

                foreach (JsonValue itemValue in jsonArray)
                {
                    JsonObject itemObject        = itemValue.GetObject();
                    JsonArray  playlistJsonArray = itemObject["list"].GetArray();

                    foreach (JsonValue playUrlValue in playlistJsonArray)
                    {
                        JsonObject playUrlObject = playUrlValue.GetObject();
                        playUrl = playUrlObject.ContainsKey("url") ? playUrlObject["url"].GetString() : "";
                        break;
                    }
                }

                string uniqueId    = Helpers.GetJosnObjectStringValue(jsonObject, "_id");
                string title       = Helpers.GetJosnObjectStringValue(jsonObject, "title");
                string actor       = Helpers.GetJosnObjectStringValue(jsonObject, "actor");
                string director    = Helpers.GetJosnObjectStringValue(jsonObject, "director");
                string cate        = Helpers.GetJosnObjectStringValue(jsonObject, "cate");
                string imagePath   = Helpers.GetJosnObjectStringValue(jsonObject, "img");
                string description = Helpers.GetJosnObjectStringValue(jsonObject, "info");
                string score       = Helpers.GetJosnObjectStringValue(jsonObject, "banben");
                if (string.IsNullOrEmpty(score))
                {
                    var loader = new Windows.ApplicationModel.Resources.ResourceLoader();
                    score = loader.GetString("DefaultScore");
                }
                else
                {
                    score = score.Substring(1);
                }
                group.Items.Add(new ReDataItem(indexInGroup, uniqueId, title, actor, director, imagePath, description, playUrl, score));

                indexInGroup++;
            }
            this._groups.Add(group);
        }
Esempio n. 12
0
        private void GetSearchResultJsonData(string jsonData)
        {
            if (string.IsNullOrEmpty(jsonData))
            {
                return;
            }

            if (jsonData.Equals("null"))
            {
                return;
            }

            _groups = new ObservableCollection<ReDataGroup>();

            string groupId = "search";
            string groupTitle = "search";
            ReDataGroup group = new ReDataGroup(groupId, groupTitle);

            JsonArray groupJsonArray = JsonArray.Parse(jsonData);
            int indexInGroup = 0;
            foreach (JsonValue groupValue in groupJsonArray)
            {
                JsonObject jsonObject = groupValue.GetObject();

                string playUrl = "";
                JsonArray jsonArray = jsonObject["playlist"].GetArray();

                foreach (JsonValue itemValue in jsonArray)
                {
                    JsonObject itemObject = itemValue.GetObject();
                    JsonArray playlistJsonArray = itemObject["list"].GetArray();

                    foreach (JsonValue playUrlValue in playlistJsonArray)
                    {
                        JsonObject playUrlObject = playUrlValue.GetObject();
                        playUrl = playUrlObject.ContainsKey("url") ? playUrlObject["url"].GetString() : "";
                        break;
                    }
                }

                string uniqueId = jsonObject.ContainsKey("_id") ? jsonObject["_id"].GetString() : "";
                string title = jsonObject.ContainsKey("title") ? jsonObject["title"].GetString() : "";
                string actor = jsonObject.ContainsKey("actor") ? jsonObject["actor"].GetString() : "";
                string director = jsonObject.ContainsKey("director") ? jsonObject["director"].GetString() : "";
                string cate = jsonObject.ContainsKey("cate") ? jsonObject["cate"].GetString() : "";
                string imagePath = jsonObject.ContainsKey("img") ? jsonObject["img"].GetString() : "";
                string description = jsonObject.ContainsKey("info") ? jsonObject["info"].GetString() : "";
                group.Items.Add(new ReDataItem(indexInGroup, uniqueId, title, actor, director, imagePath, description, playUrl));
                
                indexInGroup++;
            }
            this._groups.Add(group);
        }
Esempio n. 13
0
        private void GetContentResultJsonData(string jsonData)
        {
            if (string.IsNullOrWhiteSpace(jsonData))
            {
                return;
            }

            if (jsonData.Equals("null"))
            {
                return;
            }

            _contents = new ObservableCollection<ReDataGroup>();

            JsonArray originalGroupJsonArray = JsonArray.Parse(jsonData);
            foreach (JsonValue originalGroupValue in originalGroupJsonArray)
            {
                JsonObject originalJsonObject = originalGroupValue.GetObject();


                string groupId = Helpers.GetJosnObjectStringValue(originalJsonObject, "_id");
                string groupTitle = Helpers.GetJosnObjectStringValue(originalJsonObject, "name");
                ReDataGroup group = new ReDataGroup(groupId, groupTitle);

                JsonArray groupJsonArray = originalJsonObject["cor"].GetArray();
                int indexInGroup = 0;
                foreach (JsonValue groupValue in groupJsonArray)
                {
                    JsonObject contentJsonObject = groupValue.GetObject();

                    string playUrl = "";
                    JsonArray playUrlJsonArray = contentJsonObject["playlist"].GetArray();

                    foreach (JsonValue itemValue in playUrlJsonArray)
                    {
                        JsonObject itemObject = itemValue.GetObject();
                        JsonArray playlistJsonArray = itemObject["list"].GetArray();

                        foreach (JsonValue playUrlValue in playlistJsonArray)
                        {
                            JsonObject playUrlObject = playUrlValue.GetObject();
                            playUrl = playUrlObject.ContainsKey("url") ? playUrlObject["url"].GetString() : "";
                            break;
                        }
                    }

                    string uniqueId = Helpers.GetJosnObjectStringValue(contentJsonObject, "_id");
                    string title = Helpers.GetJosnObjectStringValue(contentJsonObject, "title");//jsonObject.ContainsKey("title") ? jsonObject["title"].GetString() : "";
                    string actor = Helpers.GetJosnObjectStringValue(contentJsonObject, "actor");//jsonObject.ContainsKey("actor") ? jsonObject["actor"].GetString() : "";
                    string director = Helpers.GetJosnObjectStringValue(contentJsonObject, "director");//jsonObject.ContainsKey("director") ? jsonObject["director"].GetString() : "";
                    string cate = Helpers.GetJosnObjectStringValue(contentJsonObject, "cate");//jsonObject.ContainsKey("cate") ? jsonObject["cate"].GetString() : "";
                    string imagePath = Helpers.GetJosnObjectStringValue(contentJsonObject, "img");//jsonObject.ContainsKey("img") ? jsonObject["img"].GetString() : "";
                    string description = Helpers.GetJosnObjectStringValue(contentJsonObject, "info");//jsonObject.ContainsKey("info") ? jsonObject["info"].GetString() : "";
                    string score = Helpers.GetJosnObjectStringValue(contentJsonObject, "banben");
                    if (string.IsNullOrEmpty(score))
                    {
                        var loader = new Windows.ApplicationModel.Resources.ResourceLoader();
                        score = loader.GetString("DefaultScore");
                    }
                    else
                    {
                        score = score.Substring(1);
                    }
                    string year = Helpers.GetJosnObjectStringValue(contentJsonObject, "year");
                    group.Items.Add(new ReDataItem(indexInGroup, uniqueId, title, actor, director, imagePath, description, playUrl, score, year));
                
                    indexInGroup++;
                }
                this._contents.Add(group);
            }            
        }
Esempio n. 14
0
        private void GetResultJsonData(string jsonData)
        {
            if (string.IsNullOrEmpty(jsonData))
            {
                return;
            }

            if (jsonData.Equals("null"))
            {
                return;
            }

            _groups = new ObservableCollection<ReDataGroup>();

            JsonObject originalJsonObject = JsonObject.Parse(jsonData);
            JsonArray groupJsonArray = originalJsonObject["data"].GetArray();

            int groupIndex = 0;
            foreach (JsonValue groupValue in groupJsonArray)
            {
                JsonObject jsonObject = groupValue.GetObject();

                string groupId = Helpers.GetJosnObjectStringValue(jsonObject, "_id");
                string groupTitle = Helpers.GetJosnObjectStringValue(jsonObject, "name");
                string description = Helpers.GetJosnObjectIntegerValue(jsonObject, "count");
                string imagePath = Helpers.GetJosnObjectStringValue(jsonObject, "img");
                ReDataGroup group = new ReDataGroup(groupId, groupTitle, imagePath, description);

                JsonArray collectionJsonArray = jsonObject["cor"].GetArray();
                int indexInGroup = 0;
                foreach (JsonValue collectionValue in collectionJsonArray)
                {
                    JsonObject collectionObject = collectionValue.GetObject();
                    string uniqueId = Helpers.GetJosnObjectStringValue(collectionObject, "id");
                    string itemTitle = Helpers.GetJosnObjectStringValue(collectionObject, "name");
                    string itemDescription = Helpers.GetJosnObjectIntegerValue(collectionObject, "count");
                    string itemImagePath = Helpers.GetJosnObjectStringValue(collectionObject, "img");
                    group.Items.Add(new ReDataItem(indexInGroup, uniqueId, itemTitle, itemImagePath, itemDescription));
                    indexInGroup++;
                }
                
                this._groups.Add(group);
                groupIndex++;
            }
        }