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


C# TryFuncUntilTimeOut.Try方法代码示例

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


在下文中一共展示了TryFuncUntilTimeOut.Try方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

示例4: TryShouldReturnTrueIfNoTimeOut

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

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

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例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: 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

示例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: 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

示例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: CreateProcess

        internal static void CreateProcess(string arguments, bool waitForMainWindow)
        {
            var ffProcess = new Process {StartInfo = {FileName = PathToExe, Arguments = arguments}};
            
            ffProcess.Start();
            ffProcess.WaitForInputIdle(5000);
            ffProcess.Refresh();

            if (!waitForMainWindow) return;
            
            var action = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(Settings.WaitForCompleteTimeOut))
                             {
                                 SleepTime = TimeSpan.FromMilliseconds(200)
                             };

            var result = action.Try(() =>
                            {
                                ffProcess.Refresh();
                                if (!ffProcess.HasExited && ffProcess.MainWindowHandle != IntPtr.Zero)
                                {
                                    Logger.LogAction("Waited for FireFox, main window handle found.");
                                    return true;
                                }
                                return false;
                            });

            if (!result)
            {
                Debug.WriteLine("Timer elapsed waiting for FireFox to start.");
            }
        }
开发者ID:exaphaser,项目名称:WatiN,代码行数:31,代码来源:FireFox.cs


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