aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Diagnostics/IDiagnosticsFrameProvider.cs
blob: 3294b341dfa76013815d67b5c2db792d7f708585 (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
31
32
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.Integration.Operation;
using Tango.PMR.Diagnostics;

namespace Tango.MachineStudio.Common.Diagnostics
{
    /// <summary>
    /// Represents a tango machine diagnostics frame provider.
    /// </summary>
    public interface IDiagnosticsFrameProvider
    {
        /// <summary>
        /// Occurs when a new data frame is available.
        /// </summary>
        event EventHandler<PushDiagnosticsResponse> FrameReceived;

        /// <summary>
        /// Disables the frame delivery from the current connected machine and enables the manual push frame method.
        /// </summary>
        bool Disable { get; set; }

        /// <summary>
        /// Push frames manual. (Only when Disable = true)
        /// </summary>
        /// <param name="frame">The frame.</param>
        void PushFrame(PushDiagnosticsResponse frame);
    }
}
System.Collections.ObjectModel; using System.IO; 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); } } } } }