aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/ValidationRules/Required.cs
blob: aac00fdf1b0208757903f0dd8096621b69b8bc6b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;

namespace Tango.MachineStudio.Common.ValidationRules
{
    /// <summary>
    /// Represents a required field validation rule.
    /// </summary>
    /// <seealso cref="System.Windows.Controls.ValidationRule" />
    public class Required : ValidationRule
    {
        /// <summary>
        /// When overridden in a derived class, performs validation checks on a value.
        /// </summary>
        /// <param name="value">The value from the binding target to check.</param>
        /// <param name="cultureInfo">The culture to use in this rule.</param>
        /// <returns>
        /// A <see cref="T:System.Windows.Controls.ValidationResult" /> object.
        /// </returns>
        public override ValidationResult Validate(object value, CultureInfo cultureInfo)
        {
            return new ValidationResult(!String.IsNullOrWhiteSpace(value.ToStringSafe()), "Required");
        }
    }
}
> using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using Tango.Core.Commands; using Tango.Protobuf.Compilers; namespace Tango.Protobuf.UI { /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : MetroWindow { private String _sourceFolder; private CompilerFolderResult _lastFolderResult; public RelayCommand LoadFileCommand { get; set; } public RelayCommand LoadFolderCommand { get; set; } public RelayCommand CompileCommand { get; set; } public RelayCommand SaveCommand { get; set; } public List<Item> SourceItems { get { return (List<Item>)GetValue(SourceItemsProperty); } set { SetValue(SourceItemsProperty, value); } } public static readonly DependencyProperty SourceItemsProperty = DependencyProperty.Register("SourceItems", typeof(List<Item>), typeof(MainWindow), new PropertyMetadata(null)); public String CurrentContent { get { return (String)GetValue(CurrentContentProperty); } set { SetValue(CurrentContentProperty, value); } } public static readonly DependencyProperty CurrentContentProperty = DependencyProperty.Register("CurrentContent", typeof(String), typeof(MainWindow), new PropertyMetadata(null)); public List<ICompilerResult> TargetItems { get { return (List<ICompilerResult>)GetValue(TargetItemsProperty); } set { SetValue(TargetItemsProperty, value); } } public static readonly DependencyProperty TargetItemsProperty = DependencyProperty.Register("TargetItems", typeof(List<ICompilerResult>), typeof(MainWindow), new PropertyMetadata(null)); public CompilerLanguage CompilerLanguage { get { return (CompilerLanguage)GetValue(CompilerLanguageProperty); } set { SetValue(CompilerLanguageProperty, value); } } public static readonly DependencyProperty CompilerLanguageProperty = DependencyProperty.Register("CompilerLanguage", typeof(CompilerLanguage), typeof(MainWindow), new PropertyMetadata(CompilerLanguage.CSharp)); public MainWindow() { SourceItems = new List<Item>(); TargetItems = new List<ICompilerResult>(); LoadFileCommand = new RelayCommand(LoadFile); LoadFolderCommand = new RelayCommand(LoadFolder); CompileCommand = new RelayCommand(Compile); SaveCommand = new RelayCommand(Save); InitializeComponent(); } private void LoadFolder() { var dialog = new CommonOpenFileDialog(); dialog.IsFolderPicker = true; CommonFileDialogResult result = dialog.ShowDialog(); if (result == CommonFileDialogResult.Ok) { _sourceFolder = dialog.FileName; SourceItems = ItemProvider.GetItems(_sourceFolder); } } private void LoadFile() { throw new NotImplementedException(); } private void Source_TreeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e) { if (e.NewValue is FileItem) { CurrentContent = File.ReadAllText((e.NewValue as FileItem).Path); } else if (e.NewValue is CompilerFileResult) { CurrentContent = (e.NewValue as CompilerFileResult).Content; } else { CurrentContent = String.Empty; } } private void Compile() { IProtoCompiler compiler = CompilerFactory.CreateCompiler(CompilerLanguage); try { _lastFolderResult = compiler.CompileFolder(_sourceFolder); TargetItems = _lastFolderResult.Results.ToList(); } catch (CompilerException ex) { ExceptionWindow exWin = new ExceptionWindow(ex.Issues); exWin.Owner = this; exWin.ShowDialog(); } } private void Save() { if (_lastFolderResult != null) { var dialog = new CommonOpenFileDialog(); dialog.IsFolderPicker = true; CommonFileDialogResult result = dialog.ShowDialog(); if (result == CommonFileDialogResult.Ok) { _lastFolderResult.Save(dialog.FileName); } } } } }