Merged in SparkPersist (pull request #28)
SPARK-1162 UserPersist should use ID Approved-by: John Colvin <john.colvin@bluetradesys.com>
This commit is contained in:
commit
eab2852773
10 files changed
+67
-34
No files matched your search
@@ -15,25 +15,26 @@ namespace mbts.ui.settings
|
||||
[Export(typeof(IUserPersistFactory))]
|
||||
class UISettingsFactory : IUserPersistFactory
|
||||
{
|
||||
Task<string[]> _users;
|
||||
Task<User[]> _users;
|
||||
readonly PersistenceService _persist;
|
||||
|
||||
[ImportingConstructor]
|
||||
public UISettingsFactory([Import("username")] string current_user, UserService login, [Import("settings")] PersistenceService persist) {
|
||||
public UISettingsFactory(UserService login, [Import("settings")] PersistenceService persist) {
|
||||
_persist = persist;
|
||||
_users = get_users(login);
|
||||
}
|
||||
|
||||
async Task<string[]> get_users(UserService login) {
|
||||
async Task<User[]> get_users(UserService login) {
|
||||
var users = await login.get_users_async(null);
|
||||
if (users.success) return users.value.Users.Select(x => x.Login).ToArray();
|
||||
else return new string[0];
|
||||
if (users.success) return users.value.Users.ToArray();
|
||||
else return new User[0];
|
||||
}
|
||||
|
||||
public IEnumerable<string> users() { return _users.Result; }
|
||||
public IEnumerable<string> users() { return _users.Result.Select(u => u.Login); }
|
||||
|
||||
public IUserPersist get_persist_for(string user) {
|
||||
return new UserUISettings(user, _persist);
|
||||
public IUserPersist get_persist_for(string name) {
|
||||
var user = _users.Result.FirstOrDefault(u => u.Login == name);
|
||||
return new UserUISettings(user.Id, _persist);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -140,9 +140,9 @@ namespace mbts.persist
|
||||
string _user;
|
||||
|
||||
[ImportingConstructor]
|
||||
public UserUISettings([Import("username")]string user, [Import("settings")]PersistenceService persist)
|
||||
public UserUISettings([Import("userid")]uint user, [Import("settings")]PersistenceService persist)
|
||||
: base(persist) {
|
||||
_user = user;
|
||||
_user = $"User {user}";
|
||||
}
|
||||
|
||||
protected override string user() { return _user; }
|
||||
|
||||
@@ -30,7 +30,9 @@ namespace mbts.ui.shell
|
||||
model.provide_services(user, persist);
|
||||
// await_login pumps the dispatcher but doesn't allow control to return to MEF until the username and workspace are available
|
||||
model.await_login();
|
||||
UserName = model.get_username();
|
||||
var u = model.get_user();
|
||||
UserName = u.name;
|
||||
UserId = u.id;
|
||||
Workspace = model.get_workspace();
|
||||
model.Dispose();
|
||||
}
|
||||
@@ -45,16 +47,24 @@ namespace mbts.ui.shell
|
||||
[Export("username")]
|
||||
public string UserName { get; private set; }
|
||||
|
||||
[Export("userid")]
|
||||
public uint UserId { get; private set; }
|
||||
|
||||
[Export("workspace")]
|
||||
public string Workspace { get; private set; }
|
||||
}
|
||||
|
||||
public struct User {
|
||||
public string name;
|
||||
public UInt32 id;
|
||||
}
|
||||
|
||||
public class LoginModel : IDisposable
|
||||
{
|
||||
// Singleton to help bootstrap the system
|
||||
private static LoginModel _instance = new LoginModel();
|
||||
public static LoginModel instance { get { return _instance; } }
|
||||
private string _username;
|
||||
private User _user;
|
||||
private string _workspace;
|
||||
private PreloginWorkspaceEnumerator _enum_workspace;
|
||||
|
||||
@@ -69,18 +79,19 @@ namespace mbts.ui.shell
|
||||
public event Action Ready;
|
||||
public string ErrorMessage { get; private set; }
|
||||
public bool HasFatalError { get; set; }
|
||||
public string[] UserNames { get; private set; }
|
||||
public User[] Users { get; private set; }
|
||||
|
||||
|
||||
// The final username
|
||||
public string get_username() {
|
||||
Logger.assert_d(!string.IsNullOrEmpty(_username));
|
||||
return _username;
|
||||
public User get_user() {
|
||||
Logger.assert_d(!string.IsNullOrEmpty(_user.name));
|
||||
return _user;
|
||||
}
|
||||
public string get_workspace() {
|
||||
return _workspace ?? "";
|
||||
}
|
||||
public Task<IEnumerable<string>> workspaces_for(string user) {
|
||||
|
||||
public Task<IEnumerable<string>> workspaces_for(User user) {
|
||||
return _enum_workspace.get_workspaces(user);
|
||||
}
|
||||
|
||||
@@ -105,8 +116,7 @@ namespace mbts.ui.shell
|
||||
_enum_workspace = new PreloginWorkspaceEnumerator(persist);
|
||||
var response = await _logon.get_users_async(new GetUsersRequest());
|
||||
if (response.success) {
|
||||
UserNames = response.value.Users.Select(x => x.Login).ToArray();
|
||||
Array.Sort(UserNames);
|
||||
Users = response.value.Users.Select(x => new User { name = x.Login, id = x.Id }).OrderBy(u => u.name).ToArray();
|
||||
}
|
||||
else {
|
||||
ErrorMessage = "Logon: " + response.error_message;
|
||||
@@ -118,7 +128,7 @@ namespace mbts.ui.shell
|
||||
#endregion
|
||||
|
||||
public async Task<(bool success,string info)> do_login(string username, string workspace, string password) {
|
||||
if (UserNames.Contains(username)) {
|
||||
if (Users.Select(u => u.name).Contains(username)) {
|
||||
var response = await _logon.authenticate_login_async(new AuthenticateLoginRequest() {
|
||||
Login = username,
|
||||
Password = password ??""
|
||||
@@ -126,7 +136,7 @@ namespace mbts.ui.shell
|
||||
if (response.success) {
|
||||
if (response.value.IsValid) {
|
||||
_workspace = workspace;
|
||||
set_authenticated_user(username);
|
||||
set_authenticated_user(new User { name =username, id = response.value.UserId});
|
||||
return (true, "");
|
||||
}
|
||||
else {
|
||||
@@ -140,16 +150,16 @@ namespace mbts.ui.shell
|
||||
return (false, "Invalid username");
|
||||
}
|
||||
|
||||
private void set_authenticated_user(string name) {
|
||||
Logger.assert(!string.IsNullOrEmpty(name));
|
||||
Logger.assert(UserNames.Contains(name));
|
||||
_username = name;
|
||||
Environment.SetEnvironmentVariable("BTS_USER", name);
|
||||
private void set_authenticated_user(User user) {
|
||||
Logger.assert(!string.IsNullOrEmpty(user.name));
|
||||
Logger.assert(Users.Select(u => u.name).Contains(user.name));
|
||||
_user = user;
|
||||
Environment.SetEnvironmentVariable("BTS_USER", user.name);
|
||||
_frame.Continue = false;
|
||||
}
|
||||
|
||||
public void await_login() {
|
||||
if (string.IsNullOrEmpty(_username)) {
|
||||
if (string.IsNullOrEmpty(_user.name)) {
|
||||
Dispatcher.PushFrame(_frame);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace mbts.ui.shell
|
||||
void _model_Ready() {
|
||||
_dispatcher.BeginInvoke(() => {
|
||||
if (!_model.HasFatalError) {
|
||||
this.UserNames.AddRange(_model.UserNames);
|
||||
this.UserNames.AddRange(_model.Users.Select(u => u.name));
|
||||
this.VisualState = "LoginState";
|
||||
load_username();
|
||||
LoginCommand.RaiseCanExecuteChanged();
|
||||
@@ -82,7 +82,8 @@ namespace mbts.ui.shell
|
||||
private async void update_workspaces(string name) {
|
||||
Workspaces.Clear();
|
||||
Workspaces.Add("New workspace...");
|
||||
var to_add = await _model.workspaces_for(name);
|
||||
var user = _model.Users.First(u => u.name == name);
|
||||
var to_add = await _model.workspaces_for(user);
|
||||
this.SelectedWorkspace = Workspaces.First();
|
||||
if (to_add != null && name == _name && Workspaces.Count == 1) {
|
||||
Workspaces.AddRange(to_add);
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace mbts.ui.shell
|
||||
{
|
||||
class PreloginWorkspaceEnumerator
|
||||
{
|
||||
private Dictionary<string, List<string>> _cache = new Dictionary<string, List<string>>();
|
||||
private Dictionary<uint, List<string>> _cache = new Dictionary<uint, List<string>>();
|
||||
private PersistenceService _persist;
|
||||
|
||||
public PreloginWorkspaceEnumerator(PersistenceService p) {
|
||||
@@ -27,12 +27,12 @@ namespace mbts.ui.shell
|
||||
return name;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<string>> get_workspaces(string username) {
|
||||
if (!_cache.TryGetValue(username, out List<string> result)) {
|
||||
using (var svc = new UserUISettings(username, _persist)) {
|
||||
public async Task<IEnumerable<string>> get_workspaces(User user) {
|
||||
if (!_cache.TryGetValue(user.id, out List<string> result)) {
|
||||
using (var svc = new UserUISettings(user.id, _persist)) {
|
||||
var workspaces = await svc.query<WorkspaceDefinition>(WorkspacesModel.WORKSPACE_NAMESPACE, ".*");
|
||||
result = workspaces.Select(w => w.key).ToList();
|
||||
_cache[username] = result;
|
||||
_cache[user.id] = result;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,6 +55,9 @@ message GLBXExchangeData {
|
||||
string security_desc = 20;
|
||||
string cfi_code = 21;
|
||||
string cme_symbol = 22;
|
||||
uint32 main_fraction = 30;
|
||||
uint32 sub_fraction = 31;
|
||||
uint32 price_display_format = 32;
|
||||
}
|
||||
message CBOEExchangeData {
|
||||
int64 exchange_id = 10;
|
||||
|
||||
@@ -71,6 +71,9 @@ string dump_security(const FixedSecurity& security) {
|
||||
res << "'display_factor': " << (int)security.display_factor << ", ";
|
||||
res << "'numeric_id': " << security.numeric_id << ", ";
|
||||
res << "'cboe_class_key': " << security.cboe_class_key << ", ";
|
||||
res << "'cme_main_frac': " << (int)security.cme_main_fraction << ", ";
|
||||
res << "'cme_sub_fract': " << (int)security.cme_sub_fraction << ", ";
|
||||
res << "'cme_price_dformat': " << (int)security.cme_price_display_format << ", ";
|
||||
|
||||
res << "'market_segment': " << security.cme_market_segment_id << ", ";
|
||||
|
||||
|
||||
@@ -157,6 +157,9 @@ void convert_security(const FixedSecurity& source, Security* presult) {
|
||||
dest.mutable_glbx()->set_security_desc(source.security_desc());
|
||||
dest.mutable_glbx()->set_cfi_code(source.cfi_code());
|
||||
dest.mutable_glbx()->set_cme_symbol(source.alt_symbol());
|
||||
if (source.cme_main_fraction != 0) dest.mutable_glbx()->set_main_fraction(source.cme_main_fraction);
|
||||
if (source.cme_sub_fraction != 0) dest.mutable_glbx()->set_sub_fraction(source.cme_sub_fraction);
|
||||
if (source.cme_price_display_format) dest.mutable_glbx()->set_price_display_format(source.cme_price_display_format);
|
||||
break;
|
||||
case Venue::VENUE_BTS:
|
||||
break;
|
||||
@@ -254,6 +257,9 @@ void convert_security(const Security& src, FixedSecurity& dest, bool set_securit
|
||||
dest.security_desc(src.glbx().security_desc());
|
||||
dest.cfi_code(src.glbx().cfi_code());
|
||||
dest.alt_symbol(src.glbx().cme_symbol());
|
||||
dest.cme_main_fraction = src.glbx().main_fraction();
|
||||
dest.cme_sub_fraction = src.glbx().sub_fraction();
|
||||
dest.cme_price_display_format = src.glbx().price_display_format();
|
||||
break;
|
||||
case Security::ExchangeDataCase::kCboe:
|
||||
dest.cboe_class_key = src.cboe().class_key();
|
||||
|
||||
@@ -54,6 +54,10 @@ public:
|
||||
double high_tick;
|
||||
double cash_per_point;
|
||||
|
||||
uint8_t cme_main_fraction;
|
||||
uint8_t cme_sub_fraction;
|
||||
uint8_t cme_price_display_format;
|
||||
|
||||
private:
|
||||
char _symbol[16]; // CME defines this as a char[6] but I'm padding
|
||||
char _cfi_code[8]; // CME defines this as char[6]
|
||||
|
||||
@@ -201,6 +201,10 @@ void set_security_common(const Definition& def, FixedSecurity& fsec) {
|
||||
// tickRule not present in futures
|
||||
fsec.cme_market_segment_id = def.marketSegmentId();
|
||||
fsec.display_factor = def.displayFactor().exponent() + floorlog10(def.displayFactor().mantissa());
|
||||
|
||||
def.mainFraction(fsec.cme_main_fraction);
|
||||
def.subFraction(fsec.cme_sub_fraction);
|
||||
def.priceDisplayFormat(fsec.cme_price_display_format);
|
||||
}
|
||||
|
||||
void MDP3Listener::onDefinition(onixs::Handler&, const onixs::Security& osec, const onixs::InstrumentDefinitionFutureArgs& def) {
|
||||
@@ -211,6 +215,7 @@ void MDP3Listener::onDefinition(onixs::Handler&, const onixs::Security& osec, co
|
||||
bts_assert(exchange_id == osec.id());
|
||||
|
||||
FixedFutureSecurity fsec;
|
||||
|
||||
set_security_common(sec, fsec);
|
||||
fsec.price_break = 0;
|
||||
// low/high tick are stored non-premultiplied and multiplied in conversion to api::Secutity
|
||||
|
||||
Reference in new issue
Block a user