Beispiel #1
0
        private async Task load()
        {
            try
            {
                List <GridClass> lg     = new List <GridClass>();
                GridClass        gd     = new GridClass();
                StorageFolder    folder = await ApplicationData.Current.LocalFolder.CreateFolderAsync(testlol + "My Collections", CreationCollisionOption.OpenIfExists);

                IReadOnlyList <StorageFolder> sf = await folder.GetFoldersAsync();

                gd.Image    = new BitmapImage(new Uri(this.BaseUri, "Assets/whataboutme.jpg"));
                gd.authName = "test me";
                gd.title    = "about me";
                lg.Add(gd);
                foreach (StorageFolder s in sf)
                {
                    gd = new GridClass();
                    ob = new MeriCollection();
                    StorageFile sampleFile = await s.GetFileAsync("UserName.txt");

                    var t = await sampleFile.OpenAsync(FileAccessMode.Read);

                    Stream na = t.AsStreamForRead();
                    using (var streamReader = new StreamReader(na, Encoding.UTF8))
                    {
                        string line;
                        line = streamReader.ReadToEnd();
                        ob   = JsonConvert.DeserializeObject <MeriCollection>(line);
                    }

                    IReadOnlyList <StorageFile> fi = await s.GetFilesAsync();

                    gd          = new GridClass();
                    gd.title    = ob.BookName;
                    gd.authName = ob.UserName;
                    lg.Add(gd);
                }

                if (lg.Count != 0)
                {
                    event1.ItemsSource = lg;
                }
                else
                {
                    LoadingBar.Visibility = Visibility.Collapsed;
                    ErrorBox.Text         = "No Collections created";
                    ErrorBox.Visibility   = Visibility.Visible;
                }
            }
            catch (Exception)
            {
                LoadingBar.Visibility = Visibility.Collapsed;
                await(new MessageDialog("Oops Something Bad Happened :(:(")).ShowAsync();
            }
        }
Beispiel #2
0
        private async void Buy_Click(object sender, RoutedEventArgs e)
        {
            MeriCollection ob = new MeriCollection();

            LoadingBar.Visibility = Visibility.Visible;

            LoadingBar.IsIndeterminate = true;
            try
            {
                items2 = await Table2.Where(Book
                                            => Book.Id == rec.sel.Id).ToCollectionAsync();

                ob.BookId   = rec.sel.Id;
                ob.UserName = testlol;
                foreach (Book lol in items2)
                {
                    ob.BookName = lol.Title;
                }
            }
            catch (Exception)
            {
                LoadingBar.Visibility = Visibility.Collapsed;
                await(new MessageDialog("Something bad happened :(:(")).ShowAsync();
                return;
            }
            try
            {
                var    test  = sender as Button;
                var    test2 = test.Parent as Grid;
                var    test3 = test2.Children[2] as TextBlock;
                var    test4 = test2.Children[0] as TextBlock;
                string ab    = test4.Text.Substring((test4.Text.Length) - 2);
                string nam   = "";
                foreach (char c in ab)
                {
                    if (char.IsDigit(c))
                    {
                        nam = nam + c.ToString();
                    }
                }

                ob.ChapterNo = nam;
                ob.ChapterId = test3.Text;
                App.mc.Add(ob);
                LoadingBar.Visibility = Visibility.Collapsed;
                await(new MessageDialog("Added Successful")).ShowAsync();
            }
            catch (Exception)
            {
                LoadingBar.Visibility = Visibility.Collapsed;
                await(new MessageDialog("Can't Add now please try after sometime")).ShowAsync();
            }
        }
Beispiel #3
0
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            LoadingBar.IsEnabled  = true;
            LoadingBar.Visibility = Visibility.Visible;
            App.mc.Clear();

            string         sn = "";
            MeriCollection l  = new MeriCollection();

            l.BookName = rec.Name;
            l.UserName = testlol;
            sn         = JsonConvert.SerializeObject(l);
            try
            {
                StorageFolder mainFol = await ApplicationData.Current.LocalFolder.CreateFolderAsync(testlol + "My Collections", CreationCollisionOption.OpenIfExists);

                if (mainFol != null)
                {
                    StorageFolder folder = await mainFol.CreateFolderAsync(rec.Name, CreationCollisionOption.OpenIfExists);

                    if (folder != null)
                    {
                        Uri        url             = new Uri("https://www.ebookstreamer.me/downloads");
                        HttpClient httpClient      = new HttpClient();
                        var        myClientHandler = new HttpClientHandler();


                        foreach (string s in Chap)
                        {
                            HttpResponseMessage httpResponse = new HttpResponseMessage();
                            var content = new FormUrlEncodedContent(new[]
                            {
                                new KeyValuePair <string, string>("id", s)
                            });
                            httpResponse = await httpClient.PostAsync(url, content);

                            httpResponse.EnsureSuccessStatusCode();
                            Stream str = await httpResponse.Content.ReadAsStreamAsync();

                            byte[] pd = new byte[str.Length];
                            str.Read(pd, 0, pd.Length);
                            items = await Table.Where(Chapter
                                                      => Chapter.Id == s).ToCollectionAsync();

                            StorageFile file = await folder.CreateFileAsync((items[0].sno + 1).ToString() + ".txt", CreationCollisionOption.ReplaceExisting);

                            using (var fileStream = await file.OpenStreamForWriteAsync())
                            {
                                str.Seek(0, SeekOrigin.Begin);
                                await str.CopyToAsync(fileStream);
                            }
                        }
                        StorageFile useFile =
                            await folder.CreateFileAsync("UserName.txt", CreationCollisionOption.ReplaceExisting);

                        await Windows.Storage.FileIO.WriteTextAsync(useFile, sn);
                    }
                }
                LoadingBar.Visibility = Visibility.Collapsed;
                await(new MessageDialog("Your collection was made!!")).ShowAsync();
                Frame.Navigate(typeof(MyCollection));
            }
            catch (Exception)
            {
                LoadingBar.Visibility = Visibility.Collapsed;
                await(new MessageDialog("Your collection was not made:(:(")).ShowAsync();
                Frame.Navigate(typeof(MyCollection));
            }
        }
