예제 #1
0
        private TaskPane EnsureTaskPane(IHydraTask task)
        {
            var taskWnd = DockSite.DocumentWindows.FirstOrDefault(w =>
            {
                var pw = w as PaneWindow;

                if (pw == null)
                {
                    return(false);
                }

                var taskPane = pw.Pane as TaskPane;

                if (taskPane == null)
                {
                    return(false);
                }

                return(taskPane.Task == task);
            });

            if (taskWnd != null)
            {
                taskWnd.Activate();
                return(null);
            }
            else
            {
                return new TaskPane {
                           Task = task
                }
            };
        }
예제 #2
0
        /// <summary>
        /// Принадлежит ли задача категории.
        /// </summary>
        /// <param name="task">Задача.</param>
        /// <param name="category">Категория.</param>
        /// <returns>Принадлежит ли задача категории.</returns>
        public static bool IsCategoryOf(this IHydraTask task, TaskCategories category)
        {
            if (task == null)
            {
                throw new ArgumentNullException(nameof(task));
            }

            return(task.GetType().IsCategoryOf(category));
        }
예제 #3
0
        /// <summary>
        /// Включено ли у задачи закачка лога собственной торговли.
        /// </summary>
        /// <param name="task">Задача.</param>
        /// <returns>Включено ли у задачи закачка лога собственной торговли.</returns>
        public static bool IsExecLogEnabled(this IHydraTask task)
        {
            if (task == null)
            {
                throw new ArgumentNullException(nameof(task));
            }

            return(task.Settings.Securities.Any(s => s.MarketDataTypesSet.Contains(typeof(ExecutionMessage))));
        }
예제 #4
0
        /// <summary>
        /// Получить отображаемое имя для задачи.
        /// </summary>
        /// <param name="task">Задача.</param>
        /// <returns>Отображаемое имя.</returns>
        public static string GetDisplayName(this IHydraTask task)
        {
            if (task == null)
            {
                throw new ArgumentNullException("task");
            }

            return(task.GetType().GetDisplayName());
        }
예제 #5
0
        /// <summary>
        /// Получить инструмент "Все инструменты" для задачи.
        /// </summary>
        /// <param name="task">Задача.</param>
        /// <returns>Инструмент "Все инструменты".</returns>
        public static HydraTaskSecurity GetAllSecurity(this IHydraTask task)
        {
            if (task == null)
            {
                throw new ArgumentNullException(nameof(task));
            }

            return(task.Settings.Securities.FirstOrDefault(s => s.Security.IsAllSecurity()));
        }
예제 #6
0
		private void EditTask(IHydraTask task)
		{
			var wnd = new TaskSettingsWindow { Task = task };
			if (!wnd.ShowModal(this))
				return;

			task.Settings.IsDefault = false;
			task.SaveSettings();
		}
예제 #7
0
        /// <summary>
        /// Получить описание задачи.
        /// </summary>
        /// <param name="task">Задача.</param>
        /// <returns>Описание задачи.</returns>
        public static string GetDescription(this IHydraTask task)
        {
            if (task == null)
            {
                throw new ArgumentNullException(nameof(task));
            }

            return(task.GetType().GetDescription());
        }
예제 #8
0
        void IPersistable.Load(SettingsStorage storage)
        {
            if (storage.ContainsKey("TaskId"))
            {
                var taskId = storage.GetValue <Guid>("TaskId");
                Task = MainWindow.Instance.Tasks.SingleOrDefault(s => s.Settings.Id == taskId);
            }

            SecuritiesCtrl.Load(storage.GetValue <SettingsStorage>("Securities"));
        }
