public async Task MainAsync(String[] args) { Console.OutputEncoding = Encoding.UTF8; // Redundant, but it's an example! VndbUtils.WithHttpMessageHandler(() => Task.FromResult((HttpMessageHandler) new HttpClientHandler())); this._client = new Vndb(true) .WithClientDetails("VndbSharpExamples", "0.1") .WithFlagsCheck(true, this.InvalidFlagsCallback); // await this.GetDatabaseStats(); // await this.GetVisualNovelAsync(); // await this.GetReleaseAsync(); // await this.GetProducerAsync(); // await this.GetCharacterAsync(); // await this.GetStaffAsync(); // await this.GetUserAsync(); // await this.GetVoteListAsync(); // await this.GetVisualNovelListAsync(); // await this.GetWishlistAsync(); // await this.GetUserListAsync(); // await this.GetFilterExampleAsync(); // await this.GetInvalidFlagsExampleAsync(); // await this.GetErrorExampleAsync(); this._client.Logout(); // Same as this._client.Dispose(); #if UserAuth var userPass = this.GetUsernameAndPassword(); // Are all usernames forced lower? I could have sworn i registered with captials >:| this._client = new Vndb(userPass.Item1.ToLower(), userPass.Item2) .WithClientDetails("VndbSharpExamples", "0.1") .WithFlagsCheck(true, this.InvalidFlagsCallback); Console.WriteLine(); // await this.SetVoteListAsync(); // await this.SetVisualNovelListAsync(); // await this.SetWishlistAsync(); this._client.Logout(); // Not the same as this._client.Dispose();, it also immediately unsets the password. #endif Boolean doRaw; while (!Boolean.TryParse(this.GetUserInput("Try Raw Input (True / False): "), out doRaw)) { ; } if (doRaw) { Console.WriteLine("Type \"exit\" to stop"); String input; while ((input = this.GetUserInput("> ")) != "exit") { Console.WriteLine(await this._client.DoRawAsync(input)); } Console.WriteLine(); } Console.WriteLine("Press any key to exit..."); Console.ReadKey(); }
private async Task GetDetailsFromTraitDump(ReadOnlyCollection <TraitMetadata> traits, UInt32 charId) { try { using (var context = new DatabaseContext()) { //checks if the dump was downloaded, or if 24 hours have passed if (_didDownloadTraitDump.Key == false || Math.Abs(_didDownloadTraitDump.Value.Subtract(DateTime.Now).TotalHours) >= 24) { #region This section deals with the daily TraitDump ONLY List <Trait> traitDump = (await VndbUtils.GetTraitsDumpAsync()).ToList(); List <VnTraitData> traitsToAdd = traitDump.Select(trait => new VnTraitData { TraitId = trait.Id, Name = trait.Name, Description = trait.Description, Meta = trait.IsMeta.ToString(), Chars = trait.Characters, Aliases = ConvertToCsv(trait.Aliases), Parents = trait.Parents != null ? string.Join(",", trait.Parents) : null }).ToList(); //traits that AREN'T exact duplicates, that also share the same ID (contents edited online/ new character/parent/... added to trait, ID wasn't), using custom .Equals List <VnTraitData> traitsToDelete = traitsToAdd.Intersect(context.VnTraitData).ToList(); traitsToAdd.RemoveAll(x => traitsToDelete.Contains(x)); context.VnTraitData.AddRange(traitsToAdd); #endregion This section deals with the daily TraitDump ONLY #region This Section is for VnCharacterTraits //gets a list of all traits from the TraitDump where the dump contains the traitIds from the character List <TraitMetadata> vnCharacterTraits = (from trait in traits from ef in traitDump where trait.Id == ef.Id select trait).ToList(); List <VnCharacterTraits> vnCharacterTraitsToAdd = vnCharacterTraits.Select(traitMetaData => new VnCharacterTraits { CharacterId = charId, TraitId = traitMetaData.Id, SpoilerLevel = (byte)traitMetaData.SpoilerLevel }).ToList(); //list of items to delete of previous entries List <VnCharacterTraits> vnCharacterTraitsToDelete = context.VnCharacterTraits.Where(x => x.CharacterId.Equals(charId)).ToList(); //remove then re-add the items context.VnCharacterTraits.RemoveRange(vnCharacterTraitsToDelete); context.VnCharacterTraits.AddRange(vnCharacterTraitsToAdd); context.SaveChanges(); _didDownloadTraitDump.Key = true; #endregion } else { #region This Section is for VnCharacterTraits //gets a list of all traits from the localdb where the database contains the traitIds from the character List <TraitMetadata> vnCharacterTraits = (from trait in traits from ef in context.VnTraitData where trait.Id == ef.Id select trait).ToList(); List <VnCharacterTraits> vnCharacterTraitsToAdd = vnCharacterTraits.Select(traitMetaData => new VnCharacterTraits { CharacterId = charId, TraitId = traitMetaData.Id, SpoilerLevel = (byte)traitMetaData.SpoilerLevel }).ToList(); //list of items to delete of previous entries List <VnCharacterTraits> vnCharacterTraitsToDelete = context.VnCharacterTraits.Where(x => x.CharacterId.Equals(charId)).ToList(); //remove then re-add the items context.VnCharacterTraits.RemoveRange(vnCharacterTraitsToDelete); context.VnCharacterTraits.AddRange(vnCharacterTraitsToAdd); context.SaveChanges(); #endregion } } } catch (Exception ex) { Globals.Logger.Error(ex); throw; } }
// Should likely be in a unique class...but meh internal static String AsString(this VndbFlags flags, String method) => String.Join(",", VndbUtils.ConvertFlagsToString(method, flags).Distinct());
//NOTE: These two methods can be tricky to debug. They should be ok, but there is a decent chance that I messed something up, due to how many times I had to redo things private async Task GetDetailsFromTagDump(ReadOnlyCollection <TagMetadata> vnTags) { try { using (var context = new DatabaseContext()) { // this query SHOULD be implementing this: foreach (TagMetadata tag in visualNovel.Tags){if (tagMatches.Any(c => c.Id == tag.Id)){} } //checks if the dump was downloaded, or if 24 hours have passed if (_didDownloadTagDump.Key == false || Math.Abs(_didDownloadTagDump.Value.Subtract(DateTime.Now).TotalHours) >= 24) { #region This section deals with the daily TagDump ONLY List <Tag> tagDump = (await VndbUtils.GetTagsDumpAsync()).ToList(); List <VnTagData> tagsToAdd = tagDump.Select(tag => new VnTagData { TagId = tag.Id, Name = tag.Name, Description = tag.Description, Meta = tag.IsMeta.ToString(), Vns = tag.VisualNovels, Cat = tag.TagCategory.ToString(), Aliases = ConvertToCsv(tag.Aliases), Parents = tag.Parents != null ? string.Join(",", tag.Parents) : null, }).ToList(); //IQueryable<VnTagData> foo = context.VnTagData.Where(x => tagsToAdd.Any(y => y.TagId == x.TagId)); //tags that AREN'T exact duplicates, that also share the same ID (contents edited online/ new vn, parent,..., ID wasn't) List <VnTagData> tagsToDelete = tagsToAdd.Intersect(context.VnTagData).ToList(); tagsToAdd.RemoveAll(x => tagsToDelete.Contains(x)); context.VnTagData.AddRange(tagsToAdd); #endregion This section deals with the daily TagDump ONLY #region This Section is for VnInfoTags //gets a list of all tags from the TagDump where the dump contains the tagIds from the vn List <TagMetadata> vnInfoTags = (from tag in vnTags from ef in tagDump where tag.Id == ef.Id select tag).ToList(); List <VnInfoTags> vnInfoTagsToAdd = vnInfoTags.Select(tagMetadata => new VnInfoTags { VnId = _vnid, TagId = tagMetadata.Id, Score = tagMetadata.Score, Spoiler = (byte)tagMetadata.SpoilerLevel }).ToList(); //list of items to delete where the db contains the vnid List <VnInfoTags> vnInfoTagsToDelete = context.VnInfoTags.Where(x => x.VnId.Equals(_vnid)).ToList(); //delete items with same vnid, then re-add them context.VnInfoTags.RemoveRange(vnInfoTagsToDelete); context.VnInfoTags.AddRange(vnInfoTagsToAdd); context.SaveChanges(); #endregion End This Section is for VnInfoTags _didDownloadTagDump.Key = true; //gets a list of items from VnTagData where it contains the tagId from the vn //List<VnTagData> matches = (from ef in context.VnTagData from tag in vnTags where ef.TagId == tag.Id select ef).ToList(); } else { //gets a list of all tags from the VnTagData where that data contains the tagId from the vn List <TagMetadata> vnInfoTags = (from tag in vnTags from ef in context.VnTagData where tag.Id == ef.TagId select tag).ToList(); List <VnInfoTags> vnInfoTagsToAdd = vnInfoTags.Select(tagMetadata => new VnInfoTags { VnId = _vnid, TagId = tagMetadata.Id, Score = tagMetadata.Score, Spoiler = (byte)tagMetadata.SpoilerLevel }).ToList(); //list of items to delete where the db contains the vnid List <VnInfoTags> vnInfoTagsToDelete = context.VnInfoTags.Where(x => x.VnId.Equals(_vnid)).ToList(); //delete items with same vnid, then re-add them context.VnInfoTags.RemoveRange(vnInfoTagsToDelete); context.VnInfoTags.AddRange(vnInfoTagsToAdd); context.SaveChanges(); //for selection. Remove once I use this elsewhere //gets a list of items from VnTagData where it contains the tagId from the vn //List<VnTagData> matches = (from ef in context.VnTagData from tag in vnTags where ef.TagId == tag.Id select ef).ToList(); } } } catch (Exception ex) { Globals.Logger.Error(ex); throw; } }