コード例 #1
0
        /// <summary>
        /// Executes the command, using the DataObjectFactory&lt;T&gt; class and serializes the result
        /// to the stream provided.
        /// </summary>
        /// <param name="stream">The stream the result will be serialized to.</param>
        /// <param name="command">The command to execute.</param>
        public static void ProcessCommand(Stream stream, FactoryTransferObject <T> command)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }

            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            Type factoryType = typeof(DataObjectFactory <T>);
            Type returnType  = GetReturnType(typeof(T), command.Command);

            MethodInfo method = factoryType.GetMethod(command.Command, BindingFlags.Public | BindingFlags.Static, null, command.GetAllParameterTypes(), null);
            object     value;

            switch (command.Command)
            {
            case "CreateObjects":
                value = method.Invoke(null, command.GetAllParameters());
                break;

            case "CreateObject":
                value = method.Invoke(null, command.GetAllParameters());
                break;

            case "WriteObject":
                method.Invoke(null, command.GetAllParameters());
                value = new DtoObjectInsertedAck(DataObjectInfo <T> .GetPrimaryKeys(command.DataObject));
                break;

            case "DeleteObject":
                method.Invoke(null, command.GetAllParameters());
                value = new DtoServerAck();
                break;

            default:
                throw new ArgumentOutOfRangeException("command");
            }

            XmlSerializer serializer = new XmlSerializer(returnType);

            serializer.Serialize(stream, value);
        }
コード例 #2
0
        public static object SendRequest(string command, T dataObject, object[] args)
        {
            FactoryTransferObject <T> fto = new FactoryTransferObject <T>();

            fto.Command    = command;
            fto.DataObject = dataObject;
            fto.Parameters = args;

            byte[] buffer = RemotingClient.SendAndReceive(fto);            //this might throw an exception if server unavailable
            object value;

            using (MemoryStream memStream = new MemoryStream(buffer)) {
                Type returnType = FactoryServer <T> .GetReturnType(typeof(T), command);

                XmlSerializer serializer = new XmlSerializer(returnType);
                value = serializer.Deserialize(memStream);
            }

            return(value);
        }