Beispiel #1
0
        private async Task DownloadCharacters()
        {
            if (ConnectionTest.VndbTcpSocketTest() == false)
            {
                Globals.Logger.Warn("Could not connect to Vndb API over SSL");
                Globals.StatusBar.SetOnlineStatusColor(false);
                Globals.StatusBar.IsShowOnlineStatusEnabled = true;
                await Task.Delay(3500);

                Globals.StatusBar.IsShowOnlineStatusEnabled = false;
                return;
            }
            try
            {
                IsCharacterDownloading             = true;
                Globals.StatusBar.IsWorkProcessing = true;
                Globals.StatusBar.ProgressText     = "Downloading Characters";
                Globals.StatusBar.IsDownloading    = true;
                using (var context = new DatabaseContext())
                {
                    List <string> characterList = context.VnCharacter.Where(x => x.VnId == Globals.VnId).Select(i => i.ImageLink).ToList();
                    if (characterList.Count <= 0)
                    {
                        return;
                    }
                    foreach (string character in characterList)
                    {
                        if (!Directory.Exists($@"{Globals.DirectoryPath}\Data\images\characters\{Globals.VnId}"))
                        {
                            Directory.CreateDirectory($@"{Globals.DirectoryPath}\Data\images\characters\{Globals.VnId}");
                        }
                        string path = $@"{Globals.DirectoryPath}\Data\images\characters\{Globals.VnId}\{Path.GetFileName(character)}";

                        if (!File.Exists(path) && !string.IsNullOrEmpty(character))
                        {
                            WebClient client = new WebClient();
                            await client.DownloadFileTaskAsync(new Uri(character), path);

                            client.Dispose();
                        }
                    }
                }
                Globals.StatusBar.IsDownloading    = false;
                Globals.StatusBar.IsWorkProcessing = false;
                Globals.StatusBar.ProgressText     = string.Empty;
                IsCharacterDownloading             = false;
            }
            catch (System.Net.WebException ex)
            {
                Globals.Logger.Error(ex);
                throw;
            }
            catch (Exception ex)
            {
                Globals.Logger.Error(ex);
                throw;
            }
        }
        private async void Validate()
        {
            if (ConnectionTest.VndbTcpSocketTest() == false)
            {
                Globals.Logger.Warn("Could not connect to Vndb API over SSL");
                Globals.StatusBar.SetOnlineStatusColor(false);
                Globals.StatusBar.IsShowOnlineStatusEnabled = true;
                await Task.Delay(3500);

                Globals.StatusBar.IsShowOnlineStatusEnabled = false;
                return;
            }
            try
            {
                IsUserInputEnabled = false;
                Globals.StatusBar.IsWorkProcessing = true;
                Globals.StatusBar.ProgressText     = "Checking input";
                ValidateExe();
                //set validation rules here, so they are are checked on submit
                ConfigureValidationRules();
                Validator.ResultChanged += OnValidationResultChanged;
                await ValidateAsync();

                if (IsValid == true)
                {
                    var    bts      = new BoolToStringConverter();
                    string idOrName = (string)bts.Convert(IsNameChecked, null, null, CultureInfo.InvariantCulture);
                    switch (idOrName)
                    {
                    case "Vn Name" when SuggestedNamesCollection.Any(x => x.Contains(VnName)) && SuggestedNamesCollection.Count > 0:
                        _vnid = _vnNameList.Items[DropdownIndex].Id;

                        GetData();
                        break;

                    case "Vn ID" when InputVnId > 0:
                        _vnid = Convert.ToUInt32(InputVnId);
                        GetData();
                        break;

                    default:
                        break;
                    }
                }
                else
                {
                    Globals.StatusBar.IsWorkProcessing = false;
                    Globals.StatusBar.ProgressText     = String.Empty;
                    IsUserInputEnabled = true;
                }
            }
            catch (Exception ex)
            {
                Globals.Logger.Error(ex);
                throw;
            }
        }
        public async void SearchName()
        {
            if (ConnectionTest.VndbTcpSocketTest() == false)
            {
                Globals.Logger.Warn("Could not connect to Vndb API over SSL");
                Globals.StatusBar.SetOnlineStatusColor(false);
                Globals.StatusBar.IsShowOnlineStatusEnabled = true;
                await Task.Delay(3500);

                Globals.StatusBar.IsShowOnlineStatusEnabled = false;
                return;
            }
            try
            {
                if (VnName == null || VnName.Length <= 2)
                {
                    return;
                }
                if (IsRunning != false)
                {
                    return;
                }
                IsRunning = true;
                using (Vndb client = new Vndb(true))
                {
                    SuggestedNamesCollection.Clear();
                    _vnNameList = null;
                    _vnNameList = await client.GetVisualNovelAsync(VndbFilters.Search.Fuzzy(VnName));

                    if (_vnNameList == null)
                    {
                        HandleError.HandleErrors(client.GetLastError(), 0);
                    }
                    //namelist gets a  list of english names if text input was english, or japanese names if input was japanese
                    List <string> nameList = IsJapaneseText(VnName) == true?_vnNameList.Select(item => item.OriginalName).ToList() : _vnNameList.Select(item => item.Name).ToList();

                    foreach (string name in nameList)
                    {
                        if (!string.IsNullOrEmpty(name))
                        {
                            SuggestedNamesCollection.Add(name);
                        }
                    }
                    IsDropDownOpen = true;
                    IsRunning      = false;
                }
            }
            catch (Exception ex)
            {
                Globals.Logger.Error(ex);
                throw;
            }
        }
