internal ProxyRequestAction(object caller, IDataBoundObject target, string methodType, string methodName, object[] parameters) { Caller = caller; Target = target; MethodType = methodType; MethodName = methodName; Parameters = parameters; }
/// <summary> /// Creates a data adapter and associates it with the data objects's commands. /// </summary> /// /// <param name="dataObj"> /// A data bound object (<see cref="DataItem"/> or <see cref="DataItemCollection"/>). /// </param> /// /// <returns> /// A <see cref="Pervasive.Data.SqlClient.SqlDataAdapter"/> object associated with the /// <see cref="PT.Data.IDataBoundObject"/>'s commands. /// </returns> internal static SqlDataAdapter CreateAdapter(IDataBoundObject dataObj) { SqlDataAdapter adapter = new SqlDataAdapter(); adapter.SelectCommand = dataObj.SelectCommand; adapter.InsertCommand = dataObj.InsertCommand; adapter.UpdateCommand = dataObj.UpdateCommand; adapter.DeleteCommand = dataObj.DeleteCommand; return(adapter); }
/// <summary> /// /// </summary> /// <param name="caller">The object on which to perform the method. Null if the method is static.</param> /// <param name="method">The method to perform on the caller, or statically.</param> /// <param name="target">The target DataItem that will contain the result. It is populated after</param> /// <param name="parameters"></param> /// <returns></returns> public ProxyRequestAction AddAction(object caller, MethodBase method, IDataBoundObject target, object[] parameters) { ProxyRequestAction action = new ProxyRequestAction(caller, target, method.DeclaringType.AssemblyQualifiedName, method.Name, parameters); _actions.Add(action); //if (target != null) // target.ActionIndex = _actions.IndexOf(action); action.ActionIndex = _actions.IndexOf(action); return(action); }
/// <summary> /// Manages connection open based on sequence. /// </summary> /// /// <param name="dataObj">If not null, associates the connection with the object's data commands.</param> /// /// <returns> /// When opening a new connection, an object that can be used to close the connection. /// Null if the connection is already open. /// </returns> public ConnectionKey OpenConnection(IDataBoundObject dataObj, SqlConnection externalConnection) { //Check for a valid connection string if (externalConnection == null && (_connectionString == "" || _connectionString == null)) { return(null); } // This is the key used to close the connection. ConnectionKey key = null; // If a connection doesn't exist, open a new one // (second condition is just in case, should never happen because we nullify the connection when closing it) if (_connection == null || _connection.State == ConnectionState.Closed) { if (externalConnection != null) { _connection = externalConnection; } else { _connection = new SqlConnection(_connectionString); key = new ConnectionKey(); } } // Associate the data bound object's commands with the current connection if (dataObj != null) { SetActiveConnection(dataObj); } if (key != null) { _connectionKey = key; _connection.Open(); } return(key); }
/// <summary> /// Sets the active connection of a data object. /// </summary> /// /// <param name="dataObj"> /// A data bound object (<see cref="DataItem"/> or <see cref="DataItemCollection"/>) /// </param> /// /// <remarks> /// The method associates the data bound object's commands with the active /// connection and transaction of the current thread's data context. /// </remarks> private static void SetActiveConnection(IDataBoundObject dataObj) { if (dataObj.SelectCommand != null) { dataObj.SelectCommand.Connection = DataManager.Current.Connection; } if (dataObj.InsertCommand != null) { dataObj.InsertCommand.Connection = DataManager.Current.Connection; } if (dataObj.UpdateCommand != null) { dataObj.UpdateCommand.Connection = DataManager.Current.Connection; } if (dataObj.DeleteCommand != null) { dataObj.DeleteCommand.Connection = DataManager.Current.Connection; } //SetActiveTransaction(dataObj); }
public ProxyResult ProcessRequest(ProxyRequest request) { _instances.Add(OperationContext.Current, this); // Proxy result used to store the results of the actions ProxyResult result = new ProxyResult(request); _result = result; // Action loop for (int currentIndex = 0; currentIndex < request.Actions.Count; currentIndex++) { ProxyRequestAction action = request.Actions[currentIndex]; CurrentAction = action; try { // Replace proxy object parameters with actual values (from previous actions) for (int p = 0; p < action.Parameters.Length; p++) { if (action.Parameters[p] is IDataBoundObject) { IDataBoundObject o = (IDataBoundObject)action.Parameters[p]; if (o.ProxyActionIndex < currentIndex) { // Parameter is a proxy object referencing a previous step, so replace with that step's result action.Parameters[p] = result[o.ProxyActionIndex].ReturnValue; } else { throw new InvalidOperationException(String.Format("Cannot execute action #{0} because it requires the result of action #{1}", currentIndex, o.ProxyActionIndex)); } } } // Get the method to invoke Type targetType = action.Caller != null?action.Caller.GetType() : Type.GetType(action.MethodType); MethodInfo method = targetType.GetMethod(action.MethodName, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); // Perform the action and store the result object val = method.Invoke(action.Caller, action.Parameters); result[currentIndex].ReturnValue = val; } catch (Exception ex) { result[currentIndex].ReturnValue = ex is TargetInvocationException ? ((TargetInvocationException)ex).InnerException : ex; // If request is specified as a transaction, break execution if (request.StopOnError) { break; } } } // Done, remove from static results and return _result = null; this.CurrentAction = null; _instances.Remove(OperationContext.Current); return(result); }
public ConnectionKey OpenConnection(IDataBoundObject dataObj) { return(OpenConnection(dataObj, null)); }