Пример #1
0
        /// <summary>
        /// Calculates subsequent end times based on the surrounding duration values
        /// </summary>
        /// <param name="currentEndTime">The current end time.</param>
        /// <param name="adjustedDuration">Duration of the adjusted.</param>
        /// <param name="nextDuration">Duration of the next.</param>
        /// <returns></returns>
        private DateTime CalculateEndTime(DateTime currentEndTime, TimeSpan adjustedDuration, TimeSpan nextDuration)
        {
            TraceFactory.Logger.Debug("ET: {0}, AD: {1}, ND: {2}"
                                      .FormatWith(currentEndTime, adjustedDuration, nextDuration));

            // Pick a simple way to "randomly" decide if the variance will be positive or negative.
            bool isPositive = currentEndTime.Ticks % 2 == 0;

            // Calculate the variance for the current duration, which has been adjusted to account for the end time
            // of the last segment. This asjusted duration may be larger or smaller than its default value.
            var variance = Variance(adjustedDuration);

            TraceFactory.Logger.Debug("Variance {0}".FormatWith(variance));

            // This variance can't extend beyond 1/2 of the next duration, if it is positive.
            if (isPositive)
            {
                TimeSpan halfNextDuration = TimeSpanUtil.Divide(nextDuration, 2);
                if (variance > halfNextDuration)
                {
                    // Keep the variance to some value less than 1/2 of this shorter duration
                    variance = TimeSpanUtil.GetRandom(halfNextDuration);
                    TraceFactory.Logger.Debug("Variance reduced {0}".FormatWith(variance));
                }
            }

            // Return the new end time based on the current end time, plus the current duration,
            // then +/- the variance.
            var newDuration = currentEndTime.Add(adjustedDuration);

            return(isPositive ? newDuration.Add(variance) : newDuration.Subtract(variance));
        }
        protected void WaitOnStartupDelay()
        {
            OfficeWorkerDetail workerDetail = GlobalDataStore.Manifest.Resources.GetWorker <OfficeWorkerDetail>(GlobalDataStore.ResourceInstanceId);

            //if (workerDetail.ResourceType.IsCitrixWorker())
            //{
            //    return;
            //}

            TimeSpan minDelay     = TimeSpan.FromSeconds(workerDetail.MinStartupDelay);
            TimeSpan maxDelay     = TimeSpan.FromSeconds(workerDetail.MaxStartupDelay);
            var      startupDelay = workerDetail.RandomizeStartupDelay ? TimeSpanUtil.GetRandom(minDelay, maxDelay) : minDelay;

            TraceFactory.Logger.Debug("Delay for {0} secs".FormatWith(startupDelay.TotalSeconds));



            _statusLogger.Caller = "StartUp";
            _statusLogger.Update(_statusLogger.Index + 1, Enum.GetName(typeof(RuntimeState), 8), true, "User");
            ExecutionServices.DataLogger.AsInternal().Submit(_statusLogger);
            ApplicationFlowControl.Instance.Wait(startupDelay);

            //CR 3192
            //We're seeing an issue with duplicate entry attempts on the primary key even though we generate a new key each time. To circumvent this issue we're creating a brand new instance, which in turn generates a new id and should prevent key issues.

            //VirtualResourceInstanceStatusLogger postwait = new VirtualResourceInstanceStatusLogger(_sessionId, Environment.UserName, ++_statusLogger.Index, Enum.GetName(typeof(RuntimeState), 6), true, GlobalDataStore.ResourceInstanceId);
            _statusLogger.Caller = "StartUp";

            _statusLogger.Update(_statusLogger.Index + 1, Enum.GetName(typeof(RuntimeState), 6), true, "StartUp");

            ExecutionServices.DataLogger.AsInternal().Submit(_statusLogger);
        }
Пример #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void CheckedChanged(object sender, EventArgs e)
        {
            if (sender is RadioButton)
            {
                this.interval =
                    TimeSpanUtil.ConvertMinutesToMilliseconds(
                        Convert.ToDouble(((RadioButton)sender).Tag));
            }
            else
            {
                if (((CheckBox)sender) == chkMonitSql)
                {
                    this.monitSql = ((CheckBox)sender).Checked;
                }
            }

            if (ValueChanged != null)
            {
                Delegate[] subscribers = ValueChanged.GetInvocationList();
                foreach (EventHandler target in subscribers)
                {
                    target(this, new EventArgs());
                }
            }
        }
Пример #4
0
    /// Performs the flashing effect on taking damage
    public IEnumerator FlashingEffect(float waitTime)
    {
        //If you are currently invisible, go un-invisible, and vice versa
        if (currentlyInvisible)
        {
            this.GetComponent <SpriteRenderer> ().color = (Color32)ColorControls.HexToColor("FFFFFFFF");
            currentlyInvisible = false;
        }
        else
        {
            this.GetComponent <SpriteRenderer> ().color = (Color32)ColorControls.HexToColor("FFFFFF11");
            currentlyInvisible = true;
        }

        //UnityEngine.Debug.Log ("Stopwatch: " + TimeSpanUtil.ConvertMillisecondsToSeconds (invincibilityStopwatch.ElapsedMilliseconds));
        //UnityEngine.Debug.Log ("Invincibility Time: " + invincibilityTime);

        //If our invincibility time is up, then we turn ourselves back to full color and vulnerable again
        if (TimeSpanUtil.ConvertMillisecondsToSeconds(InvincibilityStopwatch.ElapsedMilliseconds) > InvincibilityTime)
        {
            UnityEngine.Debug.Log("Now ending invincibility.");
            Invincible = false;
            this.GetComponent <SpriteRenderer> ().color = (Color32)ColorControls.HexToColor("FFFFFFFF");
            currentlyInvisible = false;
        }
        else
        {
            yield return(new WaitForSeconds(waitTime));

            StartCoroutine(FlashingEffect(0.20f));
        }
    }