예제 #9
0
        private void ExecutedNewTaskCommand(object sender, ExecutedRoutedEventArgs e)
        {
            var task = (IHydraTask)e.Parameter;

            if (task == null)
            {
                return;
            }

            //if (Tasks.Any(t => t.GetType() == task.GetType()))
            //{
            //	var msg = "Multi".ValidateLicense();

            //	if (msg != null)
            //	{
            //		_logManager.Application.AddErrorLog(msg);

            //		new MessageBoxBuilder()
            //			.Text(LocalizedStrings.Str2903Params.Put(task.GetDisplayName()))
            //			.Warning()
            //			.Owner(this)
            //			.Show();

            //		return;
            //	}
            //}

            BusyIndicator.BusyContent = LocalizedStrings.Str2904Params.Put(task.GetDisplayName());
            BusyIndicator.IsBusy      = true;

            IHydraTask newTask = null;

            Task.Factory
            .StartNew(() => newTask = CreateTask(task.GetType()))
            .ContinueWithExceptionHandling(this, res =>
            {
                BusyIndicator.IsBusy = false;

                if (!res)
                {
                    return;
                }

                Tasks.Add(newTask);

                NavigationBar.SelectedIndex = task.Type == TaskTypes.Source ? 0 : 1;

                GetListView(newTask).SelectedItem = newTask;
                NewSourceButton.IsOpen            = false;
                GetListView(newTask).ScrollIntoView(newTask);

                OpenPaneCommand.Execute("Task", null);
                EditTask(newTask);
            });
        }
예제 #10
0
		private void OnStopedTask(IHydraTask task)
		{
			task.Started -= OnStartedTask;
			task.Stopped -= OnStopedTask;

			_startedTasks.Remove(task);

			_taskAllSecurities.Remove(task);
			_taskSecurityCache.Remove(task);

			if (_startedTasks.IsEmpty())
				OnStoppedSources();
		}
예제 #11
0
		private void DeleteTask(IHydraTask task)
		{
			task.Settings.Securities.Clear();
			_entityRegistry.TasksSettings.Remove(task.Settings);

			Core.Extensions.Tasks.Cache.ForEach(t =>
			{
				if (t.Settings.DependFrom == task)
					t.Settings.DependFrom = null;
			});

			Core.Extensions.Tasks.Remove(task);
		}
예제 #12
0
        public static HydraTaskSecurity ToTaskSecurity(this IHydraTask task, Security security)
        {
            if (task == null)
            {
                throw new ArgumentNullException(nameof(task));
            }

            if (security == null)
            {
                throw new ArgumentNullException(nameof(security));
            }

            return(new HydraTaskSecurity
            {
                DataTypes = task.SupportedDataTypes.ToArray(),
                Settings = task.Settings,
                Security = security,
            });
        }
예제 #13
0
        public static HydraTaskSecurity ToTaskSecurity(this IHydraTask task, Security security)
        {
            if (task == null)
            {
                throw new ArgumentNullException("task");
            }

            if (security == null)
            {
                throw new ArgumentNullException("security");
            }

            return(new HydraTaskSecurity
            {
                MarketDataTypes = task.SupportedMarketDataTypes.ToArray(),
                CandleSeries = task.SupportedCandleSeries.Select(s => s.Clone()).ToArray(),
                Settings = task.Settings,
                Security = security,
            });
        }
예제 #14
0
        /// <summary>
        /// Преобразовать <see cref="Security"/> в <see cref="HydraTaskSecurity"/>.
        /// </summary>
        /// <param name="task">Задача.</param>
        /// <param name="securities">Исходные инструменты.</param>
        /// <returns>Сконвертированные инструменты.</returns>
        public static IEnumerable <HydraTaskSecurity> ToHydraSecurities(this IHydraTask task, IEnumerable <Security> securities)
        {
            if (task == null)
            {
                throw new ArgumentNullException(nameof(task));
            }

            if (securities == null)
            {
                throw new ArgumentNullException(nameof(securities));
            }

            var allSec = task.GetAllSecurity();

            var secMap = task.Settings.Securities.ToDictionary(s => s.Security, s => s);

            return(securities.Where(s => s != allSec.Security).Select(s => secMap.TryGetValue(s) ?? new HydraTaskSecurity
            {
                Security = s,
                Settings = task.Settings,
                MarketDataTypes = allSec == null ? ArrayHelper.Empty <Type>() : allSec.MarketDataTypes,
            }));
        }
예제 #15
0
			private static Languages GetLanguage(IHydraTask task)
			{
				var targetPlatform = task.GetType().GetAttribute<TargetPlatformAttribute>();
				return targetPlatform?.PreferLanguage ?? Languages.English;
			}
예제 #16
0
		private ListView GetListView(IHydraTask task)
		{
			return task.Type == TaskTypes.Source ? CurrentSources : CurrentConverters;
		}
예제 #17
0
		private void OnStartedTask(IHydraTask task)
		{
			_startedTasks.Add(task);
		}
