Exemplo n.º 1
0
        private static MaximoResult DoExecuteCrud(OperationWrapper operationWrapper, IMaximoConnector connector)
        {
            if (!OperationConstants.IsCrud(operationWrapper.OperationName))
            {
                //custom operation
                return(null);
            }

            var crudConnector     = new MaximoCrudConnectorEngine((IMaximoCrudConnector)connector);
            var crudOperationData = (CrudOperationData)operationWrapper.OperationData(null);

            switch (operationWrapper.OperationName)
            {
            case OperationConstants.CRUD_CREATE:
                return(crudConnector.Create(crudOperationData));

            case OperationConstants.CRUD_UPDATE:
                return(crudConnector.Update(crudOperationData));

            case OperationConstants.CRUD_DELETE:
                return(crudConnector.Delete(crudOperationData));

            case OperationConstants.CRUD_FIND_BY_ID:
                return(crudConnector.FindById(crudOperationData));
            }

            return(null);
        }
        public MaximoResult InvokeCustomOperation(OperationWrapper operationWrapper)
        {
            var operationName  = operationWrapper.OperationName;
            var entityMetadata = operationWrapper.EntityMetadata;

            try {
                var mi = ReflectionUtil.GetMethodNamed(_connectorTemplate, operationName);
                if (mi == null)
                {
                    throw new InvalidOperationException(String.Format("operation {0} not found on entity {1}",
                                                                      operationName,
                                                                      entityMetadata.Name));
                }
                if (mi.GetParameters().Count() != 1)
                {
                    throw new InvalidOperationException(
                              String.Format(ErrorParameter, operationName, entityMetadata.Name));
                }
                var fp = mi.GetParameters().First();
                if (!typeof(OperationData).IsAssignableFrom(fp.ParameterType))
                {
                    throw new InvalidOperationException(
                              String.Format(ErrorParameter, operationName, entityMetadata.Name));
                }
                var param = operationWrapper.OperationData(fp.ParameterType);
                if (mi.ReturnType == typeof(void))
                {
                    mi.Invoke(_connectorTemplate, new object[] { param });
                    return(null);
                }
                var ob = mi.Invoke(_connectorTemplate, new object[] { param });
                if (ob is MaximoResult)
                {
                    return((MaximoResult)ob);
                }
                return(new MaximoResult(param.Id, ob));
            } catch (AmbiguousMatchException e) {
                throw new InvalidOperationException(
                          String.Format("multiples methods found for operation {0} on entity {1}. Unable to decide", operationName,
                                        entityMetadata.Name));
            }
        }