Beispiel #4
0
 private void SetUpdateData()
 {
     if (ConnectionTest.VndbTcpSocketTest() == false)
     {
         Globals.Logger.Warn("Could not connect to Vndb API over SSL");
         Globals.StatusBar.SetOnlineStatusColor(false);
         Globals.StatusBar.IsShowOnlineStatusEnabled = true;
         Thread.Sleep(3500);
         Globals.StatusBar.IsShowOnlineStatusEnabled = false;
         return;
     }
     SetVoteList();
     SetVnList();
     SetWishlist();
 }
        private async void Login()
        {
            if (ConnectionTest.VndbTcpSocketTest() == false)
            {
                Globals.Logger.Warn("Could not connect to Vndb API over SSL");
                Globals.StatusBar.SetOnlineStatusColor(false);
                Globals.StatusBar.IsShowOnlineStatusEnabled = true;
                await Task.Delay(3500);

                Globals.StatusBar.IsShowOnlineStatusEnabled = false;
                return;
            }
            if (!IsVnListSelected && !IsVoteListSelected && !IsWishlistSelected)
            {
                return;
            }
            IsUserInputEnabled = false;
            ConfigureValidationRules();
            Validator.ResultChanged += OnValidationResultChanged;
            await ValidateAsync();

            if (IsValid == true)
            {
                _userListCollection.Clear();
                ClearInfo();
                //Set a userID here for testing
                //_userId = 7887;

                if (IsVoteListSelected)
                {
                    GetVoteList();
                }
                else if (IsVnListSelected)
                {
                    GetVisualNovelList();
                }
                else if (IsWishlistSelected)
                {
                    GetWishlist();
                }

                SetMaxWidth();
            }
            else
            {
                IsUserInputEnabled = true;
            }
        }
        private async Task DownloadScreenshots()
        {
            if (ConnectionTest.VndbTcpSocketTest() == false)
            {
                Globals.Logger.Warn("Could not connect to Vndb API over SSL");
                Globals.StatusBar.SetOnlineStatusColor(false);
                Globals.StatusBar.IsShowOnlineStatusEnabled = true;
                await Task.Delay(3500);

                Globals.StatusBar.IsShowOnlineStatusEnabled = false;
                return;
            }
            try
            {
                IsScreenshotDownloading            = true;
                Globals.StatusBar.IsWorkProcessing = true;
                Globals.StatusBar.ProgressText     = "Downloading Screenshots";
                List <Screenshot> screenshotList = LoadScreenshotList();
                foreach (Screenshot screenshot in screenshotList)
                {
                    if (screenshotList.Count < 1)
                    {
                        return;
                    }
                    if (!Directory.Exists($@"{Globals.DirectoryPath}\Data\images\screenshots\{Globals.VnId}\thumbs"))
                    {
                        Directory.CreateDirectory($@"{Globals.DirectoryPath}\Data\images\screenshots\{Globals.VnId}\thumbs");
                    }

                    string pathNoExt      = $@"{Globals.DirectoryPath}\Data\images\screenshots\{Globals.VnId}\{Path.GetFileNameWithoutExtension(screenshot.Url)}";
                    string pathNoExtThumb = $@"{Globals.DirectoryPath}\Data\images\screenshots\{Globals.VnId}\thumbs\{Path.GetFileNameWithoutExtension(screenshot.Url)}";
                    string path           = $@"{Globals.DirectoryPath}\Data\images\screenshots\{Globals.VnId}\{Path.GetFileName(screenshot.Url)}";
                    string pathThumb      = $@"{Globals.DirectoryPath}\Data\images\screenshots\{Globals.VnId}\thumbs\{Path.GetFileName(screenshot.Url)}";
                    try
                    {
                        switch (screenshot.IsNsfw)
                        {
                        case true:
                            if (!File.Exists(pathNoExt))
                            {
                                Globals.StatusBar.IsDownloading = true;
                                WebClient client = new WebClient();
                                using (MemoryStream stream = new MemoryStream(await client.DownloadDataTaskAsync(new Uri(screenshot.Url))))
                                {
                                    string base64Img = Base64Converter.ImageToBase64(Image.FromStream(stream), ImageFormat.Jpeg);
                                    File.WriteAllText(pathNoExt, base64Img);
                                }
                                client.Dispose();
                            }
                            if (!File.Exists(pathNoExtThumb))
                            {
                                Globals.StatusBar.IsDownloading = true;
                                WebClient client = new WebClient();
                                using (MemoryStream stream = new MemoryStream(await client.DownloadDataTaskAsync(new Uri(screenshot.Url))))
                                {
                                    var bitmap = new BitmapImage();
                                    bitmap.BeginInit();
                                    bitmap.StreamSource = stream;
                                    bitmap.CacheOption  = BitmapCacheOption.OnLoad;
                                    bitmap.EndInit();
                                    bitmap.Freeze();
                                    Size thumbnailSize = GetThumbnailSize(bitmap);

                                    Image thumb = Image.FromStream(stream).GetThumbnailImage(thumbnailSize.Width, thumbnailSize.Height, () => false, IntPtr.Zero);
                                    if (!File.Exists($@"{Globals.DirectoryPath}\Data\images\screenshots\{Globals.VnId}\thumbs\{Path.GetFileNameWithoutExtension(screenshot.Url)}"))
                                    {
                                        File.WriteAllText(pathNoExtThumb, Base64Converter.ImageToBase64(thumb, ImageFormat.Jpeg));
                                    }
                                    thumb.Dispose();
                                }
                                client.Dispose();
                            }
                            Globals.StatusBar.IsDownloading = false;
                            break;

                        case false:
                            if (!File.Exists(path))
                            {
                                Globals.StatusBar.IsDownloading = true;
                                WebClient client = new WebClient();
                                await client.DownloadFileTaskAsync(new Uri(screenshot.Url), path);

                                client.Dispose();
                            }
                            if (!File.Exists(pathThumb))
                            {
                                BitmapImage bitmap = new BitmapImage();
                                using (var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
                                {
                                    bitmap.BeginInit();
                                    bitmap.CacheOption  = BitmapCacheOption.OnLoad;
                                    bitmap.StreamSource = stream;
                                    bitmap.EndInit();
                                    bitmap.Freeze();
                                }
                                Size  thumnailSize = GetThumbnailSize(bitmap);
                                Image thumb        = Image.FromFile(path).GetThumbnailImage(thumnailSize.Width, thumnailSize.Height, () => false, IntPtr.Zero);

                                if (!File.Exists($@"{Globals.DirectoryPath}\Data\images\screenshots\{Globals.VnId}\thumbs\{Path.GetFileName(screenshot.Url)}"))
                                {
                                    thumb.Save($@"{Globals.DirectoryPath}\Data\images\screenshots\{Globals.VnId}\thumbs\{Path.GetFileName(screenshot.Url)}");
                                }
                                thumb.Dispose();
                            }
                            Globals.StatusBar.IsDownloading = false;
                            break;
                        }
                    }
                    catch (System.Net.WebException ex)
                    {
                        Globals.Logger.Error(ex);
                        throw;
                    }
                    catch (Exception ex)
                    {
                        Globals.Logger.Error(ex);
                    }
                }
                Globals.StatusBar.ProgressText     = string.Empty;
                Globals.StatusBar.IsWorkProcessing = false;
                IsScreenshotDownloading            = false;
            }
            catch (Exception exception)
            {
                Globals.Logger.Error(exception);
                throw;
            }
        }
Beispiel #7
0
        private async Task DownloadCoverImage()
        {
            if (ConnectionTest.VndbTcpSocketTest() == false)
            {
                //TODO: add a default cover image for when it can't connect online
                Globals.Logger.Warn("Could not connect to Vndb API over SSL");
                Globals.StatusBar.SetOnlineStatusColor(false);
                Globals.StatusBar.IsShowOnlineStatusEnabled = true;
                await Task.Delay(3500);

                Globals.StatusBar.IsShowOnlineStatusEnabled = false;
                return;
            }
            using (var context = new DatabaseContext())
            {
                Globals.StatusBar.IsWorkProcessing = true;
                Globals.StatusBar.ProgressText     = "Loading cover image";
                VnInfo vnData = context.VnInfo.FirstOrDefault(t => t.Title == (_selectedVn));
                if (vnData == null)
                {
                    return;
                }
                string url  = vnData.ImageLink;
                bool   nsfw = Convert.ToBoolean(vnData.ImageNsfw);

                string pathNoExt = $@"{Globals.DirectoryPath}\Data\images\cover\{Globals.VnId}";
                string path      = $@"{Globals.DirectoryPath}\Data\images\cover\{Globals.VnId}.jpg";

                try
                {
                    switch (nsfw)
                    {
                    case true:
                        if (!File.Exists(pathNoExt))
                        {
                            Globals.StatusBar.IsDownloading = true;
                            Globals.StatusBar.ProgressText  = "Loading cover image";
                            Thread.Sleep(150);    //to be nice to the server
                            WebClient client = new WebClient();
                            using (MemoryStream stream = new MemoryStream(await client.DownloadDataTaskAsync(new Uri(url))))
                            {
                                string base64Img = Base64Converter.ImageToBase64(Image.FromStream(stream), ImageFormat.Jpeg);
                                File.WriteAllText(pathNoExt, base64Img);
                            }
                            client.Dispose();
                        }
                        break;

                    case false:
                        if (!File.Exists(path))
                        {
                            Globals.StatusBar.IsDownloading = true;
                            Globals.StatusBar.ProgressText  = "Loading cover image";
                            Thread.Sleep(150);    //to be nice to the server
                            WebClient client = new WebClient();
                            await client.DownloadFileTaskAsync(new Uri(url), path);

                            client.Dispose();
                        }
                        break;
                    }
                    Globals.StatusBar.IsDownloading = false;
                    Globals.StatusBar.ProgressText  = String.Empty;
                }
                catch (WebException ex)
                {
                    Globals.Logger.Error(ex);
                    throw;
                }
                catch (Exception ex)
                {
                    Globals.Logger.Error(ex);
                    throw;
                }
                Globals.StatusBar.IsWorkProcessing = false;
                Globals.StatusBar.ProgressText     = String.Empty;
            }
        }