Пример #1
0
        public async Task Load( )
        {
            var p = Path.Combine(Package.Current.InstalledLocation.Path, "Assets/moq.json");
            try
            {
                var folder = await StorageFolder.GetFolderFromPathAsync(Path.GetDirectoryName(p));
                using (var stream = await folder.OpenStreamForReadAsync(Path.GetFileName(p)))
                {
                    using (var streamReader = new StreamReader(stream))
                    {
                        var content = streamReader.ReadToEnd();
                        try
                        {
                            SearchQueryResponse = JsonConvert.DeserializeObject<FanousQueryResponse>(content);
                            TotalPages = SearchQueryResponse.search.interval.nb_pages;
                            foreach (var a in SearchQueryResponse.search.ayas)
                            {
                                a.aya.keyword =
                                    SearchQueryResponse.search.words.individual.FirstOrDefault().word;
                            }
                            AyatesCollection =
                                new ObservableCollection<AyaElement>(SearchQueryResponse.search.ayas.
                                    OrderByDescending((x) => x.aya.text_no_highlight.Length));

                            var r = AyatesCollection.FirstOrDefault().aya.text;
                           
                            return;
                        }
                        catch (Exception e)
                        {

                            throw e;
                        }
                    }
                }
            }
            catch (Exception e)
            {

                throw e;
            }
        }
Пример #2
0
        public async Task Search(string query, int page)
        {
            if (!IsConnectedToInternet())
            {
                var messageDialog = new MessageDialog("البرنامج لم يستطع الاتصال بالانترنت، يرجى التأكد من وجود الاتصال ");
                messageDialog.Commands.Add(new UICommand("موافق", delegate(IUICommand command)
                {
                    // write your business logic
                }));

                // call the ShowAsync() method to display the message dialog
                messageDialog.ShowAsync();   
            }
            else
            {
  
            ///TODO delete this code
            /// 
          //var p = Path.Combine(Package.Current.InstalledLocation.Path, "Assets/moq.json");
          //try
          //{
          //    if (SearchQueryResponse != null)
          //    {
          //        NavigateCommand.Execute(null);
          //        return;
          //    }
          //         
          //
          //    var folder = await StorageFolder.GetFolderFromPathAsync(Path.GetDirectoryName(p));
          //    using (var stream = await folder.OpenStreamForReadAsync(Path.GetFileName(p)))
          //    {
          //        using (var streamReader = new StreamReader(stream))
          //        {
          //            var content = streamReader.ReadToEnd();
          //            try
          //            {
          //                SearchQueryResponse = JsonConvert.DeserializeObject<FanousQueryResponse>(content);
          //                TotalPages = SearchQueryResponse.search.interval.nb_pages;
          //                foreach (var a in SearchQueryResponse.search.ayas)
          //                {
          //                    a.aya.keyword =
          //                        SearchQueryResponse.search.words.individual.FirstOrDefault().word;
          //                }
          //                AyatesCollection =
          //                    new ObservableCollection<AyaElement>(SearchQueryResponse.search.ayas.
          //                        OrderByDescending((x) => x.aya.text_no_highlight.Length));
          //
          //                var r = AyatesCollection.FirstOrDefault().aya.text;
          //                NavigateCommand.Execute(null);
          //                return;
          //            }
          //            catch (Exception e)
          //            {
          //                
          //                throw e;
          //            }
          //        }
          //    }
          //}
          //catch (Exception e)
          //{
          //    
          //    throw e ;
          //}
          //
          //return ;
 
            using (var client = new HttpClient())
            {
                var uri = SearchApiUri + "&unit=aya&query=" + query + "&highlight=html&page=" + page + "&sortedby=score&&translation=en.maududi";
                var respo = await client.GetAsync(uri);
                respo.EnsureSuccessStatusCode();

                var content = await respo.Content.ReadAsStringAsync();
                try
                {
                    SearchQueryResponse = JsonConvert.DeserializeObject<FanousQueryResponse>(content);
                    TotalPages = SearchQueryResponse.search.interval.nb_pages;
                    foreach (var a in SearchQueryResponse.search.ayas)
                    {
                        a.aya.keyword =
                            SearchQueryResponse.search.words.individual.FirstOrDefault().word;
                    }
                    AyatesCollection = 
                        new ObservableCollection<AyaElement>  (SearchQueryResponse.search.ayas.
                            OrderByDescending((x)=>x.aya.text_no_highlight.Length)); 
                    NavigateCommand.Execute(null);
                }
                catch (Exception e)
                {

                    throw e;
                }

            }

            }
        }