Exemple #1
0
        bool TryProcessXapRequest(HttpSocket s, string path)
        {
            // must end with XAP
            if (string.Compare(Path.GetExtension(path), ".xap", StringComparison.OrdinalIgnoreCase) != 0)
            {
                return(false);
            }

            // XAP already there?
            if (File.Exists(path))
            {
                return(false);
            }

            // Directory must be present
            string dir = Path.GetDirectoryName(path) + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(path);

            if (!Directory.Exists(dir))
            {
                return(false);
            }

            byte[] xapBytes = null;

            try {
                xapBytes = XapBuilder.XapToMemory(dir);
            }
            catch (Exception e) {
                s.WriteErrorResponse(500, "error generating XAP: " + e.Message);
                return(true);
            }

            s.WriteBinaryResponse(200, "application/x-zip-compressed", xapBytes, false);
            return(true);
        }
 public override void ProcessRequest(HttpContext context)
 {
     InternalProcessRequest(context, delegate(string pdirpath, string path) {
         // create in memory XAP archive
         if (Directory.Exists(pdirpath))
         {
             var xapBuffer = XapBuilder.XapToMemory(pdirpath);
             context.Response.OutputStream.Write(xapBuffer, 0, xapBuffer.Length);
         }
         else
         {
             throw new HttpException(404, "Missing " + path);
         }
     });
 }
