public int connectToServer(int port, DXChild c)
        {
            bool wasQueued = false;
            String server;

            if (c != null)
            {
                server = c.getServer();
                if (!c.IsQueued)
                {
                    serverInfo.children.Remove(c);
                    c.unQueue();
                }
            }
            else
            {
                server = serverInfo.server;
            }
            DXPacketIF p = new DXPacketIF(server, port, DXChild.HostIsLocal(server));
            if (DXApplication.resource.debugMode)
                p.setEchoCallback(DXApplication.DebugEchoCallback, "need to get stderr");

            if (p.Error)
            {
                ErrorDialog ed = new ErrorDialog();
                ed.post("Connection to {0} failed.", server);
                p = null;
                return 0;
            }

            clearErrorList();
            if (serverInfo.packet == null)
            {
                if (wasQueued)
                {
                    InfoDialog id = new InfoDialog();
                    id.post("Your connection to {0} has been accepted.", server);
                }
                packetIFAccept(p);
            }
            else
            {
                serverInfo.queuedPackets.Insert(0, p);
                QuestionDialog qd = new QuestionDialog();
                String s = String.Format("Your connection to server {0} has been accepted. Do you want to disconnect from {0} and connect to it?",
                    server, serverInfo.server);
                qd.modalPost(this.getAnchorForm(), s, null, p, DXApplication.QueuedPacketAccept,
                    DXApplication.QueuedPacketCancel, null, "Yes", "No", null, 2);

            }
            return 1;
        }
 public void closeConnection(DXChild c)
 {
     throw new Exception("Not Yet Implemented");
 }
        public void completeConnection(DXChild c)
        {
            if (c != null)
            {
                switch (c.waitForConnection())
                {
                    case -1:
                        ErrorDialog ed = new ErrorDialog();
                        ed.post("Connection to server {0} failed: {1}",
                            c.getServer(), c.failed());
                        closeConnection(c);
                        break;
                    case 0:
                        if (resource.executeProgram)
                            getExecCtl().executeOnce();
                        break;
                    case 1:
                        InfoDialog id = new InfoDialog();
                        id.post("Connection to server {0} has been queued", c.getServer());
                        break;
                }
            }
            else if (!serverInfo.autoStart)
            {
                connectToServer(serverInfo.port, null);
            }

            // Let the application packet know that a new connection to
            // the server has been created.
            if (applicationPacket != null)
                applicationPacket.handleServerConnection();

            if (resource.executeOnChange)
                getExecCtl().enableExecOnChange();
        }
        public DXChild startServer()
        {
            List<String> args = new List<String>();
            int i = 0;

            args.Add("dx");

            if (serverInfo.autoStart)
            {
                args.Add("-exonly");
                args.Add("-local");

                if (serverInfo.memorySize > 0)
                {
                    args.Add("-memory");
                    args.Add(serverInfo.memorySize.ToString());
                }

                if (serverInfo.executive != null)
                {
                    serverInfo.executive.Trim();
                    if (serverInfo.executive.Length > 0)
                    {
                        args.Add("-exec");
                        args.Add(serverInfo.executive);
                    }
                }

                if (serverInfo.workingDirectory != null)
                {
                    serverInfo.workingDirectory.Trim();
                    if (serverInfo.workingDirectory.Length > 0)
                    {
                        args.Add("-directory");
                        if (serverInfo.workingDirectory.Contains(" ") &&
                            !serverInfo.workingDirectory.Contains("\""))
                            args.Add("\"" + serverInfo.workingDirectory + "\"");
                        else
                            args.Add(serverInfo.workingDirectory);
                    }
                }

                if (serverInfo.userModules != null &&
                    serverInfo.userModules.Length > 0)
                {
                    args.Add("-mdf");
                    args.Add(serverInfo.userModules);
                }

                if (serverInfo.executiveFlags != null)
                {
                    serverInfo.executiveFlags.Trim();
                    if (serverInfo.executiveFlags.Length > 0)
                        args.Add(serverInfo.executiveFlags);
                }

                String[] argArr = new String[args.Count];
                for (int j = 0; j < args.Count; j++)
                    argArr[j] = args[j];

                DXChild c = new DXChild(serverInfo.server, argArr, false);
                if (c.failed() != null)
                {
                    argArr[0] = this.getUIRoot() + "/bin/dx";
                    c = new DXChild(serverInfo.server, argArr, false);
                }

                serverInfo.children.Insert(0, c);
                return c;
            }
            else
                return null;
        }