Skip to content

Commit

Permalink
Тестовые примеры
Browse files Browse the repository at this point in the history
  • Loading branch information
inyutin-maxim committed Feb 18, 2018
1 parent 0fa871d commit 45006b2
Show file tree
Hide file tree
Showing 21 changed files with 669 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -11,6 +11,7 @@ Release/
.idea/

/GCopLog.txt
*/**/.vs/*
.vs/*
/VkNet.UWP/*.lock.json
/VkNet/Categories/Obsolete/
10 changes: 6 additions & 4 deletions VkNet/VkApi.cs
Expand Up @@ -29,13 +29,15 @@ namespace VkNet
/// <summary>
/// Служит для оповещения об истечении токена
/// </summary>
/// <param name="sender">Экземпляр API у которого истекло время токена</param>
/// <param name="sender">
/// Экземпляр API у которого истекло время токена
/// </param>
public delegate void VkApiDelegate(VkApi sender);

/// <inheritdoc />
/// <summary>
/// API для работы с ВКонтакте. Выступает в качестве фабрики для различных категорий API (например, для работы с пользователями,
/// группами и т.п.).
/// API для работы с ВКонтакте.
/// Выступает в качестве фабрики для различных категорий API (например, для работы с пользователями, группами и т.п.)
/// </summary>
public class VkApi : IVkApi
{
Expand Down Expand Up @@ -605,7 +607,7 @@ public string Invoke(string methodName, IDictionary<string, string> parameters,
}

_logger?.Debug(Utilities.PreetyPrintApiUrl(url));
_logger?.Trace(Utilities.PreetyPrintJson(answer));
_logger?.Debug(Utilities.PreetyPrintJson(answer));

VkErrors.IfErrorThrowException(answer);

Expand Down
6 changes: 3 additions & 3 deletions VkNet/VkNet.csproj
Expand Up @@ -36,10 +36,10 @@
<OutputPath>..\Build\Release\</OutputPath>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="HtmlAgilityPack" Version="1.6.16" />
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
<PackageReference Include="HtmlAgilityPack" Version="1.6.17" />
<PackageReference Include="JetBrains.Annotations" Version="11.1.0" />
<PackageReference Include="NLog" Version="4.5.0-rc03" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.1" />
<PackageReference Include="NLog" Version="4.5.0-rc05" />
<PackageReference Include="SimpleInjector" Version="4.0.12" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
Expand Down
6 changes: 6 additions & 0 deletions examples/Examples.sln
Expand Up @@ -4,6 +4,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VkNet.Examples", "VkNet.Exa
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VkNet.Shared", "VkNet.Shared\VkNet.Shared.csproj", "{646DE977-0B6F-4883-A93C-996B8F0F4AB6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VkNet.Wpf", "VkNet.Wpf\VkNet.Wpf.csproj", "{EEBE591E-8B68-487D-87F0-F17AEFC3A307}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -18,5 +20,9 @@ Global
{646DE977-0B6F-4883-A93C-996B8F0F4AB6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{646DE977-0B6F-4883-A93C-996B8F0F4AB6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{646DE977-0B6F-4883-A93C-996B8F0F4AB6}.Release|Any CPU.Build.0 = Release|Any CPU
{EEBE591E-8B68-487D-87F0-F17AEFC3A307}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EEBE591E-8B68-487D-87F0-F17AEFC3A307}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EEBE591E-8B68-487D-87F0-F17AEFC3A307}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EEBE591E-8B68-487D-87F0-F17AEFC3A307}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
2 changes: 1 addition & 1 deletion examples/VkNet.Examples/Program.cs
Expand Up @@ -8,7 +8,7 @@ internal class Program
{
public static void Main(string[] args)
{
var api = new VkApi();
var api = Api.GetInstance();

api.Auth();
Console.WriteLine(api.Token);
Expand Down
30 changes: 30 additions & 0 deletions examples/VkNet.Shared/Api.cs
@@ -0,0 +1,30 @@
using Microsoft.Extensions.DependencyInjection;

namespace VkNet.Shared
{
/// <summary>
///
/// </summary>
public class Api
{
/// <summary>
/// The instance
/// </summary>
private static VkApi _instance;

/// <summary>
/// Prevents a default instance of the <see cref="Api"/> class from being created.
/// </summary>
private Api()
{}

/// <summary>
/// Gets the instance.
/// </summary>
/// <returns></returns>
public static VkApi GetInstance(IServiceCollection collection = null)
{
return _instance ?? (_instance = new VkApi(collection));
}
}
}
1 change: 1 addition & 0 deletions examples/VkNet.Shared/VkNet.Shared.csproj
Expand Up @@ -77,6 +77,7 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Api.cs" />
<Compile Include="VkHelper.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
Expand Down
14 changes: 14 additions & 0 deletions examples/VkNet.Wpf/App.config
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="HtmlAgilityPack" publicKeyToken="bd319b19eaf3b43a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.6.17.0" newVersion="1.6.17.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
9 changes: 9 additions & 0 deletions examples/VkNet.Wpf/App.xaml
@@ -0,0 +1,9 @@
<Application x:Class="VkNet.Wpf.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:VkNet.Wpf"
StartupUri="MainWindow.xaml">
<Application.Resources>

</Application.Resources>
</Application>
9 changes: 9 additions & 0 deletions examples/VkNet.Wpf/App.xaml.cs
@@ -0,0 +1,9 @@
namespace VkNet.Wpf
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App
{
}
}
17 changes: 17 additions & 0 deletions examples/VkNet.Wpf/AuthForm.xaml
@@ -0,0 +1,17 @@
<Window x:Class="VkNet.Wpf.AuthForm"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:VkNet.Wpf"
mc:Ignorable="d"
Title="Авторизация" Height="155" Width="200">
<Grid>
<TextBox x:Name="loginTb" HorizontalAlignment="Left" Height="23" Margin="64,20,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" Text=""/>
<TextBox x:Name="passwordTb" HorizontalAlignment="Left" Height="23" Margin="64,55,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="120"/>
<Button Content="Войти" HorizontalAlignment="Left" Margin="64,96,0,0" VerticalAlignment="Top" Width="120" Click="Button_Click"/>
<Label Content="Логин:" HorizontalAlignment="Left" Margin="5,17,0,0" VerticalAlignment="Top"/>
<Label Content="Пароль:" HorizontalAlignment="Left" Margin="5,52,0,0" VerticalAlignment="Top"/>

</Grid>
</Window>
44 changes: 44 additions & 0 deletions examples/VkNet.Wpf/AuthForm.xaml.cs
@@ -0,0 +1,44 @@
using System.Windows;
using VkNet.Enums.Filters;
using VkNet.Shared;

namespace VkNet.Wpf
{
/// <summary>
/// Логика взаимодействия для AuthForm.xaml
/// </summary>
public partial class AuthForm : Window
{
private VkApi _api;

public string TFCode { get; set; }

public AuthForm()
{
InitializeComponent();
_api = Api.GetInstance();
}

private void Button_Click(object sender, RoutedEventArgs e)
{
_api.Authorize(new ApiAuthParams
{
ApplicationId = 4268118,
Settings = Settings.All,
Login = loginTb.Text,
Password = passwordTb.Text,
TwoFactorAuthorization = () =>
{
var tfa = new TwoFactorAuthorization {Owner = this};
var dlg = tfa.ShowDialog();
if (dlg.HasValue && dlg.Value)
{
}
return TFCode;
}
});
Close();
}
}
}
17 changes: 17 additions & 0 deletions examples/VkNet.Wpf/MainWindow.xaml
@@ -0,0 +1,17 @@
<Window x:Class="VkNet.Wpf.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:VkNet.Wpf"
mc:Ignorable="d"
Title="Главная" Height="350" Width="525" Initialized="Window_Initialized">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="197*"/>
<ColumnDefinition Width="320*"/>
</Grid.ColumnDefinitions>
<Button Content="Тест" HorizontalAlignment="Left" Margin="70,25,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click"/>

</Grid>
</Window>
40 changes: 40 additions & 0 deletions examples/VkNet.Wpf/MainWindow.xaml.cs
@@ -0,0 +1,40 @@
using System.Windows;
using VkNet.Model.RequestParams;
using VkNet.Shared;

namespace VkNet.Wpf
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow
{
private readonly VkApi _api;
public MainWindow()
{
InitializeComponent();
_api = Api.GetInstance();
if (_api.IsAuthorized)
{
return;
}

var auth = new AuthForm();
var dlg = auth.ShowDialog();
if (dlg.HasValue && dlg.Value)
{
}
}

private void Window_Initialized(object sender, System.EventArgs e)
{

}

private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
{
var tmp = _api.Groups.Get(new GroupsGetParams());
MessageBox.Show(tmp.TotalCount.ToString());
}
}
}
55 changes: 55 additions & 0 deletions examples/VkNet.Wpf/Properties/AssemblyInfo.cs
@@ -0,0 +1,55 @@
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Windows;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("VkNet.Wpf")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("VkNet.Wpf")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

//In order to begin building localizable applications, set
//<UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file
//inside a <PropertyGroup>. For example, if you are using US english
//in your source files, set the <UICulture> to en-US. Then uncomment
//the NeutralResourceLanguage attribute below. Update the "en-US" in
//the line below to match the UICulture setting in the project file.

//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]


[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]


// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

0 comments on commit 45006b2

Please sign in to comment.