Exemple #3
0
        static int Main(string[] args)
        {
            ParseOptions(args);

            if (!_nologo)
            {
                Console.WriteLine(
                    "Chiron - Silverlight Development Utility. Version {0}",
                    typeof(Chiron).Assembly.GetName().Version
                    );
            }

            if (_help)
            {
                Console.WriteLine(
                    @"Usage: Chiron [<options>]

Options:

  /w[ebserver][:<port number>]
    Launches a development web server that automatically creates
    XAP files for dynamic language applications (runs /z for every
    request of a XAP file, but generates it in memory).
    Optionally specifies server port number (default: 2060)

  /b[rowser][:<start url>]
    Launches the default browser and starts the web server
    Implies /w, cannot be combined with /x or /z

  /z[ipdlr]:<file>
    Generates a XAP file, including dynamic language DLLs, and
    auto-generates AppManifest.xaml (equivalent of /m in memory), 
    if it does not exist.
    Does not start the web server, cannot be combined with /w or /b

  /m[anifest]
    Saves the generated AppManifest.xaml file to disk
    Use /d to set the directory containing the sources
    Can only be combined with /d, /n and /s

  /d[ir[ectory]]:<path>
    Specifies directory on disk (default: the current directory)

  /r[efpath]:<path>
    Path where assemblies are located.
    Overrides appSettings.localAssemblyPath in Chiron.exe.config

  /p[ath]:<path1;path2;..;pathn>
    semi-color-separated directories to be included in the XAP file,
    in addition to what is specified by /d

  /l[ocalAppRoot]:<relative path>
    Path to look for script files on the web-server, rather than in
    the XAP file (which is default). Path is relative to the XAP file.
    If Chiron is generating the AppManifest.xaml, it will use this to 
    find which languages the application depends on.

  /e[xtUrlPrefix]:<absolute uri> (>= Silverlight 3 only)
    Does not put the assemblies inside the XAP file, and references the
    appropriate slvx files from the Uri provided.
    Overrides appSettings.externalUrlPrefix in Chiron.exe.config

  /u[rlprefix]:<relative or absolute uri>
    appends a relative or absolute Uri to each language assembly added
    to the AppManifest.xaml. Also does not put the assemblies inside the 
    xap. If it's a relative Uri and /w is also given, Chiron will serve
    the assemblies from the Uri, relative to the server root.
    Overrides appSettings.urlPrefix in Chiron.exe.config

  /x[ap[file]]:<file>
    Specifies XAP file to generate. Only XAPs a directory; does not
    generate a manifest or add dynamic language DLLs; see /z for that
    functionality.
    Does not start the web server, cannot be combined with /w or /b

  /notification
    Display notification icon
  
  /n[ologo]
    Suppresses display of the logo banner

  /s[ilent]
    Suppresses display of all output
");
            }
            else if (_error != null)
            {
                return(Error(1000, "options", _error));
            }
            else if (!string.IsNullOrEmpty(_xapfile))
            {
                try {
                    if (!_silent)
                    {
                        Console.WriteLine("Generating XAP {0} from {1}", _xapfile, _dir);
                    }

                    if (_zipdlr)
                    {
                        XapBuilder.XapToDisk(_dir, _xapfile);
                    }
                    else
                    {
                        ZipArchive xap = new ZipArchive(_xapfile, FileAccess.Write);
                        XapBuilder.AddPathDirectories(xap);
                        xap.CopyFromDirectory(_dir, "");
                        xap.Close();
                    }
                }
                catch (Exception ex) {
                    return(Error(1001, "xap", ex.Message));
                }
            }
            else if (_saveManifest)
            {
                try {
                    string manifest = Path.Combine(_dir, "AppManifest.xaml");
                    if (File.Exists(manifest))
                    {
                        return(Error(3002, "manifest", "AppManifest.xaml already exists at path " + manifest));
                    }

                    // Generate the AppManifest.xaml file to disk, as we would if we were
                    // generating it in the XAP
                    XapBuilder.GenerateManifest(_dir).Save(manifest);
                } catch (Exception ex) {
                    return(Error(3001, "manifest", ex.Message));
                }
            }
            else
            {
                string uri = string.Format("http://localhost:{0}/", _port);

                if (!_silent)
                {
                    Console.WriteLine("Chiron serving '{0}' as {1}", _dir, uri);
                }

                try {
                    HttpServer server = new HttpServer(_port, _dir);
                    server.Start();

                    if (_browser)
                    {
                        if (_startPage != null)
                        {
                            uri += _startPage;
                        }

                        ProcessStartInfo startInfo = new ProcessStartInfo(uri);
                        startInfo.UseShellExecute  = true;
                        startInfo.WorkingDirectory = _dir;

                        Process p = new Process();
                        p.StartInfo = startInfo;
                        p.Start();
                    }

                    if (_notifyIcon)
                    {
                        Thread notify = new Thread(
                            () => {
                            Application.EnableVisualStyles();
                            Application.SetCompatibleTextRenderingDefault(false);

                            var notification = new Notification(_dir, _port);
                            Application.Run();
                        }
                            );
                        notify.SetApartmentState(ApartmentState.STA);
                        notify.IsBackground = true;
                        notify.Start();
                    }

                    while (server.IsRunning)
                    {
                        Thread.Sleep(500);
                    }
                } catch (Exception ex) {
                    return(Error(2001, "server", ex.Message));
                }
            }

            return(0);
        }
Exemple #4
0
        static int Main(string[] args)
        {
            ParseOptions(args);

            if (!_NoLogo)
            {
                Console.WriteLine(
                    "Chiron - Silverlight Dynamic Language Development Utility. Version {0}",
                    typeof(Chiron).Assembly.GetName().Version
                    );
            }

            if (_Help)
            {
                Console.WriteLine(
                    @"Usage: Chiron [<options>]

Common usages:

  Chiron.exe /b
    Starts the web-server on port 2060, and opens the default browser
    to the root of the web-server. This is used for developing an
    application, as Chiron will rexap you application's directory for
    every request.
    
  Chiron.exe /d:app /z:app.xap
    Takes the contents of the app directory and generates an app.xap 
    from it, which embeds the DLR and language assemblies according to
    the settings in Chiron.exe.config. This is used for deployment,
    so you can take the generated app.xap, along with any other files,
    and host them on any web-server.

Options:

  Note: forward-slashes (/) in option names can be substituted for dashes (-).
        For example ""Chiron.exe -w"" instead of ""Chiron.exe /w"".

  /w[ebserver][:<port number>]
    Launches a development web server that automatically creates
    XAP files for dynamic language applications (runs /z for every
    request of a XAP file, but generates it in memory).
    Optionally specifies server port number (default: 2060)

  /b[rowser][:<start url>]
    Launches the default browser and starts the web server
    Implies /w, cannot be combined with /x or /z

  /z[ipdlr]:<file>
    Generates a XAP file, including dynamic language dependencies, and
    auto-generates AppManifest.xaml (equivalent of /m in memory), 
    if it does not exist.
    Does not start the web server, cannot be combined with /w or /b

  /m[anifest]
    Saves the generated AppManifest.xaml file to disk
    Use /d to set the directory containing the sources
    Can only be combined with /d, /n and /s

  /d[ir[ectory]]:<path>
    Specifies directory on disk (default: the current directory).
    Implies /w.

  /r[efpath]:<path>
    Path where assemblies are located. Defaults to the same directory
    where Chiron.exe exists.
    Overrides appSettings.localAssemblyPath in Chiron.exe.config.

  /p[ath]:<path1;path2;..;pathn>
    Semi-colon-separated directories to be included in the XAP file,
    in addition to what is specified by /d
    
  /u[rlprefix]:<relative or absolute uri>
    Appends a relative or absolute Uri to each language assembly or extension
    added to the AppManifest.xaml. If a relative Uri is provided, Chiron 
    will serve all files located in the /refpath at this Uri, relative to the
    root of the web-server.
    Overrides appSettings.urlPrefix in Chiron.exe.config.
  
  /nl /noLanguageDetection
    Without this flag, Chiron scans the current application directory for files
    with a valid language's file extension, and only makes those languages
    available to the XAP file. See /useExtensions for whether the languages
    assemblies or extension files are used.
    With this flag, no language-specific assemblies/extensions are added to the
    XAP, so the Silverlight application is responsible for parsing the
    languages.config file in the XAP and downloading the languages it needs.
    Overrides appSettings.detectLanguages in Chiron.exe.config.
  
  /e /useExtensions:true|false (default false)
    Toggles whether or not language and DLR assemblies are embedded in
    the XAP file, or whether their equivalent extension files are used.

  /a /anyAddress
    By default Chiron listens on just the loopback IP address, meaning it only
    works for local requests. Providing this flag will cause Chiron to
    listen on any IP address, making it an internet-facing webserver. This
    option should only be used during development when running the Silverlight
    app on one machine and testing on many machines; Chiron is not optimized as
    a production webserver.

  /x[ap[file]]:<file>
    Specifies XAP file to generate. Only XAPs a directory; does not
    generate a manifest or add dynamic language DLLs; see /z for that
    functionality.
    Does not start the web server, cannot be combined with /w or /b

  /notification
    Display notification icon
  
  /n[ologo]
    Suppresses display of the logo banner

  /s[ilent]
    Suppresses display of all output
");
            }
            else if (_Error != null)
            {
                return(Error(1000, "options", _Error));
            }
            else if (!string.IsNullOrEmpty(_XapFile))
            {
                try {
                    if (!_Silent)
                    {
                        Console.WriteLine("Generating XAP {0} from {1}", _XapFile, _Directory);
                    }

                    if (_XapDlr)
                    {
                        XapBuilder.XapToDisk(_Directory, _XapFile);
                    }
                    else
                    {
                        ZipArchive xap = new ZipArchive(_XapFile, FileAccess.Write);
                        XapBuilder.AddPathDirectories(xap);
                        xap.CopyFromDirectory(_Directory, "");
                        xap.Close();
                    }
                }
                catch (Exception ex) {
                    return(Error(1001, "xap", ex.Message));
                }
            }
            else if (_SaveManifest)
            {
                try {
                    string manifest = Path.Combine(_Directory, "AppManifest.xaml");
                    if (File.Exists(manifest))
                    {
                        return(Error(3002, "manifest", "AppManifest.xaml already exists at path " + manifest));
                    }

                    // Generate the AppManifest.xaml file to disk, as we would if we were
                    // generating it in the XAP
                    XapBuilder.GenerateManifest(_Directory).Save(manifest);
                } catch (Exception ex) {
                    return(Error(3001, "manifest", ex.Message));
                }
            }
            else
            {
                string uri = string.Format("http://localhost:{0}/", _Port);

                if (!_Silent)
                {
                    Console.WriteLine("Chiron serving '{0}' as {1}", _Directory, uri);
                }

                try {
                    HttpServer server = new HttpServer(_Port, _Directory);
                    server.Start();

                    if (_LaunchBrowser)
                    {
                        if (_StartPage != null)
                        {
                            uri += _StartPage;
                        }

                        ProcessStartInfo startInfo = new ProcessStartInfo(uri);
                        startInfo.UseShellExecute  = true;
                        startInfo.WorkingDirectory = _Directory;

                        Process p = new Process();
                        p.StartInfo = startInfo;
                        p.Start();
                    }

                    if (_NotifyIcon)
                    {
                        Thread notify = new Thread(
                            () => {
                            Application.EnableVisualStyles();
                            Application.SetCompatibleTextRenderingDefault(false);

                            var notification = new Notification(_Directory, _Port);
                            Application.Run();
                        }
                            );
                        notify.SetApartmentState(ApartmentState.STA);
                        notify.IsBackground = true;
                        notify.Start();
                    }

                    while (server.IsRunning)
                    {
                        Thread.Sleep(500);
                    }
                } catch (Exception ex) {
                    return(Error(2001, "server", ex.Message));
                }
            }

            return(0);
        }