Exemplo n.º 1
0
        protected void DeleteToken()
        {
            using (var context = ContextFactory())
            {
                context.ObjectTrackingEnabled = true;

                var original = context.Tokens.FirstOrDefault(t => t.Network == _network);

                if (original == null)
                    return;

                context.Tokens.DeleteOnSubmit(original);
                context.SubmitChanges();
            }

            Token = null;
        }
Exemplo n.º 2
0
        public async Task<Token> LoginAsync(Token token)
        {
            // Check for network connectivity
            if (!NetworkInterface.GetIsNetworkAvailable()) return null;

            var client = new RestClient("http://trainshare.herokuapp.com/v1/");
            var request =
                new RestRequest("login", Method.POST)
                    .AddJson(
                        new JObject(
                            new JProperty("network", token.Network),
                            new JProperty("access_token", token.AccessToken),
                            new JProperty("access_token_secret", token.AccessTokenSecret)));

            request.RequestFormat = DataFormat.Json;

            try
            {
                var json =
                    await
                    client
                        .ExecutTaskAsync(request)
                        .ContinueWith(task => JObject.Parse(task.Result.Content));

                InsertOrUpdateToken(
                    new Token
                    {
                        Network = "trainshare",
                        AccessToken = json["trainshare_id"].Value<string>(),
                        AccessTokenSecret = json["trainshare_token"].Value<string>()
                    });

                Events.Publish(Token);

                return Token;
            }
            catch (Exception e)
            {
                _logger.Error(e);
                return null;
            }
        }
Exemplo n.º 3
0
        protected void InsertOrUpdateToken(Token token)
        {
            using (var context = ContextFactory())
            {
                context.ObjectTrackingEnabled = true;

                var original = context.Tokens.FirstOrDefault(t => t.Network == _network);

                if (original == null)
                    context.Tokens.InsertOnSubmit(token);
                else
                {
                    context.Tokens.DeleteOnSubmit(original);
                    context.Tokens.InsertOnSubmit(token);
                }

                context.SubmitChanges();
            }

            Token = token;
        }
Exemplo n.º 4
0
 protected void ReloadToken()
 {
     using (var context = ContextFactory())
     {
         Token = context.Tokens.FirstOrDefault(t => t.Network == _network);
     }
 }