public void SetDriverConfiguration() { if (Agent.DriverConfiguration == null) { return; } if (Agent.ProjEnvironment == null) { Agent.ProjEnvironment = new Environments.ProjEnvironment();//to avoid value expertion exception } if (Agent.BusinessFlow == null) { Agent.BusinessFlow = new GingerCore.BusinessFlow();//to avoid value expertion exception } ValueExpression ve = new ValueExpression(Agent.ProjEnvironment, Agent.BusinessFlow, Agent.DSList); if (Agent.AgentType == Agent.eAgentType.Service) { SetServiceConfiguration(); } else { Agent.DriverClass = TargetFrameworkHelper.Helper.GetDriverType(Agent); SetDriverMissingParams(Agent.DriverClass); foreach (DriverConfigParam DCP in Agent.DriverConfiguration) { string value = null; ObservableList <DriverConfigParam> multiValues = null; //process Value expression in case used if (DCP.MultiValues != null) { multiValues = new ObservableList <DriverConfigParam>(); foreach (DriverConfigParam subValue in DCP.MultiValues) { ve.Value = subValue.Value; multiValues.Add(new DriverConfigParam() { Parameter = subValue.Parameter, Value = ve.ValueCalculated }); } } else { ve.Value = DCP.Value; value = ve.ValueCalculated; } PropertyInfo driverProp = Driver.GetType().GetProperty(DCP.Parameter); if (driverProp != null) { //set multi values prop if (DCP.MultiValues != null) { Driver.GetType().GetProperty(DCP.Parameter).SetValue(Driver, multiValues); continue; } //set eNum prop UserConfiguredEnumTypeAttribute enumTypeConfig = null; try { MemberInfo[] mf = Driver.GetType().GetMember(DCP.Parameter); if (mf != null) { enumTypeConfig = Attribute.GetCustomAttribute(mf[0], typeof(UserConfiguredEnumTypeAttribute), false) as UserConfiguredEnumTypeAttribute; if (enumTypeConfig != null) { Driver.GetType().GetProperty(DCP.Parameter).SetValue(Driver, Enum.Parse(enumTypeConfig.EnumType, value)); continue; } } } catch (Exception ex) { Reporter.ToLog(eLogLevel.WARN, string.Format("Failed to check if the driver configuration '{0}' is from EnumType", DCP.Parameter), ex); } //set standard prop types string driverPropType = driverProp.PropertyType.Name; switch (driverPropType) { case "String": Driver.GetType().GetProperty(DCP.Parameter).SetValue(Driver, value); break; case "Boolean": try { Driver.GetType().GetProperty(DCP.Parameter).SetValue(Driver, Convert.ToBoolean(value)); } catch (Exception) { Driver.GetType().GetProperty(DCP.Parameter).SetValue(Driver, true); } break; case "Int32": Driver.GetType().GetProperty(DCP.Parameter).SetValue(Driver, int.Parse(value)); break; default: Reporter.ToUser(eUserMsgKey.SetDriverConfigTypeNotHandled, DCP.GetType().ToString()); Reporter.ToLog(eLogLevel.ERROR, string.Format("The driver configuration '{0}' field type '{1}' is unknown", DCP.Parameter, driverPropType)); break; } } else { Reporter.ToLog(eLogLevel.DEBUG, string.Format("The driver configuration '{0}' was not found on the driver class", DCP.Parameter)); } } Driver.AdvanceDriverConfigurations = Agent.AdvanceAgentConfigurations; } }
private void SetDriverConfiguration() { Boolean bValue; if (DriverConfiguration == null) { return; } if (ProjEnvironment == null) { ProjEnvironment = new Environments.ProjEnvironment();//to avoid value expertion exception } if (BusinessFlow == null) { BusinessFlow = new GingerCore.BusinessFlow();//to avoid value expertion exception } foreach (DriverConfigParam DCP in DriverConfiguration) { //process Value expression in case used ValueExpression VE = new ValueExpression(ProjEnvironment, BusinessFlow, DSList); VE.Value = DCP.Value; string value = VE.ValueCalculated; //TODO: check if Convert.To is better option //TODO: hanlde other feilds type PropertyInfo tp = Driver.GetType().GetProperty(DCP.Parameter); if (tp != null) { string tpName = tp.PropertyType.Name; switch (tpName) { case "String": Driver.GetType().GetProperty(DCP.Parameter).SetValue(Driver, value); break; case "Boolean": try { bValue = Convert.ToBoolean(value); } catch (Exception) { bValue = true; } Driver.GetType().GetProperty(DCP.Parameter).SetValue(Driver, bValue); break; case "Int32": int i = int.Parse(value); Driver.GetType().GetProperty(DCP.Parameter).SetValue(Driver, i); break; case "eType": //TODO: Handle enums later... throw new Exception("Driver Config - Enum not supported yet"); default: Reporter.ToUser(eUserMsgKeys.SetDriverConfigTypeNotHandled, DCP.GetType().ToString()); break; } } else { // TODO: show message to user to remove param - old } } Driver.AdvanceDriverConfigurations = this.AdvanceAgentConfigurations; }