예제 #18
0
		private void OnStopedTask(IHydraTask task)
		{
			task.Started -= OnStartedTask;
			task.Stopped -= OnStopedTask;

			_startedTasks.Remove(task);

			_taskAllSecurities.Remove(task);
			_taskSecurityCache.Remove(task);

			if (_startedTasks.IsEmpty())
				OnStoppedSources();
		}
예제 #19
0
		private void EditTask(IHydraTask task)
		{
			var wnd = new TaskSettingsWindow { Task = task };
			if (!wnd.ShowModal(this))
				return;

			task.Settings.IsDefault = false;
			task.SaveSettings();
		}
예제 #20
0
		private TaskPane EnsureTaskPane(IHydraTask task)
		{
			var taskWnd = DockSite.DocumentWindows.FirstOrDefault(w =>
			{
				var pw = w as PaneWindow;

				if (pw == null)
					return false;

				var taskPane = pw.Pane as TaskPane;

				if (taskPane == null)
					return false;

				return taskPane.Task == task;
			});

			if (taskWnd != null)
			{
				taskWnd.Activate();
				return null;
			}
			else
				return new TaskPane { Task = task };
		}
예제 #21
0
		private void InitTask(IHydraTask task, HydraTaskSettings settings)
		{
			Core.Extensions.Tasks.Add(task);

			task.Init(settings);

			_logManager.Sources.Add(task);

			task.DataLoaded += (security, dataType, arg, time, count) =>
			{
				if (dataType == typeof(NewsMessage))
				{
					LoadedNews += count;
					return;
				}

				var allSecurity = _taskAllSecurities.SafeAdd(task, key => task.GetAllSecurity());
				var taskSecurity = _taskSecurityCache.SafeAdd(task).SafeAdd(security, key => task.Settings.Securities.FirstOrDefault(s => s.Security == key));

				HydraTaskSecurity.TypeInfo info;
				HydraTaskSecurity.TypeInfo allInfo;

				if (dataType == typeof(ExecutionMessage))
				{
					switch ((ExecutionTypes)arg)
					{
						case ExecutionTypes.Tick:
						{
							info = taskSecurity?.TradeInfo;
							allInfo = allSecurity?.TradeInfo;

							LoadedTrades += count;
							break;
						}
						case ExecutionTypes.OrderLog:
						{
							info = taskSecurity?.OrderLogInfo;
							allInfo = allSecurity?.OrderLogInfo;

							LoadedOrderLog += count;
							break;
						}
						case ExecutionTypes.Order:
						case ExecutionTypes.Trade:
						{
							info = taskSecurity?.TransactionInfo;
							allInfo = allSecurity?.TransactionInfo;

							LoadedTransactions += count;
							break;
						}
						default:
							throw new ArgumentOutOfRangeException(nameof(arg));
					}
				}
				else if (dataType == typeof(QuoteChangeMessage))
				{
					info = taskSecurity?.DepthInfo;
					allInfo = allSecurity?.DepthInfo;

					LoadedDepths += count;
				}
				else if (dataType == typeof(Level1ChangeMessage))
				{
					info = taskSecurity?.Level1Info;
					allInfo = allSecurity?.Level1Info;

					LoadedLevel1 += count;
				}
				else if (dataType.IsCandleMessage())
				{
					info = taskSecurity?.CandleInfo;
					allInfo = allSecurity?.CandleInfo;

					LoadedCandles += count;
				}
				else
					throw new ArgumentOutOfRangeException(nameof(dataType), dataType, LocalizedStrings.Str1018);

				if (allInfo != null)
				{
					allInfo.Count += count;
					allInfo.LastTime = time.LocalDateTime;

					task.Settings.Securities.Update(allSecurity);
				}

				if (info == null)
					return;

				info.Count += count;
				info.LastTime = time.LocalDateTime;

				task.Settings.Securities.Update(taskSecurity);
			};
		}
예제 #22
0
		private void DeleteTask(IHydraTask task)
		{
			task.Settings.Securities.Clear();
			_entityRegistry.TasksSettings.Remove(task.Settings);

			Core.Extensions.Tasks.Cache.ForEach(t =>
			{
				if (t.Settings.DependFrom == task)
					t.Settings.DependFrom = null;
			});

			Core.Extensions.Tasks.Remove(task);
		}
