コード例 #1
0
        public static int Main(string[] args)
        {
            // hook API logger
            Logger.SetLogSink(HandleLogEntry);

            try
            {
                string ncHostname = "JoshVM-2003";
                int    ncPort     = 80;

                using (IServerSession ncSession = CSAPI.Create().CreateServerSession(ncHostname, ncPort))
                {
                    if (!Authenticate(ncSession))
                    {
                        return(-1);
                    }

                    Console.Write("Creating proxied connection...");
                    INodeConnection playerConn;
                    using (var result = ncSession.CreateProxiedConnectionToNode((Oid)PLAYER_NODE_ID))
                    {
                        if (result.IsSuccess)
                        {
                            Console.WriteLine("success");
                            playerConn = result.Value;
                        }
                        else
                        {
                            Console.WriteLine("failed: " + result.ToString());
                            return(-2);
                        }
                    }

                    Console.Write("Querying proxied node info...");
                    playerConn.SocketTimeout = 30;
                    using (var result = playerConn.ExecuteCommand("Coolsign.System.GetInfo", null))
                    {
                        if (result.IsSuccess)
                        {
                            Console.WriteLine("success" + Console.Out.NewLine + result.ReadBody());
                        }
                        else
                        {
                            Console.WriteLine("failed: " + result.ToString());
                            return(-3);
                        }
                    }
                }

                return(0);
            }
            finally
            {
                Console.WriteLine("Press enter to continue...");
                Console.ReadLine();

                // unhook logger
                Logger.SetLogSink(null);
            }
        }