protected SpeckleApiClient(SerializationInfo info, StreamingContext context) { _settings = new System.Lazy <Newtonsoft.Json.JsonSerializerSettings>(() => { var settings = new Newtonsoft.Json.JsonSerializerSettings() { ContractResolver = new Newtonsoft.Json.Serialization.DefaultContractResolver() { NamingStrategy = new Newtonsoft.Json.Serialization.CamelCaseNamingStrategy() }, ReferenceLoopHandling = ReferenceLoopHandling.Ignore }; UpdateJsonSerializerSettings(settings); return(settings); }); UseGzip = true; BaseUrl = info.GetString("BaseUrl"); StreamId = info.GetString("StreamId"); Role = (ClientRole)info.GetInt32("Role"); ClientId = info.GetString("ClientId"); //AuthToken = info.GetString( "ApiToken" ); //string userEmail = null; // old clients will not have a user email field :/ try { var userEmail = info.GetString("UserEmail"); var acc = LocalContext.GetAccountByEmailAndRestApi(userEmail, BaseUrl); if (acc != null) { AuthToken = acc.Token; User = new User() { Email = acc.Email }; } else { throw new Exception("You do not have an account that matches this stream's server."); } } catch { var accs = LocalContext.GetAccountsByRestApi(BaseUrl); var sorted = accs.OrderByDescending(acc => acc.IsDefault).ToList(); if (sorted.Count == 0) { throw new Exception("You do not have an account that matches this stream's server."); } else { AuthToken = accs[0].Token; User = new User() { Email = sorted[0].Email }; } } Stream = StreamGetAsync(StreamId, null).Result.Resource; // does not need waiting for, as we already have a clientid. SetupClient(); SetupWebsocket(); SetReadyTimer(); SetWsReconnectTimer(); }
/// <summary> /// Purges the streams table. WARNING: Don't do this unless you know what you're doing. /// </summary> public static void PurgeCachedStreams( ) { LocalContext.Init(); Database?.Execute("DELETE FROM CachedStream"); }
protected SpeckleApiClient(SerializationInfo info, StreamingContext context) { _settings = new System.Lazy <Newtonsoft.Json.JsonSerializerSettings>(() => { var settings = new Newtonsoft.Json.JsonSerializerSettings() { ContractResolver = new Newtonsoft.Json.Serialization.DefaultContractResolver() { NamingStrategy = new Newtonsoft.Json.Serialization.CamelCaseNamingStrategy() }, ReferenceLoopHandling = ReferenceLoopHandling.Ignore }; UpdateJsonSerializerSettings(settings); return(settings); }); UseGzip = true; BaseUrl = info.GetString("BaseUrl"); StreamId = info.GetString("StreamId"); Role = ( ClientRole )info.GetInt32("Role"); ClientId = info.GetString("ClientId"); try { ClientType = info.GetString("ClientType"); } catch (Exception e) { // Meep, no client type present. old client. // NOTE: the end clients (rhino, grasshopper, dynamo, etc) should attempt to set this value again on their re-initialisation. // This is so that we can actually get types out for pre-existing clients that didn't save the ClientType property. ClientType = "undefined"; } // old clients will not have a user email field :/ try { var userEmail = info.GetString("UserEmail"); var acc = LocalContext.GetAccountByEmailAndRestApi(userEmail, BaseUrl); if (acc != null) { AuthToken = acc.Token; User = new User() { Email = acc.Email }; } else { throw new Exception("You do not have an account that matches this stream's server."); } } catch { var accs = LocalContext.GetAccountsByRestApi(BaseUrl); var sorted = accs.OrderByDescending(acc => acc.IsDefault).ToList(); if (sorted.Count == 0) { throw new Exception("You do not have an account that matches this stream's server."); } else { AuthToken = accs[0].Token; User = new User() { Email = sorted[0].Email }; } } Stream = StreamGetAsync(StreamId, null).Result.Resource; // does not need waiting for, as we already have a clientid. SetupClient(); SetupWebsocket(); SetReadyTimer(); SetWsReconnectTimer(); }
/// <summary> /// Purges the sent objects table. WARNING: Don't do this unless you know what you're doing. /// </summary> public static void PurgeSentObjects( ) { LocalContext.Init(); Database?.Execute("DELETE FROM SentObject"); }
/// <summary> /// Purges the accounts. WARNING: Don't do this unless you know what you're doing. /// </summary> public static void PurgeAccounts( ) { LocalContext.Init(); Database?.Execute("DELETE FROM Account"); }
/// <summary> /// Gets all the accounts associated with the provided email. /// </summary> /// <param name="email"></param> /// <returns></returns> public static List <Account> GetAccountsByEmail(string email) { LocalContext.Init(); return(Database.Query <Account>("SELECT * from Account WHERE Email = ?", email)); }
public static void RemoveAccount(Account ac) { LocalContext.Init(); Database.Delete <Account>(ac.AccountId); }
/// <summary> /// Gets all the accounts associated with the provided rest api. /// </summary> /// <param name="RestApi"></param> /// <returns></returns> public static List <Account> GetAccountsByRestApi(string RestApi) { LocalContext.Init(); return(Database.Query <Account>("SELECT * from Account WHERE RestApi = ?", RestApi)); }
/// <summary> /// Gets all accounts present. /// </summary> /// <returns></returns> public static List <Account> GetAllAccounts( ) { LocalContext.Init(); return(Database.Query <Account>("SELECT * FROM Account")); }
/// <summary> /// Adds a new account. /// </summary> /// <param name="account"></param> public static void AddAccount(Account account) { LocalContext.Init(); var res = Database.Insert(account); }
/// <summary> /// Udates an account by its primary key. /// </summary> /// <param name="account"></param> public static void UpdateAccount(Account account) { LocalContext.Init(); Database.Update(account); }
/// <summary> /// Clears any default account. (You will no longer have a default account) /// </summary> /// <param name="account"></param> public static void ClearDefaultAccount() { LocalContext.Init(); Database.Execute("UPDATE Account SET IsDefault=0"); }