예제 #23
0
            private static Languages GetLanguage(IHydraTask task)
            {
                var targetPlatform = task.GetType().GetAttribute <TargetPlatformAttribute>();

                return(targetPlatform != null ? targetPlatform.PreferLanguage : Languages.English);
            }
예제 #24
0
 private void OnStopedTask(IHydraTask task)
 {
     this.GuiAsync(() => ControlPanel.IsEnabled = true);
 }
예제 #25
0
 private void OnStartedTask(IHydraTask task)
 {
     _startedTasks.Add(task);
 }
예제 #26
0
 void IDisposable.Dispose()
 {
     Task = null;
 }
예제 #27
0
 private ListView GetListView(IHydraTask task)
 {
     return(task.Type == TaskTypes.Source ? CurrentSources : CurrentConverters);
 }
예제 #28
0
        private void InitTask(IHydraTask task, HydraTaskSettings settings)
        {
            Core.Extensions.Tasks.Add(task);

            task.Init(settings);

            _logManager.Sources.Add(task);

            task.DataLoaded += (security, dataType, arg, time, count) =>
            {
                if (dataType == typeof(NewsMessage))
                {
                    LoadedNews += count;
                    return;
                }

                var allSecurity  = _taskAllSecurities.SafeAdd(task, key => task.GetAllSecurity());
                var taskSecurity = _taskSecurityCache.SafeAdd(task).SafeAdd(security, key => task.Settings.Securities.FirstOrDefault(s => s.Security == key));

                HydraTaskSecurity.TypeInfo info;
                HydraTaskSecurity.TypeInfo allInfo;

                if (dataType == typeof(ExecutionMessage))
                {
                    switch ((ExecutionTypes)arg)
                    {
                    case ExecutionTypes.Tick:
                    {
                        info    = taskSecurity == null ? null : taskSecurity.TradeInfo;
                        allInfo = allSecurity == null ? null : allSecurity.TradeInfo;

                        LoadedTrades += count;
                        break;
                    }

                    case ExecutionTypes.OrderLog:
                    {
                        info    = taskSecurity == null ? null : taskSecurity.OrderLogInfo;
                        allInfo = allSecurity == null ? null : allSecurity.OrderLogInfo;

                        LoadedOrderLog += count;
                        break;
                    }

                    case ExecutionTypes.Order:
                    case ExecutionTypes.Trade:
                    {
                        info    = taskSecurity == null ? null : taskSecurity.ExecutionInfo;
                        allInfo = allSecurity == null ? null : allSecurity.ExecutionInfo;

                        LoadedExecutions += count;
                        break;
                    }

                    default:
                        throw new ArgumentOutOfRangeException("arg");
                    }
                }
                else if (dataType == typeof(QuoteChangeMessage))
                {
                    info    = taskSecurity == null ? null : taskSecurity.DepthInfo;
                    allInfo = allSecurity == null ? null : allSecurity.DepthInfo;

                    LoadedDepths += count;
                }
                else if (dataType == typeof(Level1ChangeMessage))
                {
                    info    = taskSecurity == null ? null : taskSecurity.Level1Info;
                    allInfo = allSecurity == null ? null : allSecurity.Level1Info;

                    LoadedLevel1 += count;
                }
                else if (dataType.IsSubclassOf(typeof(CandleMessage)))
                {
                    info    = taskSecurity == null ? null : taskSecurity.CandleInfo;
                    allInfo = allSecurity == null ? null : allSecurity.CandleInfo;

                    LoadedCandles += count;
                }
                else
                {
                    throw new ArgumentOutOfRangeException("dataType", dataType, LocalizedStrings.Str1018);
                }

                if (allInfo != null)
                {
                    allInfo.Count   += count;
                    allInfo.LastTime = time.LocalDateTime;

                    task.Settings.Securities.Update(allSecurity);
                }

                if (info == null)
                {
                    return;
                }

                info.Count   += count;
                info.LastTime = time.LocalDateTime;

                task.Settings.Securities.Update(taskSecurity);
            };
        }
예제 #29
0
 private void OnStartedTask(IHydraTask task)
 {
     this.GuiAsync(() => ControlPanel.IsEnabled = false);
 }