The changes made by the user in the SplitTrafficWindow dialog.
Esempio n. 1
0
        /// <summary>
        /// Called when the user clicks the Save button.  This handles error checks,
        /// populates the <seealso cref="Result"/> field and closes the dialog.
        /// </summary>
        private void OnSaveCommand()
        {
            // Build the set of allocations.
            IDictionary <string, double?> allocations = new Dictionary <string, double?>();
            int sum = 0;

            foreach (var allocation in Allocations)
            {
                // Ensure each allocation have a valid traffic allocation percent.
                int percent = allocation.TrafficAllocation;
                if (percent <= 0 || percent > 100)
                {
                    UserPromptUtils.Default.ErrorPrompt(
                        message: String.Format(Resources.SplitTrafficWindowInvalidPercentRangeErrorMessage, allocation.VersionId),
                        title: Resources.SplitTrafficWindowInvalidPercentTitle);
                    return;
                }
                sum += percent;

                double doublePercent = Math.Round((double)allocation.TrafficAllocation / 100, 2);
                allocations.Add(allocation.VersionId, doublePercent);
            }

            // Ensure that 100% of traffic is allocated.
            if (sum != 100)
            {
                UserPromptUtils.Default.ErrorPrompt(
                    Resources.SplitTrafficWindowInvalidPercentSumErrorMessage,
                    Resources.SplitTrafficWindowInvalidPercentTitle);
                return;
            }

            string shardBy = IsIpChecked ? GaeServiceExtensions.ShardByIp : GaeServiceExtensions.ShardByCookie;

            Result = new SplitTrafficChange(allocations, shardBy);
            _owner.Close();
        }
        /// <summary>
        /// Called when the user clicks the Save button.  This handles error checks, 
        /// populates the <seealso cref="Result"/> field and closes the dialog.
        /// </summary>
        private void OnSaveCommand()
        {
            // Build the set of allocations.
            IDictionary<string, double?> allocations = new Dictionary<string, double?>();
            int sum = 0;
            foreach (var allocation in Allocations)
            {
                // Ensure each allocation have a valid traffic allocation percent.
                int percent = allocation.TrafficAllocation;
                if (percent <= 0 || percent > 100)
                {
                    UserPromptUtils.ErrorPrompt(
                        message: String.Format(Resources.SplitTrafficWindowInvalidPercentRangeErrorMessage, allocation.VersionId),
                        title: Resources.SplitTrafficWindowInvalidPercentTitle);
                    return;
                }
                sum += percent;

                double doublePercent = Math.Round((double)allocation.TrafficAllocation / 100, 2);
                allocations.Add(allocation.VersionId, doublePercent);
            }

            // Ensure that 100% of traffic is allocated.
            if (sum != 100)
            {
                UserPromptUtils.ErrorPrompt(
                    Resources.SplitTrafficWindowInvalidPercentSumErrorMessage,
                    Resources.SplitTrafficWindowInvalidPercentTitle);
                return;
            }

            string shardBy = IsIpChecked ? GaeServiceExtensions.ShardByIp : GaeServiceExtensions.ShardByCookie;
            Result = new SplitTrafficChange(allocations, shardBy);
            _owner.Close();
        }