Пример #5
0
        /// <summary>
        /// Executes the specified virtual resources.
        /// </summary>
        private void StartCitrixUserSession()
        {
            // First copy a file over by username that will be used to define this client
            // and the associated dispatcher.  The remote machine will then pick it up.
            string remotePath = @"\\{0}\C$\VirtualResource\UserConfiguration".FormatWith(_citrixServer);

            if (!Directory.Exists(remotePath))
            {
                Directory.CreateDirectory(remotePath);
            }
            TraceFactory.Logger.Debug(remotePath);

            string datFile = @"{0}\{1}.dat".FormatWith(remotePath, _credential.UserName);

            File.WriteAllText(datFile, "{0},{1}".FormatWith(Environment.MachineName, _credential.ResourceInstanceId));
            TraceFactory.Logger.Debug("Created startup information file on Citrix Server");

            TraceFactory.Logger.Debug("Creating user {0} on port {1}...".FormatWith(_credential.UserName, _credential.Port));

            TimeSpan startupDelay = _randomizeStartupDelay ? TimeSpanUtil.GetRandom(_minStartupDelay, _maxStartupDelay) : _minStartupDelay;

            Delay.Wait(startupDelay);

            TriggerQueueMonitoring();

            ChangeMachineStatusMessage("Starting User Process");
            StartUserProcess(_credential, Directory.GetCurrentDirectory());
        }
Пример #6
0
        public void FromNanoseconds(long nanoseconds)
        {
            var milliseconds = nanoseconds / 1_000_000D;

            var expected = TimeSpan.FromMilliseconds(milliseconds);
            var timeSpan = TimeSpanUtil.FromNanoseconds(nanoseconds);

            timeSpan.Should().Be(expected);
        }
Пример #7
0
        private TimeSpan Variance(TimeSpan duration)
        {
            // Determine a variance maximum value by taking 12.5% of the duration's current size. The 12.5% value is
            // one half of an overall 25% value (12.5% on each side of the transition boundary).  Then use that
            // maximum value to calculate a new random value between zero and the maximum value.
            TimeSpan varianceMax = TimeSpanUtil.Divide(duration, 8);

            return(TimeSpanUtil.GetRandom(varianceMax));
        }
Пример #8
0
        /// <summary>
        /// Create a sequence number from a time. The first date will be zero, and
        /// subsequent dates will be increased according to the grandularity
        /// specified.
        /// </summary>
        /// <param name="when">The date to generate the sequence number for.</param>
        /// <returns>A sequence number.</returns>
        public virtual int GetSequenceFromDate(DateTime when)
        {
            int sequence;

            if (_startingPoint != DateTime.MinValue)
            {
                var span = new TimeSpanUtil(_startingPoint, when);
                sequence = (int)span.GetSpan(_sequenceGrandularity);
            }
            else
            {
                _startingPoint = when;
                sequence       = 0;
            }

            return(sequence);
        }
Пример #9
0
        private void StartWithTimeBasedRampUp(LoadTesterMetadataDetail metadataDetail)
        {
            var plan = metadataDetail.Plan as LoadTesterExecutionPlan;

            plan.Mode = ExecutionMode.Duration;

            // Iterate over the total thread count, but select a unique delay value for each thread.
            for (int i = 0; i < plan.ThreadCount; i++)
            {
                TimeSpan minDelay  = TimeSpan.FromSeconds(plan.MinRampUpDelay);
                TimeSpan maxDelay  = TimeSpan.FromSeconds(plan.MaxRampUpDelay);
                var      rampDelay = plan.RandomizeRampUpDelay ? TimeSpanUtil.GetRandom(minDelay, maxDelay) : minDelay;

                TraceFactory.Logger.Debug("Delay: {0}".FormatWith(rampDelay.TotalSeconds));

                _threads.Add(new LoadTestThread(metadataDetail, rampDelay));
            }

            Task.Factory.StartNew(ExecuteTasks);
        }
Пример #10
0
        public double GetRemainingBalance(string ParticipantA)
        {
            if (Com.WebServiceDefinitions.Platform == Com.WebServiceDefinitions.PlatformCode.Static)
            {
                return(25);
            }

            try
            {
                var req = new getRemainingBalanceRequest();
                req.campaignCode = this.CampaignCode;
                req.participantA = ParticipantA;

                balanceItem[] results = WebServiceLoader.TiklaKonusClient().getRemainingBalance(req);

                return(TimeSpanUtil.ConvertMillisecondsToMinutes(Convert.ToDouble(results[0].duration)));
            }
            catch (Exception)
            {
                //LOG KAYIT
                return(0);
            }
        }
Пример #11
0
 /// <summary>
 /// Updates the <see cref="_totalEvaluationTimeout" />.
 /// </summary>
 /// <param name="update">Message that caused the update.</param>
 private void HandleTimeoutUpdate(UpdateTimeout update)
 {
     this._totalEvaluationTimeout = TimeSpanUtil.Min(update.Timeout, this._totalEvaluationTimeout);
 }
Пример #12
0
 public IssueTrackedViewModel(string jiraId, double trackedTimeSeconds)
 {
     Id             = jiraId;
     TrackedMinutes = Math.Ceiling(TimeSpanUtil.ConvertSecondsToMinutes(trackedTimeSeconds));
 }
Пример #13
0
 private static TimeSpan GetDelay(TimeSpan minDelay, TimeSpan maxDelay, bool random)
 {
     return(random ? TimeSpanUtil.GetRandom(minDelay, maxDelay) : minDelay);
 }