Ejemplo n.º 1
0
        /// <summary>
        /// Generate a default setup option.
        /// </summary>
        /// <returns>
        /// default iis setting options
        /// </returns>
        public static WebAppSetupOptions GenerateDefaultOptions()
        {
            WebAppSetupOptions result = new WebAppSetupOptions();

            result.UpdateWebConfig(CreateDefaultWebConfig());

            return(result);
        }
        public virtual WebAppSetupOptions GetSetupOptions()
        {
            var appSetupOptions = WebAppSetupOptions.GenerateDefaultOptions();

            appSetupOptions.AddWebApiAssemblies();
            appSetupOptions.AddAssemblyAndReferences(typeof(TController).Assembly);
            return(appSetupOptions);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Set up a web site in IIS according to the given setup option
        /// </summary>
        /// <param name="options">
        /// the options
        /// </param>
        /// <returns>
        /// an url pointing to the new created site
        /// </returns>
        public static string SetupIIS(WebAppSetupOptions options)
        {
            if (options.NeedsGlobalAsax())
            {
                options.GenerateGlobalAsaxForCS();
            }

            using (ServerManager manager = new ServerManager())
            {
                Site site = manager.Sites[DefaultWebSiteName];

                // create site directory as well as bin directory
                string path = Path.Combine(DefaultWebSiteFolder, options.VirtualDirectory);
                EnsureDirectory(path);
                string binPath = Path.Combine(path, "Bin");
                EnsureDirectory(binPath);

                // list the required assemblies and copy
                string[] assembliesToAlwaysCopy = new string[]
                    {
                        Assembly.GetExecutingAssembly().Location, // this assembly
                    };

                foreach (var assembly in assembliesToAlwaysCopy)
                {
                    File.Copy(assembly, Path.Combine(binPath, Path.GetFileName(assembly)), true);
                }

                // generated all text based files. they are mostly configuration files.                
                if (options.TextFiles != null)
                {
                    foreach (var textFileName in options.TextFiles.Keys)
                    {
                        var file = new FileInfo(Path.Combine(path, textFileName));
                        file.Directory.Create();
                        File.WriteAllText(file.FullName, options.TextFiles[textFileName]);
                    }
                }

                // copy all required binary files
                if (options.BinaryFiles != null)
                {
                    foreach (var file in options.BinaryFiles)
                    {
                        File.Copy(file, Path.Combine(binPath, Path.GetFileName(file)), true);
                    }
                }

                // add application to web site
                site.Applications.Add("/" + options.VirtualDirectory, path);
                manager.CommitChanges();

                Thread.Sleep(SleepDelay);

                return new Uri(new Uri(BaseUrl), options.VirtualDirectory).ToString();
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Set up a web site in IIS according to the given setup option
        /// </summary>
        /// <param name="options">
        /// the options
        /// </param>
        /// <returns>
        /// an url pointing to the new created site
        /// </returns>
        public static string SetupIIS(WebAppSetupOptions options)
        {
            if (options.NeedsGlobalAsax())
            {
                options.GenerateGlobalAsaxForCS();
            }

            using (ServerManager manager = new ServerManager())
            {
                Site site = manager.Sites[DefaultWebSiteName];

                // create site directory as well as bin directory
                string path = Path.Combine(DefaultWebSiteFolder, options.VirtualDirectory);
                EnsureDirectory(path);
                string binPath = Path.Combine(path, "Bin");
                EnsureDirectory(binPath);

                // list the required assemblies and copy
                string[] assembliesToAlwaysCopy = new string[]
                {
                    Assembly.GetExecutingAssembly().Location,     // this assembly
                };

                foreach (var assembly in assembliesToAlwaysCopy)
                {
                    File.Copy(assembly, Path.Combine(binPath, Path.GetFileName(assembly)), true);
                }

                // generated all text based files. they are mostly configuration files.
                if (options.TextFiles != null)
                {
                    foreach (var textFileName in options.TextFiles.Keys)
                    {
                        var file = new FileInfo(Path.Combine(path, textFileName));
                        file.Directory.Create();
                        File.WriteAllText(file.FullName, options.TextFiles[textFileName]);
                    }
                }

                // copy all required binary files
                if (options.BinaryFiles != null)
                {
                    foreach (var file in options.BinaryFiles)
                    {
                        File.Copy(file, Path.Combine(binPath, Path.GetFileName(file)), true);
                    }
                }

                // add application to web site
                site.Applications.Add("/" + options.VirtualDirectory, path);
                manager.CommitChanges();

                Thread.Sleep(SleepDelay);

                return(new Uri(new Uri(BaseUrl), options.VirtualDirectory).ToString());
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Clean up the iis
        /// </summary>
        /// <param name="options">
        /// </param>
        public static void CleanupIIS(WebAppSetupOptions options)
        {
            using (ServerManager manager = new ServerManager())
            {
                Site site = manager.Sites[DefaultWebSiteName];

                Application app = site.Applications.Where((x, i) => x.Path == "/" + options.VirtualDirectory).FirstOrDefault();

                if (app != null)
                {
                    site.Applications.Remove(app);
                    manager.CommitChanges();
                }

                // TODO: Currently disabled for debugging purposes
                // RemoveDirectory(Path.Combine(options.IISRoot, options.vdirName));
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Clean up the iis
        /// </summary>
        /// <param name="options">
        /// </param>
        public static void CleanupIIS(WebAppSetupOptions options)
        {
            using (ServerManager manager = new ServerManager())
            {
                Site site = manager.Sites[DefaultWebSiteName];

                Application app = site.Applications.Where((x, i) => x.Path == "/" + options.VirtualDirectory).FirstOrDefault();

                if (app != null)
                {
                    site.Applications.Remove(app);
                    manager.CommitChanges();
                }

                // TODO: Currently disabled for debugging purposes
                // RemoveDirectory(Path.Combine(options.IISRoot, options.vdirName));
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Generate a default setup option.
        /// </summary>
        /// <returns>
        /// default iis setting options
        /// </returns>
        public static WebAppSetupOptions GenerateDefaultOptions()
        {
            WebAppSetupOptions result = new WebAppSetupOptions();

            result.UpdateWebConfig(CreateDefaultWebConfig());

            return result;
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Constructs a template based on a given WebAppSetupOptions
 /// </summary>
 /// <param name="options"></param>
 public GlobalAsaxTemplate(WebAppSetupOptions options)
     : this(options.Routes, options.TraceWriterType, options.ConfigureMethod)
 {
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Create the template output
        /// </summary>
        public virtual string TransformText()
        {
            this.Write("<%@ Application Language=\"C#\" %>\r\n\r\n");

            #line 12 "E:\dd\DevDiv\Offcycle\WPT\WebStackRuntime\QA\Func\src\Common\WebHost\GlobalAsaxTemplate.tt"
            // Import name spaces
            foreach (var each in this.Namespaces)
            {
            #line default
            #line hidden
                this.Write("<%@ Import namespace=\"");

            #line 16 "E:\dd\DevDiv\Offcycle\WPT\WebStackRuntime\QA\Func\src\Common\WebHost\GlobalAsaxTemplate.tt"
                this.Write(this.ToStringHelper.ToStringWithCulture(each));

            #line default
            #line hidden
                this.Write("\" %>\r\n");

            #line 17 "E:\dd\DevDiv\Offcycle\WPT\WebStackRuntime\QA\Func\src\Common\WebHost\GlobalAsaxTemplate.tt"
            }


            #line default
            #line hidden
            this.Write("\r\n<script RunAt=\"server\">\r\n\tprivate void RegisterRoutes(RouteCollection routes)\r\n" +
                       "\t{\r\n");

            #line 24 "E:\dd\DevDiv\Offcycle\WPT\WebStackRuntime\QA\Func\src\Common\WebHost\GlobalAsaxTemplate.tt"
            // Add routes
            foreach (var route in this._routes)
            {
            #line default
            #line hidden
                this.Write("\t\t");

            #line 28 "E:\dd\DevDiv\Offcycle\WPT\WebStackRuntime\QA\Func\src\Common\WebHost\GlobalAsaxTemplate.tt"
                this.Write(this.ToStringHelper.ToStringWithCulture(route.RouteMapFunctionCall));

            #line default
            #line hidden
                this.Write("(\r\n\t\t\troutes,\r\n\t\t\t\"");

            #line 30 "E:\dd\DevDiv\Offcycle\WPT\WebStackRuntime\QA\Func\src\Common\WebHost\GlobalAsaxTemplate.tt"
                this.Write(this.ToStringHelper.ToStringWithCulture(route.Name));

            #line default
            #line hidden
                this.Write("\",\r\n\t\t\t\"");

            #line 31 "E:\dd\DevDiv\Offcycle\WPT\WebStackRuntime\QA\Func\src\Common\WebHost\GlobalAsaxTemplate.tt"
                this.Write(this.ToStringHelper.ToStringWithCulture(route.Path));

            #line default
            #line hidden
                this.Write("\",\r\n\t\t\t");

            #line 32 "E:\dd\DevDiv\Offcycle\WPT\WebStackRuntime\QA\Func\src\Common\WebHost\GlobalAsaxTemplate.tt"
                this.Write(this.ToStringHelper.ToStringWithCulture((route.Defaults ?? "null")));

            #line default
            #line hidden
                this.Write(");\r\n");

            #line 33 "E:\dd\DevDiv\Offcycle\WPT\WebStackRuntime\QA\Func\src\Common\WebHost\GlobalAsaxTemplate.tt"
            }


            #line default
            #line hidden
            this.Write("    }\r\n\r\n    protected void Application_Start(object sender, System.EventArgs e)\r" +
                       "\n    {\r\n        RegisterRoutes(System.Web.Routing.RouteTable.Routes);\r\n");

            #line 41 "E:\dd\DevDiv\Offcycle\WPT\WebStackRuntime\QA\Func\src\Common\WebHost\GlobalAsaxTemplate.tt"
            // replace trace if the given trace writer type is not null
            if (this._traceWriterType != null)
            {
            #line default
            #line hidden
                this.Write("\r\n        GlobalConfiguration.Configuration.Services.Replace(\r\n            typeof" +
                           "(ITraceWriter),\r\n            new ");

            #line 48 "E:\dd\DevDiv\Offcycle\WPT\WebStackRuntime\QA\Func\src\Common\WebHost\GlobalAsaxTemplate.tt"
                this.Write(this.ToStringHelper.ToStringWithCulture(this._traceWriterType.Name));

            #line default
            #line hidden
                this.Write("());\r\n");

            #line 49 "E:\dd\DevDiv\Offcycle\WPT\WebStackRuntime\QA\Func\src\Common\WebHost\GlobalAsaxTemplate.tt"
            } // END if (this.Options.TraceWriterType != null)


            #line default
            #line hidden

            #line 52 "E:\dd\DevDiv\Offcycle\WPT\WebStackRuntime\QA\Func\src\Common\WebHost\GlobalAsaxTemplate.tt"

            // call the configuration method if it is given
            if (this._configureMethod != null)
            {
                var configMtdDeclaringType = this._configureMethod.DeclaringType;

                string declareTypeName;
                if (configMtdDeclaringType.IsGenericType)
                {
                    declareTypeName = WebAppSetupOptions.GenericTypeFullNameToString(configMtdDeclaringType);
                }
                else
                {
                    declareTypeName = this._configureMethod.DeclaringType.FullName;
                }

                string methodName = this._configureMethod.Name;


            #line default
            #line hidden
                this.Write("\t\tGlobalConfiguration.Configuration.SetHttpServer(GlobalConfiguration.DefaultServ" +
                           "er);\r\n\r\n\t\t");

            #line 72 "E:\dd\DevDiv\Offcycle\WPT\WebStackRuntime\QA\Func\src\Common\WebHost\GlobalAsaxTemplate.tt"
                this.Write(this.ToStringHelper.ToStringWithCulture(declareTypeName));

            #line default
            #line hidden
                this.Write(".");

            #line 72 "E:\dd\DevDiv\Offcycle\WPT\WebStackRuntime\QA\Func\src\Common\WebHost\GlobalAsaxTemplate.tt"
                this.Write(this.ToStringHelper.ToStringWithCulture(methodName));

            #line default
            #line hidden
                this.Write("(GlobalConfiguration.Configuration);\r\n");

            #line 73 "E:\dd\DevDiv\Offcycle\WPT\WebStackRuntime\QA\Func\src\Common\WebHost\GlobalAsaxTemplate.tt"
            } // END if (this.Options.ConfigureMethod != null)


            #line default
            #line hidden
            this.Write("    }\r\n</script>");
            return(this.GenerationEnvironment.ToString());
        }
 /// <summary>
 /// Constructs a template based on a given WebAppSetupOptions
 /// </summary>
 /// <param name="options"></param>
 public GlobalAsaxTemplate(WebAppSetupOptions options)
     : this(options.Routes, options.TraceWriterType, options.ConfigureMethod)
 {
 }