Ejemplo n.º 1
0
        private DataPacket PassThrough(DataPacket item)
        {
            Type modelType = Type.GetType(item.Typename);

            if (modelType == null)
            {
                item.SetError(500, String.Format("Could not resolve the type: '{0}'", item.Typename));
            }
            else
            {
                Type       contracts              = typeof(IDataRequestService);
                MethodInfo dataRequestContracts   = contracts.GetMethod(item.ModelAction.ToString());
                MethodInfo standardContractMethod = dataRequestContracts.MakeGenericMethod(modelType);
                var        mT          = typeof(Message <>);
                var        closedModel = mT.MakeGenericType(new Type[] { modelType });
                dynamic    message     = Activator.CreateInstance(closedModel, item.Items);
                message.Criterion = item.Criteria;

                if (verbsWithModel.Contains(item.ModelAction) && item.Buffer != null)
                {
                    object model = GenericSerializer.ByteArrayToItem(item.Buffer);
                    //var m = Convert.ChangeType(model, modelType);
                    message.TryAdd(model);
                    //message.Content.Insert(0, m);
                }
                InvokeStandardContract(DataService, standardContractMethod, new object[1] {
                    message
                }, item);
            }

            return(item);
        }
Ejemplo n.º 2
0
        private DataPacket PassThrough(DataPacket item)
        {
            Type modelType = Type.GetType(item.Typename);

            if (modelType != null)
            {
                bool        b     = false;
                List <Type> types = new List <Type>();
                types.Add(modelType);
                if (!String.IsNullOrEmpty(item.SecondaryTypename))
                {
                    b = true;
                    Type secondaryType = Type.GetType(item.SecondaryTypename);
                    types.Add(secondaryType);
                }
                Type       contracts              = typeof(IDataRequestService);
                MethodInfo dataRequestContracts   = contracts.GetMethod(item.ModelAction.ToString());
                MethodInfo standardContractMethod = dataRequestContracts.MakeGenericMethod(types.ToArray());
                var        mT = !b ? typeof(Message <>) : typeof(Message <,>);
                //var closedModel = mT.MakeGenericType(new Type[] { modelType });
                var     closedModel = mT.MakeGenericType(types.ToArray());
                dynamic message     = Activator.CreateInstance(closedModel, item.Items);
                message.Criterion = item.Criteria;

                if (verbsWithModel.Contains(item.ModelAction) && item.Buffer != null)
                {
                    object model = GenericSerializer.ByteArrayToItem(item.Buffer);
                    message.InsertContent(model);
                }
                else if (item.ModelAction.Equals(ModelActionOption.ExecuteMany) && item.Buffer != null)
                {
                    dynamic list = GenericSerializer.ByteArrayToItem(item.Buffer);
                    message.InsertContentList(list);
                }
                else if (item.ModelAction.Equals(ModelActionOption.ExecuteCommand) && item.Tables != null)
                {
                    message.Data = item.Tables;
                }
                InvokeStandardContract(DataService, standardContractMethod, new object[1] {
                    message
                }, item);
            }
            else
            {
                item.SetError(500, String.Format("The GenericService could not resolve type '{0}'.\r\nMake certain the 'Model' dll is accessible", item.Typename));
            }


            return(item);
        }
Ejemplo n.º 3
0
        private DataPacket PassThroughRpc(DataPacket item)
        {
            Type modelType = Type.GetType(item.Typename);

            if (modelType != null)
            {
                string returnTypename = item.Criteria.GetValue <string>(XFConstants.Application.ActionResultModelType);
                Type   returnType     = Type.GetType(returnTypename);

                if (returnType != null)
                {
                    Type       contracts            = typeof(IRpcDataRequestService);
                    MethodInfo dataRequestContracts = contracts.GetMethod("ExecuteRpc");

                    MethodInfo standardContractMethod = dataRequestContracts.MakeGenericMethod(modelType, returnType);
                    var        mT          = typeof(Message <,>);
                    var        closedModel = mT.MakeGenericType(new Type[] { modelType, returnType });
                    dynamic    message     = Activator.CreateInstance(closedModel, item.Items);
                    message.Criterion = item.Criteria;

                    object model = GenericSerializer.ByteArrayToItem(item.Buffer);
                    message.InsertContent(model);

                    InvokeStandardContract(RpcDataService, standardContractMethod, new object[1] {
                        message
                    }, item);
                }
                else
                {
                    string message = String.Format("The RpcService could not resolve type '{0}'.\r\nMake certain the 'Model' dll is accessible", returnTypename);
                    item.SetError(500, message);
                    EventWriter.WriteError(message, SeverityType.Error);
                }
            }
            else
            {
                string message = String.Format("The RpcService could not resolve type '{0}'.\r\nMake certain the 'Model' dll is accessible", item.Typename);
                item.SetError(500, message);
                EventWriter.WriteError(message, SeverityType.Error);
            }

            return(item);
        }