public UsageModel Clone(bool includeWeekly, bool includeMonthly)
        {
            var result     = new UsageModel();
            var properties = result.GetType().GetRuntimeProperties();

            foreach (var property in properties)
            {
                var cloneValue = property.PropertyType == typeof(int);

                if (property.Name == nameof(result.NumberOfStartupsWeek))
                {
                    cloneValue = includeWeekly;
                }
                else if (property.Name == nameof(result.NumberOfStartupsMonth))
                {
                    cloneValue = includeMonthly;
                }

                if (cloneValue)
                {
                    var value = property.GetValue(this);
                    property.SetValue(result, value);
                }
            }

            return(result);
        }
Exemple #2
0
        public UsageModel ClearCounters(bool clearWeekly, bool clearMonthly)
        {
            var result = new UsageModel();

            if (!clearWeekly)
            {
                result.NumberOfStartupsWeek = NumberOfStartupsWeek;
            }
            if (!clearMonthly)
            {
                result.NumberOfStartupsMonth = NumberOfStartupsMonth;
            }

            result.IsGitHubUser     = IsGitHubUser;
            result.IsEnterpriseUser = IsEnterpriseUser;
            result.AppVersion       = AppVersion;
            result.VSVersion        = VSVersion;
            result.Lang             = Lang;
            return(result);
        }
Exemple #3
0
        static void ClearCounters(UsageModel usage, bool weekly, bool monthly)
        {
            usage.NumberOfStartups = 0;
            usage.NumberOfClones = 0;
            usage.NumberOfReposCreated = 0;
            usage.NumberOfReposPublished = 0;
            usage.NumberOfGists = 0;
            usage.NumberOfOpenInGitHub = 0;
            usage.NumberOfLinkToGitHub = 0;
            usage.NumberOfLogins = 0;
            usage.NumberOfUpstreamPullRequests = 0;

            if (weekly)
                usage.NumberOfStartupsWeek = 0;

            if (monthly)
                usage.NumberOfStartupsMonth = 0;
        }
Exemple #4
0
        async Task SendUsage(UsageModel usage, bool weekly, bool monthly)
        {
            Debug.Assert(client != null, "SendUsage should not be called when there is no IMetricsService");

            if (connectionManager.Connections.Any(x => x.HostAddress.IsGitHubDotCom()))
            {
                usage.IsGitHubUser = true;
            }

            if (connectionManager.Connections.Any(x => !x.HostAddress.IsGitHubDotCom()))
            {
                usage.IsEnterpriseUser = true;
            }

            var model = usage.Clone(weekly, monthly);
            await client.PostUsage(model);
        }