Skip to content

Commit

Permalink
[Course work] A lot of things
Browse files Browse the repository at this point in the history
  • Loading branch information
DeoEsor committed May 26, 2022
1 parent 4ea6464 commit 0d4efd2
Show file tree
Hide file tree
Showing 39 changed files with 1,252 additions and 102 deletions.
5 changes: 4 additions & 1 deletion CryptoDesktop/App.xaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<Application
StartupUri="MainWindow.xaml"
x:Class="CryptoDesktop.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:local="clr-namespace:CryptoDesktop"
Expand All @@ -12,6 +11,10 @@
<ResourceDictionary Source="Themes/MessageBox.xaml" />
<ResourceDictionary Source="Themes/ScrollBar.xaml" />
<ResourceDictionary Source="Themes/ButtonStyle.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.DeepPurple.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Lime.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
Expand Down
27 changes: 27 additions & 0 deletions CryptoDesktop/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using CryptoDesktop.MVVM.ViewModel;
using DryIoc;
using СryptoClient;

namespace CryptoDesktop
{
Expand All @@ -13,5 +16,29 @@ namespace CryptoDesktop
/// </summary>
public partial class App : Application
{
public static Container Container { get; set; }
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);

Container = new Container();

// Grpc client
Container.Register<CryptoClient>(Reuse.Singleton);
//Views
Container.Register<Registration>(Reuse.Transient);
Container.Register<MainWindow>(Reuse.Transient);
//ViewModels
Container.Register<ChatViewModel>(Reuse.Singleton);

var reg = Container.Resolve<Registration>();
reg.DataContext = new RegistrationViewModel(reg);
reg.Show();
}

protected override void OnSessionEnding(SessionEndingCancelEventArgs e)
{
base.OnSessionEnding(e);
}
}
}
6 changes: 6 additions & 0 deletions CryptoDesktop/Core/Interfaces/IPasswordSupplier.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace CryptoDesktop.Core.Interfaces;

public interface IPasswordSupplier
{
string GetPassword();
}
13 changes: 8 additions & 5 deletions CryptoDesktop/CryptoDesktop.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,9 @@
<Private>true</Private>
<ReferenceOutputAssembly>true</ReferenceOutputAssembly>
</ProjectReference>
<ProjectReference Include="..\CryptoVisualization\CryptoVisualization.csproj" />
<ProjectReference Include="..\СryptoClient\СryptoClient.csproj" />
</ItemGroup>

<ItemGroup>
<Folder Include="MVVM\View" />
</ItemGroup>

<ItemGroup>
<None Remove="Resources\Icons\default_logo.png" />
<Content Include="Resources\Icons\default_logo.png">
Expand Down Expand Up @@ -60,4 +55,12 @@
</Content>
</ItemGroup>

<ItemGroup>
<PackageReference Include="DryIoc" Version="5.1.0" />
<PackageReference Include="MahApps.Metro.IconPacks" Version="4.11.0" />
<PackageReference Include="MaterialDesignColors" Version="2.0.6" />
<PackageReference Include="MaterialDesignThemes" Version="4.5.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
</ItemGroup>

</Project>
62 changes: 62 additions & 0 deletions CryptoDesktop/MVVM/Convertors/BaseConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using System;
using System.Globalization;
using System.Windows.Data;
using System.Windows.Markup;
using Google.Protobuf.Reflection;

namespace CryptoDesktop.MVVM.Convertors;

/// <summary>
/// A base value converter that allows direct XAML usage
/// </summary>
/// <typeparam name="T">The type of this value converter</typeparam>
public abstract class BaseValueConverter<T> : MarkupExtension, IValueConverter
where T : class, new()
{
#region Private Members

/// <summary>
/// A single static instance of this value converter
/// </summary>
private static T mConverter = null;

#endregion

#region Markup Extension Methods

/// <summary>
/// Provides a static instance of the value converter
/// </summary>
/// <param name="serviceProvider">The service provider</param>
/// <returns></returns>
public override object ProvideValue(IServiceProvider serviceProvider)
{
return mConverter ?? (mConverter = new T());
}

#endregion

#region Value Converter Methods

/// <summary>
/// The method to convert one type to another
/// </summary>
/// <param name="value"></param>
/// <param name="targetType"></param>
/// <param name="parameter"></param>
/// <param name="culture"></param>
/// <returns></returns>
public abstract object Convert(object value, Type targetType, object parameter, CultureInfo culture);

/// <summary>
/// The method to convert a value back to it's source type
/// </summary>
/// <param name="value"></param>
/// <param name="targetType"></param>
/// <param name="parameter"></param>
/// <param name="culture"></param>
/// <returns></returns>
public abstract object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture);

#endregion
}
6 changes: 3 additions & 3 deletions CryptoDesktop/MVVM/Convertors/ByteStringConvertor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@

namespace CryptoDesktop.MVVM.Convertors;

public class ByteStringConvertor : IValueConverter
public class ByteStringConvertor : BaseValueConverter<ByteStringConvertor>
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (!(value is byte[] message))
throw new ArgumentException("Parameter incorrect", nameof(parameter));

return Encoding.UTF8.GetString(message);
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
if (!(value is string message))
throw new ArgumentException("Parameter incorrect", nameof(parameter));
Expand Down
6 changes: 0 additions & 6 deletions CryptoDesktop/MVVM/Model/ContactCard.cs

This file was deleted.

4 changes: 3 additions & 1 deletion CryptoDesktop/MVVM/Model/ContactModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ public sealed class ContactModel : INotifyPropertyChanged
private string _username;
private string _status;
private string _imageSource;

