Exemplo n.º 1
0
        public static T Request <T>(string commandName, Server server,
                                    object arguments, out CommandResponse commandResponse, bool waitForResponse = true,
                                    ProxyRequestType requestType = ProxyRequestType.Xml, JsonSerializerSettings settings = null)
        {
            try
            {
                commandResponse = new CommandResponse();
                if (requestType == ProxyRequestType.Json)
                {
                    arguments = JsonConvert.SerializeObject(arguments);
                }
                if (!server.ModuleApiGateway.ExecuteModuleCommand(commandName, arguments, ref commandResponse,
                                                                  waitForResponse))
                {
                    throw new Exception("Proxy command execution failed.");
                }
                switch (requestType)
                {
                case ProxyRequestType.Xml:
                {
                    var xmlToObject = (T)ObjectXml.XmlToObject(commandResponse.Response.ToString(), typeof(T));
                    return(xmlToObject);
                }

                case ProxyRequestType.Json:
                    if (settings == null)
                    {
                        settings = Utilities.NoErrorJsonSettings;
                    }

                    Console.WriteLine("Respoinse = " + commandResponse.Response);
                    return(JsonConvert.DeserializeObject <T>(commandResponse.Response.ToString()));

                default:
                    throw new ArgumentOutOfRangeException(nameof(requestType), requestType, null);
                }
            }
            catch (Exception e)
            {
                Logger.Fatal(e);
                commandResponse = new CommandResponse {
                    SerializedException = e.Message
                };
                return(Activator.CreateInstance <T>());
            }
        }
Exemplo n.º 2
0
 public virtual void Request(object arguments, int serverId, out CommandResponse commandResponse,
                             ProxyRequestType requestType = ProxyRequestType.Xml)
 {
     ProxyManager.Request <object>(CommandName, new Server(serverId), arguments, out commandResponse, requestType: requestType);
 }
Exemplo n.º 3
0
 public virtual T Request <T>(object arguments, int serverId, out CommandResponse commandResponse,
                              ProxyRequestType requestType = ProxyRequestType.Xml)
 {
     return(ProxyManager.Request <T>(CommandName, Server.GetServerFromCache(serverId), arguments, out commandResponse, requestType: requestType));
 }
Exemplo n.º 4
0
 public virtual T Request <T>(object arguments, Server server, out CommandResponse commandResponse,
                              ProxyRequestType requestType = ProxyRequestType.Xml)
 {
     return(ProxyManager.Request <T>(CommandName, server, arguments, out commandResponse, requestType: requestType));
 }