Пример #1
0
        public InvokeResponse Build()
        {
            if (this.invokeRequest.M == null || this.invokeRequest.I == null || this.invokeRequest.V == null)
            {
                throw new ArgumentException();
            }

            var obj         = this.session.Instantiate(this.invokeRequest.I);
            var composite   = (Composite)obj.Strategy.Class;
            var methodTypes = composite.MethodTypesByGroup[@group];
            var methodType  = methodTypes.FirstOrDefault(x => x.Name.Equals(this.invokeRequest.M));

            if (methodType == null)
            {
                throw new Exception("Method " + this.invokeRequest.M + " not found.");
            }

            var invokeResponse = new InvokeResponse();

            if (!this.invokeRequest.V.Equals(obj.Strategy.ObjectVersion.ToString()))
            {
                invokeResponse.AddVersionError(obj);
            }
            else
            {
                var acl = new AccessControlList(obj, this.user);
                if (acl.CanExecute(methodType))
                {
                    var method = obj.GetType().GetMethod(methodType.Name, new Type[] { });
                    method.Invoke(obj, null);

                    var derivationLog = this.session.Derive();
                    if (!derivationLog.HasErrors)
                    {
                        this.session.Commit();
                    }
                    else
                    {
                        invokeResponse.AddDerivationErrors(derivationLog);
                    }
                }
                else
                {
                    invokeResponse.AddAccessError(obj);
                }
            }

            return(invokeResponse);
        }
Пример #2
0
        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);
        }
        public InvokeResponse Build()
        {
            if (this.invokeRequest.M == null || this.invokeRequest.I == null || this.invokeRequest.V == null)
            {
                throw new ArgumentException();
            }

            var obj         = this.session.Instantiate(this.invokeRequest.I);
            var composite   = (Composite)obj.Strategy.Class;
            var methodTypes = composite.WorkspaceMethodTypes;
            var methodType  = methodTypes.FirstOrDefault(x => x.Name.Equals(this.invokeRequest.M));

            if (methodType == null)
            {
                throw new Exception("Method " + this.invokeRequest.M + " not found.");
            }

            var invokeResponse = new InvokeResponse();

            if (!this.invokeRequest.V.Equals(obj.Strategy.ObjectVersion.ToString()))
            {
                invokeResponse.AddVersionError(obj);
            }
            else
            {
                var acl = new AccessControlList(obj, this.user);
                if (acl.CanExecute(methodType))
                {
                    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;
                    }

                    var validation = this.session.Derive();
                    if (!validation.HasErrors)
                    {
                        this.session.Commit();
                    }
                    else
                    {
                        invokeResponse.AddDerivationErrors(validation);
                    }
                }
                else
                {
                    invokeResponse.AddAccessError(obj);
                }
            }

            return(invokeResponse);
        }
Пример #4
0
        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);
        }