• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# TryFuncUntilTimeOut类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中TryFuncUntilTimeOut的典型用法代码示例。如果您正苦于以下问题:C# TryFuncUntilTimeOut类的具体用法?C# TryFuncUntilTimeOut怎么用?C# TryFuncUntilTimeOut使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



TryFuncUntilTimeOut类属于命名空间,在下文中一共展示了TryFuncUntilTimeOut类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: ShouldCreateTimeOutException

        public void ShouldCreateTimeOutException()
        {
            // GIVEN
            var timeoutsec = 1;
            var timeOut = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(timeoutsec))
                              {
                                  ExceptionMessage = () => string.Format("returning false for {0} seconds", timeoutsec)
                              };

            // WHEN
            try
            {
                timeOut.Try(() => false);
            }
            catch(Exception e)
            {
                // THEN
                Assert.That(e is Exceptions.TimeoutException, "Unexpected exception type: " + e.GetType());
                Assert.That(e.Message, Is.EqualTo("Timeout while returning false for 1 seconds"), "Unexpected exception message");
                Assert.That(e.InnerException, Is. Null, "Expected no InnerException");
                return;
            }

            Assert.Fail("Expected TimeOutException");
        }
开发者ID:fschwiet,项目名称:watin_unbranched,代码行数:25,代码来源:TryActionUntilTimeOutTests.cs


示例2: WaitUntilHandled

        public bool WaitUntilHandled(int timeoutAfterSeconds)
        {
            var tryActionUntilTimeOut = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(timeoutAfterSeconds));
            tryActionUntilTimeOut.Try(() => HasHandledDialog);

            return HasHandledDialog;
        }
开发者ID:exaphaser,项目名称:WatiN,代码行数:7,代码来源:WaitUntilHandledDialogHandler.cs


示例3: TryFindIe

        public IE TryFindIe(Constraint findBy, SimpleTimer timer)
        {
            var action = new TryFuncUntilTimeOut(timer)
            {
                SleepTime = TimeSpan.FromMilliseconds(500)
            };

            return action.Try(() => FindIEPartiallyInitialized(findBy));
        }
开发者ID:modulexcite,项目名称:FluentSharp_Fork.WatiN,代码行数:9,代码来源:AttachToIeHelper.cs


示例4: WaitUntilExists

		public void WaitUntilExists(int waitDurationInSeconds)
		{
            var tryActionUntilTimeOut = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(waitDurationInSeconds));
            tryActionUntilTimeOut.Try(() => Exists());
            
			if (!Exists())
			{
				throw new WatiNException(string.Format("Dialog not available within {0} seconds.", waitDurationInSeconds));
			}
		}
开发者ID:exaphaser,项目名称:WatiN,代码行数:10,代码来源:JavaDialogHandler.cs


示例5: TryShouldReturnFalseIfDidTimeOut

        public void TryShouldReturnFalseIfDidTimeOut()
        {
            // GIVEN
            var timeOut = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(1));
            
            // WHEN
            var result = timeOut.Try(() => false );

            // THEN
            Assert.That(result, Is.False);
        }
开发者ID:kevinswarner,项目名称:Hover_OLD,代码行数:11,代码来源:TryActionUntilTimeOutTests.cs


示例6: ShouldCallTheAction

        public void ShouldCallTheAction()
        {
            // GIVEN
            var actionCalled = false;
            var timeOut = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(2));

            // WHEN
            timeOut.Try(() => { actionCalled = true; return true; });

            // THEN
            Assert.That(actionCalled, Is.True, "action not called");
        }
开发者ID:fschwiet,项目名称:watin_unbranched,代码行数:12,代码来源:TryActionUntilTimeOutTests.cs


