protected virtual Boolean SetMaximumRecordsForApiToReturn() { try { StringBuilder stringBuilder = new StringBuilder(); UInt32 size = 128; ReturnCode = MvxSock.Trans(ref serverId, String.Format("SetLstMaxRec {0}", MaximumRecordsToReturn.ToString()), stringBuilder, ref size); if (ReturnCode.Value == 0) { return(true); } else { Trace.WriteLine(String.Format("The 'MvxSock.Trans' method retured non zero code:{0}.", ReturnCode)); String errorText = GetErrorText(); Trace.WriteLineIf((errorText != null), errorText); } } catch (Exception exception) { Trace.WriteLine(exception); } TraceUtilities.WriteMethodError(MethodBase.GetCurrentMethod()); return(false); }
protected virtual Boolean SetMaximumWaitTime() { try { ReturnCode = MvxSock.SetMaxWait(ref serverId, MaximumWaitTime); if (ReturnCode.Value == 0) { return(true); } else { Trace.WriteLine(String.Format("The 'MvxSock.SetMaxWait' method retured the following non zero code. {0}", ReturnCode)); } } catch (Exception exception) { Trace.WriteLine(exception.ToString()); } String errorText = GetErrorText(); Trace.WriteLineIf((errorText != null), errorText); TraceUtilities.WriteMethodError(MethodBase.GetCurrentMethod()); return(false); }
protected virtual Boolean ConnectToServer() { try { ReturnCode = MvxSock.Connect(ref serverId, ConnectionData.Server, ConnectionData.Port, ConnectionData.UserName, ConnectionData.Password, ApiData.Api, null); if (ReturnCode.Value == 0) { return(true); } else { Trace.WriteLine(String.Format("The 'MvxSock.Connect' method retured the following non zero code. {0}", ReturnCode)); } } catch (Exception exception) { Trace.WriteLine(exception.ToString()); } String errorText = GetErrorText(); Trace.WriteLineIf((errorText != null), errorText); TraceUtilities.WriteMethodError(MethodBase.GetCurrentMethod()); return(false); }
protected virtual Boolean SetEnableZippedTransactions() { try { ReturnCode = MvxSock.SetZippedTransactions(ref serverId, 1); if (ReturnCode.Value == 0) { return(true); } else { Trace.WriteLine(String.Format("The 'MvxSock.SetZippedTransactions' method retured non zero code:{0}.", ReturnCode)); String errorText = GetErrorText(); Trace.WriteLineIf((errorText != null), errorText); } } catch (Exception exception) { Trace.WriteLine(exception); } TraceUtilities.WriteMethodError(MethodBase.GetCurrentMethod()); return(false); }
protected virtual bool ProcessApiResult() { try { T_DataObject dataObject = CreateDataObject(); AddDataObjectToDataObjectCollection(dataObject); return(true); } catch (Exception exception) { Trace.WriteLine(exception); } TraceUtilities.WriteMethodError(MethodBase.GetCurrentMethod()); return(false); }
protected virtual Boolean SetRequestField(RequestFieldData requestFieldData) { try { ReturnCode = null; MvxSock.SetField(ref serverId, requestFieldData.FieldName, requestFieldData.FieldValue); return(true); } catch (Exception exception) { Trace.WriteLine(exception.ToString()); } TraceUtilities.WriteMethodError(MethodBase.GetCurrentMethod()); return(false); }
protected virtual String GetErrorText() { String errorText; try { errorText = MvxSock.GetLastError(ref serverId).Trim(); return(errorText.Length == 0 ? null : errorText); } catch (Exception exception) { Trace.WriteLine(exception.ToString()); } TraceUtilities.WriteMethodError(MethodBase.GetCurrentMethod()); return(null); }
protected virtual Boolean ExecuteApi() { try { ReturnCode = MvxSock.Access(ref serverId, ApiData.Method); return(EvaluateMvxSockAccessReturnCode()); } catch (Exception exception) { Trace.WriteLine(exception.ToString()); } TraceUtilities.WriteMethodError(MethodBase.GetCurrentMethod()); ReturnCode = null; return(false); }
protected virtual Boolean SetRequestFields() { try { foreach (RequestFieldData requestField in InputFieldDataList) { if (!SetRequestField(requestField)) { return(false); } } return(true); } catch (Exception exception) { Trace.WriteLine(exception.ToString()); } TraceUtilities.WriteMethodError(MethodBase.GetCurrentMethod()); return(false); }
protected virtual Boolean GetOutputFieldData() { try { foreach (OutputFieldData _OutputFieldData in OutputFieldData) { _OutputFieldData.Value = GetValueFromField(_OutputFieldData.FieldName); } return(true); } catch (Exception exception) { Trace.WriteLine(exception.ToString()); } String errorText = GetErrorText(); Trace.WriteLineIf((errorText != null), errorText); TraceUtilities.WriteMethodError(MethodBase.GetCurrentMethod()); return(false); }
protected virtual Boolean ExecuteApi() { try { ReturnCode = MvxSock.Access(ref serverId, ApiData.Method); if (ReturnCode.Value == 0) { return(true); } else { Trace.WriteLine(String.Format("The 'MvxSock.Access' method retured the following non zero code. {0}", ReturnCode)); } } catch (Exception exception) { Trace.WriteLine(exception.ToString()); } TraceUtilities.WriteMethodError(MethodBase.GetCurrentMethod()); return(false); }
protected override bool ProcessApiResults() { DataObjectCollection = new T_DataObjectCollection(); try { while (MvxSock.More(ref serverId)) { if (!ProcessApiResult()) { return(false); } ReturnCode = MvxSock.Access(ref serverId, null); if (ReturnCode.Value != 0) { Trace.WriteLine(String.Format("The 'MvxSock.Access' method retured the following non zero code. {0}", ReturnCode)); String errorText = GetErrorText(); Trace.WriteLineIf((errorText != null), errorText); return(false); } } return(true); } catch (Exception exception) { Trace.WriteLine(exception); } TraceUtilities.WriteMethodError(MethodBase.GetCurrentMethod()); return(false); }
//FUNCTIONS protected virtual Boolean CloseServerConnection() { try { ReturnCode = MvxSock.Close(ref serverId); if (ReturnCode.Value == 0) { return(true); } else { Trace.WriteLine(String.Format("The 'MvxSock.Close' method retured non zero code:{0}", ReturnCode)); } } catch (Exception exception) { Trace.WriteLine(exception.ToString()); } TraceUtilities.WriteMethodError(MethodBase.GetCurrentMethod()); ReturnCode = null; return(false); }
//METHODS public virtual Boolean ExecuteProcess() { try { if (ApiData == null) { throw new InvalidOperationException("'ApiData' cannot be null."); } if (ApiData.Api == null) { throw new InvalidOperationException("'ApiData.Api' cannot be null"); } if (ConnectionData == null) { throw new InvalidOperationException("'ConnectionData' cannot be null."); } if (ConnectionData.Password == null) { throw new InvalidOperationException("'ConnectionData.Password' cannot be null."); } if (ConnectionData.Port == 0) { throw new InvalidOperationException("'ConnectionData.Port' cannot be 0."); } if (ConnectionData.Server == null) { throw new InvalidOperationException("'ConnectionData.Server' cannot be null."); } if (ConnectionData.UserName == null) { throw new InvalidOperationException("'ConnectionData.UserName' cannot be null."); } if (InputFieldDataList == null) { throw new InvalidOperationException("RequestFieldDataList cannot be null."); } if (InputFieldDataList.Count == 0) { throw new InvalidOperationException("RequestFieldDataList.Count cannot be 0."); } serverId = new SERVER_ID(); if (!ConnectToServer()) { CloseServerConnection(); return(false); } if (!SetMaximumWaitTime()) { CloseServerConnection(); return(false); } if (!SetRequestFields()) { CloseServerConnection(); return(false); } if (!ExecuteApi()) { CloseServerConnection(); return(false); } if (!GetOutputFieldData()) { CloseServerConnection(); return(false); } CloseServerConnection(); return(true); } catch (Exception exception) { Trace.WriteLine(exception.ToString()); } TraceUtilities.WriteMethodError(MethodBase.GetCurrentMethod()); return(false); }
//METHODS public virtual Boolean ExecuteProcess() { try { Boolean returnState = false; while ((ExecutionsAttempted <= ExecutionsToAttempt) && (!returnState)) { if (ExecutionsAttempted > 1) { System.Threading.Thread.Sleep(random.Next((Int32)MinimumTimeToWaitBetweenRetries, (Int32)MaximumTimeToWaitBetweenRetries)); Trace.WriteLine(String.Format("Attempting to retry the API call. Execution Attempt:{0}", ExecutionsAttempted)); } if (ApiData == null) { throw new InvalidOperationException("ApiData can not be null."); } if (ConnectionData == null) { throw new InvalidOperationException("ConnectionData can not be null."); } if (RequestFieldDataList == null) { throw new InvalidOperationException("RequestFieldDataList can not be null."); } if (!ValidateInputs()) { return(false); } returnCode = null; serverId = new SERVER_ID(); ExecutionsAttempted++; if (!ConnectToServer()) { CloseServerConnection(); continue; } if (EnableZippedTransactions) { if (!SetEnableZippedTransactions()) { CloseServerConnection(); continue; } } if (!SetMaximumRecordsForApiToReturn()) { CloseServerConnection(); continue; } if (!SetMaximumWaitTime()) { CloseServerConnection(); continue; } if (!SetRequestFields()) { CloseServerConnection(); continue; } if (!ExecuteApi()) { CloseServerConnection(); continue; } if (ReturnCode.Value == 0) { if (!ProcessApiResults()) { CloseServerConnection(); continue; } } CloseServerConnection(); returnState = true; } return(returnState); } catch (Exception exception) { Trace.WriteLine(exception.ToString()); } TraceUtilities.WriteMethodError(MethodBase.GetCurrentMethod()); return(false); }