コード例 #1
0
        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();
        }
コード例 #2
0
 /// <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");
 }
コード例 #3
0
        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();
        }
コード例 #4
0
 /// <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");
 }
コード例 #5
0
 /// <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");
 }
コード例 #6
0
 /// <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));
 }
コード例 #7
0
 public static void RemoveAccount(Account ac)
 {
     LocalContext.Init();
     Database.Delete <Account>(ac.AccountId);
 }
コード例 #8
0
 /// <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));
 }
コード例 #9
0
 /// <summary>
 /// Gets all accounts present.
 /// </summary>
 /// <returns></returns>
 public static List <Account> GetAllAccounts( )
 {
     LocalContext.Init();
     return(Database.Query <Account>("SELECT * FROM Account"));
 }
コード例 #10
0
 /// <summary>
 /// Adds a new account.
 /// </summary>
 /// <param name="account"></param>
 public static void AddAccount(Account account)
 {
     LocalContext.Init();
     var res = Database.Insert(account);
 }
コード例 #11
0
 /// <summary>
 /// Udates an account by its primary key.
 /// </summary>
 /// <param name="account"></param>
 public static void UpdateAccount(Account account)
 {
     LocalContext.Init();
     Database.Update(account);
 }
コード例 #12
0
 /// <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");
 }