示例7: Find

        public Browser Find(Constraint findBy, int timeout, bool waitForComplete)
        {
            Logger.LogAction("Busy finding FireFox matching constraint {0}", findBy);

            var action = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(timeout)) { SleepTime = TimeSpan.FromMilliseconds(500) };
            var fireFox = action.Try(() => FindFireFox(findBy));

            if (fireFox != null)
            {
                if (waitForComplete) fireFox.WaitForComplete();
                return fireFox;
            }

            throw new BrowserNotFoundException("FireFox", findBy.ToString(), timeout);
        }
开发者ID:pusp,项目名称:o2platform,代码行数:15,代码来源:AttachToFireFoxHelper.cs


示例8: ShouldNotAllowNullAsAction

 public void ShouldNotAllowNullAsAction()
 {
     // Given
     var timeout = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(30));
     
     // When
     try
     {
         timeout.Try<object>(null);
     }
     catch (Exception e)
     {
         Assert.That(e is ArgumentNullException, Is.True, "Action should be required");
         Assert.That(e.Message, Text.Contains("func"), "Expected for argument 'func'");
         return;
     }
     Assert.Fail("Expected an ArgumentNullException");
 }
开发者ID:kevinswarner,项目名称:Hover_OLD,代码行数:18,代码来源:TryActionUntilTimeOutTests.cs


示例9: CloseFireFoxProcess

        public void CloseFireFoxProcess()
        {
            //if (Process == null) return;
            
            //Process.WaitForExit(5000);
            
            //if (Process == null || Process.HasExited) return;

            System.Diagnostics.Process firefoxProcess = FireFox.CurrentProcess;
            if (firefoxProcess == null)
            {
                return;
            }

            firefoxProcess.WaitForExit(5000);

            firefoxProcess = FireFox.CurrentProcess;
            if (firefoxProcess == null)
            {
                return;
            }
            else if (firefoxProcess.HasExited)
            {
                TryFuncUntilTimeOut waiter = new TryFuncUntilTimeOut(TimeSpan.FromMilliseconds(5000));
                bool procIsNull = waiter.Try<bool>(() => { firefoxProcess = FireFox.CurrentProcess; return firefoxProcess == null; });
                if (procIsNull)
                {
                    if (!waiter.DidTimeOut && firefoxProcess == null)
                    {
                        return;
                    }
                }
            }

            Logger.LogDebug("Killing FireFox process");
            UtilityClass.TryActionIgnoreException(() => Process.Kill());
        }
开发者ID:modulexcite,项目名称:FluentSharp_Fork.WatiN,代码行数:37,代码来源:FireFoxClientPort.cs


示例10: ShouldSetInnerExcpetionWithLastException

        public void ShouldSetInnerExcpetionWithLastException()
        {
            // GIVEN
            var timeOut = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(1))
                              {
                                  ExceptionMessage = () => "throwing exceptions"
                              };
            
            // WHEN
            try
            {
                timeOut.Try(() =>
                    {
                        var zero = 0;
                        return 1 / zero == 0;
                    });
            }
            catch(Exception e)
            {
                // THEN
                Assert.That(e.InnerException, Is.Not.Null, "Expected an innerexception");
                Assert.That(e.InnerException.GetType(), Is.EqualTo(typeof(DivideByZeroException)), "Expected DivideByZeroException");
                return;
            }

            Assert.Fail("Expected TimeOutException");
        }
开发者ID:kevinswarner,项目名称:Hover_OLD,代码行数:27,代码来源:TryActionUntilTimeOutTests.cs


示例11: SleepTimeShouldDefaultToSettingsSleepTime

        public void SleepTimeShouldDefaultToSettingsSleepTime()
        {
            // GIVEN
            Settings.SleepTime = 123;

            // WHEN
            var timeOut = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(1));

            // THEN
            Assert.That(timeOut.SleepTime.TotalMilliseconds, Is.EqualTo(123), "Unexpected default timeout");
        }
开发者ID:kevinswarner,项目名称:Hover_OLD,代码行数:11,代码来源:TryActionUntilTimeOutTests.cs


