Skip to content

Instantly share code, notes, and snippets.

View Platonenkov's full-sized avatar
🏠
Working from home

Aleksandr Platonenkov

🏠
Working from home
View GitHub Profile
@Platonenkov
Platonenkov / CustomAuthorizationPolicyProvider.cs
Last active May 14, 2021 09:06
Policy for authorization
public class CustomAuthorizationPolicyProvider : DefaultAuthorizationPolicyProvider
{
private readonly AuthorizationOptions _Options;
public CustomAuthorizationPolicyProvider(IOptions<AuthorizationOptions> options) : base(options) { _Options = options.Value; }
#region Overrides of DefaultAuthorizationPolicyProvider
public override async Task<AuthorizationPolicy> GetPolicyAsync(string policyName)
{
@Platonenkov
Platonenkov / HoverButton.xaml
Created May 8, 2021 16:27
Hover Button style
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:p="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options"
xmlns:s="clr-namespace:System;assembly=mscorlib">
<DropShadowEffect x:Key="Shadow" p:Freeze="True"/>
<ScaleTransform x:Key="Scale1.1" ScaleX="1.1" ScaleY="1.1" p:Freeze="True"/>
<ScaleTransform x:Key="Scale0.9" ScaleX="0.9" ScaleY="0.9" p:Freeze="True"/>
<SolidColorBrush x:Key="DarkGrayBrush" Color="DarkGray" p:Freeze="True"/>
<SolidColorBrush x:Key="BorderBrush" Color="#EEE" p:Freeze="True"/>
@Platonenkov
Platonenkov / ToggleButtonCheckBox.xaml
Created May 8, 2021 16:29
Toggle Button CheckBox style
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:p="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<SolidColorBrush x:Key="WhiteBrush" Color="White" p:Freeze="True"/>
<!--форма переключателя-->
<ControlTemplate x:Key="ToggleButtonCheckBoxTemplate" TargetType="{x:Type CheckBox}">
<ControlTemplate.Resources>
<SolidColorBrush x:Key="ToggleButton.CheckedBackgroundBrush" p:Freeze="true">DarkBlue</SolidColorBrush>
@Platonenkov
Platonenkov / ToggleHoverButton.xaml
Created May 8, 2021 16:30
Toggle Hover Button
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:p="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options"
xmlns:s="clr-namespace:System;assembly=mscorlib">
<DropShadowEffect x:Key="Shadow" p:Freeze="True"/>
<ScaleTransform x:Key="Scale1.1" ScaleX="1.1" ScaleY="1.1" p:Freeze="True"/>
<ScaleTransform x:Key="Scale0.9" ScaleX="0.9" ScaleY="0.9" p:Freeze="True"/>
<ScaleTransform x:Key="Scale0.7" ScaleX="0.7" ScaleY="0.7" p:Freeze="True"/>
<SolidColorBrush x:Key="DarkGrayBrush" Color="DarkGray" p:Freeze="True"/>
@Platonenkov
Platonenkov / TokenContainer.cs
Created May 14, 2021 06:03
Get token from context
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Http;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
namespace Management.Ui.Services
{
public class TokenContainer
{
@Platonenkov
Platonenkov / 1Startup.cs
Last active May 17, 2021 12:47
Authentication
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication(options =>
{
options.DefaultScheme =
CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme =
OpenIdConnectDefaults.AuthenticationScheme;
})
public static async Task<string> CallServiceAsync(string token, string controller)
{
var baseAddress = Constants.SampleApi;
var client = new HttpClient
{
BaseAddress = new Uri(baseAddress)
};
client.SetBearerToken(token);
@Platonenkov
Platonenkov / ApplicationInstance.cs
Created May 25, 2021 10:36
WPF Check for second Instance
public static class ApplicationInstance
{
/// <summary> Проверяет запущен ли уже экземпляр приложения </summary>
/// <returns>true - запущен, false - нет</returns>
public static bool CheckForSecondInstance()
{
var startup_path = System.Reflection.Assembly.GetEntryAssembly()?.Location;
var startup_file_name = System.IO.Path.GetFileNameWithoutExtension(startup_path);
var processes_with_same_file = Process.GetProcessesByName(startup_file_name);
return processes_with_same_file.Length > 1;
@Platonenkov
Platonenkov / JsonInFile.cs
Last active May 27, 2021 07:36
Save data to Json format
public static class JsonInFile
{
/// <summary>
/// Сохранение данных в файл
/// </summary>
public static async Task<bool> SaveToFileAsync<T>(string FilePath, T data)
{
try
{
using var file = File.Create(FilePath);
@Platonenkov
Platonenkov / App.xaml.cs
Last active June 29, 2021 08:51
Add Host, service
public partial class App
{
public static bool IsDesignMode { get; private set; } = true;
private static IHost __Host;
public static IHost Host => __Host ??= Program.CreateHostBuilder(Environment.GetCommandLineArgs()).Build();
protected override async void OnStartup(StartupEventArgs e)
{