public string Password { get; set; }
public string Color { get; set; }
public int Id { get; set; }

public ObservableCollection<MessageModel> Messages { get; set; }

Expand Down
8 changes: 5 additions & 3 deletions CryptoDesktop/MVVM/Model/MessageModel.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
using System;
using CryptoServices;

namespace CryptoDesktop.MVVM.Model;

public class MessageModel
{
public string Username { get; set; }
public string UsernameColor { get; set; }
public string ImageSource { get; set; }
public CryptoDesktop.MVVM.Model.ContactModel Owner { get; set; }
public string Username => Owner.Username;
public string UsernameColor => Owner.Color;
public string ImageSource => Owner.ImageSource;
public Message Message { get; set; }


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
</Window.DataContext>
<Window.Resources>
<BitmapImage x:Key="DefaultImage" UriSource="/resources/Icons/default_logo.png" />
<Image x:Key="SendButtonImage" Source="Resources/Icons/send.png" Width="20" Height="20"
<Image x:Key="SendButtonImage" Source="../../Resources/Icons/send.png" Width="20" Height="20"
RenderOptions.BitmapScalingMode="Fant"/>
<Image x:Key="SendFileButtonImage" Source="Resources/Icons/plus.png" Width="20" Height="20"
<Image x:Key="SendFileButtonImage" Source="../../Resources/Icons/plus.png" Width="20" Height="20"
RenderOptions.BitmapScalingMode="Fant"/>
<Image x:Key="AddUserImage" Source="Resources/Icons/user_add.png" Width="20" Height="20"
<Image x:Key="AddUserImage" Source="../../Resources/Icons/user_add.png" Width="20" Height="20"
RenderOptions.BitmapScalingMode="Fant"/>
</Window.Resources>
<Grid>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Windows;
using System.Windows.Input;
using DryIoc;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using СryptoClient;
Expand Down
130 changes: 130 additions & 0 deletions CryptoDesktop/MVVM/View/Registration.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<Window x:Class="CryptoDesktop.Registration"
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:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
xmlns:viewModel="clr-namespace:CryptoDesktop.MVVM.ViewModel"
mc:Ignorable="d"
Title="Registration" Height="450" Width="380"
AllowsTransparency="True" Background="Transparent"
WindowStartupLocation="CenterScreen"
WindowStyle="None" ResizeMode="NoResize"
MouseDown="Registration_OnMouseDown">
<Grid>
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>


<Border CornerRadius="10" Grid.RowSpan="2">
<Border.Background>
<LinearGradientBrush>
<GradientStop Color="#252525" Offset="0.0"/>
<GradientStop Color="#292B2A" Offset="0.5"/>
<GradientStop Color="#252525" Offset="0.8"/>
</LinearGradientBrush>
</Border.Background>
</Border>


<StackPanel VerticalAlignment="Center">
<Border
BorderBrush="Black"
BorderThickness="1"
CornerRadius="60"
HorizontalAlignment="Center">
<Image Source="../../Resources/Icons/default_logo.png" Width="80"/>
</Border>

<TextBlock Text="Crypto Chat"
FontWeight="Light"
FontFamily="helvetica"
FontSize="22"
Foreground="White"
HorizontalAlignment="Center"/>
</StackPanel>



<StackPanel Grid.Row="1" >
<StackPanel Orientation="Horizontal">
<TextBox FontFamily="Helvetica"
FontWeight="Light"
Text="{Binding UserName}"
FontSize="20"
HorizontalAlignment="Center"
Foreground="White"
Background="Transparent"
BorderThickness="0"
Width="235"
HorizontalContentAlignment="Left"
Height="25"
Margin="63,0,0,0"/>
<iconPacks:PackIconMaterial Kind="Account"
VerticalAlignment="Center"
HorizontalAlignment="Center"
Foreground="White"/>
</StackPanel>
<Border Width="250"
Height="2"
Background="White"
Opacity="0.5"/>



<StackPanel Orientation="Horizontal" Margin="0,20,0,0">
<PasswordBox
x:Name="PasswordBox"
FontFamily="Helvetica"
FontWeight="Light"
Password="Password"
FontSize="20"
HorizontalAlignment="Center"
Foreground="White"
Background="Transparent"
BorderThickness="0"
Width="235"
HorizontalContentAlignment="Left"
Height="25"
Margin="63,0,0,0"/>
<iconPacks:PackIconMaterial Kind="FormTextboxPassword"
VerticalAlignment="Center"
HorizontalAlignment="Center"
Foreground="White"/>
</StackPanel>
<Border Width="250"
Height="2"
Background="White"
Opacity="0.5"/>


<StackPanel Orientation="Horizontal" Margin="0,50,0,0">
<Button
Command="{Binding LoginCommand}"
CommandParameter="{Binding ElementName=PasswordBox}"
Style="{StaticResource RoundCorner}"
Width="100" Height="40"
Content="LOGIN" Margin="60,0,60,0"
Foreground="White"/>
<Button
Command="{Binding RegisterCommand}"
CommandParameter="{Binding ElementName=PasswordBox}"
Style="{StaticResource RoundCorner}"
Width="100" Height="40"
Content="REGISTER"
Foreground="White"/>
</StackPanel>

</StackPanel>






</Grid>
</Grid>
</Window>
18 changes: 18 additions & 0 deletions CryptoDesktop/MVVM/View/Registration.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Windows;
using System.Windows.Input;

namespace CryptoDesktop;

public partial class Registration : Window
{
public Registration()
{
InitializeComponent();
}

private void Registration_OnMouseDown(object sender, MouseButtonEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
DragMove();
}
}
Loading

0 comments on commit 0d4efd2

Please sign in to comment.