public TelemetricsClient(IAmazonCognitoIdentity cognitoIdentityClient, IParameterStore parameterStore)
 {
     _cognitoIdentityClient = cognitoIdentityClient;
     _parameterStore        = parameterStore;
     _clientId   = parameterStore.GetParameter(CLIENT_ID);
     _httpClient = new HttpClient();
 }
Beispiel #2
0
        /// <summary>
        /// Get the current KinesisTap build number stored in the parameter store.
        /// </summary>
        public static int GetStoredBuildNumber(this IParameterStore store)
        {
            var storedValue = store.GetParameter(BuildNumberKey);

            return(int.TryParse(storedValue, out var buildNumber)
                ? buildNumber
                : 0);
        }
        public KinesisTapService()
        {
            this.parameterStore.StoreConventionalValues();

            // configure logging
            var nlogConfigPath = parameterStore.GetParameter(HostingUtility.NLogConfigPathKey);

            NLog.LogManager.LoadConfiguration(nlogConfigPath);

            this.serviceLoggerFactory = new LoggerFactory()
                                        .AddEventLog(new EventLogSettings
            {
                SourceName = KinesisTapServiceManager.ServiceName,
                LogName    = "Application",
                Filter     = (msg, level) => level >= LogLevel.Information
            })
                                        .AddNLog();

            logger = this.serviceLoggerFactory.CreateLogger <KinesisTapService>();

            this.serviceManager = new KinesisTapServiceManager(this.typeLoader, this.parameterStore,
                                                               this.serviceLoggerFactory.CreateLogger <KinesisTapServiceManager>(),
                                                               new DefaultNetworkStatusProvider());

            // Try to enable pre-shutdown notifications to give KT an early start on shutdown.
            // By enabling this, as soon as a shutdown is triggered in the OS, KT will be notified.
            // https://docs.microsoft.com/en-us/windows/win32/services/service-control-handler-function
            try
            {
                // Unfortunately there's no convenience property for enabling pre-shutdown notifications, so we have to do it via reflection.
                // http://www.sivachandran.in/2012/03/handling-pre-shutdown-notification-in-c.html
                var acceptedCommandsFieldInfo = typeof(ServiceBase).GetField("acceptedCommands", BindingFlags.Instance | BindingFlags.NonPublic);
                if (acceptedCommandsFieldInfo != null)
                {
                    int value = (int)acceptedCommandsFieldInfo.GetValue(this);
                    acceptedCommandsFieldInfo.SetValue(this, value | SERVICE_ACCEPT_PRESHUTDOWN);
                }
                // when 'preshutdown' is enabled, we need to disable 'shutdown' command so that shutdown event is not handled twice
                this.CanShutdown = false;
            }
            catch (Exception ex)
            {
                // If this fails, we'll just log an error and ignore.
                // Since we're setting internal field properties, Windows may change this at any time.
                this.EventLog.WriteEntry($"An error occurred trying to configure the Service to accept pre-shutdown notifications: {ex}", EventLogEntryType.Information);
                // Set this to 'true' so we can handle OS's SHUTDOWN command
                this.CanShutdown = true;
            }
        }
        private void btnStart_Click(object sender, EventArgs e)
        {
            btnStart.Enabled = false;
            _parameterStore.StoreConventionalValues();
            var nlogConfigPath = _parameterStore.GetParameter(HostingUtility.NLogConfigPathKey);

            NLog.LogManager.LoadConfiguration(nlogConfigPath);

            // configure logging
            _serviceManager = new KinesisTapServiceManager(new PluginLoader(), _parameterStore,
                                                           _serviceLoggerFactory.CreateLogger <KinesisTapServiceManager>(), new DefaultNetworkStatusProvider());
            _serviceManager.Start();

            btnStop.Enabled = true;
        }
Beispiel #5
0
        private void GenerateUniqueClientID()
        {
            //Generate a unique client id for the KinesisTap based on the system properties
            string uniqueClientID        = Utility.UniqueClientID;
            string currentUniqueClientID = _parameterStore.GetParameter(ConfigConstants.UNIQUE_CLIENT_ID);

            //Set Unique id here
            if (uniqueClientID != currentUniqueClientID)
            {
                _logger.LogInformation($"Unique Client ID of the system changed from '{currentUniqueClientID}' to '{uniqueClientID}' ");
                _parameterStore.SetParameter(ConfigConstants.UNIQUE_CLIENT_ID, uniqueClientID);
            }

            _logger.LogInformation($"Unique Client ID of the system is '{uniqueClientID}' ");
            _logger.LogInformation($"Unique System properties used to generate Unique Client ID is '{Utility.UniqueSystemProperties}' ");

            //Store the value in enviornment variable
            if (string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable(ConfigConstants.UNIQUE_CLIENT_ID)))
            {
                Environment.SetEnvironmentVariable(ConfigConstants.UNIQUE_CLIENT_ID, uniqueClientID);
            }

            return;
        }
 public static string GetExtraConfigDirPath(this IParameterStore store)
 => Path.Combine(store.GetParameter(ConfigDirPathKey), Utility.ExtraConfigDirectoryName);
 public static string GetDefaultConfigFilePath(this IParameterStore store)
 => Path.Combine(store.GetParameter(ConfigDirPathKey), DefaultConfigFileName);
 public static string GetConfigDirPath(this IParameterStore store) => store.GetParameter(ConfigDirPathKey);
Beispiel #9
0
 public TelemetricsSinkConnector(IPlugInContext context) : base(context)
 {
     _parameterStore = context.ParameterStore;
     _clientId       = _parameterStore.GetParameter(ClientIdParameterName);
 }