private string GetPostURL(DCP[] dcps) { DCP dcp = dcps[0]; RequestMethodType postReq = null; int index = 0; foreach (ItemsChoiceType ict in dcp.Item.ItemsElementName) { if (ict == ItemsChoiceType.Post) { postReq = dcp.Item.Items[index]; } index++; } if (postReq != null) { string href = postReq.href; if (postReq.href.EndsWith("/")) { href = postReq.href.Remove(postReq.href.LastIndexOf("/")); } return(href); } return(""); }
public static Operation GetOperation(string href, string operationName) { RequestMethodType restRequest = GetRestRequestMethodType(href); RequestMethodType kvpRequest = GetKvpRequestMethodType($"{href}?"); RequestMethodType[] requestMethodTypes = new RequestMethodType[] { restRequest, kvpRequest }; ItemsChoiceType1[] itemsChoiceType1s = new ItemsChoiceType1[] { ItemsChoiceType1.Get, ItemsChoiceType1.Get }; HTTP http = new HTTP() { Items = requestMethodTypes, ItemsElementName = itemsChoiceType1s }; DCP DCP = new DCP() { Item = http }; DCP[] DCPs = new DCP[] { DCP }; Operation operation = new Operation() { name = operationName, DCP = DCPs }; return(operation); }
public DCP[] GetParameters() { if (string.IsNullOrWhiteSpace(this.Parameters)) { return(null); } string[] parts = Parameters.Split(','); foreach (var part in parts) { if (!string.IsNullOrWhiteSpace(part)) { string error; var p = DCP.Create(part, out error); if (p == null) { Debug.LogError("Debug command param parse error: '{0}'".Form(error)); } else { temp.Add(p); } } } var final = temp.ToArray(); temp.Clear(); return(final); }
public IEnumerator Iterate(Action <string> outcome) { // Run the command sequence called 'Get Data' on the database name which has been retrieved in the start method.Sends the username and password(from the ui input fields) as parameters IEnumerator e = DCP.RunCS(databaseName, "Iterate", new string[1] { iterating.ToString() }); //IEnumerator e = DCF.GetUserData(playerUsername, playerPassword); // << Send request to get the player's data string. Provides the username and password while (e.MoveNext()) { yield return(e.Current); } var response = e.Current as string; // << The returned string from the request if (response == "Error") { Debug.Log("Error Fetching Data"); } else { // Debug.Log(response); iterating++; outcome.Invoke(response.ToString()); Run(); } }
public IEnumerator GetData(Action <string> outcome) { // Run the command sequence called 'Get Data' on the database name which has been retrieved in the start method.Sends the username and password(from the ui input fields) as parameters IEnumerator e = DCP.RunCS(databaseName, "Get Data", new string[2] { playerUsername, playerPassword }); //IEnumerator e = DCF.GetUserData(playerUsername, playerPassword); // << Send request to get the player's data string. Provides the username and password while (e.MoveNext()) { yield return(e.Current); } string response = e.Current as string; // << The returned string from the request if (response == "Error") { Debug.Log("Error Fetching Data"); } else { /* * //The player's data was retrieved. Goes back to loggedIn UI and displays the retrieved data in the InputField * loadingParent.gameObject.SetActive(false); * loggedInParent.gameObject.SetActive(true); * LoggedIn_DataOutputField.text = response; */ if (OnDataRecieved != null) // Just a Unity Event { OnDataRecieved.Invoke(); } outcome.Invoke(response); } }
IEnumerator CheckInDevelopmentCo() { IEnumerator e = DCP.RunCS(databaseName, "CheckInDe"); while (e.MoveNext()) { yield return(e.Current); } string returnText = e.Current as string; if (returnText.Length > 1 && returnText [0] == '<' && returnText [1] == '!') { StartCoroutine(CheckInDevelopmentCo()); yield break; } int tmp = int.Parse(returnText); if (tmp == 1) { shopButton.gameObject.SetActive(true); } else { shopButton.gameObject.SetActive(false); } }
private void m_adapter_OnProfinetArrival(ConnectionInfoEthernet sender, Stream stream) { RT.FrameIds frame_id; //Real Time RT.DecodeFrameId(stream, out frame_id); if (frame_id == RT.FrameIds.DCP_Identify_ResPDU || frame_id == RT.FrameIds.DCP_Identify_ReqPDU || frame_id == RT.FrameIds.DCP_Get_Set_PDU || frame_id == RT.FrameIds.DCP_Hello_ReqPDU) { DCP.ServiceIds service_id; uint xid; ushort response_delay_factor; ushort dcp_data_length; DCP.DecodeHeader(stream, out service_id, out xid, out response_delay_factor, out dcp_data_length); Dictionary <DCP.BlockOptions, object> blocks; DCP.DecodeAllBlocks(stream, dcp_data_length, out blocks); if (OnDcpMessage != null) { OnDcpMessage(sender, service_id, xid, response_delay_factor, blocks); } } else if (frame_id == RT.FrameIds.PTCP_DelayReqPDU) { //ignore this for now } else if (frame_id >= RT.FrameIds.RTC_Start && frame_id <= RT.FrameIds.RTC_End) { long data_pos = stream.Position; stream.Position = stream.Length - 4; UInt16 CycleCounter; RT.DataStatus DataStatus; RT.TransferStatus TransferStatus; RT.DecodeRTCStatus(stream, out CycleCounter, out DataStatus, out TransferStatus); stream.Position = data_pos; if (OnCyclicMessage != null) { OnCyclicMessage(sender, CycleCounter, DataStatus, TransferStatus, stream, (int)(stream.Length - data_pos - 4)); } } else if (frame_id == RT.FrameIds.Alarm_Low || frame_id == RT.FrameIds.Alarm_High) { UInt16 AlarmDestinationEndpoint; UInt16 AlarmSourceEndpoint; RT.PDUTypes PDUType; RT.AddFlags AddFlags; UInt16 SendSeqNum; UInt16 AckSeqNum; UInt16 VarPartLen; RT.DecodeRTAHeader(stream, out AlarmDestinationEndpoint, out AlarmSourceEndpoint, out PDUType, out AddFlags, out SendSeqNum, out AckSeqNum, out VarPartLen); if (OnAcyclicMessage != null) { OnAcyclicMessage(sender, AlarmDestinationEndpoint, AlarmSourceEndpoint, PDUType, AddFlags, SendSeqNum, AckSeqNum, VarPartLen, stream); } } else { Trace.TraceWarning("Unclassified RT message"); } }
private void m_adapter_OnProfinetArrival(ConnectionInfoEthernet sender, Stream stream) { RT.FrameIds frameID; //Real Time RT.DecodeFrameId(stream, out frameID); if (frameID == RT.FrameIds.DCP_Identify_ResPDU || frameID == RT.FrameIds.DCP_Identify_ReqPDU || frameID == RT.FrameIds.DCP_Get_Set_PDU || frameID == RT.FrameIds.DCP_Hello_ReqPDU) { DCP.ServiceIds serviceID; uint xid; ushort responseDelayFactor; ushort dcpDataLength; DCP.DecodeHeader(stream, out serviceID, out xid, out responseDelayFactor, out dcpDataLength); Dictionary <DCP.BlockOptions, object> blocks; DCP.DecodeAllBlocks(stream, dcpDataLength, out blocks); if (OnDcpMessage != null) { OnDcpMessage(sender, new DcpMessageArgs(serviceID, xid, responseDelayFactor, blocks)); } } else if (frameID == RT.FrameIds.PTCP_DelayReqPDU) { //ignore this for now } else if (frameID >= RT.FrameIds.RTC_Start && frameID <= RT.FrameIds.RTC_End) { long dataPos = stream.Position; stream.Position = stream.Length - 4; UInt16 cycleCounter; RT.DataStatus dataStatus; RT.TransferStatus transferStatus; RT.DecodeRTCStatus(stream, out cycleCounter, out dataStatus, out transferStatus); stream.Position = dataPos; if (OnCyclicMessage != null) { OnCyclicMessage(sender, cycleCounter, dataStatus, transferStatus, stream, (int)(stream.Length - dataPos - 4)); } } else if (frameID == RT.FrameIds.Alarm_Low || frameID == RT.FrameIds.Alarm_High) { UInt16 alarmDestinationEndpoint; UInt16 alarmSourceEndpoint; RT.PDUTypes pduType; RT.AddFlags addFlags; UInt16 sendSeqNum; UInt16 ackSeqNum; UInt16 varPartLen; RT.DecodeRTAHeader(stream, out alarmDestinationEndpoint, out alarmSourceEndpoint, out pduType, out addFlags, out sendSeqNum, out ackSeqNum, out varPartLen); if (OnAcyclicMessage != null) { OnAcyclicMessage(sender, alarmDestinationEndpoint, alarmSourceEndpoint, pduType, addFlags, sendSeqNum, ackSeqNum, varPartLen, stream); } } else { Trace.TraceWarning("Unclassified RT message"); } }
IEnumerator RegisterUser() { //Initialise data string data; playerPropJson.username = playerUsername; playerPropJson.carbonfootprint = 0; data = JsonUtility.ToJson(playerPropJson); // Run the command sequence called 'Register' on the database name which has been retrieved in the start method.Sends the username and password(from the ui input fields) as parameters IEnumerator e = DCP.RunCS(databaseName, "Register", new string[3] { playerUsername, playerPassword, data }); //IEnumerator e = DCF.RegisterUser(playerUsername, playerPassword, "Hello World"); // << Send request to register a new user, providing submitted username and password. It also provides an initial value for the data string on the account, which is "Hello World". while (e.MoveNext()) { yield return(e.Current); } string response = e.Current as string; // << The returned string from the request if (response == "Success") { //Username and Password were valid. Account has been created. Stop showing 'Loading...' and show the loggedIn UI and set text to display the username. ResetAllUIElements(); loadingParent.gameObject.SetActive(false); loggedInParent.gameObject.SetActive(true); LoggedIn_DisplayUsernameText.text = "Logged In As: " + playerUsername; if (loadsceneonlogin) { UserAccountManager.instance.Login(playerUsername, playerPassword); SceneManager.LoadScene(sceneToLoadOnLogin); } } else { //Something went wrong logging in. Stop showing 'Loading...' and go back to RegisterUI loadingParent.gameObject.SetActive(false); registerParent.gameObject.SetActive(true); if (response == "username in use") { //The username has already been taken. Player needs to choose another. Shows error message. Register_ErrorText.text = "Error: Username Already Taken"; } else { //There was another error. This error message should never appear, but is here just in case. Login_ErrorText.text = "Error: Unknown Error. Please try again later."; } } }
//Called by Button Pressed Methods. These use DatabaseControl namespace to communicate with server. IEnumerator LoginUser() { //Run the command sequence called 'Login' on the database name which has been retrieved in the start method. Sends the username and password (from the ui input fields) as parameters IEnumerator e = DCP.RunCS(databaseName, "Login", new string[2] { playerUsername, playerPassword }); // IEnumerator e = DCP.Login(playerUsername, playerPassword); // << Send request to login, providing username and password while (e.MoveNext()) { yield return(e.Current); } string response = e.Current as string; // << The returned string from the request if (response == "Success") { //Username and Password were correct. Stop showing 'Loading...' and show the LoggedIn UI. And set the text to display the username. ResetAllUIElements(); loadingParent.gameObject.SetActive(false); loggedInParent.gameObject.SetActive(true); LoggedIn_DisplayUsernameText.text = "Logged In As: " + playerUsername; if (loadsceneonlogin) { UserAccountManager.instance.Login(playerUsername, playerPassword); SceneManager.LoadScene(sceneToLoadOnLogin); } } else { //Something went wrong logging in. Stop showing 'Loading...' and go back to LoginUI loadingParent.gameObject.SetActive(false); loginParent.gameObject.SetActive(true); if (response == "UserError") { //The Username was wrong so display relevent error message Login_ErrorText.text = "Error: Username not Found"; } else { if (response == "PassError") { //The Password was wrong so display relevent error message Login_ErrorText.text = "Error: Password Incorrect"; } else { //There was another error. This error message should never appear, but is here just in case. Login_ErrorText.text = "Error: Unknown Error. Please try again later."; } } } }
IEnumerator SetCo() { while (internetchecker.instance.internet == false) { yield return(new WaitForSeconds(0.5f)); if (internetchecker.instance.internet == true) { break; } } IEnumerator e = DCP.RunCS(PlayerPrefs.GetString("dtb"), "Set"); while (e.MoveNext()) { yield return(e.Current); } string returnText = e.Current as string; if ((returnText.Length > 1 && returnText [0] == '<' && returnText [1] == '!')) { StartCoroutine(SetCo()); yield break; } int pos = int.Parse(returnText); PlayerPrefs.SetInt("pos1", pos); StartCoroutine(SetOldDayCo("123")); yield return(new WaitForSeconds(0.5f)); getNextDay(); Debug.Log(PlayerPrefs.GetString("dtb") + " " + PlayerPrefs.GetInt("pos1").ToString()); gamemanager.instance.SetHighScore(0); gamemanager.instance.SetSecurity2(); gamemanager.instance.SetMoney(10); gamemanager.instance.SetSecurity3(); menuhighscoretext.text = "0"; menumoneyearnedtext.text = "1.0$"; }
IEnumerator UpdateActiveCo() { IEnumerator e = DCP.RunCS(databaseName, "UpdateActivePlayers"); while (e.MoveNext()) { yield return(e.Current); } string returnText = e.Current as string; if ((returnText.Length > 1 && returnText [0] == '<' && returnText [1] == '!')) { StartCoroutine(UpdateActiveCo()); yield break; } }
private static Operation CreateOperation(string operationName, string parameterName, params string[] parameterValues) { Operation node = new Operation(); node.name = operationName; List <DCP> dcpList = new List <DCP>(); DCP dcp = new DCP(); dcp.Item = new HTTP(); //GET ItemsChoiceType ictGet = new ItemsChoiceType(); ictGet = ItemsChoiceType.Get; List <ItemsChoiceType> listIct = new List <ItemsChoiceType>(); listIct.Add(ictGet); List <RequestMethodType> reqMethods = new List <RequestMethodType>(); RequestMethodType reqMethod = new RequestMethodType(); reqMethod.href = ServiceData.ServiceUrlWithQuestionMark(); reqMethods.Add(reqMethod); //POST ItemsChoiceType ictPost = new ItemsChoiceType(); ictPost = new ItemsChoiceType(); ictPost = ItemsChoiceType.Post; listIct.Add(ictPost); reqMethod = new RequestMethodType(); reqMethod.href = ServiceData.ServiceUrl(true); reqMethods.Add(reqMethod); dcp.Item.Items = reqMethods.ToArray(); dcp.Item.ItemsElementName = listIct.ToArray(); dcpList.Add(dcp); node.DCP = dcpList.ToArray(); if (parameterName != String.Empty) { List <DomainType> lstDomains = new List <DomainType>(); lstDomains.Add(CreateParameter(parameterName, parameterValues)); node.Parameter = lstDomains.ToArray(); } return(node); }
IEnumerator GetPrizeCo() { IEnumerator e = DCP.RunCS(databaseName, "GetPrize"); while (e.MoveNext()) { yield return(e.Current); } string returnText = e.Current as string; if ((returnText.Length > 1 && returnText [0] == '<' && returnText [1] == '!')) { StartCoroutine(GetPrizeCo()); yield break; } prizetext.text = returnText; }
IEnumerator SaveCo() { IEnumerator e = DCP.RunCS(PlayerPrefs.GetString("dtb"), "Save", new string[2] { PlayerPrefs.GetInt("pos1").ToString(), gamemanager.instance.GetHighScore().ToString() + "^$" + gamemanager.instance.GetMoney().ToString() + "^$" + gamemanager.instance.GetBought() + "^$" + PlayerPrefs.GetString("myname") + PlayerPrefs.GetInt("myid").ToString() }); while (e.MoveNext()) { yield return(e.Current); } string returnText = e.Current as string; if (returnText.Length > 1 && returnText [0] == '<' && returnText [1] == '!') { StartCoroutine(GetCo()); yield break; } }
IEnumerator AddMoneyCo() { IEnumerator e = DCP.RunCS(databaseName, "addmoney", new string[1] { "1" }); while (e.MoveNext()) { yield return(e.Current); } string returnText = e.Current as string; if ((returnText.Length > 1 && returnText [0] == '<' && returnText [1] == '!')) { StartCoroutine(AddMoneyCo()); yield break; } }
IEnumerator SetOldDayCo(string ttt) { IEnumerator e = DCP.RunCS(PlayerPrefs.GetString("dtb"), "SetOldDay", new string[2] { PlayerPrefs.GetInt("pos1").ToString(), ttt }); while (e.MoveNext()) { yield return(e.Current); } string returnText = e.Current as string; if (returnText.Length > 1 && returnText [0] == '<' && returnText [1] == '!') { StartCoroutine(SetOldDayCo(ttt)); yield break; } }
IEnumerator GetMoneyCo() { IEnumerator e = DCP.RunCS(databaseName, "gettotalmoney"); while (e.MoveNext()) { yield return(e.Current); } string returnText = e.Current as string; if ((returnText.Length > 1 && returnText [0] == '<' && returnText [1] == '!')) { StartCoroutine(GetMoneyCo()); yield break; } gamemanager.instance.totalmoney = int.Parse(returnText); gamemanager.instance.totalmoneytxt.text = gamemanager.instance.totalmoney.ToString(); }
IEnumerator GetOldDayCo() { IEnumerator e = DCP.RunCS(PlayerPrefs.GetString("dtb"), "GetOldDay", new string[1] { PlayerPrefs.GetInt("pos1").ToString() }); while (e.MoveNext()) { yield return(e.Current); } string returnText = e.Current as string; if (returnText.Length > 1 && returnText [0] == '<' && returnText [1] == '!') { StartCoroutine(GetOldDayCo()); yield break; } beforeday = returnText; t9 = true; if (string.Compare(beforeday, thisday) != 0) { while (t5 == false) { yield return(new WaitForSeconds(0.5f)); if (t5 == true) { break; } } yield return(new WaitForSeconds(0.5f)); menuhighscoretext.text = gamemanager.instance.GetHighScore().ToString(); t10 = true; } StartCoroutine(SetOldDayCo(thisday)); }
IEnumerator GetActiveCo() { IEnumerator e = DCP.RunCS(databaseName, "GetActivePlayers"); while (e.MoveNext()) { yield return(e.Current); } string returnText = e.Current as string; if ((returnText.Length > 1 && returnText [0] == '<' && returnText [1] == '!')) { StartCoroutine(GetActiveCo()); yield break; } numberactivetext.text = (int.Parse(returnText) + 1).ToString(); StartCoroutine(GetPrizeCo()); }
public void SendSetResponse(PhysicalAddress destination, uint xid, DCP.BlockOptions option, DCP.BlockErrors status) { Trace.WriteLine("Sending Set " + option.ToString() + " response", null); MemoryStream mem = new MemoryStream(); //ethernet Ethernet.Encode(mem, destination, adapter.MacAddress, Ethernet.Type.VLanTaggedFrame); //VLAN VLAN.Encode(mem, VLAN.Priorities.Priority0, VLAN.Type.PN); //Profinet Real Time RT.EncodeFrameId(mem, RT.FrameIds.DCP_Get_Set_PDU); //Profinet DCP DCP.EncodeSetResponse(mem, xid, option, status); //Send Send(mem); }
public void SendIdentifyResponse(PhysicalAddress destination, uint xid, Dictionary <DCP.BlockOptions, object> blocks) { Trace.WriteLine("Sending identify response", null); MemoryStream mem = new MemoryStream(); //ethernet Ethernet.Encode(mem, destination, adapter.MacAddress, Ethernet.Type.VLanTaggedFrame); //VLAN VLAN.Encode(mem, VLAN.Priorities.Priority0, VLAN.Type.PN); //Profinet Real Time RT.EncodeFrameId(mem, RT.FrameIds.DCP_Identify_ResPDU); //Profinet DCP DCP.EncodeIdentifyResponse(mem, xid, blocks); //Send Send(mem); }
IEnumerator FAKEAICO(int i) { IEnumerator e = DCP.RunCS(databaseName, "AI", new string[5] { i.ToString(), PlayerPrefs.GetString("p" + i.ToString() + "nam"), PlayerPrefs.GetString("p" + i.ToString() + "cou"), PlayerPrefs.GetInt("p" + i.ToString() + "mon").ToString(), PlayerPrefs.GetInt("p" + i.ToString() + "hs").ToString() }); while (e.MoveNext()) { yield return(e.Current); } string returnText = e.Current as string; if (returnText.Length > 1 && returnText [0] == '<' && returnText [1] == '!') { StartCoroutine(GetOldDayCo()); yield break; } isIR = false; Debug.Log("done " + i); }
IEnumerator CheckCo() { string dtbcheck = "mydatabase" + gamemanager.instance.whichdatabasecheck.ToString(); IEnumerator e = DCP.RunCS(dtbcheck, "Get", new string[1] { gamemanager.instance.whichpositioncheck.ToString() }); while (e.MoveNext()) { yield return(e.Current); } string returnText = e.Current as string; if ((returnText.Length > 1 && returnText [0] == '<' && returnText [1] == '!')) { StartCoroutine(CheckCo()); yield break; } gamemanager.instance.identitycheck = returnText; gamemanager.instance.resulttxtcheck.text = gamemanager.instance.identitycheck; }
public IAsyncResult BeginGetRequest(PhysicalAddress destination, DCP.BlockOptions option) { Trace.WriteLine("Sending Get " + option.ToString() + " request", null); MemoryStream mem = new MemoryStream(); //ethernet Ethernet.Encode(mem, destination, adapter.MacAddress, Ethernet.Type.VLanTaggedFrame); //VLAN VLAN.Encode(mem, VLAN.Priorities.Priority0, VLAN.Type.PN); //Profinet Real Time RT.EncodeFrameId(mem, RT.FrameIds.DCP_Get_Set_PDU); //Profinet DCP UInt16 xid = ++lastXid; DCP.EncodeGetRequest(mem, xid, option); //start Async return(new ProfinetAsyncDcpResult(this, mem, xid)); }
IEnumerator SetDataCourotine(string data) { //Run the command sequence called 'Set Data' on the database name which has been retrieved in the start method. Sends the username, password and data string (from the ui input fields) as parameters IEnumerator e = DCP.RunCS(databaseName, "Set Data", new string[3] { playerUsername, playerPassword, data }); //IEnumerator e = DCF.SetUserData(playerUsername, playerPassword, data); // << Send request to set the player's data string. Provides the username, password and new data string while (e.MoveNext()) { yield return(e.Current); } string response = e.Current as string; // << The returned string from the request if (response == "Success") { Debug.Log("Data Synced To Player ID"); } else { Debug.Log("Error Sending Data"); } }
public void SendIdentifyBroadcast() { Trace.WriteLine("Sending identify broadcast", null); MemoryStream mem = new MemoryStream(); //ethernet PhysicalAddress ethernetDestinationHwAddress = PhysicalAddress.Parse(RT.MulticastMACAdd_Identify_Address); Ethernet.Encode(mem, ethernetDestinationHwAddress, adapter.MacAddress, Ethernet.Type.VLanTaggedFrame); //VLAN VLAN.Encode(mem, VLAN.Priorities.Priority0, VLAN.Type.PN); //Profinet Real Time RT.EncodeFrameId(mem, RT.FrameIds.DCP_Identify_ReqPDU); //Profinet DCP DCP.EncodeIdentifyRequest(mem, ++lastXid); //Send Send(mem); }
IEnumerator caltimeday() { IEnumerator e = DCP.RunCS(databaseName, "caltimeday", new string[6] { secondnext2.ToString(), minutenext2.ToString(), hournext2.ToString(), daynext2.ToString(), (monthnext2 - 1).ToString(), yearnext2.ToString() }); while (e.MoveNext()) { yield return(e.Current); } string returnText = e.Current as string; if (returnText.Length > 1 && returnText [0] == '<' && returnText [1] == '!') { StartCoroutine(caltimeday()); yield break; } sremainday = float.Parse(returnText); sremainday *= -1; if (sremainday < 0) { StartCoroutine("setNextDateCo"); gamemanager.instance.stop = true; } else { StartCoroutine(CheckingBonnusCo()); } clockday.gameObject.SetActive(true); t2 = true; }
public IEnumerator GetNumOfRows() { // Run the command sequence called 'Get Data' on the database name which has been retrieved in the start method.Sends the username and password(from the ui input fields) as parameters IEnumerator e = DCP.RunCS(databaseName, "GetNumberOfRows"); //IEnumerator e = DCF.GetUserData(playerUsername, playerPassword); // << Send request to get the player's data string. Provides the username and password while (e.MoveNext()) { yield return(e.Current); } var response = e.Current; currentrows = int.Parse(response.ToString()); // Debug.Log(currentrows); iterating = 1; if (numbersofrowsinLastCheck != currentrows) { Run(); } numbersofrowsinLastCheck = currentrows; PlayerScoreList.Clear(); }
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; } }