private async Task <uint> IsAboveMaxId()
        {
            try
            {
                using (Vndb client = new Vndb(true))
                {
                    RequestOptions ro = new RequestOptions
                    {
                        Reverse = true,
                        Sort    = "id",
                        Count   = 1
                    };
                    VndbResponse <VisualNovel> response = await client.GetVisualNovelAsync(VndbFilters.Id.GreaterThan(1), VndbFlags.Basic, ro);

                    if (response != null)
                    {
                        return(response.Items[0].Id);
                    }
                    else
                    {
                        HandleError.HandleErrors(client.GetLastError(), 0);
                        return(0);
                    }
                }
            }
            catch (Exception ex)
            {
                Globals.Logger.Error(ex);
                throw;
            }
        }
        private async Task <bool> IsDeletedVn()
        {
            try
            {
                using (Vndb client = new Vndb(true))
                {
                    uint vnid = Convert.ToUInt32(InputVnId);
                    VndbResponse <VisualNovel> response = await client.GetVisualNovelAsync(VndbFilters.Id.Equals(vnid));

                    if (response != null)
                    {
                        return(response.Count < 1);
                    }
                    else
                    {
                        HandleError.HandleErrors(client.GetLastError(), 0);
                        return(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;
            }
        }
 private void Register_Click(object sender, EventArgs e)
 {
     try
     {
         CreateNewUser();
     }
     catch (Exception exception)
     {
         HandleError.HandleErrors(exception);
         Server.Transfer(ErrorPageURL, false);
     }
 }
Beispiel #5
0
        private async void SetVoteList()
        {
            try
            {
                bool didErrorOccur = false;
                IsUserInputEnabled = false;
                if (VoteDropDownSelected == "No Change")
                {
                    return;
                }
                if (_vnId == 0)
                {
                    return;
                }
                using (Vndb client = new Vndb(Username, Password))
                {
                    var check = await client.GetDatabaseStatsAsync();

                    if (check == null)
                    {
                        HandleError.HandleErrors(client.GetLastError(), 0);
                        didErrorOccur = true;
                    }
                    if (didErrorOccur == false)
                    {
                        if (VoteDropDownSelected == "Clear Entry")
                        {
                            if (_vnId > 0)
                            {
                                await client.SetVoteListAsync(_vnId, null);
                            }
                        }
                        if (VoteDropDownSelected == "Add/Update Vote")
                        {
                            SetValidationRules();
                            Validator.ResultChanged += OnValidationResultChanged;
                            await ValidateAsync();

                            if (IsValid == true)
                            {
                                await client.SetVoteListAsync(_vnId, Convert.ToByte(VotelistVote.Replace(".", String.Empty)));
                            }
                        }
                    }
                }
                IsUserInputEnabled = true;
            }
            catch (Exception exception)
            {
                Globals.Logger.Error(exception);
                throw;
            }
        }
Beispiel #6
0
        void Application_Error(object sender, EventArgs e)
        {
            Exception exception = Server.GetLastError();

            if (exception != null)
            {
                if (HttpContext.Current.Server != null)
                {
                    HandleError.HandleErrors(exception);
                    Server.Transfer("/Error.aspx");
                }
            }
        }
 protected override void OnLoad(EventArgs e)
 {
     try
     {
         if (!IsPostBack)
         {
             LoadExistingValues();
         }
     }
     catch (Exception exception)
     {
         HandleError.HandleErrors(exception);
         Server.Transfer(ErrorPageURL, false);
     }
 }
Beispiel #8
0
        private async void BindImage()
        {
            try
            {
                using (Vndb client = new Vndb())
                {
                    var data = await client.GetVisualNovelAsync(VndbFilters.Title.Equals(SelectedItem), VndbFlags.Details);

                    if (data != null)
                    {
                        var id = data.Items[0].Id;
                        if (!File.Exists($@"{Globals.DirectoryPath}\Data\images\userlist\{id}.jpg"))
                        {
                            Globals.StatusBar.IsDownloading = true;
                            Globals.StatusBar.ProgressText  = "Loading Image";
                            Thread.Sleep(100);
                            WebClient webclient = new WebClient();
                            await webclient.DownloadFileTaskAsync(new Uri(data.Items[0].Image), $@"{Globals.DirectoryPath}\Data\images\userlist\{id}.jpg");

                            webclient.Dispose();
                            VnLinksModel.Image = new BitmapImage(new Uri($@"{Globals.DirectoryPath}\Data\images\userlist\{id}.jpg"));
                            Globals.StatusBar.IsDownloading = false;
                            Globals.StatusBar.ProgressText  = String.Empty;
                        }
                        else if (File.Exists($@"{Globals.DirectoryPath}\Data\images\userlist\{id}.jpg"))
                        {
                            VnLinksModel.Image = new BitmapImage(new Uri($@"{Globals.DirectoryPath}\Data\images\userlist\{id}.jpg"));
                        }
                    }
                    else
                    {
                        HandleError.HandleErrors(client.GetLastError(), 0);
                    }
                    client.Dispose();
                }
            }
            catch (Exception e)
            {
                Globals.Logger.Error(e);
                throw;
            }
        }
 private void Login_Click(object sender, EventArgs e)
 {
     try
     {
         if (CheckIfValidUser())
         {
             RedirectToProgramsList();
         }
         else
         {
             lblMessage.Text      = "Please enter correct username or password";
             lblMessage.ForeColor = System.Drawing.Color.Red;
         }
     }
     catch (Exception exception)
     {
         HandleError.HandleErrors(exception);
         Server.Transfer(ErrorPageURL, false);
     }
 }
 protected override void OnLoad(EventArgs e)
 {
     try
     {
         HttpCookie cookieLoginSuccess = HttpContext.Current.Request.Cookies["loginSuccess"];
         if (cookieLoginSuccess != null && cookieLoginSuccess.Value == "1")
         {
             LoadPaidProgramsList();
             Page.ClientScript.RegisterStartupScript(this.GetType(), "loadViewMoreLink", "loadViewMoreLink();", true);
         }
         else
         {
             LoadProgramsList();
         }
     }
     catch (Exception exception)
     {
         HandleError.HandleErrors(exception);
         Server.Transfer(ErrorPageURL, false);
     }
 }
Beispiel #11
0
 protected override void OnLoad(EventArgs e)
 {
     try
     {
         HttpCookie cookieLoginSuccess = HttpContext.Current.Request.Cookies["loginSuccess"];
         if (cookieLoginSuccess == null || cookieLoginSuccess.Value == "0")
         {
             Response.Redirect(LoginPageURL, false);
         }
         else
         {
             int ProgramID = Convert.ToInt32(Request.QueryString["id"]);
             LoadProgramDetails(ProgramID);
         }
     }
     catch (Exception exception)
     {
         HandleError.HandleErrors(exception);
         Server.Transfer(ErrorPageURL, false);
     }
 }
        private async Task <uint> GetVnId()
        {
            using (var context = new DatabaseContext())
            {
                uint data = 0;
                data = context.VnInfo.Where(v => v.Title == SelectedItem).Select(x => x.VnId).FirstOrDefault();
                if (data != 0)
                {
                    return(data);
                }
                if (data == 0)
                {
                    data = context.VnIdList.Where(v => v.Title == SelectedItem).Select(x => x.VnId)
                           .FirstOrDefault();
                    return(data);
                }
                if (data == 0)
                {
                    Vndb client   = new Vndb(true);
                    var  response = await client.GetVisualNovelAsync(VndbFilters.Title.Equals(SelectedItem));

                    if (response == null)
                    {
                        HandleError.HandleErrors(client.GetLastError(), 0);
                    }
                    else
                    {
                        VisualNovel firstOrDefault = response?.Items.FirstOrDefault();
                        if (firstOrDefault != null)
                        {
                            data = firstOrDefault.Id;
                        }
                        client.Logout();
                        client.Dispose();
                        return(data);
                    }
                }
                return(0);
            }
        }
        private async Task <bool> IsValidLogin()
        {
            if (string.IsNullOrEmpty(Username) || Password.Length <= 0)
            {
                return(false);
            }
            using (var client = new Vndb(Username, Password))
            {
                var users = await client.GetUserAsync(VndbFilters.Username.Equals(Username));

                if (users == null)
                {
                    HandleError.HandleErrors(client.GetLastError(), 0);
                    return(false);
                }
                else
                {
                    _userId = users.Items[0].Id;
                    return(true);
                }
            }
        }
Beispiel #14
0
        private async void SetWishlist()
        {
            try
            {
                bool didErrorOccur = false;
                IsUserInputEnabled = false;
                if (WishlistPriority == "No Change")
                {
                    return;
                }
                if (_vnId == 0)
                {
                    return;
                }
                using (Vndb client = new Vndb(Username, Password))
                {
                    var check = await client.GetDatabaseStatsAsync();

                    if (check == null)
                    {
                        HandleError.HandleErrors(client.GetLastError(), 0);
                        didErrorOccur = true;
                    }
                    if (didErrorOccur == false)
                    {
                        if (WishlistPriority == "Clear Entry")
                        {
                            if (_vnId > 0)
                            {
                                await client.SetWishlistAsync(_vnId, null);
                            }
                        }
                        switch (WishlistPriority)
                        {
                        case "Clear Entry":
                            await client.SetWishlistAsync(_vnId, null);

                            break;

                        case "High":
                            await client.SetWishlistAsync(_vnId, Priority.High);

                            break;

                        case "Medium":
                            await client.SetWishlistAsync(_vnId, Priority.Medium);

                            break;

                        case "Low":
                            await client.SetWishlistAsync(_vnId, Priority.Low);

                            break;

                        case "Blacklist":
                            await client.SetWishlistAsync(_vnId, Priority.Blacklist);

                            break;
                        }
                    }
                }
                IsUserInputEnabled = true;
            }
            catch (Exception exception)
            {
                Globals.Logger.Error(exception);
                throw;
            }
        }
Beispiel #15
0
        private async void GetData()
        {
            Globals.StatusBar.ProgressPercentage = 0;
            Globals.StatusBar.IsWorkProcessing   = true;
            Globals.StatusBar.ProgressText       = "Retrieving Data";
            try
            {
                using (Vndb client = new Vndb(true))
                {
                    bool           hasMore = true;
                    RequestOptions ro      = new RequestOptions {
                        Count = 25
                    };
                    int pageCount      = 1;
                    int characterCount = 0;
                    int releasesCount  = 0;


                    List <Character> characterList = new List <Character>();
                    while (hasMore)
                    {
                        ro.Page = pageCount;
                        VndbResponse <Character> characters = await client.GetCharacterAsync(VndbFilters.VisualNovel.Equals(_vnid), VndbFlags.FullCharacter, ro);

                        if (characters != null)
                        {
                            hasMore = characters.HasMore;
                            characterList.AddRange(characters.Items);
                            characterCount = characterCount + characters.Count;
                            pageCount++;
                        }
                        if (characters != null)
                        {
                            continue;
                        }
                        HandleError.HandleErrors(client.GetLastError(), 0);
                        return;
                    }

                    hasMore   = true;
                    pageCount = 1;
                    //do progress here

                    VndbResponse <VisualNovel> visualNovels = await client.GetVisualNovelAsync(VndbFilters.Id.Equals(_vnid), VndbFlags.FullVisualNovel);

                    if (visualNovels == null)
                    {
                        HandleError.HandleErrors(client.GetLastError(), 0);
                        return;
                    }



                    List <Release> releaseList = new List <Release>();
                    while (hasMore)
                    {
                        ro.Page = pageCount;
                        VndbResponse <Release> releases = await client.GetReleaseAsync(VndbFilters.VisualNovel.Equals(_vnid), VndbFlags.FullRelease, ro);

                        if (releases == null)
                        {
                            HandleError.HandleErrors(client.GetLastError(), 0);
                            break;
                        }
                        hasMore = releases.HasMore;
                        releaseList.AddRange(releases.Items);
                        releasesCount = releasesCount + releases.Count;
                        pageCount++;
                    }


                    _progressIncrement = (double)100 / (1 + characterCount);
                    //await save vn data here
                    Globals.StatusBar.ProgressText   = "Processing Data";
                    Globals.StatusBar.IsDbProcessing = true;
                    await AddToDatabase(visualNovels, releaseList, characterList);
                }
            }
            catch (Exception ex)
            {
                Globals.Logger.Error(ex);
                throw;
            }
        }
Beispiel #16
0
        private async void SetVnList()
        {
            try
            {
                bool didErrorOccur = false;
                IsUserInputEnabled = false;
                if (VnListStatus == "No Change")
                {
                    return;
                }
                if (_vnId == 0)
                {
                    return;
                }
                using (Vndb client = new Vndb(Username, Password))
                {
                    var check = await client.GetDatabaseStatsAsync();

                    if (check == null)
                    {
                        HandleError.HandleErrors(client.GetLastError(), 0);
                        didErrorOccur = true;
                    }
                    if (didErrorOccur == false)
                    {
                        switch (VnListStatus)
                        {
                        case "Clear Entry":
                            if (_vnId > 0 && NoteEnabled == true && string.IsNullOrEmpty(VnListNote))
                            {
                                await client.SetVisualNovelListAsync(_vnId, null, null);
                            }
                            if (_vnId > 0)
                            {
                                await client.SetVisualNovelListAsync(_vnId, (Status?)null);
                            }
                            break;

                        case "Playing":
                            await client.SetVisualNovelListAsync(_vnId, Status.Playing);

                            break;

                        case "Finished":
                            await client.SetVisualNovelListAsync(_vnId, Status.Finished);

                            break;

                        case "Stalled":
                            await client.SetVisualNovelListAsync(_vnId, Status.Stalled);

                            break;

                        case "Dropped":
                            await client.SetVisualNovelListAsync(_vnId, Status.Dropped);

                            break;

                        case "Unknown":
                            await client.SetVisualNovelListAsync(_vnId, Status.Unknown);

                            break;
                        }
                        if (NoteEnabled == true && !string.IsNullOrEmpty(VnListNote))
                        {
                            await client.SetVisualNovelListAsync(_vnId, VnListNote);
                        }
                    }
                }
                IsUserInputEnabled = true;
            }
            catch (Exception exception)
            {
                Globals.Logger.Error(exception);
                throw;
            }
        }
        private async void GetVisualNovelList()
        {
            if (string.IsNullOrEmpty(_username) || _password.Length <= 0)
            {
                return;
            }
            Globals.StatusBar.IsDbProcessing   = true;
            Globals.StatusBar.IsWorkProcessing = true;
            Globals.StatusBar.ProgressText     = "Loading Data...";

            UInt32[] dbIdList = { };
            using (var context = new DatabaseContext())
            {
                //gets a list of all vnids that are in the VnVisualNovelList where the userId is the logged in user
                List <uint> idEntry = (from v in context.VnVisualNovelList where v.UserId.Equals(_userId) select v.VnId).ToList();
                List <uint> idList  = idEntry.ToList();

                //gets a list of titles of all items in VnIdList which contain an id from the above vnlist,
                //which is any item in the visualnovelList table
                List <string> entry = (from first in context.VnIdList
                                       join second in idList on first.VnId equals second
                                       select first.Title).ToList();

                if (entry.Count > 0)
                {
                    _userListCollection.InsertRange(entry);
                }
                if (idList.Count > 0)
                {
                    dbIdList = idList.ToArray();
                }
            }
            List <Tuple <uint, string> > dbItemsToAdd         = new List <Tuple <uint, string> >();
            List <VnVisualNovelList>     visualNovelListItems = new List <VnVisualNovelList>();
            bool removeItems = false;

            using (Vndb client = new Vndb(Username, Password))
            {
                bool           hasMore = true;
                RequestOptions ro      = new RequestOptions();
                int            page    = 1;
                List <UInt32>  idList  = new List <uint>();
                //get the list of all ids on the vnList
                int errorCounter = 0;
                //var vnList = await client.GetVisualNovelListAsync(VndbFilters.UserId.Equals(_userId), VndbFlags.FullVisualNovelList, ro);
                while (hasMore)
                {
                    ro.Page  = page;
                    ro.Count = 100;
                    try
                    {
                        if (dbIdList.Length > 0)
                        {
                            var vnList = await client.GetVisualNovelListAsync(VndbFilters.UserId.Equals(_userId)& VndbFilters.VisualNovel.NotEquals(dbIdList), VndbFlags.FullVisualNovelList, ro);

                            if (vnList != null && vnList.Count > 0)
                            {
                                hasMore = vnList.HasMore;
                                idList.AddRange(vnList.Select(vn => vn.VisualNovelId));
                                visualNovelListItems.AddRange(vnList.Select(item => new VnVisualNovelList()
                                {
                                    UserId = item.UserId,
                                    VnId   = item.VisualNovelId,
                                    Status = item.Status.ToString(),
                                    Notes  = item.Notes,
                                    Added  = item.AddedOn.ToString(CultureInfo.InvariantCulture)
                                }));
                                page++;
                            }
                            else if (vnList != null && vnList.Count == 0)
                            {
                                vnList = await client.GetVisualNovelListAsync(VndbFilters.UserId.Equals(_userId), VndbFlags.FullVisualNovelList, ro);

                                if (vnList != null)
                                {
                                    hasMore = vnList.HasMore;
                                    idList.AddRange(vnList.Select(vn => vn.VisualNovelId));
                                    visualNovelListItems.AddRange(vnList.Select(item => new VnVisualNovelList()
                                    {
                                        UserId = item.UserId,
                                        VnId   = item.VisualNovelId,
                                        Status = item.Status.ToString(),
                                        Notes  = item.Notes,
                                        Added  = item.AddedOn.ToString(CultureInfo.InvariantCulture)
                                    }));
                                    page++;
                                    removeItems = true;
                                }
                            }
                            else
                            {
                                HandleError.HandleErrors(client.GetLastError(), errorCounter);
                                errorCounter++;
                            }
                        }
                        else
                        {
                            var vnList = await client.GetVisualNovelListAsync(VndbFilters.UserId.Equals(_userId), VndbFlags.FullVisualNovelList, ro);

                            if (vnList != null)
                            {
                                hasMore = vnList.HasMore;
                                idList.AddRange(vnList.Select(wish => wish.VisualNovelId));
                                //dbWishlistToAdd.AddRange(votelist);
                                visualNovelListItems.AddRange(vnList.Select(item => new VnVisualNovelList()
                                {
                                    UserId = item.UserId,
                                    VnId   = item.VisualNovelId,
                                    Status = item.Status.ToString(),
                                    Notes  = item.Notes,
                                    Added  = item.AddedOn.ToString(CultureInfo.InvariantCulture)
                                }));
                                page++;
                                removeItems = true;
                            }
                            else
                            {
                                HandleError.HandleErrors(client.GetLastError(), errorCounter);
                                errorCounter++;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Globals.Logger.Error(ex);
                        throw;
                    }
                }
                //get names from ids on vnlist, and add them to ObservableCollection
                hasMore = true;
                page    = 1;
                while (hasMore)
                {
                    ro.Page  = page;
                    ro.Count = 25;
                    try
                    {
                        var data = await client.GetVisualNovelAsync(VndbFilters.Id.Equals(idList.ToArray()), VndbFlags.Basic, ro);

                        if (data != null)
                        {
                            hasMore = data.HasMore;
                            foreach (var item in data)
                            {
                                _userListCollection.Add(item.Name);
                                dbItemsToAdd.Add(new Tuple <uint, string>(item.Id, item.Name));
                            }
                            page++;
                        }
                        else
                        {
                            HandleError.HandleErrors(client.GetLastError(), errorCounter);
                            errorCounter++;
                        }
                    }
                    catch (Exception ex)
                    {
                        Globals.Logger.Error(ex);
                        throw;
                    }
                }
                client.Dispose();
            }
            AddToIdListDb(dbItemsToAdd);
            AddVnListToDb(visualNovelListItems, removeItems);

            Globals.StatusBar.ProgressText     = "Done";
            Globals.StatusBar.IsDbProcessing   = false;
            Globals.StatusBar.IsWorkProcessing = false;
            await Task.Delay(1500);

            Globals.StatusBar.ProgressText = string.Empty;
            IsUserInputEnabled             = true;
        }