Compare commits
14
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5bc629e9f8 | ||
|
|
17c2321a82 | ||
|
|
0affc8a942 | ||
|
|
ce36ea4109 | ||
|
|
1ba6e3280c | ||
|
|
3a6f50dfea | ||
|
|
d711f99548 | ||
|
|
07ace80871 | ||
|
|
93c6277bfc | ||
|
|
7ac9d05ae2 | ||
|
|
fb568aab39 | ||
|
|
85f2285ac0 | ||
|
|
1f80c3366e | ||
|
|
19e66a1c32 |
No files matched your search
@@ -115,7 +115,7 @@ namespace mbts.ui.shell
|
||||
{
|
||||
try
|
||||
{
|
||||
var path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\BTS\\stunnel\\";
|
||||
string path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\BTS\\stunnel\\";
|
||||
if (File.Exists(path + "config\\stunnel.conf"))
|
||||
{
|
||||
uint job_error = BTSUINativeMethods.setup_process_job_object();
|
||||
@@ -124,6 +124,15 @@ namespace mbts.ui.shell
|
||||
kill_stunnel();
|
||||
start_stunnel(path, job_error);
|
||||
}
|
||||
path = AppDomain.CurrentDomain.BaseDirectory + "\\..\\stunnel\\";
|
||||
if (File.Exists(path + "config\\stunnel.conf"))
|
||||
{
|
||||
uint job_error = BTSUINativeMethods.setup_process_job_object();
|
||||
//if we can't put this process and stunnel into a job, try to stop stunnel then restart
|
||||
if (job_error != 0)
|
||||
kill_stunnel();
|
||||
start_stunnel(path, job_error);
|
||||
}
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
|
||||
@@ -534,8 +534,7 @@ namespace mbts.spark {
|
||||
_size_from_row(row, _price_list, _asks, _vm.security.ContractSpec);
|
||||
|
||||
uint _volume_from_row(int row) {
|
||||
if (_price_list != null) {
|
||||
var price = _price_list[row];
|
||||
if (_price_list.SafeTryGetAt(row, out var price)) {
|
||||
var vapls = _volume_container.read_new_value();
|
||||
if (vapls != null) {
|
||||
return vapls.SelectFirstOrDefault(v => MathUtils.epsilon_equals(v.Price, price), v => v.Volume);
|
||||
|
||||
@@ -2,6 +2,7 @@ using bts.api;
|
||||
using bts.api.core;
|
||||
using bts.api.position;
|
||||
using bts.collections;
|
||||
using bts.utils;
|
||||
using mbts;
|
||||
using mbts.spark;
|
||||
using mbts.ui;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using bts.api;
|
||||
using bts.shell;
|
||||
using bts.spark;
|
||||
using bts.utils;
|
||||
using mbts.config;
|
||||
using mbts.persist;
|
||||
using mbts.spark;
|
||||
@@ -114,6 +115,7 @@ namespace mbts.ui {
|
||||
void dispose_core() {
|
||||
Disposable.dispose(ref _settings_sub);
|
||||
Disposable.dispose(ref _toast_controller);
|
||||
Disposable.dispose(ref _sound_player);
|
||||
if (_dispatcher != null && !_dispatcher.HasShutdownStarted) {
|
||||
_dispatcher.BeginInvokeShutdown(DispatcherPriority.Background);
|
||||
}
|
||||
@@ -158,15 +160,25 @@ namespace mbts.ui {
|
||||
}
|
||||
}
|
||||
|
||||
class SoundNotificationPlayer {
|
||||
readonly IReadOnlyDictionary<SoundNotification.SystemSound, NAudioPlayer> _players;
|
||||
|
||||
public static SoundNotificationPlayer create() => new SoundNotificationPlayer(_all_players());
|
||||
class SoundNotificationPlayer : IDisposable {
|
||||
IReadOnlyDictionary<SoundNotification.SystemSound, NAudioPlayer> _players;
|
||||
|
||||
SoundNotificationPlayer(IReadOnlyDictionary<SoundNotification.SystemSound, NAudioPlayer> players) =>
|
||||
_players = players;
|
||||
|
||||
public static SoundNotificationPlayer create() =>
|
||||
new SoundNotificationPlayer(_all_players());
|
||||
|
||||
public void Dispose() {
|
||||
if (_players != null) {
|
||||
_players.Values.DisposeAll();
|
||||
_players = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void play_sounds(IEnumerable<SoundNotification> sounds) {
|
||||
if (_players == null)
|
||||
return;
|
||||
foreach (var s in sounds) {
|
||||
switch (s.sound_type_case) {
|
||||
case SoundNotification.SoundTypeOneofCase.System: _players.GetValueOrDefault(s.system_sound.Value)?.play(); break;
|
||||
@@ -177,7 +189,8 @@ namespace mbts.ui {
|
||||
}
|
||||
|
||||
static IReadOnlyDictionary<SoundNotification.SystemSound, NAudioPlayer> _all_players() =>
|
||||
EnumHelper.get_values<SoundNotification.SystemSound>().ToReadOnlyDictionary(s => s, NAudioPlayer.create);
|
||||
EnumHelper.get_values<SoundNotification.SystemSound>()
|
||||
.ToReadOnlyDictionaryWhere<SoundNotification.SystemSound, NAudioPlayer>(NAudioPlayer.try_create);
|
||||
}
|
||||
|
||||
// This class adopts to role of view-controller in the mvc paradigm, rather than view-model in mvvm.
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using bts.shell;
|
||||
using bts;
|
||||
using bts.shell;
|
||||
using mbts.ui.utility;
|
||||
using NAudio.Wave;
|
||||
using System;
|
||||
@@ -6,29 +7,71 @@ using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace mbts.ui {
|
||||
class NAudioPlayer {
|
||||
class NAudioPlayer : IDisposable {
|
||||
// number of milliseconds to delay playing sound,
|
||||
// during which time all subsequent requests to play the same sound will be ignored.
|
||||
const int _delay_ms = 75;
|
||||
readonly int _start_position;
|
||||
IDisposable _stream_in;
|
||||
WaveOutEvent _wave_out = new WaveOutEvent();
|
||||
WaveFileReader _wave_reader;
|
||||
bool _is_playing, _is_play_requested;
|
||||
|
||||
public NAudioPlayer(Stream uwave_stream, int start_position = 0) {
|
||||
var ms = new MemoryStream();
|
||||
uwave_stream.CopyTo(ms);
|
||||
ms.Position = 0;
|
||||
_wave_reader = new WaveFileReader(ms);
|
||||
/// <paramref name="stream_in"/> should not be disposed by the caller,
|
||||
/// as NAudioPlayer handles that in its own Dispose method;
|
||||
/// this constructor is private is to prevent such misuse.
|
||||
NAudioPlayer(Stream stream_in, int start_position = 0) {
|
||||
_stream_in = stream_in;
|
||||
_wave_reader = new WaveFileReader(stream_in);
|
||||
_wave_reader.Position = _start_position = (start_position < _wave_reader.Length ? start_position : 0);
|
||||
_wave_out.Init(_wave_reader);
|
||||
_wave_out.PlaybackStopped += _on_playback_stopped;
|
||||
}
|
||||
|
||||
public static NAudioPlayer create(SoundNotification.SystemSound system_sound) {
|
||||
var stream = _get_stream(system_sound);
|
||||
var sb = EnumHelper.get_attribute<SoundNotification.SystemSound, SilenceBufferAttribute>(system_sound);
|
||||
return sb != null ? new NAudioPlayer(stream, sb.start_position) : new NAudioPlayer(stream);
|
||||
/// <see cref="_playback_stopped"/> is a proxy/buffer for the _wave_out.PlaybackStopped event.
|
||||
/// It serves a couple purposes:
|
||||
/// 1) The main callback (<see cref="_on_playback_stopped(object, StoppedEventArgs)"/>)
|
||||
/// is guarenteed to be executed first (though it would be anyways, since that
|
||||
/// callback is hooked up in the constructor, the proxy event makes it obvious).
|
||||
/// 2) <see cref="_playback_stopped"/> is only raised after playback is truly complete,
|
||||
/// meaning there are no pending requests to repeat the sound.
|
||||
event Action _playback_stopped;
|
||||
|
||||
public static bool try_create(SoundNotification.SystemSound system_sound, out NAudioPlayer result) {
|
||||
if (_try_get_stream(system_sound, out var stream)) {
|
||||
var sb = EnumHelper.get_attribute<SoundNotification.SystemSound, SilenceBufferAttribute>(system_sound);
|
||||
result = sb != null ? new NAudioPlayer(stream, sb.start_position) : new NAudioPlayer(stream);
|
||||
return true;
|
||||
}
|
||||
result = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void play(SoundNotification.SystemSound system_sound) {
|
||||
if (try_create(system_sound, out var player)) {
|
||||
try {
|
||||
var temp = player;
|
||||
temp._playback_stopped += temp.Dispose;
|
||||
player.play();
|
||||
player = null;
|
||||
} catch (Exception ex) {
|
||||
Log.Ui.warn($"Encountered exception playing the system sound '{system_sound}': {ex}.");
|
||||
} finally {
|
||||
player?.Dispose();
|
||||
}
|
||||
} else {
|
||||
Log.Ui.warn($"Unable to play the system sound '{system_sound}': unexpected sound type (did not find an audio stream that corresponds to this enum value).");
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
if (_wave_out != null) {
|
||||
_wave_out.PlaybackStopped -= _on_playback_stopped;
|
||||
_wave_out.Dispose();
|
||||
_wave_out = null;
|
||||
}
|
||||
Disposable.dispose(ref _wave_reader);
|
||||
Disposable.dispose(ref _stream_in);
|
||||
}
|
||||
|
||||
public void play() {
|
||||
@@ -46,6 +89,8 @@ namespace mbts.ui {
|
||||
if (_is_play_requested) {
|
||||
_is_play_requested = false;
|
||||
_play_core();
|
||||
} else {
|
||||
_playback_stopped?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,18 +101,26 @@ namespace mbts.ui {
|
||||
_is_playing = false;
|
||||
}
|
||||
|
||||
static Stream _get_stream(SoundNotification.SystemSound system_sound) {
|
||||
static bool _try_get_stream(SoundNotification.SystemSound system_sound, out Stream stream) {
|
||||
UnmanagedMemoryStream um_stream;
|
||||
switch (system_sound) {
|
||||
case SoundNotification.SystemSound.GameCorrect: return bts.Properties.Resources.game_sound_correct;
|
||||
case SoundNotification.SystemSound.GameIncorrect: return bts.Properties.Resources.game_sound_wrong;
|
||||
case SoundNotification.SystemSound.GameOverArcade: return bts.Properties.Resources.game_over_arcade;
|
||||
case SoundNotification.SystemSound.Whistle: return bts.Properties.Resources.whistle;
|
||||
case SoundNotification.SystemSound.BellCounter: return bts.Properties.Resources.bell_counter;
|
||||
case SoundNotification.SystemSound.Powerup: return bts.Properties.Resources.powerup;
|
||||
case SoundNotification.SystemSound.CashRegister: return bts.Properties.Resources.cash_register_purchase;
|
||||
case SoundNotification.SystemSound.Reload: return bts.Properties.Resources.reload_1911;
|
||||
default: throw new NotImplementedException($"Unknown {nameof(SoundNotification.SystemSound)}: {system_sound}.");
|
||||
case SoundNotification.SystemSound.GameCorrect: um_stream = bts.Properties.Resources.game_sound_correct; break;
|
||||
case SoundNotification.SystemSound.GameIncorrect: um_stream = bts.Properties.Resources.game_sound_wrong; break;
|
||||
case SoundNotification.SystemSound.GameOverArcade: um_stream = bts.Properties.Resources.game_over_arcade; break;
|
||||
case SoundNotification.SystemSound.Whistle: um_stream = bts.Properties.Resources.whistle; break;
|
||||
case SoundNotification.SystemSound.BellCounter: um_stream = bts.Properties.Resources.bell_counter; break;
|
||||
case SoundNotification.SystemSound.Powerup: um_stream = bts.Properties.Resources.powerup; break;
|
||||
case SoundNotification.SystemSound.CashRegister: um_stream = bts.Properties.Resources.cash_register_purchase; break;
|
||||
case SoundNotification.SystemSound.Reload: um_stream = bts.Properties.Resources.reload_1911; break;
|
||||
default:
|
||||
stream = null;
|
||||
return false;
|
||||
}
|
||||
stream = new MemoryStream();
|
||||
um_stream.CopyTo(stream);
|
||||
um_stream.Dispose();
|
||||
stream.Position = 0;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -215,8 +215,11 @@ namespace mbts.spark {
|
||||
FillTuple.key_fn);
|
||||
on_fill_tuples_with_root = fill_order_tuples_with_root_join.Cache();
|
||||
// manual fills
|
||||
on_manual_fills_securities = _position_service.subscribei_manual_fills()
|
||||
.Naggle(interval, scheduler)
|
||||
on_manual_fills_securities = admin_model
|
||||
.permission_filter(
|
||||
_position_service.subscribei_manual_fills()
|
||||
.Naggle(interval, scheduler),
|
||||
f => f.AccountId)
|
||||
.Filter(f => f.FillType == ManualFill.Types.FillType.Local)
|
||||
.join(sstore, mf => mf.SecurityKey)
|
||||
.Table().Cache();
|
||||
|
||||
+1
-5
@@ -38,11 +38,7 @@ namespace mbts.ui.controls {
|
||||
}
|
||||
|
||||
public static ICommand PreviewSoundCommand =>
|
||||
new DelegateCommand<SoundNotification.SystemSound>(s => {
|
||||
try {
|
||||
NAudioPlayer.create(s).play();
|
||||
} catch (NAudio.MmException) { }
|
||||
});
|
||||
new DelegateCommand<SoundNotification.SystemSound>(NAudioPlayer.play);
|
||||
|
||||
#region SoundTypes
|
||||
public static readonly DependencyProperty SoundTypesProperty =
|
||||
|
||||
@@ -418,6 +418,15 @@ namespace System.Collections.Generic {
|
||||
public static ReadOnlyDictionary<TKey, TElement> ToReadOnlyDictionary<T, TKey, TElement>(this IEnumerable<T> enumerable, Func<T, TKey> key_selector, Func<T, TElement> element_selector, IEqualityComparer<TKey> comparer) =>
|
||||
new ReadOnlyDictionary<TKey, TElement>(enumerable.ToDictionary(key_selector, element_selector, comparer));
|
||||
|
||||
public static ReadOnlyDictionary<TKey, TElement> ToReadOnlyDictionaryWhere<TKey, TElement>(this IEnumerable<TKey> keys, TryGetValue<TKey, TElement> value_selector) {
|
||||
var mdict = new Dictionary<TKey, TElement>();
|
||||
foreach (var k in keys) {
|
||||
if (value_selector(k, out var val))
|
||||
mdict[k] = val;
|
||||
}
|
||||
return new ReadOnlyDictionary<TKey, TElement>(mdict);
|
||||
}
|
||||
|
||||
public static ILookup<TKey, TElement> ToFlatLookup<T, TKey, TElement>(this IEnumerable<T> source, Func<T, TKey> key_selector, Func<T, IEnumerable<TElement>> selector) =>
|
||||
source.SelectMany(v => {
|
||||
var k = key_selector(v);
|
||||
|
||||
@@ -103,6 +103,15 @@ namespace bts.collections {
|
||||
return array;
|
||||
}
|
||||
|
||||
public static bool SafeTryGetAt<T>(this IList<T> list, int index, out T value) {
|
||||
if (list != null && index >= 0 && index < list.Count) {
|
||||
value = list[index];
|
||||
return true;
|
||||
}
|
||||
value = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool TryGetAt<T>(this IList<T> list, int index, out T value) {
|
||||
if (index >= 0 && index < list.Count) {
|
||||
value = list[index];
|
||||
|
||||
+6
-6
@@ -1,11 +1,11 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
|
||||
namespace mbts.utils {
|
||||
delegate bool TryGetValue<T>(out T value);
|
||||
delegate bool TryGetValue<TKey, TValue>(TKey key, out TValue value);
|
||||
namespace bts.utils {
|
||||
public delegate bool TryGetValue<T>(out T value);
|
||||
public delegate bool TryGetValue<TKey, TValue>(TKey key, out TValue value);
|
||||
|
||||
static class LogicalDelegates {
|
||||
public static class LogicalDelegates {
|
||||
public static readonly Func<bool, bool, bool>
|
||||
And = (a, b) => a && b,
|
||||
Or = (a, b) => a || b,
|
||||
@@ -13,7 +13,7 @@ namespace mbts.utils {
|
||||
None = (a, b) => !a && !b;
|
||||
}
|
||||
|
||||
static class FormattingDelegates {
|
||||
public static class FormattingDelegates {
|
||||
public static class Price {
|
||||
public static readonly Func<double, string> Value =
|
||||
p => double.IsNaN(p) ? "" : p.ToString("#,0.00");
|
||||
@@ -26,4 +26,4 @@ namespace mbts.utils {
|
||||
p => p.ToString("#,0.00", CultureInfo.CurrentCulture);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -1,13 +1,10 @@
|
||||
|
||||
|
||||
#nusers: 1
|
||||
#allow concurrent : true
|
||||
#expires: 2020-Mar-31 00:00:00 637212096000000000
|
||||
#generation_time: 2020-Jan-06 18:56:23.406931 5248825356261457214
|
||||
#expires: 2021-Jan-01 00:00:00 637450560000000000
|
||||
#generation_time: 2020-Apr-03 18:39:31.010863 5248901378137496534
|
||||
EncryptedKeyCode {
|
||||
value {
|
||||
keycode: "Ixb/z6hwFQmojpm4GwNEpQmsqpYT9OTHbcKtROIqj38GwGqyVn54JMDB04V048quO+NAI78DKJXsUWgjDH0y5HQlwN6Lq48s/bdwKqR1OTBPr6xoTImtCb+l5b+8fUGlg7t3X8gfMdxohHgcUi9k9n7ZrnNvqcjdYKoP0CaTZT8zHuBQx3f4Lqrz32gq9rJ5skRjH6ZqNblNdlsF+kOAqXCkvI5p0QfyKgtCodr33qsW2cbqY5gUD9KwsnmFVa8/zuFBucsoM7dHB47yRaIeOFFu7xGayAdAHA8SwLyoxE5y+adIX1SYnAiqAu1raZpeXgRE1LNQk3c7uhUjt0coag=="
|
||||
keycode: "BJBQWsbdTXWa/iLmOf3ekE8vP/NYkf0Q/nUsp/rJ78Ze3W9pNXICCMabmmsr1xOM7aqRIclPgZd955uSSfvFkdNWFTxwPQ5IfnDGopj3QdhUVxhzgVLaXHN+vC0H/MWrDQ5K4WY5J/6VXgUn1LSN/2HNb5iR2sKXeh3Alamg87YtCWEi+scelffE7HK5ERT/3A3Y/e0pqUFhP6xouIjHRhC2FRBb6OoJQVvFwVDADSuKZNo9B6GhC3H0YdHqjFhGDoky5ecgzeKIX8uWJEQNnQXQJ0iTgQ95+YR5IMU+XWdlVfSrc0fuTmj3YWcBQ8Kl2ItEcobyZzJYega3tu6Ftw=="
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user