diff --git a/.idea/.idea.GazpromApp/.idea/avalonia.xml b/.idea/.idea.GazpromApp/.idea/avalonia.xml
index b3c12de..122bbc9 100644
--- a/.idea/.idea.GazpromApp/.idea/avalonia.xml
+++ b/.idea/.idea.GazpromApp/.idea/avalonia.xml
@@ -6,6 +6,7 @@
+
diff --git a/Enums/ErrorSeverity.cs b/Enums/ErrorSeverity.cs
new file mode 100644
index 0000000..83e2cbc
--- /dev/null
+++ b/Enums/ErrorSeverity.cs
@@ -0,0 +1,8 @@
+namespace GazpromApp.Enums;
+
+public enum ErrorSeverity
+{
+ Message = 0,
+ Warning = 1,
+ Error = 2
+}
diff --git a/Messages/ErrorMessage.cs b/Messages/ErrorMessage.cs
new file mode 100644
index 0000000..edf699f
--- /dev/null
+++ b/Messages/ErrorMessage.cs
@@ -0,0 +1,9 @@
+using CommunityToolkit.Mvvm.Messaging.Messages;
+using GazpromApp.ViewModels;
+
+namespace GazpromApp.Messages;
+
+public class ErrorMessage(ErrorViewModel error) : AsyncRequestMessage
+{
+ public ErrorViewModel Error { get; } = error;
+}
\ No newline at end of file
diff --git a/Models/Error.cs b/Models/Error.cs
new file mode 100644
index 0000000..937a4cc
--- /dev/null
+++ b/Models/Error.cs
@@ -0,0 +1,11 @@
+using GazpromApp.Enums;
+using GazpromApp.ViewModels;
+
+namespace GazpromApp.Models;
+
+public class Error
+{
+ public string? Title { get; set; }
+ public string? Message { get; set; }
+ public ErrorSeverity Severity { get; set; }
+}
\ No newline at end of file
diff --git a/ViewModels/Basic/ErrorViewModel.cs b/ViewModels/Basic/ErrorViewModel.cs
new file mode 100644
index 0000000..2ea9be6
--- /dev/null
+++ b/ViewModels/Basic/ErrorViewModel.cs
@@ -0,0 +1,69 @@
+using Avalonia.Controls;
+using CommunityToolkit.Mvvm.ComponentModel;
+using CommunityToolkit.Mvvm.Input;
+using GazpromApp.Enums;
+using GazpromApp.Models;
+
+namespace GazpromApp.ViewModels;
+
+public partial class ErrorViewModel : ViewModelBase
+{
+ [ObservableProperty]
+ private string? _title;
+
+ [ObservableProperty]
+ private string? _message;
+
+ [RelayCommand]
+ private static void Ok(Window w)
+ {
+ w.Close();
+ }
+
+ private ErrorSeverity severity;
+
+ // Visual and other properties
+ [ObservableProperty] private bool _isErrorVisible;
+ [ObservableProperty] private bool _isWarnVisible;
+ [ObservableProperty] private bool _isInfoVisible;
+
+ public ErrorViewModel()
+ {
+ IsInfoVisible = true;
+ Title = "Тест ошибки";
+ Message = "Сообщение ошибки";
+ }
+
+ public ErrorViewModel(Error error)
+ {
+ Title = error.Title;
+ Message = error.Message;
+ severity = error.Severity;
+ switch (error.Severity)
+ {
+ case ErrorSeverity.Error:
+ IsErrorVisible = true;
+ break;
+ case ErrorSeverity.Warning:
+ IsWarnVisible = true;
+ break;
+ case ErrorSeverity.Message:
+ IsInfoVisible = true;
+ break;
+ default:
+ IsInfoVisible = true;
+ break;
+ }
+ }
+
+ public Error GetError()
+ {
+ Error error = new Error()
+ {
+ Title = Title,
+ Message = Message,
+ Severity = severity,
+ };
+ return error;
+ }
+}
\ No newline at end of file
diff --git a/ViewModels/EditEquipmentDialogViewModel.cs b/ViewModels/EditEquipmentDialogViewModel.cs
index b473afc..85a7013 100644
--- a/ViewModels/EditEquipmentDialogViewModel.cs
+++ b/ViewModels/EditEquipmentDialogViewModel.cs
@@ -1,4 +1,5 @@
-using System.Collections.Generic;
+using System;
+using System.Collections.Generic;
using System.Threading.Tasks;
using System.Web;
using Avalonia.Controls;
@@ -7,6 +8,7 @@ using Avalonia.Platform.Storage;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using CommunityToolkit.Mvvm.Messaging;
+using GazpromApp.Enums;
using GazpromApp.Messages;
using GazpromApp.Models;
@@ -57,7 +59,22 @@ public partial class EditEquipmentDialogViewModel : ViewModelBase
IsImageSelected = files.Count > 0;
- Image = IsImageSelected ? new ImageViewModel(new Models.Image()) { FileName = new Bitmap(HttpUtility.UrlDecode(files[0].Path.AbsolutePath)) } : null;
+ try
+ {
+ Image = IsImageSelected ? new ImageViewModel(new Models.Image()) { FileName = new Bitmap(HttpUtility.UrlDecode(files[0].Path.AbsolutePath)) } : null;
+ }
+ catch (ArgumentException)
+ {
+ Error error = new Error()
+ {
+ Title = "Ошибка обработки картинки",
+ Message = "Картинка не была добавлена",
+ Severity = ErrorSeverity.Error,
+ };
+ _ = await WeakReferenceMessenger.Default.Send(new ErrorMessage(new ErrorViewModel(error)));
+
+ IsImageSelected = false;
+ }
}
[RelayCommand]
diff --git a/ViewModels/EditPointDialogViewModel.cs b/ViewModels/EditPointDialogViewModel.cs
index f4ce40e..07c847a 100644
--- a/ViewModels/EditPointDialogViewModel.cs
+++ b/ViewModels/EditPointDialogViewModel.cs
@@ -1,4 +1,5 @@
-using System.Collections.Generic;
+using System;
+using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
@@ -10,6 +11,7 @@ using Avalonia.Platform.Storage;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using CommunityToolkit.Mvvm.Messaging;
+using GazpromApp.Enums;
using GazpromApp.Messages;
using GazpromApp.Models;
using GazpromApp.Views;
@@ -59,7 +61,22 @@ public partial class EditPointDialogViewModel : ViewModelBase
FileTypeFilter = [FilePickerFileTypes.ImageAll],
});
foreach (var file in files)
- Images.Add(new ImageViewModel(new Image()) { FileName = new Bitmap(HttpUtility.UrlDecode(file.Path.AbsolutePath) ) });
+ {
+ try
+ {
+ Images.Add(new ImageViewModel(new Image()) { FileName = new Bitmap(HttpUtility.UrlDecode(file.Path.AbsolutePath) ) });
+ }
+ catch (ArgumentException)
+ {
+ Error error = new Error()
+ {
+ Title = "Ошибка обработки картинки",
+ Message = $"Картинка не была добавлена: \"{HttpUtility.UrlDecode(file.Name)}\"",
+ Severity = ErrorSeverity.Error,
+ };
+ _ = await WeakReferenceMessenger.Default.Send(new ErrorMessage(new ErrorViewModel(error)));
+ }
+ }
IsImagesEmpty = Images.Count == 0;
}
diff --git a/ViewModels/NewEquipmentDialogViewModel.cs b/ViewModels/NewEquipmentDialogViewModel.cs
index 260bb9f..638544b 100644
--- a/ViewModels/NewEquipmentDialogViewModel.cs
+++ b/ViewModels/NewEquipmentDialogViewModel.cs
@@ -1,4 +1,5 @@
-using System.Collections.Generic;
+using System;
+using System.Collections.Generic;
using System.Threading.Tasks;
using System.Web;
using Avalonia.Controls;
@@ -7,6 +8,7 @@ using Avalonia.Platform.Storage;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using CommunityToolkit.Mvvm.Messaging;
+using GazpromApp.Enums;
using GazpromApp.Messages;
using GazpromApp.Models;
@@ -37,7 +39,22 @@ public partial class NewEquipmentDialogViewModel : ViewModelBase
IsImageSelected = files.Count > 0;
- Image = IsImageSelected ? new ImageViewModel(new Models.Image()) { FileName = new Bitmap(HttpUtility.UrlDecode(files[0].Path.AbsolutePath)) } : null;
+ try
+ {
+ Image = IsImageSelected ? new ImageViewModel(new Models.Image()) { FileName = new Bitmap(HttpUtility.UrlDecode(files[0].Path.AbsolutePath)) } : null;
+ }
+ catch (ArgumentException)
+ {
+ Error error = new Error()
+ {
+ Title = "Ошибка обработки картинки",
+ Message = "Картинка не была добавлена",
+ Severity = ErrorSeverity.Error,
+ };
+ _ = await WeakReferenceMessenger.Default.Send(new ErrorMessage(new ErrorViewModel(error)));
+
+ IsImageSelected = false;
+ }
}
[RelayCommand]
diff --git a/ViewModels/NewPointDialogViewModel.cs b/ViewModels/NewPointDialogViewModel.cs
index 7d1f0f4..e801605 100644
--- a/ViewModels/NewPointDialogViewModel.cs
+++ b/ViewModels/NewPointDialogViewModel.cs
@@ -1,5 +1,7 @@
-using System.Collections.Generic;
+using System;
+using System.Collections.Generic;
using System.Collections.ObjectModel;
+using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using System.Web;
@@ -9,7 +11,9 @@ using Avalonia.Platform.Storage;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using CommunityToolkit.Mvvm.Messaging;
+using GazpromApp.Enums;
using GazpromApp.Messages;
+using GazpromApp.Models;
using Image = GazpromApp.Models.Image;
using Point = GazpromApp.Models.Point;
@@ -37,7 +41,22 @@ public partial class NewPointDialogViewModel : ViewModelBase
FileTypeFilter = [FilePickerFileTypes.ImageAll],
});
foreach (var file in files)
- Images.Add(new ImageViewModel(new Image()) { FileName = new Bitmap(HttpUtility.UrlDecode(file.Path.AbsolutePath)) });
+ {
+ try
+ {
+ Images.Add(new ImageViewModel(new Image()) { FileName = new Bitmap(HttpUtility.UrlDecode(file.Path.AbsolutePath)) });
+ }
+ catch (ArgumentException)
+ {
+ Error error = new Error()
+ {
+ Title = "Ошибка обработки картинки",
+ Message = $"Картинка не была добавлена: \"{HttpUtility.UrlDecode(file.Name)}\"",
+ Severity = ErrorSeverity.Error,
+ };
+ _ = await WeakReferenceMessenger.Default.Send(new ErrorMessage(new ErrorViewModel(error)));
+ }
+ }
IsImagesEmpty = Images.Count == 0;
}
diff --git a/Views/EditEquipmentDialog.axaml.cs b/Views/EditEquipmentDialog.axaml.cs
index 44854a6..c9550cf 100644
--- a/Views/EditEquipmentDialog.axaml.cs
+++ b/Views/EditEquipmentDialog.axaml.cs
@@ -30,6 +30,16 @@ public partial class EditEquipmentDialog : Window
m.Reply(dialog.ShowDialog(w));
});
+ // error handling
+ WeakReferenceMessenger.Default.Register(this, static (w, m) =>
+ {
+ ErrorView dialog = new ErrorView()
+ {
+ DataContext = m.Error
+ };
+ m.Reply(dialog.ShowDialog(w));
+ });
+
// new property dialog
// edit property dialog
@@ -50,6 +60,7 @@ public partial class EditEquipmentDialog : Window
private void Window_OnClosed(object? sender, EventArgs e)
{
WeakReferenceMessenger.Default.Unregister(this);
+ WeakReferenceMessenger.Default.Unregister(this);
//
//
WeakReferenceMessenger.Default.Unregister(this);
diff --git a/Views/EditPointDialog.axaml.cs b/Views/EditPointDialog.axaml.cs
index 77a2cfa..907c307 100644
--- a/Views/EditPointDialog.axaml.cs
+++ b/Views/EditPointDialog.axaml.cs
@@ -28,9 +28,20 @@ public partial class EditPointDialog : Window
m.Reply(dialog.ShowDialog(w));
});
- // new equipment
- WeakReferenceMessenger.Default.Register(this, static (w, m) =>
+ // error
+ WeakReferenceMessenger.Default.Register(this, static (w, m) =>
{
+ ErrorView dialog = new ErrorView()
+ {
+ DataContext = m.Error
+ };
+ m.Reply(dialog.ShowDialog(w));
+ });
+
+ // new equipment
+ WeakReferenceMessenger.Default.Register(this, (w, m) =>
+ {
+ WeakReferenceMessenger.Default.Unregister(this);
NewEquipmentDialog dialog = new NewEquipmentDialog()
{
DataContext = new NewEquipmentDialogViewModel()
@@ -42,6 +53,7 @@ public partial class EditPointDialog : Window
WeakReferenceMessenger.Default.Register(this, (w, m) =>
{
WeakReferenceMessenger.Default.Unregister(this);
+ WeakReferenceMessenger.Default.Unregister(this);
EditEquipmentDialog dialog = new EditEquipmentDialog()
{
DataContext = new EditEquipmentDialogViewModel(m.Equipment)
@@ -49,8 +61,21 @@ public partial class EditPointDialog : Window
m.Reply(dialog.ShowDialog(w));
});
- // re registering view image
- WeakReferenceMessenger.Default.Register(this, (w, m) =>
+ // re registering error when new equipment done
+ WeakReferenceMessenger.Default.Register(this, (_, _) =>
+ {
+ WeakReferenceMessenger.Default.Register(this, static (w, m) =>
+ {
+ ErrorView dialog = new ErrorView()
+ {
+ DataContext = m.Error
+ };
+ m.Reply(dialog.ShowDialog(w));
+ });
+ });
+
+ // re registering view image and error view
+ WeakReferenceMessenger.Default.Register(this, (_, _) =>
{
WeakReferenceMessenger.Default.Register(this, static (w, m) =>
{
@@ -60,6 +85,15 @@ public partial class EditPointDialog : Window
};
m.Reply(dialog.ShowDialog(w));
});
+
+ WeakReferenceMessenger.Default.Register(this, static (w, m) =>
+ {
+ ErrorView dialog = new ErrorView()
+ {
+ DataContext = m.Error
+ };
+ m.Reply(dialog.ShowDialog(w));
+ });
});
// new property
@@ -82,6 +116,7 @@ public partial class EditPointDialog : Window
private void Window_OnClosed(object? sender, EventArgs e)
{
WeakReferenceMessenger.Default.Unregister(this);
+ WeakReferenceMessenger.Default.Unregister(this);
WeakReferenceMessenger.Default.Unregister(this);
WeakReferenceMessenger.Default.Unregister(this);
// new prop
diff --git a/Views/ErrorView.axaml b/Views/ErrorView.axaml
new file mode 100644
index 0000000..15d8eab
--- /dev/null
+++ b/Views/ErrorView.axaml
@@ -0,0 +1,44 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Views/ErrorView.axaml.cs b/Views/ErrorView.axaml.cs
new file mode 100644
index 0000000..384ddd8
--- /dev/null
+++ b/Views/ErrorView.axaml.cs
@@ -0,0 +1,29 @@
+using System;
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Markup.Xaml;
+
+namespace GazpromApp.Views;
+
+public partial class ErrorView : Window
+{
+ public ErrorView()
+ {
+ InitializeComponent();
+
+ if (Design.IsDesignMode)
+ return;
+
+
+ }
+
+ private void Window_OnClosing(object? sender, WindowClosingEventArgs e)
+ {
+
+ }
+
+ private void Window_OnClosed(object? sender, EventArgs e)
+ {
+
+ }
+}
\ No newline at end of file
diff --git a/Views/NewEquipmentDialog.axaml.cs b/Views/NewEquipmentDialog.axaml.cs
index 37339de..f3c1dc2 100644
--- a/Views/NewEquipmentDialog.axaml.cs
+++ b/Views/NewEquipmentDialog.axaml.cs
@@ -2,6 +2,7 @@
using Avalonia.Controls;
using CommunityToolkit.Mvvm.Messaging;
using GazpromApp.Messages;
+using GazpromApp.ViewModels;
namespace GazpromApp.Views;
@@ -11,14 +12,26 @@ public partial class NewEquipmentDialog : Window
{
InitializeComponent();
+ // done entering new equipment
WeakReferenceMessenger.Default.Register(this, static (w, m) =>
{
w.Close(m.Equipment);
});
+
+ // register to work with errors
+ WeakReferenceMessenger.Default.Register(this, static (w, m) =>
+ {
+ ErrorView dialog = new ErrorView()
+ {
+ DataContext = m.Error
+ };
+ m.Reply(dialog.ShowDialog(w));
+ });
}
private void Window_OnClosed(object? sender, EventArgs e)
{
WeakReferenceMessenger.Default.Unregister(this);
+ WeakReferenceMessenger.Default.Unregister(this);
}
}
\ No newline at end of file
diff --git a/Views/NewPointDialog.axaml b/Views/NewPointDialog.axaml
index 4d4e74f..db22666 100644
--- a/Views/NewPointDialog.axaml
+++ b/Views/NewPointDialog.axaml
@@ -10,7 +10,8 @@
x:DataType="vm:NewPointDialogViewModel"
Title="Создание нового объекта"
Icon="/Assets/ic_fluent_home_add_24_filled (Custom).png"
- WindowStartupLocation="CenterOwner">
+ WindowStartupLocation="CenterOwner"
+ Closed="Window_OnClosed">
diff --git a/Views/NewPointDialog.axaml.cs b/Views/NewPointDialog.axaml.cs
index 1330a4c..aa99dca 100644
--- a/Views/NewPointDialog.axaml.cs
+++ b/Views/NewPointDialog.axaml.cs
@@ -1,6 +1,8 @@
-using Avalonia.Controls;
+using System;
+using Avalonia.Controls;
using CommunityToolkit.Mvvm.Messaging;
using GazpromApp.Messages;
+using GazpromApp.ViewModels;
namespace GazpromApp.Views;
@@ -10,9 +12,25 @@ public partial class NewPointDialog : Window
{
InitializeComponent();
+ // done entering new point
WeakReferenceMessenger.Default.Register(this, static (w, m) =>
{
w.Close(m.Point);
});
+
+ // register to work with errors
+ WeakReferenceMessenger.Default.Register(this, static (w, m) =>
+ {
+ ErrorView dialog = new ErrorView()
+ {
+ DataContext = m.Error
+ };
+ m.Reply(dialog.ShowDialog(w));
+ });
+ }
+
+ private void Window_OnClosed(object? sender, EventArgs e)
+ {
+ WeakReferenceMessenger.Default.Unregister(this);
}
}
\ No newline at end of file
diff --git a/obj/Debug/net8.0/Avalonia/Resources.Inputs.cache b/obj/Debug/net8.0/Avalonia/Resources.Inputs.cache
index d6b97ba..ef9c195 100644
--- a/obj/Debug/net8.0/Avalonia/Resources.Inputs.cache
+++ b/obj/Debug/net8.0/Avalonia/Resources.Inputs.cache
@@ -1 +1 @@
-41a928e641efcd3e89b584959a8b8be084763735298d1e3a4ead534f873c57ec
+c7763810c7c9fe86f032a444db49dfe85bfa277e9aa1a02ca59b8891c1bb6265
diff --git a/obj/Debug/net8.0/Avalonia/resources b/obj/Debug/net8.0/Avalonia/resources
index c1953c8..1574e1b 100644
Binary files a/obj/Debug/net8.0/Avalonia/resources and b/obj/Debug/net8.0/Avalonia/resources differ
diff --git a/obj/Debug/net8.0/GazpromApp.AssemblyInfo.cs b/obj/Debug/net8.0/GazpromApp.AssemblyInfo.cs
index 1803dba..fddd7b9 100644
--- a/obj/Debug/net8.0/GazpromApp.AssemblyInfo.cs
+++ b/obj/Debug/net8.0/GazpromApp.AssemblyInfo.cs
@@ -13,7 +13,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("GazpromApp")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
-[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+c0178625cd3b6493e3edb6c1847a526192a67b27")]
+[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+8806d287870ff52e89394ebf3740eb9130b2fa6c")]
[assembly: System.Reflection.AssemblyProductAttribute("GazpromApp")]
[assembly: System.Reflection.AssemblyTitleAttribute("GazpromApp")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
diff --git a/obj/Debug/net8.0/GazpromApp.AssemblyInfoInputs.cache b/obj/Debug/net8.0/GazpromApp.AssemblyInfoInputs.cache
index 63a3315..e669ef4 100644
--- a/obj/Debug/net8.0/GazpromApp.AssemblyInfoInputs.cache
+++ b/obj/Debug/net8.0/GazpromApp.AssemblyInfoInputs.cache
@@ -1 +1 @@
-bd707ac6740d23b45223f7c5e6320a05563f812a5bd2e1dc1b2ba3f2023ec0f2
+fca2f4a4c1933f8850b7151879ad727af085b4f7d1499d3a22126a355fadba2d
diff --git a/obj/Debug/net8.0/GazpromApp.GeneratedMSBuildEditorConfig.editorconfig b/obj/Debug/net8.0/GazpromApp.GeneratedMSBuildEditorConfig.editorconfig
index f883420..b4e0635 100644
--- a/obj/Debug/net8.0/GazpromApp.GeneratedMSBuildEditorConfig.editorconfig
+++ b/obj/Debug/net8.0/GazpromApp.GeneratedMSBuildEditorConfig.editorconfig
@@ -38,6 +38,9 @@ build_metadata.AdditionalFiles.SourceItemGroup = AvaloniaXaml
[D:/RiderProjects/GazpromApp/Views/EditPointDialog.axaml]
build_metadata.AdditionalFiles.SourceItemGroup = AvaloniaXaml
+[D:/RiderProjects/GazpromApp/Views/ErrorView.axaml]
+build_metadata.AdditionalFiles.SourceItemGroup = AvaloniaXaml
+
[D:/RiderProjects/GazpromApp/Views/ImageView.axaml]
build_metadata.AdditionalFiles.SourceItemGroup = AvaloniaXaml