当前位置: 首页>>代码示例>>C#>>正文


C# TimeSpan.Multiply方法代码示例

本文整理汇总了C#中System.TimeSpan.Multiply方法的典型用法代码示例。如果您正苦于以下问题:C# TimeSpan.Multiply方法的具体用法?C# TimeSpan.Multiply怎么用?C# TimeSpan.Multiply使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.TimeSpan的用法示例。


在下文中一共展示了TimeSpan.Multiply方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AzureQueueDefaultPolicies

 static AzureQueueDefaultPolicies()
 {
     MaxQueueOperationRetries = 5;
     PauseBetweenQueueOperationRetries = TimeSpan.FromMilliseconds(100);
     QueueOperationRetryPolicy = new LinearRetry(PauseBetweenQueueOperationRetries, MaxQueueOperationRetries); // 5 x 100ms
     QueueOperationTimeout = PauseBetweenQueueOperationRetries.Multiply(MaxQueueOperationRetries).Multiply(6);    // 3 sec
 }
开发者ID:Carlm-MS,项目名称:orleans,代码行数:7,代码来源:AzureQueueDataManager.cs

示例2: Multiply

        public void Multiply()
        {
            var oneMinute = new TimeSpan(0, 1, 0);
            var fourMinutes = new TimeSpan(0, 4, 0);

            Assert.AreEqual(fourMinutes, oneMinute.Multiply(4));
        }
开发者ID:jeremiahredekop,项目名称:Nvelope,代码行数:7,代码来源:TimeSpanExtensionTests.cs

示例3: AddIteration

        public void AddIteration(TimeSpan ts)
        {
            if (Min>ts)
            {
                Min = ts;
            }

            if (Max<=ts)
            {
                Max = ts;
            }
            i++;
            Total = Total.Add(ts);
            Average = Total.Multiply(1/(double)i);
        }
开发者ID:geffzhang,项目名称:cavemantools,代码行数:15,代码来源:BenchmarkResult.cs

示例4: RunLoggerPerfTest

        private void RunLoggerPerfTest(string testName, int n, int logCode, TimeSpan target, TraceLogger logger)
        {
            var stopwatch = new Stopwatch();
            stopwatch.Start();
            for (int i = 0; i < n; i++)
            {
                logger.Warn(logCode, "msg " + i);
            }
            var elapsed = stopwatch.Elapsed;
            string msg = testName + " : Elapsed time = " + elapsed;

            // Wait until the BulkMessageInterval time interval expires before wring the final log message - should cause bulk message flush
            while (stopwatch.Elapsed <= TraceLogger.BulkMessageInterval)
            {
                Thread.Sleep(10);
            }

            Console.WriteLine(msg);
            logger.Info(logCode, msg);
            Assert.IsTrue(elapsed < target.Multiply(timingFactor), "{0}: Elapsed time {1} exceeds target time {2}", testName, elapsed, target);
        }
开发者ID:sbambach,项目名称:orleans,代码行数:21,代码来源:LoggerTest.cs

示例5: RunLogWriterPerfTest

 private void RunLogWriterPerfTest(string testName, int n, int logCode, TimeSpan target, ITraceTelemetryConsumer log)
 {
     var stopwatch = new Stopwatch();
     stopwatch.Start();
     for (int i = 0; i < n; i++)
     {
         log.TrackTrace(string.Format( "{0}|{1}|{2}|{3}", TraceLogger.LoggerType.Runtime, testName, "msg " + i, logCode), Severity.Info);
     }
     stopwatch.Stop();
     var elapsed = stopwatch.Elapsed;
     Console.WriteLine(testName + " : Elapsed time = " + elapsed);
     Assert.IsTrue(elapsed < target.Multiply(timingFactor), "{0}: Elapsed time {1} exceeds target time {2}", testName, elapsed, target);
 }
开发者ID:sbambach,项目名称:orleans,代码行数:13,代码来源:LoggerTest.cs

示例6: EqualMaxResponseTime

 private static bool EqualMaxResponseTime(TimeSpan value1, TimeSpan value2)
 {
     return value1.Divide(2) <= value2 && value1.Multiply(2) >= value2;
 }
开发者ID:njannink,项目名称:sonarlint-vs,代码行数:4,代码来源:IgmpLayer.cs

