/// <summary> /// Asynchronously gets a json file in this category /// </summary> /// <typeparam name="T">The type of the json file</typeparam> /// <param name="category">The base category</param> /// <param name="name">The name of the json file</param> /// <returns>The deserialized object from the json file</returns> public static async Task <T> GetJsonAsync <T>(this DatabaseCategory category, string name) { var FilePath = $"{category.Path}\\{name}.json"; var text = await File.ReadAllTextAsync(FilePath); return(JsonConvert.DeserializeObject <T>(text)); }
public void GetCountriesById_1And65_RussiaAndGermany() { const string url = "https://api.vk.com/method/database.getCountriesById?country_ids=1,65&access_token="; const string json = @"{ 'response': [ { 'cid': 1, 'name': 'Россия' }, { 'cid': 65, 'name': 'Германия' } ] }"; DatabaseCategory db = GetMockedDatabaseCategory(url, json); ReadOnlyCollection <Country> countries = db.GetCountriesById(1, 65); Assert.That(countries.Count, Is.EqualTo(2)); Assert.That(countries[0].Id, Is.EqualTo(1)); Assert.That(countries[0].Title, Is.EqualTo("Россия")); Assert.That(countries[1].Id, Is.EqualTo(65)); Assert.That(countries[1].Title, Is.EqualTo("Германия")); }
/// <summary> /// Инициализирует новый экземпляр класса <see cref="VkApi"/>. /// </summary> public VkApi() { Browser = new Browser(); Users = new UsersCategory(this); Friends = new FriendsCategory(this); Status = new StatusCategory(this); Messages = new MessagesCategory(this); Groups = new GroupsCategory(this); Audio = new AudioCategory(this); Wall = new WallCategory(this); Database = new DatabaseCategory(this); Utils = new UtilsCategory(this); Fave = new FaveCategory(this); Video = new VideoCategory(this); Account = new AccountCategory(this); Photo = new PhotoCategory(this); Docs = new DocsCategory(this); Likes = new LikesCategory(this); Pages = new PagesCategory(this); Gifts = new GiftsCategory(this); Apps = new AppsCategory(this); NewsFeed = new NewsFeedCategory(this); Stats = new StatsCategory(this); Auth = new AuthCategory(this); Markets = new MarketsCategory(this); Execute = new ExecuteCategory(this); RequestsPerSecond = 3; }
/// <summary> /// Инициализирует новый экземпляр класса <see cref="VkApi"/>. /// </summary> public VkApi(ICaptchaSolver captchaSolver = null) { Browser = new Browser(); Users = new UsersCategory(this); Friends = new FriendsCategory(this); Status = new StatusCategory(this); Messages = new MessagesCategory(this); Groups = new GroupsCategory(this); Audio = new AudioCategory(this); Wall = new WallCategory(this); Board = new BoardCategory(this); Database = new DatabaseCategory(this); Utils = new UtilsCategory(this); Fave = new FaveCategory(this); Video = new VideoCategory(this); Account = new AccountCategory(this); Photo = new PhotoCategory(this); Docs = new DocsCategory(this); Likes = new LikesCategory(this); Pages = new PagesCategory(this); Gifts = new GiftsCategory(this); Apps = new AppsCategory(this); NewsFeed = new NewsFeedCategory(this); Stats = new StatsCategory(this); Auth = new AuthCategory(this); Markets = new MarketsCategory(this); Execute = new ExecuteCategory(this); RequestsPerSecond = 3; MaxCaptchaRecognitionCount = 5; _captchaSolver = captchaSolver; }
/// <summary> /// Инициализирует новый экземпляр класса <see cref="VkApi"/>. /// </summary> public VkApi() { Browser = new Browser(); Users = new UsersCategory(this); Friends = new FriendsCategory(this); Status = new StatusCategory(this); Messages = new MessagesCategory(this); Groups = new GroupsCategory(this); Audio = new AudioCategory(this); Wall = new WallCategory(this); Database = new DatabaseCategory(this); Utils = new UtilsCategory(this); Fave = new FaveCategory(this); Video = new VideoCategory(this); Account = new AccountCategory(this); Photo = new PhotoCategory(this); Docs = new DocsCategory(this); Likes = new LikesCategory(this); Pages = new PagesCategory(this); Gifts = new GiftsCategory(this); Apps = new AppsCategory(this); NewsFeed = new NewsFeedCategory(this); Stats = new StatsCategory(this); Auth = new AuthCategory(this); RequestsPerSecond = 3; }
public static DatabaseCategory GetOrDefault(string name, DatabaseCategory defaultDatabase) { if (name == null || name.Trim() == string.Empty) { return(defaultDatabase); } return((DatabaseCategory)Enum.Parse(typeof(DatabaseCategory), name)); }
/// <summary> /// Asynchronously saves a file in this category with the specified name, extension and data /// </summary> /// <param name="category">The base category</param> /// <param name="name">The name of the file</param> /// <param name="extension">The extension of the file with a period (for example: ".jpg")</param> /// <param name="data">The data to be stored in the file</param> public static async Task SaveFileAsync(this DatabaseCategory category, string name, string extension, Stream data) { var path = $"{category.FullPath}\\{name}{extension}"; if (File.Exists(path)) { File.Delete(path); } using FileStream fileStream = File.Create(path); await data.CopyToAsync(fileStream); }
/// <summary> /// Asynchronously saves a file in this category with the specified name, extension and data /// </summary> /// <param name="category">The base category</param> /// <param name="name">The name of the file</param> /// <param name="extension">The extension of the file with a period (for example: ".jpg")</param> /// <param name="data">The data to be stored in the file</param> public static async Task SaveFileAsync(this DatabaseCategory category, string name, string extension, Stream data) { if (data is MemoryStream) { await File.WriteAllBytesAsync($"{category.Path}\\{name}{extension}", ((MemoryStream)data).ToArray()); } else { var ms = new MemoryStream(); await data.CopyToAsync(ms); await File.WriteAllBytesAsync($"{category.Path}\\{name}{extension}", ms.ToArray()); } }
public void GetCountriesById_EmptyList() { const string url = "https://api.vk.com/method/database.getCountriesById?access_token="; const string json = @"{ 'response': [] }"; DatabaseCategory db = GetMockedDatabaseCategory(url, json); ReadOnlyCollection <Country> countries = db.GetCountriesById(); Assert.That(countries, Is.Not.Null); Assert.That(countries.Count, Is.EqualTo(0)); }
/// <summary> /// Инициализирует новый экземпляр класса <see cref="VkApi"/>. /// </summary> public VkApi() { Browser = new Browser(); Users = new UsersCategory(this); Friends = new FriendsCategory(this); Status = new StatusCategory(this); Messages = new MessagesCategory(this); Groups = new GroupsCategory(this); Audio = new AudioCategory(this); Wall = new WallCategory(this); Database = new DatabaseCategory(this); Utils = new UtilsCategory(this); Fave = new FaveCategory(this); Video = new VideoCategory(this); Account = new AccountCategory(this); }
/// <summary> /// Инициализирует новый экземпляр класса <see cref="VkApi"/>. /// </summary> public VkApi() { ServicePointManager.ServerCertificateValidationCallback = new PositiveCertificatePolicy().ServerCertificateValidationCallback; Browser = new Browser(); Users = new UsersCategory(this); Friends = new FriendsCategory(this); Status = new StatusCategory(this); Messages = new MessagesCategory(this); Groups = new GroupsCategory(this); Audio = new AudioCategory(this); Wall = new WallCategory(this); Database = new DatabaseCategory(this); Utils = new UtilsCategory(this); Fave = new FaveCategory(this); Video = new VideoCategory(this); Account = new AccountCategory(this); Likes = new LikesCategory(this); Photo = new PhotoCategory(this); }
public static IDbConnection CreateConnection(DatabaseCategory dbc, string connectionString) { IDbConnection connection = null; switch (dbc) { case DatabaseCategory.SQLServer: connection = DatabaseService.CreateInstance(new SqlConnection(connectionString)); break; case DatabaseCategory.Oracle: //ms 提供 connection = DatabaseService.CreateInstance(new OracleConnection(connectionString)); break; case DatabaseCategory.MySQL: //需要自已提供Dll //connection = DatabaseService.CreateInstance(new SqlConnection(connectionString)); break; } return(connection); }
/// <summary> /// Инициализирует новый экземпляр класса <see cref="VkApi"/>. /// </summary> public VkApi() { Browser = new Browser(); Users = new UsersCategory(this); Friends = new FriendsCategory(this); Status = new StatusCategory(this); Messages = new MessagesCategory(this); Groups = new GroupsCategory(this); Audio = new AudioCategory(this); Wall = new WallCategory(this); Database = new DatabaseCategory(this); Utils = new UtilsCategory(this); Fave = new FaveCategory(this); Video = new VideoCategory(this); Account = new AccountCategory(this); Photo = new PhotoCategory(this); Docs = new DocsCategory(this); RequestsPerSecond = 3; AutoTokenRefresh = false; }
public void GetRegions_NormalCase_ListOfRegions() { const string url = "https://api.vk.com/method/database.getRegions?country_id=1&offset=5&count=3&access_token="; const string json = @"{ 'response': [ { 'region_id': '1000236', 'title': 'Архангельская область' }, { 'region_id': '1004118', 'title': 'Астраханская область' }, { 'region_id': '1004565', 'title': 'Башкортостан' } ] }"; DatabaseCategory db = GetMockedDatabaseCategory(url, json); ReadOnlyCollection <Region> regions = db.GetRegions(1, count: 3, offset: 5); Assert.That(regions.Count, Is.EqualTo(3)); Assert.That(regions[0].Id, Is.EqualTo(1000236)); Assert.That(regions[0].Title, Is.EqualTo("Архангельская область")); Assert.That(regions[1].Id, Is.EqualTo(1004118)); Assert.That(regions[1].Title, Is.EqualTo("Астраханская область")); Assert.That(regions[2].Id, Is.EqualTo(1004565)); Assert.That(regions[2].Title, Is.EqualTo("Башкортостан")); }
public void GetRegions_OffsetIsNegative_ThrowArgumentException() { DatabaseCategory db = GetMockedDatabaseCategory("", ""); This.Action(() => db.GetRegions(1, offset: -2)).Throws <ArgumentException>(); }
public bool Support(StorageType storageType, DatabaseCategory databaseType) => new Persistence(storageType, string.Empty).IsJournal() && databaseType == DatabaseCategory.InMemory;
internal DatabaseCategoryExtended(DatabaseCategory databaseCategory, VkApi vk) { _database = databaseCategory; _vk = vk; }
public void GetRegions_OffsetIsNegative_ThrowArgumentException() { DatabaseCategory db = GetMockedDatabaseCategory("", ""); db.GetRegions(1, offset: -2); }
public bool Support(StorageType storageType, DatabaseCategory databaseType) => storageType == StorageType.StateStore && databaseType != DatabaseCategory.InMemory;
public void GetRegions_CountryIdIsNegative_ThrowArgumentException() { DatabaseCategory db = GetMockedDatabaseCategory("", ""); db.GetRegions(-1); }
/// <summary> /// Asynchronously gets a list of all text files from the category /// </summary> /// /// <param name="category">The base category</param> /// <returns>A dictionary with the key being the name of the file and the value the text in the file</returns> public static async Task <IReadOnlyDictionary <string, string> > GetAllTextAsync(this DatabaseCategory category) { var info = new DirectoryInfo(category.Path); var files = info.GetFiles(); var dictionary = new Dictionary <string, string>(); foreach (var file in files) { if (file.Extension == ".txt") { var text = await File.ReadAllTextAsync(file.FullName); dictionary.Add(Path.GetFileNameWithoutExtension(file.Name), text); } } return(dictionary); }
public bool Support(StorageType storageType, DatabaseCategory databaseType) => databaseType == DatabaseCategory.InMemory;
/// <summary> /// Asynchronously saves the given text in a .txt file /// </summary> /// <param name="category">The base category</param> /// <param name="name">The name of the file</param> /// <param name="text">The text to be written in the file</param> public static async Task SaveTextAsync(this DatabaseCategory category, string name, string text) { await File.WriteAllTextAsync($"{category.Path}\\{name}.txt", text); }
/// <summary> /// Asynchronously gets the text from the given file /// </summary> /// <param name="category">The base category</param> /// <param name="name">The name of the file</param> /// <returns>The text from the file</returns> public static async Task <string> GetTextAsync(this DatabaseCategory category, string name) { var text = await File.ReadAllTextAsync($"{category.Path}\\{name}.txt"); return(text); }
/// <summary> /// Asynchronously gets a list of deseralized json files in this category /// </summary> /// <typeparam name="T">The type of the json files</typeparam> /// <param name="category">The base category</param> /// <returns>A dictionary with the key being the name of the file and the value a the object</returns> public static async Task <IReadOnlyDictionary <string, T> > GetAllJsonAsync <T>(this DatabaseCategory category) { var info = new DirectoryInfo(category.Path); var files = info.GetFiles(); var dictionary = new Dictionary <string, T>(); foreach (var file in files) { if (file.Extension == ".json") { var text = await File.ReadAllTextAsync(file.FullName); dictionary.Add(Path.GetFileNameWithoutExtension(file.Name), JsonConvert.DeserializeObject <T>(text)); } } return(dictionary); }
/// <summary> /// Инициализирует новый экземпляр класса <see cref="VkApi"/>. /// </summary> public VkApi() { Browser = new Browser(); Users = new UsersCategory(this); Friends = new FriendsCategory(this); Status = new StatusCategory(this); Messages = new MessagesCategory(this); Groups = new GroupsCategory(this); Audio = new AudioCategory(this); Wall = new WallCategory(this); Database = new DatabaseCategory(this); Utils = new UtilsCategory(this); Fave = new FaveCategory(this); Video = new VideoCategory(this); Account = new AccountCategory(this); ApiVersion = "5.9"; }
public bool Support(StorageType storageType, DatabaseCategory databaseType) { //databaseType.IsInMemory; throw new System.NotImplementedException(); }
public void GetRegions_CountryIdIsNegative_ThrowArgumentException() { DatabaseCategory db = GetMockedDatabaseCategory("", ""); This.Action(() => db.GetRegions(-1)).Throws <ArgumentException>(); }
/// <summary> /// Инициализирует новый экземпляр класса <see cref="VkApi"/>. /// </summary> public VkApi() { Browser = new Browser(); Users = new UsersCategory(this); Friends = new FriendsCategory(this); Status = new StatusCategory(this); Messages = new MessagesCategory(this); Groups = new GroupsCategory(this); Audio = new AudioCategory(this); Wall = new WallCategory(this); Database = new DatabaseCategory(this); Utils = new UtilsCategory(this); Fave = new FaveCategory(this); Video = new VideoCategory(this); Account = new AccountCategory(this); Photo = new PhotoCategory(this); Docs = new DocsCategory(this); Likes = new LikesCategory(this); RequestsPerSecond = 3; }
/// <summary> /// Asynchronously saves or overwrites a json file in this category /// </summary> /// <param name="category">The base category</param> /// <param name="name">The name of the file to create</param> /// <param name="data">The object to serialize and store</param> public static async Task SaveJsonAsync(this DatabaseCategory category, string name, object data) { var json = JsonConvert.SerializeObject(data); await File.WriteAllTextAsync($"{category.Path}\\{name}.json", json); }
/// <summary> /// Asynchronously saves a file in this category with the specified name, extension and data /// </summary> /// <param name="category">The base category</param> /// <param name="name">The name of the file</param> /// <param name="extension">The extension of the file with a period (for example: ".jpg")</param> /// <param name="data">The data to be stored in the file</param> public static async Task SaveFileAsync(this DatabaseCategory category, string name, string extension, byte[] data) { await File.WriteAllBytesAsync($"{category.Path}\\{name}{extension}", data); }