Beispiel #4
0
        async Task retreive(string name)
        {
            try
            {
                List <GridClass> lg = new List <GridClass>();
                GridClass        gd = new GridClass();

                if (name.CompareTo("about me") == 0)
                {
                    gd.Image    = new BitmapImage(new Uri(this.BaseUri, "Assets/whataboutme.jpg"));
                    gd.authName = "";
                    gd.title    = "about me";
                    lg.Add(gd);
                    event1.Visibility  = Visibility.Collapsed;
                    event2.ItemsSource = lg;
                    event2.Visibility  = Visibility.Visible;
                }
                else
                {
                    StorageFolder mainFol = await ApplicationData.Current.LocalFolder.CreateFolderAsync(testlol + "My Collections", CreationCollisionOption.OpenIfExists);

                    if (mainFol != null)
                    {
                        ob = new MeriCollection();
                        StorageFolder folder = await mainFol.CreateFolderAsync(name, CreationCollisionOption.OpenIfExists);

                        openBook = folder;

                        StorageFile sampleFile = await folder.GetFileAsync("UserName.txt");

                        var t = await sampleFile.OpenAsync(FileAccessMode.Read);

                        Stream na = t.AsStreamForRead();
                        using (var streamReader = new StreamReader(na, Encoding.UTF8))
                        {
                            string line;
                            line = streamReader.ReadToEnd();
                            ob   = JsonConvert.DeserializeObject <MeriCollection>(line);
                        }
                        IReadOnlyList <StorageFile> sf = await folder.GetFilesAsync();

                        foreach (StorageFile s in sf)
                        {
                            gd = new GridClass();
                            if (s.Name.CompareTo("UserName.txt") == 0)
                            {
                                break;
                            }
                            if (s.Name.CompareTo("image.jpeg") == 0)
                            {
                                break;
                            }
                            gd          = new GridClass();
                            gd.title    = "Chapter No:" + s.DisplayName;
                            gd.authName = "";
                            lg.Add(gd);
                        }
                        event1.Visibility  = Visibility.Collapsed;
                        event2.ItemsSource = lg;
                        event2.Visibility  = Visibility.Visible;
                    }
                }
            }
            catch (Exception)
            {
                await(new MessageDialog("ahhmm Something not so good Happened :(:(")).ShowAsync();
            }
        }
Beispiel #5
0
        private async void NextBar_Click(object sender, RoutedEventArgs e)
        {
            int i = 0;

            LoadingBar.Visibility = Visibility.Visible;
            App.mc.Clear();
            foreach (CollSort d in myList)
            {
                MeriCollection c = new MeriCollection();
                c.BookId    = d.BookId;
                c.BookName  = d.BookName;
                c.ChapterId = d.ChapterId;
                c.ChapterNo = d.ChapterNo;
                c.UserName  = d.UserName;
                App.mc.Insert(i, c);
                i++;
            }
            LoadingBar.IsActive = true;
            string         sn = "";
            MeriCollection l  = new MeriCollection();

            l.BookName = CollName.Text;
            l.UserName = testlol;
            sn         = JsonConvert.SerializeObject(l);
            try
            {
                StorageFolder mainFol = await ApplicationData.Current.LocalFolder.CreateFolderAsync(testlol + "My Collections", CreationCollisionOption.OpenIfExists);

                if (mainFol != null)
                {
                    StorageFolder folder = await mainFol.CreateFolderAsync(CollName.Text, CreationCollisionOption.OpenIfExists);

                    if (folder != null)
                    {
                        Uri        url             = new Uri("https://www.ebookstreamer.me/downloads");
                        HttpClient httpClient      = new HttpClient();
                        var        myClientHandler = new HttpClientHandler();


                        foreach (MeriCollection d in App.mc)
                        {
                            HttpResponseMessage httpResponse = new HttpResponseMessage();
                            var content = new FormUrlEncodedContent(new[]
                            {
                                new KeyValuePair <string, string>("id", d.ChapterId)
                            });
                            httpResponse = await httpClient.PostAsync(url, content);

                            httpResponse.EnsureSuccessStatusCode();
                            Stream str = await httpResponse.Content.ReadAsStreamAsync();

                            byte[] pd = new byte[str.Length];
                            str.Read(pd, 0, pd.Length);

                            StorageFile file = await folder.CreateFileAsync(d.ChapterNo + ".txt", CreationCollisionOption.ReplaceExisting);

                            using (var fileStream = await file.OpenStreamForWriteAsync())
                            {
                                str.Seek(0, SeekOrigin.Begin);
                                await str.CopyToAsync(fileStream);
                            }
                        }
                        StorageFile useFile =
                            await folder.CreateFileAsync("UserName.txt", CreationCollisionOption.ReplaceExisting);

                        await Windows.Storage.FileIO.WriteTextAsync(useFile, sn);
                    }
                }
                LoadingBar.Visibility = Visibility.Collapsed;
                await(new MessageDialog("Your collection was made!!")).ShowAsync();
                Frame.Navigate(typeof(ShareColl), CollName.Text);
            }
            catch (Exception)
            {
            }
        }