示例12: CreateIEPartiallyInitializedInNewProcess

		private static IEBrowser CreateIEPartiallyInitializedInNewProcess()
		{
			var m_Proc = CreateIExploreInNewProcess();
		    var helper = new AttachToIeHelper();

		    var action = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(Settings.AttachToBrowserTimeOut))
            {
                SleepTime = TimeSpan.FromMilliseconds(500)
            };

            var ie = action.Try(() =>
            {
                m_Proc.Refresh();
                var mainWindowHandle = m_Proc.MainWindowHandle;

                return mainWindowHandle != IntPtr.Zero
                    ? helper.FindIEPartiallyInitialized(new AttributeConstraint("hwnd", mainWindowHandle.ToString()))
                    : null;
            });

            if (ie != null) return ie._ieBrowser; 

			throw new BrowserNotFoundException("IE", "Timeout while waiting to attach to newly created instance of IE.", Settings.AttachToBrowserTimeOut);
		}
开发者ID:fschwiet,项目名称:WatiN-2.0.20.1089-net-2.0,代码行数:24,代码来源:IE.cs


示例13: FindHtmlDialog

		private HtmlDialog FindHtmlDialog(Constraint findBy, int timeout)
		{
			Logger.LogAction("Busy finding HTMLDialog matching criteria: {0}", findBy);

            var action = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(timeout))
            {
                SleepTime = TimeSpan.FromMilliseconds(500)
            };

            var result = action.Try(() => HtmlDialogs.First(findBy));
            
            if (result == null)
            {
                throw new HtmlDialogNotFoundException(findBy.ToString(), timeout);
            }
            
            return result;
		}
开发者ID:fschwiet,项目名称:WatiN-2.0.20.1089-net-2.0,代码行数:18,代码来源:IE.cs


示例14: WaitUntilDownloadCompleted

        /// <summary>
        /// Wait until the download progress window does not exist any more
        /// </summary>
        /// <param name="waitDurationInSeconds">duration in seconds to wait</param>
        public void WaitUntilDownloadCompleted(int waitDurationInSeconds)
        {
            var tryActionUntilTimeOut = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(waitDurationInSeconds));
            tryActionUntilTimeOut.Try(() => !ExistsOrNull(DownloadProgressDialog));

            if (ExistsOrNull(DownloadProgressDialog))
            {
                throw new WatiNException(string.Format("Still downloading after {0} seconds.", waitDurationInSeconds));
            }

            Logger.LogAction("Download complete at {0}", DateTime.Now.ToLongTimeString());
        }
开发者ID:kumichou,项目名称:WatiN_FindByCssSelector,代码行数:16,代码来源:FileDownloadHandler.cs


示例15: WaitUntilClosed

        public virtual void WaitUntilClosed(int timeout)
	    {
            var tryActionUntilTimeOut = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(timeout))
            {
                ExceptionMessage = () => string.Format("waiting {0} seconds for HtmlDialog to close.", timeout)
            };

            tryActionUntilTimeOut.Try(() => !Exists);
        }
开发者ID:exaphaser,项目名称:WatiN,代码行数:9,代码来源:HTMLDialog.cs


示例16: WaitUntilVisibleOrTimeOut

	    private static void WaitUntilVisibleOrTimeOut(Window window)
		{
			// Wait untill window is visible so all properties
			// of the window class (like Style and StyleInHex)
			// will return valid values.
		    var tryActionUntilTimeOut = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(Settings.WaitForCompleteTimeOut));
            var success = tryActionUntilTimeOut.Try(() => window.Visible);

            if (!success)
            {
                Logger.LogAction("Dialog with title '{0}' not visible after {1} seconds.", window.Title, Settings.WaitForCompleteTimeOut);
            }
		}
开发者ID:kevinswarner,项目名称:Hover_OLD,代码行数:13,代码来源:DialogWatcher.cs


