private void SetDriverConfigsPageContent() { DriverBase driver = (DriverBase)TargetFrameworkHelper.Helper.GetDriverObject(mAgent); if (driver.GetDriverConfigsEditPageName(mAgent.DriverType) != null) { DriverConfigurationGrid.Visibility = System.Windows.Visibility.Collapsed; DriverConfigurationFrame.Visibility = System.Windows.Visibility.Visible; //Custome edit page string classname = "Ginger.Drivers.DriversConfigsEditPages." + driver.GetDriverConfigsEditPageName(mAgent.DriverType); Type t = Assembly.GetExecutingAssembly().GetType(classname); if (t == null) { throw new Exception(string.Format("The Driver edit page was not found '{0}'", classname)); } Page p = (Page)Activator.CreateInstance(t, mAgent); if (p != null) { DriverConfigurationFrame.Content = p; } } else { //Grid DriverConfigurationGrid.Visibility = System.Windows.Visibility.Visible; DriverConfigurationFrame.Visibility = System.Windows.Visibility.Collapsed; SetGridView(); } }
public static DriverBase CreateDriver(IConfigurationSource src = null, string typename = TypeName) { lock (lockobj) { string driverString; string connString; try { if (db != null) { return(db); } if (Starter.Properties == null) { Starter.Initialize(typename, src); } Starter.Properties.TryGetValue(Environment.ConnectionDriver, out driverString); Starter.Properties.TryGetValue(Environment.ConnectionString, out connString); TypeX typex = TypeX.Create(ReflectHelper.ClassForName(driverString)); db = (DriverBase)typex.CreateInstance(); //db = (DriverBase)Activator.CreateInstance(ReflectHelper.ClassForName(driverString)); db.ConnString = connString; return(db); } catch (Exception ex) { throw ex; } } }
internal TestBase() { _driver = new DriverBase(); // _driver.Initialize(); ExamplePage = new ExamplePage(); }
public MobileDriverWindow(DriverBase driver, Agent agent) { InitializeComponent(); mDriver = (IMobileDriverWindow)driver; mAgent = agent; ((DriverBase)mDriver).DriverMessageEvent += MobileDriverWindow_DriverMessageEvent; ((DriverBase)mDriver).SpyingElementEvent += CurrentMousePosToSpy; }
private static void DriverWindowUtils_DriverWindowEvent(DriverWindowEventArgs args) { switch (args.EventType) { case DriverWindowEventArgs.eEventType.ShowDriverWindow: Thread staThread = new Thread(new ThreadStart(() => { if (args.Driver is IDriverWindow) //TODO: think if better to do it with reflection using DriverWindowPath { try { DriverBase driver = args.Driver; AgentOperations agentOperations = (AgentOperations)args.DataObject; string classname = "Ginger.Drivers.DriversWindows." + ((IDriverWindow)driver).GetDriverWindowName(agentOperations.Agent.DriverType); Type t = Assembly.GetExecutingAssembly().GetType(classname); if (t == null) { throw new Exception(string.Format("The Driver Window was not found '{0}'", classname)); } Window window = (Window)Activator.CreateInstance(t, driver, agentOperations.Agent); if (window != null) { mOpenWindowsDic.Add(args.Driver, window); window.Show(); System.Windows.Threading.Dispatcher.Run(); } } catch (Exception ex) { Reporter.ToUser(eUserMsgKey.StaticErrorMessage, string.Format("Error occurred while loading/showing Agent windows, error: '{0}'", ex.Message)); Reporter.ToLog(eLogLevel.ERROR, "Error occurred while loading/showing Agent windows", ex); } } })); staThread.SetApartmentState(ApartmentState.STA); staThread.IsBackground = true; staThread.Start(); break; case DriverWindowEventArgs.eEventType.CloseDriverWindow: if (mOpenWindowsDic.ContainsKey(args.Driver)) { try { //mOpenWindowsDic[args.Driver].Close(); mOpenWindowsDic.Remove(args.Driver); } catch (Exception ex) { Reporter.ToLog(eLogLevel.WARN, "Exception while trying to close Driver Window", ex); } } break; } }
/// <summary> /// Gets the Spring IDbProvider given the ISessionFactory. /// </summary> /// <remarks>The matching is performed by comparing the assembly qualified /// name string of the hibernate Driver.ConnectionType to those in /// the DbProviderFactory definitions. No connections are created /// in performing this comparison.</remarks> /// <param name="sessionFactory">The session factory.</param> /// <returns>The corresponding IDbProvider, null if no mapping was found.</returns> /// <exception cref="InvalidOperationException">If DbProviderFactory's ApplicaitonContext is not /// an instance of IConfigurableApplicaitonContext.</exception> public static IDbProvider GetDbProvider(ISessionFactory sessionFactory) { ISessionFactoryImplementor sfi = sessionFactory as ISessionFactoryImplementor; if (sfi != null) { IConnectionProvider cp = sfi.ConnectionProvider as IConnectionProvider; if (cp != null) { IConfigurableApplicationContext ctx = Spring.Data.Common.DbProviderFactory.ApplicationContext as IConfigurableApplicationContext; if (ctx == null) { throw new InvalidOperationException( "Implementations of IApplicationContext must also implement IConfigurableApplicationContext"); } #if NET_1_1 DriverBase db = cp.Driver as DriverBase; #else IDriver db = cp.Driver; #endif if (db != null) { Type hibCommandType = db.CreateCommand().GetType(); string[] providerNames = ctx.GetObjectNamesForType(typeof(DbProvider), true, false); string hibCommandAQN = hibCommandType.AssemblyQualifiedName; foreach (string providerName in providerNames) { IObjectDefinition objectdef = ctx.ObjectFactory.GetObjectDefinition(providerName); ConstructorArgumentValues ctorArgs = objectdef.ConstructorArgumentValues; ConstructorArgumentValues.ValueHolder vh = ctorArgs.NamedArgumentValues["dbmetadata"] as ConstructorArgumentValues.ValueHolder; IObjectDefinition od = ((ObjectDefinitionHolder)vh.Value).ObjectDefinition; ConstructorArgumentValues dbmdCtorArgs = od.ConstructorArgumentValues; string commandType = dbmdCtorArgs.GetArgumentValue("commandType", typeof(string)).Value as string; if (hibCommandAQN.Equals(commandType)) { IDbProvider prov = Spring.Data.Common.DbProviderFactory.GetDbProvider(providerName); return(prov); } } } else { log.Info("Could not derive IDbProvider from SessionFactory"); } } } return(null); }
public TestsBase(string browser, string version, string platform) { TestContextResult = new TestCaseResult(); _testStartTime = DateTime.Now; _currentTestCtx = TestContext.CurrentContext; TestContextResult.Add("id", _currentTestCtx.Test.ID); TestContextResult.Add("TestStartTime", _testStartTime.ToFormattedString()); TestContextResult.Add("TestName", _currentTestCtx.Test.FullName); TestContextResult.Add("Browser", browser); TestContextResult.Add("Version", version); TestContextResult.Add("Platform", platform); _driverBase = new DriverBase(browser, version, platform); }
public static string GetReportLine(string key, string value, int charsPerLine) { if (key == DriverBase.SEPARATOR) { return(DriverBase.GetAlignedString(DriverBase.SEPARATOR, charsPerLine, DriverBase.TextAlign.Left)); } int valueMaxLen = charsPerLine - key.Length; value = value.Length > valueMaxLen?value.Substring(0, valueMaxLen) : value.PadLeft(valueMaxLen); return(key + value); }
public void OneTimeSetup() { // Starts HTML reporter var htmlReporter = new ExtentHtmlReporter( AppDomain.CurrentDomain.BaseDirectory + ConfigurationManager.AppSettings["ReportPath"] + "TestReport " + DateTime.Now.ToString("MM-dd-yyyy hh-mm") + "/"); _htmlReport = new ExtentReports(); _htmlReport.AttachReporter(htmlReporter); // Initializes a new instance of Selenium Web Driver _driver = DriverBase.Initialize(); PageBase.Driver = _driver; // Creates a new instance of a AEyeBase class AEye = new AEye(); }
public void SessionFactoryUtilsWithGetDbProvider() { ISessionFactoryImplementor sessionFactory = A.Fake <ISessionFactoryImplementor>(); DriverBase driver = A.Fake <DriverBase>(); A.CallTo(() => driver.CreateCommand()).Returns(new SqlCommand()); IConnectionProvider cp = A.Fake <IConnectionProvider>(); A.CallTo(() => cp.Driver).Returns(driver); A.CallTo(() => sessionFactory.ConnectionProvider).Returns(cp); IDbProvider provider = SessionFactoryUtils.GetDbProvider(sessionFactory); Assert.AreEqual(typeof(SqlCommand), provider.DbMetadata.CommandType); }
public void Close() { try { if (Driver == null) { return; } Driver.IsDriverRunning = false; Thread.Sleep(1000); if (Driver.Dispatcher != null) { Driver.Dispatcher.Invoke(() => { Driver.CloseDriver(); }); } else { Driver.CloseDriver(); } if (MSTATask != null) { // Using Cancelleation token soucrce to cancel CancelTask = new BackgroundWorker(); CancelTask.DoWork += new DoWorkEventHandler(CancelTMSTATask); CancelTask.RunWorkerAsync(); } Driver = null; } finally { OnPropertyChanged(Fields.Status); OnPropertyChanged(Fields.IsWindowExplorerSupportReady); } }
public void SessionFactoryUtilsWithGetDbProvider() { MockRepository mockery = new MockRepository(); ISessionFactoryImplementor sessionFactory = mockery.DynamicMock <ISessionFactoryImplementor>(); DriverBase driver = mockery.DynamicMock <DriverBase>(); Expect.Call(driver.CreateCommand()).Repeat.AtLeastOnce().Return(new SqlCommand()); IConnectionProvider cp = mockery.DynamicMock <IConnectionProvider>(); Expect.Call(cp.Driver).Repeat.AtLeastOnce().Return(driver); Expect.Call(sessionFactory.ConnectionProvider).Repeat.AtLeastOnce().Return(cp); mockery.ReplayAll(); IDbProvider provider = SessionFactoryUtils.GetDbProvider(sessionFactory); Assert.AreEqual(typeof(SqlCommand), provider.DbMetadata.CommandType); mockery.VerifyAll(); }
/// <summary> /// This method is used to Start the agent /// </summary> public static bool StartAgent(Activity activity, GingerExecutionEngine runner, Context context, out IWindowExplorer windowExplorerDriver) { bool isAgentStarted = false; windowExplorerDriver = null; ApplicationAgent appAgent = GetAppAgent(activity, runner, context); if (appAgent != null) { if (((AgentOperations)appAgent.Agent.AgentOperations).Driver == null) { appAgent.Agent.AgentOperations.StartDriver(); isAgentStarted = true; } else if (!((AgentOperations)appAgent.Agent.AgentOperations).Driver.IsRunning()) { if (Reporter.ToUser(eUserMsgKey.PleaseStartAgent, eUserMsgOption.OKCancel, eUserMsgSelection.OK) == eUserMsgSelection.OK) { appAgent.Agent.AgentOperations.StartDriver(); isAgentStarted = true; } else { isAgentStarted = false; } } DriverBase driver = ((AgentOperations)appAgent.Agent.AgentOperations).Driver; if (driver is IWindowExplorer) { windowExplorerDriver = (IWindowExplorer)((AgentOperations)appAgent.Agent.AgentOperations).Driver; } } else { isAgentStarted = false; } return(isAgentStarted); }
public static void OnDriverWindowEvent(DriverWindowEventArgs.eEventType eventType, DriverBase driver, object dataObject) { DriverWindowEventHandler handler = DriverWindowEvent; if (handler != null) { handler(new DriverWindowEventArgs(eventType, driver, dataObject)); } }
public void StartDriver() { mIsStarting = true; OnPropertyChanged(Fields.Status); try { try { if (Remote) { throw new Exception("Remote is Obsolete, use GingerGrid"); //We pass the agent info } else { switch (DriverType) { case eDriverType.InternalBrowser: Driver = new InternalBrowser(BusinessFlow); break; case eDriverType.SeleniumFireFox: Driver = new SeleniumDriver(GingerCore.Drivers.SeleniumDriver.eBrowserType.FireFox); break; case eDriverType.SeleniumChrome: Driver = new SeleniumDriver(GingerCore.Drivers.SeleniumDriver.eBrowserType.Chrome); break; case eDriverType.SeleniumIE: Driver = new SeleniumDriver(GingerCore.Drivers.SeleniumDriver.eBrowserType.IE); break; case eDriverType.SeleniumRemoteWebDriver: Driver = new SeleniumDriver(GingerCore.Drivers.SeleniumDriver.eBrowserType.RemoteWebDriver); // set capabilities if (DriverConfiguration == null) { DriverConfiguration = new ObservableList <DriverConfigParam>(); } ((SeleniumDriver)Driver).RemoteGridHub = GetParamValue(SeleniumDriver.RemoteGridHubParam); ((SeleniumDriver)Driver).RemoteBrowserName = GetParamValue(SeleniumDriver.RemoteBrowserNameParam); ((SeleniumDriver)Driver).RemotePlatform = GetParamValue(SeleniumDriver.RemotePlatformParam); ((SeleniumDriver)Driver).RemoteVersion = GetParamValue(SeleniumDriver.RemoteVersionParam); break; case eDriverType.SeleniumEdge: Driver = new SeleniumDriver(GingerCore.Drivers.SeleniumDriver.eBrowserType.Edge); break; case eDriverType.SeleniumPhantomJS: Driver = new SeleniumDriver(GingerCore.Drivers.SeleniumDriver.eBrowserType.PhantomJS); break; case eDriverType.ASCF: Driver = new ASCFDriver(BusinessFlow, Name); break; case eDriverType.DOSConsole: Driver = new DOSConsoleDriver(BusinessFlow); break; case eDriverType.UnixShell: Driver = new UnixShellDriver(BusinessFlow, ProjEnvironment); ((UnixShellDriver)Driver).SetScriptsFolder(SolutionFolder + @"\Documents\sh\"); break; case eDriverType.MobileAppiumAndroid: Driver = new SeleniumAppiumDriver(SeleniumAppiumDriver.eSeleniumPlatformType.Android, BusinessFlow); break; case eDriverType.MobileAppiumIOS: Driver = new SeleniumAppiumDriver(SeleniumAppiumDriver.eSeleniumPlatformType.iOS, BusinessFlow); break; case eDriverType.MobileAppiumAndroidBrowser: Driver = new SeleniumAppiumDriver(SeleniumAppiumDriver.eSeleniumPlatformType.AndroidBrowser, BusinessFlow); break; case eDriverType.MobileAppiumIOSBrowser: Driver = new SeleniumAppiumDriver(SeleniumAppiumDriver.eSeleniumPlatformType.iOSBrowser, BusinessFlow); break; case eDriverType.PerfectoMobile: Driver = new PerfectoDriver(BusinessFlow); break; case eDriverType.WebServices: WebServicesDriver WebServicesDriver = new WebServicesDriver(BusinessFlow); Driver = WebServicesDriver; break; case eDriverType.WindowsAutomation: Driver = new WindowsDriver(BusinessFlow); break; case eDriverType.FlaUIWindow: Driver = new WindowsDriver(BusinessFlow, UIAutomationDriverBase.eUIALibraryType.FlaUI); break; case eDriverType.PowerBuilder: Driver = new PBDriver(BusinessFlow); break; case eDriverType.FlaUIPB: Driver = new PBDriver(BusinessFlow, UIAutomationDriverBase.eUIALibraryType.FlaUI); break; case eDriverType.JavaDriver: Driver = new JavaDriver(BusinessFlow); break; case eDriverType.MainFrame3270: Driver = new MainFrameDriver(BusinessFlow); break; case eDriverType.AndroidADB: string DeviceConfigFolder = GetOrCreateParam("DeviceConfigFolder").Value; if (!string.IsNullOrEmpty(DeviceConfigFolder)) { Driver = new AndroidADBDriver(BusinessFlow, SolutionFolder + @"\Documents\Devices\" + DeviceConfigFolder + @"\"); } else { //TODO: Load create sample folder/device, or start the wizard throw new Exception("Please set device config folder"); } break; //TODO: default mess } } } catch (Exception e) { Reporter.ToUser(eUserMsgKeys.FailedToConnectAgent, Name, e.Message); } Driver.BusinessFlow = this.BusinessFlow; SetDriverConfiguration(); //if STA we need to start it on seperate thread, so UI/Window can be refreshed: Like IB, Mobile, Unix if (Driver.IsSTAThread()) { CTS = new CancellationTokenSource(); MSTATask = new Task(() => { Driver.StartDriver(); }, CTS.Token, TaskCreationOptions.LongRunning); MSTATask.Start(); } else { Driver.StartDriver(); } } finally { // Give the driver time to start Thread.Sleep(500); mIsStarting = false; Driver.IsDriverRunning = true; OnPropertyChanged(Fields.Status); Driver.driverMessageEventHandler += driverMessageEventHandler; OnPropertyChanged(Fields.IsWindowExplorerSupportReady); } }
public void StartAgentDriver(IAgent IAgent) { Agent agent = (Agent)IAgent; BusinessFlow BusinessFlow = agent.BusinessFlow; ProjEnvironment ProjEnvironment = agent.ProjEnvironment; bool Remote = agent.Remote; DriverBase Driver = null; try { agent.mIsStarting = true; agent.OnPropertyChanged(Fields.Status); try { if (Remote) { throw new Exception("Remote is Obsolete, use GingerGrid"); } else { switch (agent.DriverType) { case eDriverType.InternalBrowser: Driver = new InternalBrowser(BusinessFlow); break; case eDriverType.SeleniumFireFox: Driver = new SeleniumDriver(GingerCore.Drivers.SeleniumDriver.eBrowserType.FireFox); break; case eDriverType.SeleniumChrome: Driver = new SeleniumDriver(GingerCore.Drivers.SeleniumDriver.eBrowserType.Chrome); break; case eDriverType.SeleniumIE: Driver = new SeleniumDriver(GingerCore.Drivers.SeleniumDriver.eBrowserType.IE); break; case eDriverType.SeleniumRemoteWebDriver: Driver = new SeleniumDriver(GingerCore.Drivers.SeleniumDriver.eBrowserType.RemoteWebDriver); // set capabilities if (agent.DriverConfiguration == null) { agent.DriverConfiguration = new ObservableList <DriverConfigParam>(); } ((SeleniumDriver)Driver).RemoteGridHub = agent.GetParamValue(SeleniumDriver.RemoteGridHubParam); ((SeleniumDriver)Driver).RemoteBrowserName = agent.GetParamValue(SeleniumDriver.RemoteBrowserNameParam); ((SeleniumDriver)Driver).RemotePlatform = agent.GetParamValue(SeleniumDriver.RemotePlatformParam); ((SeleniumDriver)Driver).RemoteVersion = agent.GetParamValue(SeleniumDriver.RemoteVersionParam); break; case eDriverType.SeleniumEdge: Driver = new SeleniumDriver(GingerCore.Drivers.SeleniumDriver.eBrowserType.Edge); break; case eDriverType.ASCF: Driver = new ASCFDriver(BusinessFlow, agent.Name); break; case eDriverType.DOSConsole: Driver = new DOSConsoleDriver(BusinessFlow); break; case eDriverType.UnixShell: Driver = new UnixShellDriver(BusinessFlow, ProjEnvironment); ((UnixShellDriver)Driver).SetScriptsFolder(System.IO.Path.Combine(agent.SolutionFolder, @"Documents\sh\")); break; case eDriverType.MobileAppiumAndroid: Driver = new SeleniumAppiumDriver(SeleniumAppiumDriver.eSeleniumPlatformType.Android, BusinessFlow); break; case eDriverType.MobileAppiumIOS: Driver = new SeleniumAppiumDriver(SeleniumAppiumDriver.eSeleniumPlatformType.iOS, BusinessFlow); break; case eDriverType.MobileAppiumAndroidBrowser: Driver = new SeleniumAppiumDriver(SeleniumAppiumDriver.eSeleniumPlatformType.AndroidBrowser, BusinessFlow); break; case eDriverType.MobileAppiumIOSBrowser: Driver = new SeleniumAppiumDriver(SeleniumAppiumDriver.eSeleniumPlatformType.iOSBrowser, BusinessFlow); break; case eDriverType.PerfectoMobileAndroid: Driver = new PerfectoDriver(PerfectoDriver.eContextType.NativeAndroid, BusinessFlow); break; case eDriverType.PerfectoMobileAndroidWeb: Driver = new PerfectoDriver(PerfectoDriver.eContextType.WebAndroid, BusinessFlow); break; case eDriverType.PerfectoMobileIOS: Driver = new PerfectoDriver(PerfectoDriver.eContextType.NativeIOS, BusinessFlow); break; case eDriverType.PerfectoMobileIOSWeb: Driver = new PerfectoDriver(PerfectoDriver.eContextType.WebIOS, BusinessFlow); break; case eDriverType.WebServices: WebServicesDriver WebServicesDriver = new WebServicesDriver(BusinessFlow); Driver = WebServicesDriver; break; case eDriverType.WindowsAutomation: Driver = new WindowsDriver(BusinessFlow); break; case eDriverType.PowerBuilder: Driver = new PBDriver(BusinessFlow); break; case eDriverType.JavaDriver: Driver = new JavaDriver(BusinessFlow); break; case eDriverType.MainFrame3270: Driver = new MainFrameDriver(BusinessFlow); break; //case eDriverType.AndroidADB: // string DeviceConfigFolder = agent.GetOrCreateParam("DeviceConfigFolder").Value; // if (!string.IsNullOrEmpty(DeviceConfigFolder)) // { // Driver = new AndroidADBDriver(BusinessFlow, System.IO.Path.Combine(agent.SolutionFolder, @"Documents\Devices", DeviceConfigFolder, @"\")); // } // else // { // //TODO: Load create sample folder/device, or start the wizard // throw new Exception("Please set device config folder"); // } // break; default: { throw new Exception("Matching Driver was not found."); } } } } catch (Exception e) { Reporter.ToLog(eLogLevel.ERROR, "Failed to set Agent Driver", e); return; } if (agent.AgentType == eAgentType.Service) { throw new Exception("Error - Agent type is service and trying to launch from Ginger.exe"); // we should never get here with service } else { agent.Driver = Driver; Driver.BusinessFlow = agent.BusinessFlow; agent.SetDriverConfiguration(); //if STA we need to start it on seperate thread, so UI/Window can be refreshed: Like IB, Mobile, Unix if (Driver.IsSTAThread()) { agent.CTS = new CancellationTokenSource(); agent.MSTATask = new Task(() => { Driver.StartDriver(); }, agent.CTS.Token, TaskCreationOptions.LongRunning); agent.MSTATask.Start(); } else { Driver.StartDriver(); } } } finally { if (agent.AgentType == eAgentType.Service) { agent.mIsStarting = false; } else { if (Driver != null) { // Give the driver time to start Thread.Sleep(500); Driver.IsDriverRunning = true; Driver.driverMessageEventHandler += agent.driverMessageEventHandler; } agent.mIsStarting = false; agent.OnPropertyChanged(Fields.Status); agent.OnPropertyChanged(Fields.IsWindowExplorerSupportReady); } } }
/// <summary> /// Example code of pulling an order - used for testing /// </summary> /// <param name="msg"></param> public void pullOrder(DriverBase.CancelRequestData cancelData) { /* QuickFix.Message myQFPullOrder = null; try { // is this new market processing? QuickFix.SecurityID securityID = new QuickFix.SecurityID(); if (myQFPullOrder.isSetField(securityID)) { myQFPullOrder.getField(securityID); // is this new market processing? if (m_Markets.ContainsKey(securityID.ToString())) { m_Markets[securityID.ToString()].pullOrder(msg); return; } } // send order canceled exec report QuickFix.OrdStatus myOrdStatus = new QuickFix.OrdStatus(QuickFix.OrdStatus.CANCELED); QuickFix.ExecType myExecType = new QuickFix.ExecType(QuickFix.ExecType.ORDER_STATUS); sendExecReport(cancelData.OrderContext.QFOrder, new QuickFix.OrderID(cancelData.OrderContext.OrderID), myOrdStatus, myExecType, 0, cancelData.OrderContext.LeavesQty, cancelData.OrderContext.CumQty, 0, 0); } catch (Exception myE) { log.Error("pullOrder", myE); // To provide the end user with more information // send an advisory message, again this is optional // and depends on the adpater SendAdvisoryMessage("pullOrder: problem pulling order:" + myE.ToString()); } */ }
/// <summary> /// Modify an order /// </summary> /// <param name="msg"></param> public override OrderReplaceResult modifyOrder(DriverBase.ModifyRequestData replaceData) { try { // Get the context - we must have this to access the order if (replaceData.Price.HasValue) { replaceData.OrderContext.Price = (decimal)replaceData.Price.Value; } if (replaceData.StopPrice.HasValue) { replaceData.OrderContext.StopPrice = (decimal)replaceData.StopPrice.Value; } // modify the qty if (replaceData.qty.HasValue) { replaceData.OrderContext.OrderQty = (int)replaceData.qty.Value; // force the leaves qty for the purpose of a simple simulation //myContext.LeavesQty = (int)newOrderQty.getValue(); } // record the context against the new clordid //RecordOrderContext(replaceData.ClOrdID, replaceData.OrderContext); //m_OrderContextClOrdID.Add(replaceData.ClOrdID, replaceData.OrderContext); // send order in book exec report // fully fill KaiTrade.Interfaces.IFill fill = new K2DataObjects.Fill(); fill.OrderStatus = KaiTrade.Interfaces.OrderStatus.REPLACED; fill.ExecType = KaiTrade.Interfaces.ExecType.ORDER_STATUS; fill.OrderID = replaceData.OrderContext.OrderID; fill.LastPx = 0; fill.AvgPx = 0; sendExecReport(replaceData.OrderContext, fill.OrderID, fill.OrderStatus, fill.ExecType, 0.0, replaceData.OrderContext.LeavesQty, replaceData.OrderContext.CumQty,fill.LastPx,fill.AvgPx ,"", ""); if (replaceData.Price.HasValue) { if (replaceData.Price.Value == 100) { m_FillList.Add(replaceData.OrderContext); } } return OrderReplaceResult.success; } catch (Exception myE) { log.Error("modifyOrderRD", myE); // To provide the end user with more information // send an advisory message, again this is optional // and depends on the adpater SendAdvisoryMessage("SIM:modifyOrderRD: problem modify order:" + myE.ToString()); return OrderReplaceResult.error; } }
public void gradualFill(DriverBase.OrderContext myContext) { try { int qtyToFill = 0; if (myContext.LeavesQty > 2) { qtyToFill = myContext.LeavesQty / 2; } else { qtyToFill = myContext.LeavesQty; } fixedAmountFill(myContext, qtyToFill,null); } catch (Exception myE) { log.Error("gradualFill", myE); } }
public void fixedAmountFill(DriverBase.OrderContext myContext, int qtyToFill, decimal? fillPx) { try { // send order in book exec report // fully fill KaiTrade.Interfaces.IFill fill = new K2DataObjects.Fill(); fill.ClOrdID = myContext.ClOrdID; fill.OrderID = myContext.OrderID; if (fillPx.HasValue) { fill.LastPx = (double)fillPx.Value; } else { fill.LastPx = (double)myContext.Price; } fill.AvgPx = 0; if (myContext.LeavesQty > 0) { if (myContext.LeavesQty > qtyToFill) { fill.OrderStatus = KaiTrade.Interfaces.OrderStatus.PARTIALLY_FILLED; fill.ExecType = KaiTrade.Interfaces.ExecType.PARTIAL_FILL; fill.FillQty = qtyToFill; myContext.CumQty += qtyToFill; fill.CumQty = myContext.CumQty; } else { fill.OrderStatus = KaiTrade.Interfaces.OrderStatus.FILLED; fill.ExecType = KaiTrade.Interfaces.ExecType.FILL; double myQty = myContext.LeavesQty; myContext.CumQty += (int)myQty; fill.FillQty = myContext.LeavesQty; fill.CumQty = myContext.CumQty; } fill.LeavesQty = myContext.LeavesQty; sendExecReport(fill); } } catch (Exception myE) { log.Error("gradualFill", myE); } }
public AutomationBase(string browser) { _driverBase = new DriverBase(browser); }
public DriverWindowEventArgs(eEventType eventType, DriverBase driver, object dataObject) { this.EventType = eventType; this.Driver = driver; this.DataObject = dataObject; }
public void BeforeScenario() { driver = DriverBase.GetDefaultDriver(); }
public SqlHelper(DriverBase _driver) { Driver = _driver; }
public void StartDriver() { WorkSpace.Instance.Telemetry.Add("startagent", new { AgentType = Agent.AgentType.ToString(), DriverType = Agent.DriverType.ToString() }); if (Agent.AgentType == Agent.eAgentType.Service) { StartPluginService(); GingerNodeProxy.StartDriver(); Agent.OnPropertyChanged(nameof(Agent.Status)); } else { try { Agent.mIsStarting = true; Agent.OnPropertyChanged(nameof(Agent.Status)); try { if (Agent.Remote) { throw new Exception("Remote is Obsolete, use GingerGrid"); } else { Driver = (DriverBase)TargetFrameworkHelper.Helper.GetDriverObject(Agent); } } catch (Exception e) { Reporter.ToLog(eLogLevel.ERROR, "Failed to set Agent Driver", e); return; } if (Agent.AgentType == Agent.eAgentType.Service) { throw new Exception("Error - Agent type is service and trying to launch from Ginger.exe"); // we should never get here with service } else { Driver.InitDriver(Agent); Driver.BusinessFlow = Agent.BusinessFlow; SetDriverConfiguration(); IVirtualDriver VirtualDriver = null; if (Driver is IVirtualDriver VD) { VirtualDriver = VD; string ErrorMessage; if (!VirtualDriver.CanStartAnotherInstance(out ErrorMessage)) { throw new NotSupportedException(ErrorMessage); } } //if STA we need to start it on seperate thread, so UI/Window can be refreshed: Like IB, Mobile, Unix if (Driver is IDriverWindow && ((IDriverWindow)Driver).ShowWindow) { DriversWindowUtils.OnDriverWindowEvent(DriverWindowEventArgs.eEventType.ShowDriverWindow, Driver, this); Driver.StartDriver(); } else if (Driver.IsSTAThread()) { CTS = new CancellationTokenSource(); MSTATask = new Task(() => { Driver.StartDriver(); } , CTS.Token, TaskCreationOptions.LongRunning); MSTATask.Start(); } else { Driver.StartDriver(); } if (VirtualDriver != null) { VirtualDriver.DriverStarted(Agent.Guid.ToString()); } } } finally { if (Agent.AgentType == Agent.eAgentType.Service) { Agent.mIsStarting = false; } else { if (Driver != null) { // Give the driver time to start Thread.Sleep(500); Driver.IsDriverRunning = true; Driver.DriverMessageEvent += driverMessageEventHandler; } Agent.mIsStarting = false; Agent.OnPropertyChanged(nameof(Agent.Status)); Agent.OnPropertyChanged(nameof(IsWindowExplorerSupportReady)); } } } }
private void fillOrder(DriverBase.OrderContext cntx) { try { if (m_Product == null) { m_Product = m_Parent.Facade.GetProductManager().GetProductMnemonic(m_Mnemonic); if (m_Product == null) { return; } } IL1PX L1PX = m_Parent.Facade.PriceHandler.GetPXPublisher(m_Product) as IL1PX; if (cntx.OrderType == KaiTrade.Interfaces.OrderType.MARKET) { if (cntx.Side == KaiTrade.Interfaces.Side.BUY) { fillOrder(cntx, L1PX.OfferSize.Value, L1PX.OfferPrice); } else if (cntx.Side == KaiTrade.Interfaces.Side.SELL) { fillOrder(cntx, L1PX.BidSize.Value, L1PX.BidPrice.Value); } } else { if (cntx.Side == KaiTrade.Interfaces.Side.BUY) { if (cntx.Price >= L1PX.OfferPrice.Value) { fillOrder(cntx, L1PX.OfferSize.Value, L1PX.OfferPrice); } } else if (cntx.Side == KaiTrade.Interfaces.Side.SELL) { if (cntx.Price <= L1PX.BidPrice.Value) { fillOrder(cntx, L1PX.BidSize.Value, L1PX.BidPrice); } } else { } } } catch (Exception myE) { m_Parent.Log.Error("fillOrder", myE); } }
static void Main(string[] args) { int times = 2; DynamicMethodExecutor executor = new DynamicMethodExecutor(typeof(Program).GetMethod("Call")); Stopwatch watch3 = new Stopwatch(); watch3.Start(); for (int i = 0; i < times; i++) { executor.Execute(new Program(), new object[3] { "test", "", "" }); } watch3.Stop(); Console.WriteLine(watch3.Elapsed + " (Dynamic executor)"); ModelBinderFactory.Current.SetModelBinder(new DefaultModelBinder());//a way set selfdefined modelbinder,you can ignore it IConfigurationSource src = ConfigurationManager.GetSection("DataAccess") as IConfigurationSource; DriverBase db = DatabaseFactory.CreateDriver(src); //DataTable dt = db.GetDataTable("select employeeid,lastname,firstname from dbo.Employees"); //IEnumerable<Employee> list = db.FindAll<Employee>("select employeeid,lastname,firstname from dbo.Employees"); //int count = 0; //IEnumerable<Employee> list = db.PagerList<Employee>("select employeeid,lastname,firstname from dbo.Employees", 1, count, "employeeid"); System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch(); timer.Start(); //int count; //IEnumerable<Blog> list = db.SetPageSize(1) // .PagerList<Blog>("select * from blog", 1,out count); // DataTable dt = db.GetDataTable("select * from blog"); IEnumerable <Blog> list = db.FindAll <Blog>("select * from blog"); timer.Stop(); Console.WriteLine("first timespan:" + timer.Elapsed); timer.Reset(); timer.Start(); list = db.FindAll <Blog>("select * from blog"); timer.Stop(); Console.WriteLine("second timespan:" + timer.Elapsed); // list = db.FindAll<Employee>("select employeeid,lastname,firstname from dbo.Employees"); //foreach (Employee model in DefaultModelBinder.BindModel<Employee>(dt)) //{ // Console.WriteLine(model.FirstName); //} //Console.WriteLine("Count:"+count); //foreach (Blog model in list) //{ // Console.WriteLine(model.Name); //} //foreach (DataRow dr in dt.Rows) //{ // foreach (DataColumn dc in dt.Columns) // { // Console.Write(dc.ColumnName + ":" + dr[dc.ColumnName] + "\t"); // } // Console.WriteLine(); //} //Console.WriteLine("Run 1 - configuration with xml file"); //using (WindsorContainer container = new WindsorContainer("castle.config")) //{ // container.AddFacility<LoggingFacility>(f => f.UseLog4Net()); // ISomething something = container.Resolve<ISomething>(); // something.DoSomething(""); // Console.WriteLine("Augment 10 returns " + something.Augment(10)); //} //Console.WriteLine("Run 2 - configuration fluent"); //using (WindsorContainer container = new WindsorContainer()) //{ // container.Register( // Component.For<IInterceptor>() // .ImplementedBy<BetterDumpInterceptor>() // .Named("myinterceptor")); // container.Register( // Component.For<ISomething>() // .ImplementedBy<Something>() // .Interceptors(InterceptorReference.ForKey("myinterceptor")).Anywhere); // ISomething something = container.Resolve<ISomething>(); // something.DoSomething(""); // Console.WriteLine("Augment 10 returns " + something.Augment(10)); //} //Console.WriteLine("Run 3 - configuration fluent"); //using (WindsorContainer container = new WindsorContainer()) //{ // Dictionary<Type, List<String>> RegexSelector = new Dictionary<Type, List<string>>(); // RegexSelector.Add(typeof(DumpInterceptor), new List<string>() { "DoSomething" }); // RegexSelector.Add(typeof(LogInterceptor), new List<string>() { "Augment" }); // InterceptorSelector selector = new InterceptorSelector(RegexSelector); // container.Register( // Component.For<IInterceptor>() // .ImplementedBy<DumpInterceptor>() // .Named("myinterceptor")); // container.Register( // Component.For<IInterceptor>() // .ImplementedBy<LogInterceptor>() // .Named("LogInterceptor")); // container.AddFacility<LoggingFacility>(f => f.UseLog4Net().WithConfig("log4net.config")); // container.Register( // Component.For<ISomething>() // .ImplementedBy<Something>() // .Interceptors(InterceptorReference.ForKey("myinterceptor") , // InterceptorReference.ForKey("LogInterceptor") // ) // .SelectedWith(selector).Anywhere); // ISomething something = container.Resolve<ISomething>(); // something.DoSomething(""); // Console.WriteLine("Augment 10 returns " + something.Augment(10)); //} Console.ReadKey(); }
private void fillOrder(DriverBase.OrderContext cntx, decimal availableQty, decimal? fillPx) { try { m_Parent.fixedAmountFill(cntx, cntx.TargetFillAmount, fillPx); } catch (Exception myE) { m_Parent.Log.Error("fillOrder", myE); } }