protected SpeckleApiClient(SerializationInfo info, StreamingContext context) { _settings = new System.Lazy <Newtonsoft.Json.JsonSerializerSettings>(() => { var settings = new Newtonsoft.Json.JsonSerializerSettings(); 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 }; } } 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(); }
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(); }