Exemplo n.º 1
0
        private static dynamic ExecuteMethod(string method, params object[] obj)
        {
            IPowerQueryService powerQueryService = null;

            TimeSpan ipcTimeout;
            string   ipcAddress;

            using (var keyPQ = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\PowerQueryNet"))
            {
                if (keyPQ == null)
                {
                    throw new Exception("PowerQueryNet was not found. Please install the application first.");
                }

                ipcTimeout = TimeSpan.Parse(keyPQ.GetValue("IpcTimeout").ToString());
                ipcAddress = keyPQ.GetValue("IpcAddress").ToString();
            }

            NetNamedPipeBinding binding         = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None);
            EndpointAddress     endpointAddress = new EndpointAddress(ipcAddress);

            binding.SendTimeout            = ipcTimeout;
            binding.ReceiveTimeout         = ipcTimeout;
            binding.OpenTimeout            = ipcTimeout;
            binding.CloseTimeout           = ipcTimeout;
            binding.MaxBufferPoolSize      = 2147483647;
            binding.MaxBufferPoolSize      = 2147483647;
            binding.MaxReceivedMessageSize = 2147483647;
            powerQueryService = ChannelFactory <IPowerQueryService> .CreateChannel(binding, endpointAddress);

            if (method == "Execute")
            {
                var powerQueryCommand = (PowerQueryCommand)obj[0];
                powerQueryCommand.TempPath = System.IO.Path.GetTempPath();
                var executeResponse = powerQueryService.Execute(powerQueryCommand);
                executeResponse.LoadReturnValues(powerQueryCommand.ExecuteOutputFlags);

                return(executeResponse);
            }
            else if (method == "MashupFromFile")
            {
                return(powerQueryService.MashupFromFile((string)obj[0]));
            }
            else
            {
                throw new NotImplementedException(string.Format("Method '{0}' is not implemented.", method));
            }
        }
        private static dynamic ExecuteMethod(string method, params object[] obj)
        {
            IPowerQueryService powerQueryService = null;

            TimeSpan ipcTimeout;
            string   ipcAddress;

            //using (var keyPQ = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432Node\PowerQueryNet"))
            using (var keyPQ = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\PowerQueryNet"))
            {
                if (keyPQ == null)
                {
                    throw new Exception("PowerQueryNet was not found. Please install the application first.");
                }

                ipcTimeout = TimeSpan.Parse(keyPQ.GetValue("IpcTimeout").ToString());
                ipcAddress = keyPQ.GetValue("IpcAddress").ToString();
            }

            NetNamedPipeBinding binding         = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None);
            EndpointAddress     endpointAddress = new EndpointAddress(ipcAddress);

            binding.SendTimeout            = ipcTimeout;
            binding.ReceiveTimeout         = ipcTimeout;
            binding.OpenTimeout            = ipcTimeout;
            binding.CloseTimeout           = ipcTimeout;
            binding.MaxReceivedMessageSize = 2147483647;
            powerQueryService = ChannelFactory <IPowerQueryService> .CreateChannel(binding, endpointAddress);

            if (method == "Execute")
            {
                return(powerQueryService.Execute((ExecuteRequest)obj[0]));
            }
            //else if (method == "ExecuteToSQL")
            //    return powerQueryService.ExecuteToSQL((string)obj[0], (string)obj[1], (Queries)obj[2], (Credentials)obj[3]);
            else if (method == "MashupFromFile")
            {
                return(powerQueryService.MashupFromFile((string)obj[0]));
            }
            else
            {
                throw new NotImplementedException(string.Format("Method '{0}' is not implemented.", method));
            }
        }