Ejemplo n.º 1
0
        public ModelBasic readModel(BinaryReader reader)
        {
            ModelBasic model     = null;
            string     nameSpace = readString(reader);

            Type modelCls = ContextUtil.getInstance(null).getModel(nameSpace);

            model = (ModelBasic)System.Activator.CreateInstance(modelCls);
            int len = reader.ReadInt32();

            string       fieldName;
            PropertyInfo property;

            for (int loop = 0; loop < len; loop++)
            {
                fieldName = readString(reader);
                object param = readAll(reader);

                property = modelCls.GetProperty(fieldName);
                property.SetValue(model, param, null);
            }

            return(model);
        }
Ejemplo n.º 2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        byte[] byteData = null;
        try
        {
            if (context == null)
            {
                context = ContextUtil.getInstance(Server.MapPath("."));
                encrypt = context.getOuterEncrypt();
            }

            if (encoder == null)
            {
                encoder = ParamEncoder.getInstance();
            }
            if (decoder == null)
            {
                decoder = ParamDecoder.getInstance();
            }

            encoder.outEncoder = context.getOuterResolve();
            decoder.outDecoder = context.getOuterResolve();

            Stream input = Request.InputStream;

            if (input.CanRead)
            {
                byteData = new byte[input.Length];
                input.Read(byteData, 0, (int)input.Length);
                input.Close();
                input.Dispose();

                // 解密
                if (encrypt != null)
                {
                    byteData = encrypt.decrypt(byteData);
                }

                dataVo = decoder.decoder(byteData);
                Type serviceCls = context.getService(context.getServiceNameSpace() + "." + dataVo.ServiceName);

                MethodInfo method = serviceCls.GetMethod(dataVo.MethodName);

                object result = method.Invoke(System.Activator.CreateInstance(serviceCls), dataVo.Param);

                dataVo.Result       = result;
                dataVo.ResultStatus = "success";
                byte[] resultData = encoder.encode(dataVo);

                if (encrypt != null)
                {
                    resultData = encrypt.encrypt(resultData);
                }

                output = Response.OutputStream;
                output.Write(resultData, 0, resultData.Length);
                output.Flush();
                output.Close();
                output.Dispose();
            }
            else
            {
            }
        }
        catch (Exception exc)
        {
            if (dataVo == null && byteData != null)
            {
                dataVo = decoder.decoder(byteData);
            }
            if (dataVo == null)
            {
                dataVo = new DataVO();
            }
            dataVo.ResultStatus = "error";
            dataVo.ErrorMessage = exc.ToString();
            byte[] resultData = encoder.encode(dataVo);

            if (encrypt != null)
            {
                resultData = encrypt.encrypt(resultData);
            }
            output = Response.OutputStream;
            output.Write(resultData, 0, resultData.Length);
            output.Flush();
            output.Close();
            output.Dispose();
        }
    }