Ejemplo n.º 1
0
 public static void Send(string socketServerAccessTokenToken, string sessionToken, string msg, params object[] msgPars)
 {
     lock (serializer)
     {
         var _wsClient = Connect(Configsettings.SocketServerUrl(), socketServerAccessTokenToken);
         if (Connected(_wsClient))
         {
             string total_msg = string.Format("{0}#-_-_-{1}", sessionToken, string.Format(msg, msgPars));
             var    tokSrc    = new CancellationTokenSource();
             var    tsk       = _wsClient.SendAsync(
                 new ArraySegment <byte>(Encoding.UTF8.GetBytes(total_msg)),
                 WebSocketMessageType.Text,
                 true,
                 tokSrc.Token
                 );
             if (!tsk.IsFaulted)
             {
                 tsk.Wait();
             }
             tsk.Dispose();
             tokSrc.Dispose();
             Close(_wsClient);
         }
     }
 }
Ejemplo n.º 2
0
        public static string NewSiliconClientToken(string scope)
        {
            var tokenUrl = string.Format("{0}connect/token", Configsettings.AuthUrl());

            _logger.Debug("Getting a new Client Token for scope {1} at {0} ", tokenUrl, scope);

            var client = new TokenClient(tokenUrl, Configsettings.SiliconClientId(), Configsettings.SiliconClientSecret());

            var token = client.RequestClientCredentialsAsync(scope).Result;

            if (token.IsError)
            {
                return("Error Getting a Silicon Token for scope " + scope);
            }
            return(token.AccessToken);
        }