示例#1
0
        public UserContext(ClaimsPrincipal principal, IdentityDbContext identityDb, UserManager userManager, GroupManager groupManager)
        {
            if (principal?.Identity != null)
            {
                IsAuthenticated    = principal.Identity.IsAuthenticated;
                AuthenticationType = principal.Identity.AuthenticationType;
                Name = principal.Identity.Name;
            }

            UserId    = principal.FindFirst(ProfileClaimTypes.Subject)?.Value;
            Roles     = principal.FindAll(ProfileClaimTypes.Role).Select(x => x.Value);
            Principal = principal;

            SecurityClaims = BuildSecurityClaims(identityDb, userManager, UserId, groupManager);

            IsCorpUser = SecurityClaims.Any(x => x.Type == KnownClaims.CorpClaimTypes.CorpUser);
        }
示例#2
0
        private static void Main(string[] args)
        {
            if (args.Length < 3)
            {
                Console.WriteLine("Required arguments not found!");
                Console.WriteLine("URI AppKey ScanRate");
                Console.WriteLine("Example:");
                Console.WriteLine("SteamSensorClient.exe wss://localhost:443/Thingworx/WS xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx 1000");
                return;
            }

            // Set the required configuration information
            var config = new ClientConfigurator
            {
                // Set the size of the threadpools
                MaxMsgHandlerThreadCount = 8,
                MaxApiTaskerThreadCount  = 8,
                DisableCertValidation    = true,
                OfflineMsgStoreDir       = ".",
                // The uri for connecting to Thingworx
                Uri = args[0],
                // Reconnect every 15 seconds if a disconnect occurs or if initial connection cannot be made
                ReconnectInterval = 15
            };

            // Set the security using an Application Key
            var appKey = args[1];

            var claims = SecurityClaims.fromAppKey(appKey);

            config.Claims = claims;

            // Set the name of the client
            config.Name = "SteamSensorGateway";

            // Get the scan rate (milliseconds) that is specific to this example
            // The example will execute the processScanRequest of the VirtualThing
            // based on this scan rate
            var scanRate = int.Parse(args[2]);

            // Create the client passing in the configuration from above
            var client = new SteamSensorClient(config);

            try
            {
                // Create think
                var sensor1 = new SteamThing("ThingTemperature_dntichy", "Senzor id: ...dorob ID ak viac senzorov", "SN000", client);
                client.bindThing(sensor1);

                LoggerFactory.Log(Logger, TraceEventType.Critical,
                                  "CONNECTNG TO PLATFORM:\n   " +
                                  "Uri: {0} \n   " +
                                  "AppKey: {1} \n   " +
                                  "Think: [name: {2}, identifier: {3}] \n   " +
                                  "AllowSelfSignedCertificates: {4} \n   " +
                                  "DisableCertValidation: {5}",
                                  config.Uri, appKey, sensor1.getName(), sensor1.getIdentifier(),
                                  config.AllowSelfSignedCertificates, config.DisableCertValidation);

                // Start the client
                ThreadPool.QueueUserWorkItem(client.StartClient);
            }
            catch (Exception eStart)
            {
                Console.WriteLine("Initial Start Failed : " + eStart.Message);
            }

            // Wait for the SteamSensorClient to connect, then process its associated things.
            // As long as the client has not been shutdown, continue
            while (!client.isShutdown())
            {
                // Only process the Virtual Things if the client is connected
                if (client.isConnected())
                {
                    ThreadPool.QueueUserWorkItem(client.RunClient);
                }

                // Suspend processing at the scan rate interval
                Thread.Sleep(scanRate);
            }
        }
        static void Main(string[] args)
        {
            /*if(args.Length < 3)
             * {
             *              Console.WriteLine("Required arguments not found!");
             *              Console.WriteLine("URI AppKey ScanRate");
             *              Console.WriteLine("Example:");
             *  Console.WriteLine("SteamSensorClient.exe wss://localhost:443/Thingworx/WS xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx 1000");
             *  return;
             *      }*/

            // Set the required configuration information
            var config = new ClientConfigurator();

            // Set the size of the threadpools
            config.MaxMsgHandlerThreadCount = 8;
            config.MaxApiTaskerThreadCount  = 8;


            /***** WARNING: For Development purposes only. Do not use these settings in a production environment. *****/
            config.AllowSelfSignedCertificates = true;
            config.DisableCertValidation       = true;
            /***** WARNING *****/

            // The uri for connecting to Thingworx
            config.Uri = ConfigurationManager.AppSettings["config.Uri"].ToString();

            // Reconnect every 15 seconds if a disconnect occurs or if initial connection cannot be made
            config.ReconnectInterval = 15;

            // Set the security using an Application Key
            var appKey = ConfigurationManager.AppSettings["appKey"].ToString();

            var claims = SecurityClaims.fromAppKey(appKey);

            config.Claims = claims;

            // Set the name of the client
            config.Name           = "TakePhotoGateway";
            config.MaxMessageSize = 1048576;

            // Get the scan rate (milliseconds) that is specific to this example
            // The example will execute the processScanRequest of the VirtualThing
            // based on this scan rate
            int scanRate = 1000;

            // Create the client passing in the configuration from above
            SteamSensorClient client = new SteamSensorClient(config);

            // prepare the camera IP
            FindCameraIp();

            try
            {
                // Create two Virtual Things
                SteamThing sensor1 = new SteamThing("AlexaAgentTR", "desc", null, client);
                // SteamThing sensor2 = new SteamThing("SteamSensor2", "2nd Floor Steam Sensor", "SN0002", client);

                // Bind the Virtual Things
                client.bindThing(sensor1);
                // client.bindThing(sensor2);

                // Start the client
                ThreadPool.QueueUserWorkItem(client.startClient);
            }
            catch (Exception eStart)
            {
                Console.WriteLine("Initial Start Failed : " + eStart.Message);
            }


            // Wait for the SteamSensorClient to connect, then process its associated things.
            // As long as the client has not been shutdown, continue
            while (!client.isShutdown())
            {
                // Only process the Virtual Things if the client is connected
                if (client.isConnected())
                {
                    ThreadPool.QueueUserWorkItem(client.runClient);
                }

                // Suspend processing at the scan rate interval
                Thread.Sleep(scanRate);
            }
        }