using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Threading;
using Tango.Core.Commands;
using Tango.Core.Helpers;
using Tango.MachineStudio.Common.Modules;
using Tango.MachineStudio.Common.Notifications;
using Tango.Scripting;
using Tango.SharedUI;
namespace Tango.MachineStudio.UI.Console
{
public class ConsoleWindowVM : ViewModel
{
private IStudioModuleLoader _moduleLoader;
private INotificationProvider _notificatrion;
private TextBox _txtLog;
private String _currentFile;
private ScriptEngine _engine;
///
/// Gets or sets the additional highlight C# types.
///
public ObservableCollection> HighlightTypes { get; set; }
internal void SetLogTextBox(TextBox txtLog)
{
_txtLog = txtLog;
}
///
/// Gets or sets the intellisense types.
///
public ObservableCollection> IntellisenseTypes { get; set; }
private String _code;
///
/// Gets or sets the code.
///
public String Code
{
get { return _code; }
set { _code = value; RaisePropertyChangedAuto(); }
}
private bool _isRunning;
///
/// Gets or sets a value indicating whether a stub is currently running.
///
public bool IsRunning
{
get { return _isRunning; }
set { _isRunning = value; RaisePropertyChanged(nameof(IsRunning)); InvalidateRelayCommands(); }
}
///
/// Gets or sets the run command.
///
public RelayCommand RunCommand { get; set; }
///
/// Gets or sets the stop command.
///
public RelayCommand StopCommand { get; set; }
///
/// Gets or sets the clear command.
///
public RelayCommand ClearCommand { get; set; }
///
/// Gets or sets the new command.
///
public RelayCommand NewCommand { get; set; }
///
/// Gets or sets the open command.
///
public RelayCommand OpenCommand { get; set; }
///
/// Gets or sets the save command.
///
public RelayCommand SaveCommand { get; set; }
///
/// Gets or sets the save as command.
///
public RelayCommand SaveAsCommand { get; set; }
public ConsoleWindowVM(IStudioModuleLoader moduleLoader, INotificationProvider notification)
{
_moduleLoader = moduleLoader;
_notificatrion = notification;
RunCommand = new RelayCommand(Run);
StopCommand = new RelayCommand(Stop);
HighlightTypes = new ObservableCollection>();
IntellisenseTypes = new ObservableCollection>();
IntellisenseTypes.Add(new KeyValuePair("manager", typeof(ConsoleManager)));
foreach (var moduleType in moduleLoader.UserModules.SelectMany(x => x.MainViewType.Assembly.GetTypes()))
{
if (!moduleType.FullName.Contains("<") && !moduleType.FullName.Contains(">"))
{
HighlightTypes.Add(new KeyValuePair(moduleType.FullName, moduleType));
}
}
foreach (var type in this.GetType().Assembly.GetTypes())
{
if (!type.FullName.Contains("<") && !type.FullName.Contains(">"))
{
HighlightTypes.Add(new KeyValuePair(type.Name, type));
}
}
foreach (var type in typeof(INotificationProvider).Assembly.GetTypes())
{
if (!type.FullName.Contains("<") && !type.FullName.Contains(">"))
{
HighlightTypes.Add(new KeyValuePair(type.Name, type));
}
}
HighlightTypes.Add(new KeyValuePair("Thread", typeof(Thread)));
HighlightTypes.Add(new KeyValuePair("DateTime", typeof(DateTime)));
HighlightTypes.Add(new KeyValuePair("TimeSpan", typeof(TimeSpan)));
HighlightTypes.Add(new KeyValuePair("Dispatcher", typeof(Dispatcher)));
HighlightTypes.Add(new KeyValuePair("Task", typeof(Task)));
HighlightTypes.Add(new KeyValuePair("List", typeof(IList