示例17: WaitUntilFileDownloadDialogIsHandled

        /// <summary>
        /// Wait until the save/open/run dialog opens.
        /// This exists because some web servers are slower to start a file than others.
        /// </summary>
        /// <param name="waitDurationInSeconds">duration in seconds to wait</param>
        public void WaitUntilFileDownloadDialogIsHandled(int waitDurationInSeconds)
        {
            var tryActionUntilTimeOut = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(waitDurationInSeconds));
            tryActionUntilTimeOut.Try(() => HasHandledFileDownloadDialog);

            if (!HasHandledFileDownloadDialog)
            {
                throw new WatiNException(string.Format("Has not shown dialog after {0} seconds.", waitDurationInSeconds));
            }
        }
开发者ID:kumichou,项目名称:WatiN_FindByCssSelector,代码行数:15,代码来源:FileDownloadHandler.cs


示例18: HandledDownloadProgressDialog

        private bool HandledDownloadProgressDialog(Window window)
        {
            if (IsDownloadProgressDialog(window))
            {
                DownloadProgressDialog = window;

                var openOrRun= new WinButton(4377, new Hwnd(window.Hwnd));

                if (openOrRun.Enabled)
                {
                    var close = new WinButton(2, new Hwnd(window.Hwnd));
                    close.Click();

                    var actionUntilTimeOut = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(5));
                    actionUntilTimeOut.Try(() => window.Exists());

                    // TODO: What to do if the window doesn't close after timeout?
                }

                return true;
            }
            return false;
        }
开发者ID:kumichou,项目名称:WatiN_FindByCssSelector,代码行数:23,代码来源:FileDownloadHandler.cs


示例19: Dispose

        /// <summary>
        /// Releases unmanaged and - optionally - managed resources
        /// </summary>
        /// <param name="disposing">
        /// <c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.
        /// </param>
        public void Dispose(bool disposing)
        {
            // Check to see if Dispose has already been called.
            if (!_disposed)
            {
                // If disposing equals true, dispose all managed 
                // and unmanaged resources.
                if (disposing)
                {
                    // Dispose managed resources.
                    if (_telnetSocket != null && _telnetSocket.Connected && (Process == null || !Process.HasExited))
                    {
                        try
                        {
                            WriteAndRead("{0}.home();", PromptName);
                            var windowCount = WriteAndReadAsInt("{0}.getWindows().length", PromptName);
                            Logger.LogDebug(string.Format("Closing window. {0} total windows found", windowCount));
                            SendCommand(string.Format("{0}.close();", WindowVariableName));
                            if (windowCount == 1)
                            {
                                Logger.LogDebug("No further windows remain open.");
                                CloseConnection();
                                CloseFireFoxProcess();
                            }
                            else
                            {
                                TryFuncUntilTimeOut waiter = new TryFuncUntilTimeOut(TimeSpan.FromMilliseconds(2000));
                                bool windowClosed = waiter.Try<bool>(() => { return WriteAndReadAsInt("{0}.getWindows().length", PromptName) == windowCount - 1; });
                            }
                        }
                        catch (IOException ex)
                        {
                            Logger.LogDebug("Error communicating with mozrepl server to initiate shut down, message: {0}", ex.Message);
                        }
                    }
                }
            }

            _disposed = true;
            Connected = false;
        }
开发者ID:modulexcite,项目名称:FluentSharp_Fork.WatiN,代码行数:47,代码来源:FireFoxClientPort.cs


示例20: WaitUntil

        protected virtual void WaitUntil(DoFunc<bool> waitWhile, BuildTimeOutExceptionMessage exceptionMessage)
        {
            if (Timer == null)
                throw new WatiNException("_waitForCompleteTimer not initialized");

            var timeOut = new TryFuncUntilTimeOut(Timer) {ExceptionMessage = exceptionMessage};
            timeOut.Try(waitWhile);
        }
开发者ID:koshdim,项目名称:KoWatIn,代码行数:8,代码来源:WaitForCompleteBase.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Tuple类代码示例发布时间:2022-05-24
下一篇:
C# TryCatchStatement类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap