Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects
Commit 7c2774aa authored by Markus Quaritsch's avatar Markus Quaritsch
Browse files

loading file, hasing and saving works (sort of)

parent c2384b74
No related branches found
No related tags found
No related merge requests found
<Application x:Class="HashingTool.App" <Application x:Class="HashingTool.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
StartupUri="MainWindow.xaml"> <Application.Resources>
<Application.Resources>
</Application.Resources>
</Application.Resources> </Application>
</Application> \ No newline at end of file
...@@ -41,14 +41,14 @@ namespace HashingTool ...@@ -41,14 +41,14 @@ namespace HashingTool
/// </summary> /// </summary>
public partial class App : Application public partial class App : Application
{ {
//protected override void OnStartup(StartupEventArgs e) protected override void OnStartup(StartupEventArgs e)
//{ {
// base.OnStartup(e); base.OnStartup(e);
// var app = new MainWindow(); var app = new MainWindow();
// var context = new MainWindowViewModel(); var context = new ApplicationViewModel();
// app.DataContext = context; app.DataContext = context;
// //app.Show(); app.Show();
//} }
} }
} }
...@@ -63,6 +63,8 @@ ...@@ -63,6 +63,8 @@
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType> <SubType>Designer</SubType>
</ApplicationDefinition> </ApplicationDefinition>
<Compile Include="Helper\BoolViewConverter.cs" />
<Compile Include="Helper\IOService.cs" />
<Compile Include="Model\TestModel.cs" /> <Compile Include="Model\TestModel.cs" />
<Compile Include="Properties\Annotations.cs" /> <Compile Include="Properties\Annotations.cs" />
<Compile Include="Properties\Version.cs"> <Compile Include="Properties\Version.cs">
...@@ -77,6 +79,7 @@ ...@@ -77,6 +79,7 @@
<Compile Include="ViewModel\RelayCommand.cs" /> <Compile Include="ViewModel\RelayCommand.cs" />
<Compile Include="ViewModel\HashComponentDataViewModel.cs" /> <Compile Include="ViewModel\HashComponentDataViewModel.cs" />
<Compile Include="ViewModel\VerifyInputDataViewModel.cs" /> <Compile Include="ViewModel\VerifyInputDataViewModel.cs" />
<Compile Include="ViewModel\XMLValidator.cs" />
<Compile Include="Views\HashComponentData.xaml.cs"> <Compile Include="Views\HashComponentData.xaml.cs">
<DependentUpon>HashComponentData.xaml</DependentUpon> <DependentUpon>HashComponentData.xaml</DependentUpon>
</Compile> </Compile>
...@@ -145,6 +148,16 @@ ...@@ -145,6 +148,16 @@
<ItemGroup> <ItemGroup>
<Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" /> <Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<ProjectReference Include="..\VectoCommon\VectoHashing\VectoHashing.csproj">
<Project>{B673E12F-D323-4C4C-8805-9915B2C72D3D}</Project>
<Name>VectoHashing</Name>
</ProjectReference>
<ProjectReference Include="..\VectoCore\VectoCore\VectoCore.csproj">
<Project>{CD36938A-ADD9-4C65-96DA-B397CDEEA90A}</Project>
<Name>VectoCore</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets. Other similar extension points exist, see Microsoft.Common.targets.
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
xmlns:viewModel="clr-namespace:HashingTool.ViewModel" xmlns:viewModel="clr-namespace:HashingTool.ViewModel"
xmlns:views="clr-namespace:HashingTool.Views" xmlns:views="clr-namespace:HashingTool.Views"
x:Class="HashingTool.MainWindow" x:Class="HashingTool.MainWindow"
Title="VECTO Hashing Tool" Height="243" Width="593"> Title="VECTO Hashing Tool" Height="534" Width="665" ResizeMode="NoResize">
<Window.DataContext> <Window.DataContext>
<viewModel:ApplicationViewModel /> <viewModel:ApplicationViewModel />
</Window.DataContext> </Window.DataContext>
...@@ -18,11 +18,11 @@ ...@@ -18,11 +18,11 @@
<DataTemplate DataType="{x:Type viewModel:VerifyInputDataViewModel}"> <DataTemplate DataType="{x:Type viewModel:VerifyInputDataViewModel}">
<views:VerifyInputData /> <views:VerifyInputData />
</DataTemplate> </DataTemplate>
</Window.Resources> </Window.Resources>
<Grid Margin="10"> <Grid Margin="10">
<ContentControl Content="{Binding CurrentViewModel}" /> <ContentControl Content="{Binding CurrentViewModel}" />
</Grid> </Grid>
</Window> </Window>
\ No newline at end of file
...@@ -14,7 +14,7 @@ namespace HashingTool.ViewModel ...@@ -14,7 +14,7 @@ namespace HashingTool.ViewModel
private IMainView _currentView; private IMainView _currentView;
public static List<IMainView> AvailableViews; public static List<IMainView> AvailableViews;
public ApplicationViewModel() public ApplicationViewModel()
{ {
......
using System; using System;
using System.ComponentModel; using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input; using System.Windows.Input;
using HashingTool.Model; using System.Xml;
using System.Xml.Linq;
using System.Xml.Schema;
using HashingTool.Helper;
using TUGraz.VectoCore.Utils;
using TUGraz.VectoHashing;
namespace HashingTool.ViewModel namespace HashingTool.ViewModel
{ {
public class HashComponentDataViewModel : ObservableObject, IMainView public class HashComponentDataViewModel : ObservableObject, IMainView
{ {
private readonly ApplicationViewModel _applicationViewModel; private readonly ApplicationViewModel _applicationViewModel;
private bool? _componentDataValid;
private string _digestValue;
//private ObservableCollection<string> _xmlValidationErrors = new ObservableCollection<string>();
private Stream _stream;
private XDocument _result;
public HashComponentDataViewModel() {} private IOService _ioService = new WPFIoService();
private RelayCommand _saveCommand;
private bool _busy;
private string _source;
public HashComponentDataViewModel(ApplicationViewModel applicationViewModel) public HashComponentDataViewModel()
{
XMLValidationErrors = new ObservableCollection<string>();
_saveCommand = new RelayCommand(SaveDocument,
() => !_busy && ComponentDataValid != null && ComponentDataValid.Value && _result != null);
_busy = false;
}
public HashComponentDataViewModel(ApplicationViewModel applicationViewModel) : this()
{ {
_applicationViewModel = applicationViewModel; _applicationViewModel = applicationViewModel;
} }
...@@ -25,5 +51,135 @@ namespace HashingTool.ViewModel ...@@ -25,5 +51,135 @@ namespace HashingTool.ViewModel
{ {
get { return ApplicationViewModel.HomeView; } get { return ApplicationViewModel.HomeView; }
} }
public string Source
{
get { return _source; }
private set {
if (_source == value) {
return;
}
_source = value;
RaisePropertyChanged("Source");
}
}
public bool? ComponentDataValid
{
get { return _componentDataValid; }
private set {
if (_componentDataValid == value) {
return;
}
_componentDataValid = value;
RaisePropertyChanged("ComponentDataValid");
}
}
public ObservableCollection<string> XMLValidationErrors { get; set; }
//{
// get { return _xmlValidationErrors; }
// private set {
// _xmlValidationErrors = value;
// RaisePropertyChanged("XMLValidationErrors");
// }
//}
public string DigestValue
{
get { return _digestValue; }
set {
if (_digestValue == value) {
return;
}
_digestValue = value;
RaisePropertyChanged("DigestValue");
}
}
public ICommand SetComponentData
{
get { return new RelayCommand(HashComponentData, () => !_busy); }
}
public ICommand SaveHashedDocument
{
get { return _saveCommand; }
}
private void SaveDocument()
{
string filename;
var stream = _ioService.SaveData(null, ".xml", "VECTO XML file|*.xml", out filename);
if (stream == null) {
return;
}
using (var writer = new XmlTextWriter(stream, Encoding.UTF8) {
Formatting = Formatting.Indented,
Indentation = 4
}) {
_result.WriteTo(writer);
writer.Flush();
writer.Close();
}
}
private void HashComponentData()
{
string filename;
var xml = _ioService.OpenFileDialog(null, ".xml", "VECTO XML file|*.xml", out filename);
if (xml == null) {
return;
}
_busy = true;
ComponentDataValid = null;
XMLValidationErrors.Clear();
DigestValue = "";
Source = filename;
_stream = xml;
DoComputeHash();
}
private async void DoComputeHash()
{
try {
var h = VectoHash.Load(_stream);
_result = h.AddHash();
using (MemoryStream ms = new MemoryStream()) {
using (XmlWriter xw = XmlWriter.Create(ms, new XmlWriterSettings { Indent = true })) {
_result.WriteTo(xw);
xw.Flush();
}
ms.Flush();
ms.Seek(0, SeekOrigin.Begin);
ComponentDataValid = true;
var validator = new XMLValidator(r => { ComponentDataValid = r; },
(s, e) => {
Application.Current.Dispatcher.Invoke(() => XMLValidationErrors.Add(
string.Format("Validation {0} Line {2}: {1}", s == XmlSeverityType.Warning ? "WARNING" : "ERROR",
e.ValidationEventArgs == null
? e.Exception.Message +
(e.Exception.InnerException != null ? Environment.NewLine + e.Exception.InnerException.Message : "")
: e.ValidationEventArgs.Message,
e.ValidationEventArgs == null ? 0 : e.ValidationEventArgs.Exception.LineNumber)));
});
await validator.ValidateXML(ms);
}
if (ComponentDataValid != null && ComponentDataValid.Value) {
DigestValue = h.ComputeHash();
}
_saveCommand.RaiseCanExecuteChanged();
} catch (Exception e) {
ComponentDataValid = false;
DigestValue = "";
XMLValidationErrors.Add(e.Message);
} finally {
_busy = false;
}
}
} }
} }
...@@ -52,6 +52,12 @@ namespace HashingTool.ViewModel ...@@ -52,6 +52,12 @@ namespace HashingTool.ViewModel
} }
} }
public void RaiseCanExecuteChanged()
{
CommandManager.InvalidateRequerySuggested();
}
[DebuggerStepThrough] [DebuggerStepThrough]
public Boolean CanExecute(Object parameter) public Boolean CanExecute(Object parameter)
{ {
...@@ -112,6 +118,11 @@ namespace HashingTool.ViewModel ...@@ -112,6 +118,11 @@ namespace HashingTool.ViewModel
} }
} }
public void RaiseCanExecuteChanged()
{
CommandManager.InvalidateRequerySuggested();
}
[DebuggerStepThrough] [DebuggerStepThrough]
public Boolean CanExecute(Object parameter) public Boolean CanExecute(Object parameter)
{ {
......
...@@ -3,16 +3,31 @@ ...@@ -3,16 +3,31 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:ViewModel="clr-namespace:HashingTool.ViewModel" x:Class="HashingTool.Views.HashComponentData" xmlns:ViewModel="clr-namespace:HashingTool.ViewModel" xmlns:Helper="clr-namespace:HashingTool.Helper"
x:Class="HashingTool.Views.HashComponentData"
mc:Ignorable="d" mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300"> d:DesignHeight="501.425" d:DesignWidth="548">
<UserControl.Resources>
<Helper:BoolViewConverter x:Key="BoolViewConverter" />
</UserControl.Resources>
<UserControl.DataContext> <UserControl.DataContext>
<ViewModel:HashComponentDataViewModel /> <ViewModel:HashComponentDataViewModel />
</UserControl.DataContext> </UserControl.DataContext>
<Grid> <Grid>
<Label HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" <Label HorizontalAlignment="Center" Margin="10,10,0,0" VerticalAlignment="Top"
Content="{Binding Name}" /> Content="{Binding Name}" FontWeight="Bold" FontSize="18" />
<Button Content="Home" Command="{Binding ShowHomeViewCommand}" HorizontalAlignment="Left" Margin="201,194,0,0" VerticalAlignment="Top" Width="75"/> <Button Content="Back" Command="{Binding ShowHomeViewCommand}" Margin="0,0,10,10" HorizontalAlignment="Right"
Width="75" Height="22" VerticalAlignment="Bottom" />
<Button x:Name="btSelectComponentFile" Content="Browse ..." HorizontalAlignment="Left" Margin="300,79,0,0"
VerticalAlignment="Top" Width="75" Command="{Binding SetComponentData, Mode=OneWay}" />
<TextBox x:Name="tbComponentFile" HorizontalAlignment="Left" Height="23" Margin="10,79,0,0" TextWrapping="Wrap"
VerticalAlignment="Top" Width="285" IsReadOnly="True" Text="{Binding Source, Mode=OneWay}" />
<Label Content="{Binding ComponentDataValid, Converter={StaticResource BoolViewConverter}, Mode=OneWay}"
HorizontalAlignment="Left" Margin="10,141,0,0" VerticalAlignment="Top" Height="26" Width="154" />
<Label Content="{Binding DigestValue}" HorizontalAlignment="Left" Margin="10,172,0,0" VerticalAlignment="Top" />
<Button Content="Save" HorizontalAlignment="Right" Margin="0,0,90,10" Width="75" Height="22"
VerticalAlignment="Bottom" Command="{Binding SaveHashedDocument, Mode=OneWay}" />
<ListBox HorizontalAlignment="Left" Height="214" Margin="71,230,0,0" VerticalAlignment="Top" Width="436" IsSynchronizedWithCurrentItem="False" ItemsSource="{Binding XMLValidationErrors}"/>
</Grid> </Grid>
</UserControl> </UserControl>
\ No newline at end of file
using System; using System;
using System.Collections.Generic; using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Media; using HashingTool.ViewModel;
using System.Windows.Media.Imaging; using Microsoft.Win32;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace HashingTool.Views namespace HashingTool.Views
{ {
......
<UserControl <UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:viewModel="clr-namespace:HashingTool.ViewModel" x:Class="HashingTool.Views.HomeView" xmlns:viewModel="clr-namespace:HashingTool.ViewModel" x:Class="HashingTool.Views.HomeView"
mc:Ignorable="d" mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300"> d:DesignHeight="300" d:DesignWidth="300">
<Grid> <Grid x:Name="MainGrid">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.DataContext> <Grid.DataContext>
<viewModel:HomeViewModel/> <viewModel:HomeViewModel />
</Grid.DataContext> </Grid.DataContext>
<ItemsControl ItemsSource="{Binding MainViewModels}"> <ItemsControl x:Name="ViewSelectionPanel"
ItemsSource="{Binding MainViewModels}"
Grid.Column="1">
<ItemsControl.ItemTemplate> <ItemsControl.ItemTemplate>
<DataTemplate> <DataTemplate>
<Grid Margin="0,0,0,5"> <Grid Margin="0,30,0,5">
<Button Content="{Binding Name}" Margin="2,5" <Button Content="{Binding Name}" Margin="2,5" Padding="15,10"
Command="{Binding DataContext.ChangeViewCommand, RelativeSource={RelativeSource AncestorType={x:Type Window}}}" Command="{Binding DataContext.ChangeViewCommand, RelativeSource={RelativeSource AncestorType={x:Type Window}}}"
CommandParameter="{Binding ''}" /> CommandParameter="{Binding ''}" />
</Grid> </Grid>
</DataTemplate> </DataTemplate>
</ItemsControl.ItemTemplate> </ItemsControl.ItemTemplate>
</ItemsControl> </ItemsControl>
</Grid> </Grid>
</UserControl> </UserControl>
\ No newline at end of file
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> <wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeInspection/CodeAnnotations/NamespacesWithAnnotations/=HashingTool_002EAnnotations/@EntryIndexedValue">True</s:Boolean>
<s:String x:Key="/Default/CodeStyle/CodeCleanup/SilentCleanupProfile/@EntryValue">Default: Reformat Code</s:String> <s:String x:Key="/Default/CodeStyle/CodeCleanup/SilentCleanupProfile/@EntryValue">Default: Reformat Code</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CommonFormatter/ALIGNMENT_TAB_FILL_STYLE/@EntryValue">USE_TABS_ONLY</s:String> <s:String x:Key="/Default/CodeStyle/CodeFormatting/CommonFormatter/ALIGNMENT_TAB_FILL_STYLE/@EntryValue">USE_TABS_ONLY</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ANONYMOUS_METHOD_DECLARATION_BRACES/@EntryValue">END_OF_LINE</s:String> <s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ANONYMOUS_METHOD_DECLARATION_BRACES/@EntryValue">END_OF_LINE</s:String>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment