Skip to content

Commit

Permalink
Terminal added
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey-Dvortsov committed Oct 6, 2015
1 parent ce16a30 commit cc32d65
Show file tree
Hide file tree
Showing 33 changed files with 2,405 additions and 966 deletions.
1,941 changes: 975 additions & 966 deletions StockSharp.sln

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions Terminal/Terminal.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.23107.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Terminal", "Terminal\Terminal.csproj", "{BDDB57FB-3404-48C8-B730-94B0957BBBD8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{BDDB57FB-3404-48C8-B730-94B0957BBBD8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BDDB57FB-3404-48C8-B730-94B0957BBBD8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BDDB57FB-3404-48C8-B730-94B0957BBBD8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BDDB57FB-3404-48C8-B730-94B0957BBBD8}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
6 changes: 6 additions & 0 deletions Terminal/Terminal/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1"/>
</startup>
</configuration>
14 changes: 14 additions & 0 deletions Terminal/Terminal/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<sx:ExtendedBaseApplication
x:Class="Terminal.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Startup="App_Startup"
xmlns:sx="http://schemas.stocksharp.com/xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="TemplateDictionary.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</sx:ExtendedBaseApplication>
40 changes: 40 additions & 0 deletions Terminal/Terminal/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
namespace Terminal
{
using System;
using System.Diagnostics;
using System.IO;
using System.Windows;

public partial class App
{
static void OnUnhandledException(object sender, UnhandledExceptionEventArgs args)
{
((Exception)args.ExceptionObject).ToTraceError();
}

private void App_Startup(object sender, StartupEventArgs e)
{

var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TraceLog.txt");
var trl = new TextWriterTraceListener(File.CreateText(path));
Trace.AutoFlush = true;
Trace.Listeners.Add(trl);

var currentDomain = AppDomain.CurrentDomain;
currentDomain.UnhandledException += OnUnhandledException;

try
{
Root.GetInstance();
var mnd = new MainWindow();
this.MainWindow = mnd;
this.MainWindow.Show();
}
catch (Exception ex)
{
ex.ToTraceError();
}
}
}

}
230 changes: 230 additions & 0 deletions Terminal/Terminal/Common/DockSiteViewModelBehavior.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
namespace Terminal
{
using System;
using System.Collections.Generic;
using System.Windows;
using ActiproSoftware.Windows.Controls.Docking;

public static class DockSiteViewModelBehavior
{

#region Dependency Properties

/// <summary>
/// Identifies the <c>IsManaged</c> attached dependency property. This field is read-only.
/// </summary>
/// <value>The identifier for the <c>IsManaged</c> attached dependency property.</value>
public static readonly DependencyProperty IsManagedProperty = DependencyProperty.RegisterAttached("IsManaged",
typeof(bool), typeof(DockSiteViewModelBehavior), new FrameworkPropertyMetadata(false, OnIsManagedPropertyValueChanged));

/// <summary>
/// Identifies the <c>WindowsPendingOpen</c> attached dependency property. This field is read-only.
/// </summary>
/// <value>The identifier for the <c>WindowsPendingOpen</c> attached dependency property.</value>
private static readonly DependencyProperty _windowsPendingOpenProperty = DependencyProperty.RegisterAttached("_windowsPendingOpen",
typeof(IList<DockingWindow>), typeof(DockSiteViewModelBehavior), new FrameworkPropertyMetadata(null));

#endregion // Dependency Properties

/// <summary>
/// Gets the first <see cref="ToolWindow"/> associated with the specified dock group.
/// </summary>
/// <param name="dockSite">The dock site to search.</param>
/// <param name="dockGroup">The dock group.</param>
/// <returns>
/// A <see cref="ToolWindow"/>; otherwise, <see langword="null"/>.
/// </returns>
private static ToolWindow GetToolWindow(DockSite dockSite, string dockGroup)
{
if (dockSite == null || string.IsNullOrEmpty(dockGroup))
return null;
foreach (var toolWindow in dockSite.ToolWindows)
{
var toolItemViewModel = toolWindow.DataContext as ToolItemViewModel;
if (toolItemViewModel != null && toolItemViewModel.DockGroup == dockGroup)
return toolWindow;
}

return null;
}

/// <summary>
/// Handles the <c>Loaded</c> event of the <c>DockSite</c> control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
private static void OnDockSiteLoaded(object sender, RoutedEventArgs e)
{
var dockSite = sender as DockSite;
if (dockSite == null)
return;

// Open any windows that were waiting for the DockSite to be loaded
var windowsPendingOpen = dockSite.GetValue(_windowsPendingOpenProperty) as IList<DockingWindow>;
dockSite.ClearValue(_windowsPendingOpenProperty);

if (windowsPendingOpen == null || windowsPendingOpen.Count == 0)
return;
foreach (var dockingWindow in windowsPendingOpen)
OpenDockingWindow(dockSite, dockingWindow);
}

/// <summary>
/// Handles the <c>WindowRegistered</c> event of the <c>DockSite</c> control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="DockingWindowEventArgs"/> instance containing the event data.</param>
private static void OnDockSiteWindowRegistered(object sender, DockingWindowEventArgs e)
{
var dockSite = sender as DockSite;
if (dockSite == null)
return;

// Ensure the DockingWindow exists and is generated for an item
var dockingWindow = e.Window;
if (dockingWindow == null || !dockingWindow.IsContainerForItem)
return;

// Pass down the name, if any as this cannot be done via a Style
if (string.IsNullOrEmpty(dockingWindow.Name))
{
var viewModel = dockingWindow.DataContext as ViewModelBase;
if (viewModel != null && !string.IsNullOrEmpty(viewModel.Name))
dockingWindow.Name = viewModel.Name;
}

// Open the DockingWindow, if it's not already open
if (dockingWindow.IsOpen)
return;
if (!dockSite.IsLoaded)
{
// Need to delay the opening until after the DockSite is loaded because it's content will not be loaded
var windowsPendingOpen = dockSite.GetValue(_windowsPendingOpenProperty) as IList<DockingWindow>;
if (windowsPendingOpen == null)
{
windowsPendingOpen = new List<DockingWindow>();
dockSite.SetValue(_windowsPendingOpenProperty, windowsPendingOpen);
}

windowsPendingOpen.Add(dockingWindow);
}
else
{
OpenDockingWindow(dockSite, dockingWindow);
}
}

/// <summary>
/// Handles the <c>WindowUnregistered</c> event of the <c>DockSite</c> control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="DockingWindowEventArgs"/> instance containing the event data.</param>
private static void OnDockSiteWindowUnregistered(object sender, DockingWindowEventArgs e)
{
var dockSite = sender as DockSite;
if (dockSite == null)
return;

// Ensure the DockingWindow exists and is generated for an item
var dockingWindow = e.Window;
if (dockingWindow == null || !dockingWindow.IsContainerForItem)
return;

// Need to remove the window from the list of windows that are waiting to be opened
var windowsPendingOpen = dockSite.GetValue(_windowsPendingOpenProperty) as IList<DockingWindow>;
if (windowsPendingOpen == null)
return;
var index = windowsPendingOpen.IndexOf(dockingWindow);
if (index != -1)
windowsPendingOpen.RemoveAt(index);
}

/// <summary>
/// Called when <see cref="IsManagedProperty"/> is changed.
/// </summary>
/// <param name="d">The dependency object that was changed.</param>
/// <param name="e">The <see cref="DependencyPropertyChangedEventArgs"/> instance containing the event data.</param>
private static void OnIsManagedPropertyValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var dockSite = d as DockSite;
if (dockSite == null)
return;

// Add/Remove handlers for various events, which will allow us to open/position generated windows
if ((bool)e.NewValue)
{
dockSite.Loaded += DockSiteViewModelBehavior.OnDockSiteLoaded;
dockSite.WindowRegistered += DockSiteViewModelBehavior.OnDockSiteWindowRegistered;
dockSite.WindowUnregistered += DockSiteViewModelBehavior.OnDockSiteWindowUnregistered;
}
else
{
dockSite.Loaded -= DockSiteViewModelBehavior.OnDockSiteLoaded;
dockSite.WindowRegistered -= DockSiteViewModelBehavior.OnDockSiteWindowRegistered;
dockSite.WindowUnregistered -= DockSiteViewModelBehavior.OnDockSiteWindowUnregistered;
}
}

/// <summary>
/// Opens the specified docking window.
/// </summary>
/// <param name="dockSite">The dock site that owns the docking window.</param>
/// <param name="dockingWindow">The docking window to open.</param>
private static void OpenDockingWindow(DockSite dockSite, DockingWindow dockingWindow)
{
if (dockingWindow.IsOpen)
return;
if (dockingWindow is DocumentWindow)
dockingWindow.Open();
else
{
var toolWindow = dockingWindow as ToolWindow;
var toolItemViewModel = dockingWindow.DataContext as ToolItemViewModel;
if (toolWindow != null && toolItemViewModel != null)
{
// Look for a ToolWindow within the same group, if found then dock to that group, otherwise either dock or auto-hide the window
var targetToolWindow = GetToolWindow(dockSite, toolItemViewModel.DockGroup);
if (targetToolWindow != null && !Equals(targetToolWindow, toolWindow))
toolWindow.Dock(targetToolWindow, Direction.Content);
else if (toolItemViewModel.IsInitiallyAutoHidden)
toolWindow.AutoHide(toolItemViewModel.DefaultDock);
else
toolWindow.Dock(dockSite, toolItemViewModel.DefaultDock);
}
else
{
dockingWindow.Open();
}
}
}

/// <summary>
/// Gets the value of the <see cref="IsManagedProperty"/> attached property for a specified <see cref="DockSite"/>.
/// </summary>
/// <param name="obj">The object to which the attached property is retrieved.</param>
/// <returns>
/// <c>true</c> if the specified <see cref="DockSite"/> is being managed; otherwise <c>false</c>.
/// </returns>
public static bool GetIsManaged(DockSite obj)
{
if (null == obj)
throw new ArgumentNullException(nameof(obj));
return (bool)obj.GetValue(DockSiteViewModelBehavior.IsManagedProperty);
}

/// <summary>
/// Sets the value of the <see cref="IsManagedProperty"/> attached property to a specified <see cref="DockSite"/>.
/// </summary>
/// <param name="obj">The object to which the attached property is written.</param>
/// <param name="value">
/// A value indicating whether the specified <see cref="DockSite"/> is being managed.
/// </param>
public static void SetIsManaged(DockSite obj, bool value)
{
if (null == obj)
throw new ArgumentNullException(nameof(obj));
obj.SetValue(DockSiteViewModelBehavior.IsManagedProperty, value);
}

}
}
20 changes: 20 additions & 0 deletions Terminal/Terminal/Common/Helpers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace Terminal
{
using System;
using System.Diagnostics;

public static class Helpers
{

public static void ToTraceError(this Exception ex)
{
Trace.WriteLine(string.Format("{0} /{1}", ex.Message, ex.StackTrace), DateTime.Now.TimeOfDay.ToString());
}

public static void ToTraceInfo(this string message)
{
Trace.WriteLine(string.Format("{0}", message), DateTime.Now.TimeOfDay.ToString());
}

}
}
43 changes: 43 additions & 0 deletions Terminal/Terminal/Common/Root.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
namespace Terminal
{
using ActiproSoftware.Windows;

using StockSharp.Quik;
using StockSharp.Algo;

public class Root
{
private static Root _root;

private Root()
{
Connector = new QuikTrader();
}

public static Root GetInstance()
{
if (_root == null)
{
lock (typeof(Root))
{
_root = new Root();
}
}
return _root;
}

public Connector Connector { private set; get; }

private DeferrableObservableCollection<ToolItemViewModel> _toolItems;
public DeferrableObservableCollection<ToolItemViewModel> ToolItems
{
get
{
if (_toolItems == null) ToolItems = new DeferrableObservableCollection<ToolItemViewModel>();
return _toolItems;
}
set { _toolItems = value; }
}

}
}
9 changes: 9 additions & 0 deletions Terminal/Terminal/MainWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Window x:Class="Terminal.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="600" Width="800">
<DockPanel LastChildFill="True">
<ContentControl Content="{Binding}" />
</DockPanel>
</Window>

Loading

0 comments on commit cc32d65

Please sign in to comment.