Exemple #1
0
        private static Guid GetInstallGuid(MetricAppId appId, out RegistryKey rootRegistryKey, out RegistryKey appKey)
        {
            rootRegistryKey = Registry.CurrentUser.OpenSubKey(RegistryRootKey, RegistryKeyPermissionCheck.ReadWriteSubTree) ??
                              Registry.CurrentUser.CreateSubKey(RegistryRootKey, RegistryKeyPermissionCheck.ReadWriteSubTree);

            var shortName = appId.Name.Replace("Stride", string.Empty);

            // Get the appKey
            if (rootRegistryKey != null)
            {
                appKey = rootRegistryKey.OpenSubKey(shortName, RegistryKeyPermissionCheck.ReadWriteSubTree) ??
                         rootRegistryKey.CreateSubKey(shortName, RegistryKeyPermissionCheck.ReadWriteSubTree);

                // Get or create InstallGuid
                var guidObj = rootRegistryKey.GetValue(RegistryInstallKey);
                var guid    = Guid.Empty;
                if (guidObj != null)
                {
                    Guid.TryParse(guidObj.ToString(), out guid);
                }

                if (guid == Guid.Empty)
                {
                    guid = Guid.NewGuid();
                    rootRegistryKey.SetValue(RegistryInstallKey, guid);
                }

                return(guid);
            }

            appKey = null;
            return(Guid.Empty);
        }
Exemple #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MetricsClient" /> class.
        /// </summary>
        /// <param name="appId">The application identifier.</param>
        /// <param name="heartbeatRateMs">The rate the heartbeats are sent in ms </param>
        /// <param name="endpointUrl">The endpoint URL.</param>
        /// <param name="versionOverride">The version number to override.</param>
        /// <exception cref="System.ArgumentNullException">endpointUrl
        /// or
        /// appId</exception>
        public MetricsClient(MetricAppId appId, int?heartbeatRateMs = null, string endpointUrl = null, string versionOverride = null)
        {
            if (heartbeatRateMs != null)
            {
                heartbeatRate = heartbeatRateMs.Value;
            }

            if (endpointUrl == null)
            {
                endpointUrl = "https://metrics.stride3d.net";
            }
            if (appId == null)
            {
                throw new ArgumentNullException(nameof(appId));
            }

            // Make sure the endpoint ends with /
            if (!endpointUrl.EndsWith("/"))
            {
                endpointUrl += "/";
            }

            this.versionOverride = versionOverride;

            // Get special env variable
            var disableIdStr = Environment.GetEnvironmentVariable(EnvSpecial);

            if (disableIdStr != null)
            {
                Guid.TryParse(disableIdStr, out specialGuid);
            }

            scheduledTasks = new BlockingCollection <Action>();
            httpClient     = new HttpClient {
                BaseAddress = new Uri(endpointUrl)
            };
            this.appId = appId;

            // Get installation guid
            installGuid = GetInstallGuid(appId, out rootRegistryKey, out appRegistryKey);

            heartbeatStopwatch.Start();

            // Use a custom task scheduler
            metricSenderThread = new Thread(MetricThreadSender)
            {
                Name = "MetricThreadSender"
            };
            metricSenderThread.Start();

            scheduledTasks.Add(Initialize);
        }