Exemple #1
0
        internal static void SingularityIOError(ErrorCode code, String str)
        {
            string errString = SdsUtils.ErrorCodeToString(code);

            switch (code)
            {
            case ErrorCode.NotFound: {
                throw new FileNotFoundException(String.Format("FileNotFound: {0}", str));
            }

            default: {
                throw new IOException(String.Format("{0}: {1}", errString, str));
            }
            }
        }
        public static bool ConnectEndPoint(string !lookupName, [Claims] ServiceContract.Exp !ep)
        {
            DirectoryServiceContract.Imp epNS = DirectoryService.NewClientEndpoint();

            try {
                ErrorCode errorOut;
                bool      ok = SdsUtils.Bind(lookupName, epNS, ep, out errorOut);
                if (!ok)
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
//
//              epNS.SendBind(Microsoft.Singularity.Bitter.FromString2(lookupName), ep);
//
//              switch receive {
//                  case epNS.NakBind(ServiceContract.Exp:Start rejectedEP, error) :
//                      // failure
//                      delete rejectedEP;
//                      return false;
//                      break;
//
//                  case epNS.AckBind() :
//                      // success
//                      return true;
//                      break;
//
//                  case epNS.ChannelClosed() :
//                      // failure
//                      return false;
//              }
//
            }
            finally {
                delete epNS;
            }
        }
Exemple #3
0
        internal static int AppMain(Parameters !config)
        {
            bool verbose = config.verbose;
            bool silent  = config.silent;

            string virtualPath = config.virtualPath;

            if (virtualPath != null)
            {
                virtualPath = virtualPath.Trim();
            }
            if ((virtualPath == null) || (virtualPath.Length == 0))
            {
                virtualPath = "/";
            }
            else
            {
                if (virtualPath.StartsWith("/") == false)
                {
                    if (!silent)
                    {
                        ShowUsage();
                    }
                    return(-1);
                }
            }

            string physicalPath = "\\";
            //
            //TODO: HACKHACK FIXME: the file system is not wired up
            //in Singularity; avoid using it!
//
            //string physicalPath = (string)commandLine.Options["path"];
            //if (physicalPath != null) {
            //  physicalPath = physicalPath.Trim();
            //}
            //if ((physicalPath == null) || (physicalPath.Length == 0)) {
            //  if (!silent) {
            //      ShowUsage();
            //  }
            //  return -1;
            //}
            //else {
            //  if (Directory.Exists(physicalPath) == false) {
            //      if (!silent) {
            //          ShowMessage("The physical path '"+ physicalPath + "' does not exist!");
            //      }
            //      return -2;
            //  }
//
            //  // added this to resolve paths like "."
            //  physicalPath = Path.GetFullPath(physicalPath);
            //}
            //

            int    port     = 0;
            string portText = config.portString;

            if (portText != null)
            {
                portText = portText.Trim();
            }
            if ((portText != null) && (portText.Length != 0))
            {
                try {
                    port = Int32.Parse(portText);
                    if ((port < 1) || (port > 65535))
                    {
                        if (!silent)
                        {
                            ShowUsage();
                        }
                        return(-1);
                    }
                }
                catch {
                    if (!silent)
                    {
                        ShowMessage("Invalid port '" + portText + "'");
                    }
                    return(-3);
                }
            }
            else
            {
                port = 80;
            }

            // clientIP was added so that we could test using Cassini remotely on
            // lab machines. This now allows the client to be localhost or clientIP.
            string clientIP = config.client;

            if (clientIP != null)
            {
                clientIP = clientIP.Trim();
            }
            if ((clientIP == null) || (clientIP.Length == 0))
            {
                clientIP = "localhost";
            }

            //
            // Singularity-specific initialization
            //
            string webApp  = config.app;
            bool   quitURL = config.quitURL;

            // FIXME: should generalize this so more than one arg can be passed to
            // the webapp!
            string[] appArgs = null;

            if (config.appArg != null)
            {
                appArgs    = new string[1];
                appArgs[0] = config.appArg;
            }

            if ((webApp == null) || (webApp.Length == 0))
            {
                webApp = "HelloWebApp";
            }

            webApp.Trim();

            // If a nsPath was provide, then connect to the client.
            if (config.nsPath != null)
            {
                Console.WriteLine("Cassini: Connecting to {0}.", config.nsPath);
                DirectoryServiceContract.Imp !dsImp = config.nsRef.Acquire();
                dsImp.RecvSuccess();

                WebAppContract.Imp !waImp;
                WebAppContract.Exp !waExp;
                WebAppContract.NewChannel(out waImp, out waExp);

                ErrorCode error;
                if (!SdsUtils.Bind(config.nsPath, dsImp, waExp, out error))
                {
                    DebugStub.WriteLine("Failed to bind to webapp store...error {0}\n",
                                        __arglist(SdsUtils.ErrorCodeToString(error)));
                    Console.WriteLine("Failed to bind to webapp store...error {0}\n",
                                      SdsUtils.ErrorCodeToString(error));

                    delete dsImp;
                    delete waImp;
                    return(-1);
                }
                delete dsImp;

                waImp.RecvWebAppReady();
                Dispatcher.BalanceConnection(waImp, config.load);
            }

            if (!Dispatcher.Initialize(webApp, appArgs, verbose, quitURL))
            {
                if (!silent)
                {
                    ShowMessage("Invalid web application name \"" + webApp + "\"");
                    return(-5);
                }
            }

            // ====================
            // Actually start the server below
            // ===================

            try {
                Server server = new Server(port, virtualPath, physicalPath, clientIP);
                server.Start();

                Console.WriteLine();
                Console.WriteLine("Running Web Server on port {0}.", port);
                Console.WriteLine("Application '{0}' is mapped to '{1}'.", virtualPath, physicalPath);
                Console.WriteLine("http://localhost:{0}{1}", port, virtualPath);

                // Currently no console-read support in Singularity. Run forever!
                //Console.WriteLine("Hit Enter to stop the server");
                //Console.ReadLine();
                //server.Stop();
            }
            catch (Exception ex) {
                if (!silent)
                {
                    ShowMessage("Error opening port " + port + ": " + ex.Message);
                }
                return(-5);
            }

            return(0);
        }