private bool Invoke(Invocation invocation, InvokeResponse invokeResponse) { if (invocation.M == null || invocation.I == null || invocation.V == null) { throw new ArgumentException(); } var obj = this.session.Instantiate(invocation.I); if (obj == null) { invokeResponse.AddMissingError(invocation.I); return(true); } var composite = (Composite)obj.Strategy.Class; var methodTypes = composite.WorkspaceMethodTypes; var methodType = methodTypes.FirstOrDefault(x => x.Name.Equals(invocation.M)); if (methodType == null) { throw new Exception("Method " + invocation.M + " not found."); } if (!invocation.V.Equals(obj.Strategy.ObjectVersion.ToString())) { invokeResponse.AddVersionError(obj); return(true); } var acl = new AccessControlList(obj, this.user); if (!acl.CanExecute(methodType)) { invokeResponse.AddAccessError(obj); return(true); } var method = obj.GetType().GetMethod(methodType.Name, new Type[] { }); try { method.Invoke(obj, null); } catch (Exception e) { var innerException = e; while (innerException.InnerException != null) { innerException = innerException.InnerException; } invokeResponse.ErrorMessage = innerException.Message; return(true); } var validation = this.session.Derive(false); if (validation.HasErrors) { invokeResponse.AddDerivationErrors(validation); return(true); } return(false); }
private bool Invoke(Invocation invocation, InvokeResponse invokeResponse) { // TODO: M should be a methodTypeId instead of the methodName if (invocation.m == null || invocation.i == null || invocation.v == null) { throw new ArgumentException(); } var obj = this.session.Instantiate(invocation.i); if (obj == null) { invokeResponse.AddMissingError(invocation.i); return(true); } var composite = (Composite)obj.Strategy.Class; var methodTypes = composite.WorkspaceMethodTypes; var methodType = methodTypes.FirstOrDefault(x => x.Id.Equals(Guid.Parse(invocation.m))); if (methodType == null) { throw new Exception("Method " + invocation.m + " not found."); } if (!invocation.v.Equals(obj.Strategy.ObjectVersion.ToString())) { invokeResponse.AddVersionError(obj); return(true); } var acl = this.acls[obj]; if (!acl.CanExecute(methodType)) { invokeResponse.AddAccessError(obj); return(true); } var method = obj.GetType().GetMethod(methodType.Name, new Type[] { }); try { method.Invoke(obj, null); } catch (Exception e) { var innerException = e; while (innerException.InnerException != null) { innerException = innerException.InnerException; } invokeResponse.errorMessage = innerException.Message; return(true); } var validation = this.session.Derive(false); if (validation.HasErrors) { invokeResponse.AddDerivationErrors(validation); return(true); } return(false); }