Example #1
0
        private void StartProxyWithCredentialJson(string platform, string instances, string tokenJson)
        {
            switch (platform)
            {
            case Platform_Linux_Arm64:
                statusCallbackReferenceLinux = new StaticProxy.StatusCallbackLinux(SetStatus);
                StaticProxy.StartProxyWithCredentialJsonLinuxArm64(Encoding.UTF8.GetBytes(instances), Encoding.UTF8.GetBytes(tokenJson), statusCallbackReferenceLinux);
                break;

            case Platform_Linux_64:
                statusCallbackReferenceLinux = new StaticProxy.StatusCallbackLinux(SetStatus);
                StaticProxy.StartProxyWithCredentialJsonLinux(Encoding.UTF8.GetBytes(instances), Encoding.UTF8.GetBytes(tokenJson), statusCallbackReferenceLinux);
                break;

            case Platform_Win_64:
                statusCallbackReference = new StaticProxy.StatusCallback(SetStatus);
                StaticProxy.StartProxyWithCredentialJsonx64(Encoding.UTF8.GetBytes(instances), Encoding.UTF8.GetBytes(tokenJson), statusCallbackReference);
                break;

            case Platform_Win_32:
                statusCallbackReference = new StaticProxy.StatusCallback(SetStatus);
                StaticProxy.StartProxyWithCredentialJsonx86(Encoding.UTF8.GetBytes(instances), Encoding.UTF8.GetBytes(tokenJson), statusCallbackReference);
                break;

            default:
                throw new Exception(Invalid_Platform);
            }
        }
Example #2
0
        /// <summary>
        /// Gets the <see cref="Status"/> of the Proxy.
        /// </summary>
        /// <exception cref="InvalidProxyException"></exception>
        public Status GetStatus(string instances)
        {
            if (!tcss.ContainsKey(instances))
            {
                throw new InvalidProxyException($"The proxy instance {instances} has not been started");
            }

            int status;

            switch (Platform)
            {
            case Platform_Linux_Arm64:
                status = StaticProxy.GetStatusLinuxArm64(Encoding.UTF8.GetBytes(instances));
                break;

            case Platform_Linux_64:
                status = StaticProxy.GetStatusLinux(Encoding.UTF8.GetBytes(instances));
                break;

            case Platform_Win_64:
                status = StaticProxy.GetStatusx64(Encoding.UTF8.GetBytes(instances));
                break;

            case Platform_Win_32:
                status = StaticProxy.GetStatusx86(Encoding.UTF8.GetBytes(instances));
                break;

            default:
                throw new Exception(Invalid_Platform);
            }

            return((Status)status);
        }
Example #3
0
        /// <summary>
        /// Stops all proxies.
        /// </summary>
        public void StopAll()
        {
            switch (Platform)
            {
            case Platform_Linux_Arm64:
                StaticProxy.StopAllLinuxArm64();
                break;

            case Platform_Linux_64:
                StaticProxy.StopAllLinux();
                break;

            case Platform_Win_64:
                StaticProxy.StopAllx64();
                break;

            case Platform_Win_32:
                StaticProxy.StopAllx86();
                break;

            default:
                throw new Exception(Invalid_Platform);
            }

            proxyCounter.Clear();
            tcss.Clear();
        }
Example #4
0
        /// <summary>
        /// Get the port number that the proxy is listening on.
        /// </summary>
        /// <exception cref="ProxyNotConnectedException">
        /// Thrown when function is called and proxy is not connected.
        /// </exception>
        /// <exception cref="InvalidProxyException">
        /// Thrown when function is called and proxy has not been started.
        /// </exception>
        /// <returns>Port number</returns>
        public int GetPort(string instances)
        {
            if (!tcss.ContainsKey(instances))
            {
                throw new InvalidProxyException($"The proxy instance {instances} has not been started");
            }

            if (GetStatus(instances) == Status.Connected)
            {
                switch (Platform)
                {
                case Platform_Linux_Arm64:
                    return(StaticProxy.GetPortLinuxArm64(Encoding.UTF8.GetBytes(instances)));

                case Platform_Linux_64:
                    return(StaticProxy.GetPortLinux(Encoding.UTF8.GetBytes(instances)));

                case Platform_Win_64:
                    return(StaticProxy.GetPortx64(Encoding.UTF8.GetBytes(instances)));

                case Platform_Win_32:
                    return(StaticProxy.GetPortx86(Encoding.UTF8.GetBytes(instances)));

                default:
                    throw new Exception(Invalid_Platform);
                }
            }
            else
            {
                // not connected yet, so port is unallocated.
                throw new ProxyNotConnectedException();
            }
        }
Example #5
0
        /// <summary>
        /// Stops the Proxy.
        /// <exception cref="ProxyNotConnectedException">
        /// Thrown when function is called and proxy is not connected.
        /// </exception>
        /// <exception cref="InvalidProxyException">
        /// Thrown when function is called and proxy has not been started.
        /// </exception>
        /// </summary>
        public void StopProxy(string instances)
        {
            if (!tcss.ContainsKey(instances))
            {
                return;
            }

            // only shut down once we know we don't have any more connections
            if (proxyCounter[instances] > 1)
            {
                proxyCounter[instances]--;
            }
            else
            {
                if (GetStatus(instances) == Status.Connected)
                {
                    switch (Platform)
                    {
                    case Platform_Linux_Arm64:
                        StaticProxy.StopProxyLinuxArm64(Encoding.UTF8.GetBytes(instances));
                        break;

                    case Platform_Linux_64:
                        StaticProxy.StopProxyLinux(Encoding.UTF8.GetBytes(instances));
                        break;

                    case Platform_Win_64:
                        StaticProxy.StopProxyx64(Encoding.UTF8.GetBytes(instances));
                        break;

                    case Platform_Win_32:
                        StaticProxy.StopProxyx86(Encoding.UTF8.GetBytes(instances));
                        break;

                    default:
                        throw new Exception(Invalid_Platform);
                    }

                    proxyCounter.TryRemove(instances, out _);
                    _ = tcss.TryRemove(instances, out _);
                }
                else
                {
                    // not connected yet, so port is unallocated.
                    throw new ProxyNotConnectedException();
                }
            }
        }
Example #6
0
        /// <summary>
        /// Echo from the go library, used to test the go library connectivity.
        /// </summary>
        /// <param name="message">message to send</param>
        public string Echo(string message)
        {
            switch (Platform)
            {
            case Platform_Linux_Arm64:
                return(Marshal.PtrToStringAnsi(StaticProxy.EchoLinuxArm64(Encoding.UTF8.GetBytes(message))));

            case Platform_Linux_64:
                return(Marshal.PtrToStringAnsi(StaticProxy.EchoLinux(Encoding.UTF8.GetBytes(message))));

            case Platform_Win_64:
                return(Marshal.PtrToStringAnsi(StaticProxy.Echox64(Encoding.UTF8.GetBytes(message))));

            case Platform_Win_32:
                return(Marshal.PtrToStringAnsi(StaticProxy.Echox86(Encoding.UTF8.GetBytes(message))));

            default:
                throw new Exception(Invalid_Platform);
            }
        }