示例7: RunPerfTest

        // ---------- Utility functions ----------

        private void RunPerfTest(int n, string testName, TimeSpan target,
            Func<IEchoTaskGrain, Task> actionNoState,
            Func<IPersistenceTestGrain, Task> actionMemory,
            Func<IMemoryStorageTestGrain, Task> actionMemoryStore,
            Func<IAzureStorageTestGrain, Task> actionAzureTable)
        {
            IEchoTaskGrain[] noStateGrains = new IEchoTaskGrain[n];
            IPersistenceTestGrain[] memoryGrains = new IPersistenceTestGrain[n];
            IAzureStorageTestGrain[] azureStoreGrains = new IAzureStorageTestGrain[n];
            IMemoryStorageTestGrain[] memoryStoreGrains = new IMemoryStorageTestGrain[n];

            for (int i = 0; i < n; i++)
            {
                Guid id = Guid.NewGuid();
                noStateGrains[i] = GrainClient.GrainFactory.GetGrain<IEchoTaskGrain>(id);
                memoryGrains[i] = GrainClient.GrainFactory.GetGrain<IPersistenceTestGrain>(id);
                azureStoreGrains[i] = GrainClient.GrainFactory.GetGrain<IAzureStorageTestGrain>(id);
                memoryStoreGrains[i] = GrainClient.GrainFactory.GetGrain<IMemoryStorageTestGrain>(id);
            }

            TimeSpan baseline, elapsed;

            elapsed = baseline = TestUtils.TimeRun(n, TimeSpan.Zero, testName + " (No state)",
                () => RunIterations(testName, n, i => actionNoState(noStateGrains[i])));

            elapsed = TestUtils.TimeRun(n, baseline, testName + " (Local Memory Store)",
                () => RunIterations(testName, n, i => actionMemory(memoryGrains[i])));

            elapsed = TestUtils.TimeRun(n, baseline, testName + " (Dev Store Grain Store)",
                () => RunIterations(testName, n, i => actionMemoryStore(memoryStoreGrains[i])));

            elapsed = TestUtils.TimeRun(n, baseline, testName + " (Azure Table Store)",
                () => RunIterations(testName, n, i => actionAzureTable(azureStoreGrains[i])));

            if (elapsed > target.Multiply(timingFactor))
            {
                string msg = string.Format("{0}: Elapsed time {1} exceeds target time {2}", testName, elapsed, target);

                if (elapsed > target.Multiply(2.0 * timingFactor))
                {
                    Assert.Fail(msg);
                }
                else
                {
                    Assert.Inconclusive(msg);
                }
            }
        }
开发者ID:fgq841103,项目名称:orleans,代码行数:50,代码来源:PersistenceGrainTests_AzureStore.cs

示例8: MissingActivation_Runner

        private async Task MissingActivation_Runner(int grainId, TimeSpan lazyDeregistrationDelay, bool forceCreationInSecondary = false)
        {
            logger.Info("\n\n\n SMissingActivation_Runner.\n\n\n");

            var realGrainId = grainId;

            ITestGrain grain;

            var isMultipleSilosPresent = testCluster.SecondarySilos != null && testCluster.SecondarySilos.Count > 0;

            if (!isMultipleSilosPresent && forceCreationInSecondary)
            {
                throw new InvalidOperationException("If 'forceCreationInSecondary' is true multiple silos must be present, check the test!");
            }

            var grainSiloAddress = String.Empty;
            var primarySiloAddress = testCluster.Primary.SiloAddress.ToString();
            var secondarySiloAddress = isMultipleSilosPresent ? testCluster.SecondarySilos[0].SiloAddress.ToString() : String.Empty;

            //
            // We only doing this for multiple silos.
            //

            if (isMultipleSilosPresent && forceCreationInSecondary)
            {
                //
                // Make sure that we proceeding with a grain which is created in the secondary silo for first!
                //

                while (true)
                {
                    output.WriteLine($"GetGrain: {realGrainId}");

                    grain = GrainClient.GrainFactory.GetGrain<ITestGrain>(realGrainId);

                    grainSiloAddress = await grain.GetRuntimeInstanceId();

                    if (grainSiloAddress != secondarySiloAddress)
                    {
                        output.WriteLine($"GetGrain: {realGrainId} Primary, skipping.");

                        realGrainId++;
                    }
                    else
                    {
                        output.WriteLine($"GetGrain: {realGrainId} Secondary, proceeding.");

                        break;
                    }
                }
            }
            else
            {
                grain = GrainClient.GrainFactory.GetGrain<ITestGrain>(realGrainId);
            }

            await grain.SetLabel("hello_" + grainId);
            var grainReference = ((GrainReference)await grain.GetGrainReference()).GrainId;

            // Call again to make sure the grain is in all silo caches
            for (int i = 0; i < 10; i++)
            {
                var label = await grain.GetLabel();
            }

            // Now we know that there's an activation; try both silos and deactivate it incorrectly
            int primaryActivation = await testCluster.Primary.TestHook.UnregisterGrainForTesting(grainReference);
            int secondaryActivation = 0;

            if (isMultipleSilosPresent)
            {
                secondaryActivation = await testCluster.SecondarySilos[0].TestHook.UnregisterGrainForTesting(grainReference);
            }

            Assert.Equal(1, primaryActivation + secondaryActivation);

            // If we try again, we shouldn't find any
            primaryActivation = await testCluster.Primary.TestHook.UnregisterGrainForTesting(grainReference);
            secondaryActivation = 0;

            if (isMultipleSilosPresent)
            {
                secondaryActivation = await testCluster.SecondarySilos[0].TestHook.UnregisterGrainForTesting(grainReference);
            }

            Assert.Equal(0, primaryActivation + secondaryActivation);

            if (lazyDeregistrationDelay > TimeSpan.Zero)
            {
                // Wait a bit
                TimeSpan pause = lazyDeregistrationDelay.Multiply(2);
                logger.Info($"Pausing for {0} because we are using lazy deregistration", pause);
                await Task.Delay(pause);
            }

            // Now send a message again; it should fail);
            var firstEx = await Assert.ThrowsAsync<OrleansException>(() => grain.GetLabel());
            Assert.Contains("Non-existent activation", firstEx.Message);
            logger.Info("Got 1st Non-existent activation Exception, as expected.");

//.........这里部分代码省略.........
开发者ID:Carlm-MS,项目名称:orleans,代码行数:101,代码来源:DeactivateOnIdleTests.cs

示例9: RunPerfTest

        //[Fact]
        //public void Persistence_Silo_StorageProvider_SimpleSQL(Type providerType)
        //{
        //    List<SiloHandle> silos = testingHost.GetActiveSilos().ToList();
        //    foreach (var silo in silos)
        //    {
        //        string provider = providerType.FullName;
        //        List<string> providers = silo.Silo.TestHook.GetStorageProviderNames().ToList();
        //        Assert.IsTrue(providers.Contains(provider), "No storage provider found: {0}", provider);
        //    }
        //}

        #region Utility functions
        // ---------- Utility functions ----------

        void RunPerfTest(int n, string testName, TimeSpan target,
            Func<ISimpleSQLStorageTestGrain, Task> actionSimpleSQL)
        {
            ISimpleSQLStorageTestGrain[] simpleSQLStoreGrains = new ISimpleSQLStorageTestGrain[n];

            for (int i = 0; i < n; i++)
            {
                Guid id = Guid.NewGuid();
                simpleSQLStoreGrains[i] = GrainClient.GrainFactory.GetGrain<ISimpleSQLStorageTestGrain>(id);
            }

            TimeSpan baseline = new TimeSpan(0, 0, 5), elapsed;

            elapsed = TimeRun(n, baseline, testName + " (SimpleSQL Store)",
                () => RunIterations(testName, n, i => actionSimpleSQL(simpleSQLStoreGrains[i])));

            if (elapsed > target.Multiply(timingFactor))
            {
                string msg = string.Format("{0}: Elapsed time {1} exceeds target time {2}", testName, elapsed, target);

                if (elapsed > target.Multiply(2.0 * timingFactor))
                {
                    Assert.True(false,msg);
                }
                else
                {
                    //this is from xunit
                    //throw new SkipException(msg);
                }
            }
        }
开发者ID:OrleansContrib,项目名称:Orleans.StorageProviders.SimpleSQLServerStorage,代码行数:46,代码来源:GrainStorageTests.cs

示例10: updateTimeslots

        public void updateTimeslots(ref List<Timeslot> timeslots, ref Dictionary<string,int> pointsources, DateTime ecoStart, TimeSpan timeslotLen)
        {
            int timeslot = 0;
            TimeSpan ts = DateTime.Now - ecoStart;
            stackPanel.Children.Clear();
            stackPanel.Children.Add(new Label() { Content = "Altijd", FontWeight = FontWeights.Bold });
            foreach (KeyValuePair<String, int> kvp in pointsources)
            {
                stackPanel.Children.Add(new Label() { Content = String.Format("{0} ({1})", kvp.Key.Trim('%').UppercaseFirst(), kvp.Value) });
            }

            if (ts > TimeSpan.Zero)
            {
                timeslot = (int)(ts.Ticks / timeslotLen.Ticks);
            }
            if (timeslot >= 0 && timeslot < timeslots.Count && ts > TimeSpan.Zero)
            {
                stackPanel.Children.Add(new Label() { Content = "Nu", FontWeight = FontWeights.Bold });
                foreach (KeyValuePair<String, int> kvp in timeslots[timeslot].Items)
                {
                    stackPanel.Children.Add(new Label() { Content = String.Format("{0} ({1})", kvp.Key.Trim('%').UppercaseFirst(), kvp.Value) });
                }
            }
            if (ts <= TimeSpan.Zero)
            {
                timeslot = -1;
            }
            TimeSpan timeToNext = ecoStart.Add(timeslotLen.Multiply(timeslot + 1)).Subtract(DateTime.Now);
            string minleft = timeToNext.TotalMinutes < 0.5 ? "<1" : timeToNext.TotalMinutes.ToString("F0");
            if (timeslot+1 >= 0 && timeslot+1 < timeslots.Count)
            {
                stackPanel.Children.Add(new Label() { Content = String.Format("Straks (nog {0} min)", minleft), FontWeight = FontWeights.Bold });
                foreach (KeyValuePair<String, int> kvp in timeslots[timeslot + 1].Items)
                {
                    stackPanel.Children.Add(new Label() { Content = String.Format("{0} ({1})", kvp.Key.Trim('%').UppercaseFirst(), kvp.Value) });
                }
            }
        }
开发者ID:hcnobel,项目名称:Nobelprijzen,代码行数:38,代码来源:BeamerWindow.xaml.cs

示例11: AnimateTiles

        private void AnimateTiles(EnterMode mode, XDirection xDirection, ZDirection zDirection, TimeSpan duration, Action callback)
        {
            // If the control has not been rendered or it's empty, cancel the animation
            if (this.ActualWidth <= 0 || this.ActualHeight <= 0 || this._positions == null || this._positions.Count <= 0) return;

            // Get the visible tiles for the current configuration
            // Tiles that are partially visible are also counted
            var visibleitems = this._positions.Where(x => x.Value.X + x.Key.ActualWidth >= 0 && x.Value.X <= this.ActualWidth &&
                                                     x.Value.Y + x.Key.ActualHeight >= 0 && x.Value.Y <= this.ActualHeight);

            // No visible tiles, do nothing
            if (visibleitems.Count() <= 0) return;

            // The Y coordinate of the lowest element is useful 
            // when we animate from bottom to top
            double lowestX = visibleitems.Max(el => el.Value.X);

            // Store the animations to group them in one Storyboard in the end
            var animations = new List<Timeline>();

            foreach (var tilePosition in visibleitems)
            {
                // To make syntax lighter
                var tile = tilePosition.Key;
                var position = tilePosition.Value;
                var projection = tile.Projection as PlaneProjection;

                double rotationFrom, rotationTo, opacityTo;

                // Reset all children's opacity regardless of their animations
                if (mode == EnterMode.Exit)
                {
                    tile.Opacity = 1;
                    opacityTo = 0;
                    rotationFrom = 0;
                    rotationTo = zDirection == ZDirection.BackToFront ? -90 : 90;
                }
                else
                {
                    tile.Opacity = 0;
                    opacityTo = 1;
                    rotationFrom = zDirection == ZDirection.BackToFront ? -90 : 90;
                    rotationTo = 0;
                }

                // Used to determine begin time - depends if we're moving from bottom or from top
                double relativeX;

                if (xDirection == XDirection.LeftToRight)
                {
                    // The lowest element should have relativeY == 0
                    relativeX = lowestX - position.X;
                }
                else
                {
                    relativeX = position.X;
                }

                var easing = new QuadraticEase() { EasingMode = EasingMode.EaseInOut };

                var rotationAnimation = new DoubleAnimation { From = rotationFrom, To = rotationTo, EasingFunction = easing };
                rotationAnimation.Duration = duration;
                rotationAnimation.BeginTime = duration.Multiply(this.GetBeginTimeFactorFavorite(relativeX, position.Y, mode));
                rotationAnimation.SetTargetAndProperty(projection, PlaneProjection.RotationYProperty);

                var opacityAnimation = new DoubleAnimation { To = opacityTo, EasingFunction = easing };
                // The opacity animation takes the last 60% of the rotation animation
                opacityAnimation.Duration = duration.Multiply(0.6);
                opacityAnimation.BeginTime = rotationAnimation.BeginTime;
                if (mode == EnterMode.Exit)
                    opacityAnimation.BeginTime += duration - opacityAnimation.Duration.TimeSpan;
                opacityAnimation.SetTargetAndProperty(tile, UIElement.OpacityProperty);

                animations.Add(rotationAnimation);
                animations.Add(opacityAnimation);
            }

            // Begin all animations
            var sb = new Storyboard();
            sb.Completed += (sender, args) =>
            {
                if (callback != null)
                {
                    callback();
                }
            };

            foreach (var a in animations)
                sb.Children.Add(a);
            sb.Begin();
        }
开发者ID:mparsin,项目名称:Elements,代码行数:91,代码来源:Wave.cs


注:本文中的System.TimeSpan.Multiply方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。