public void Init()
        {
            // use a default set
            m_config = new Web.Configuration.ServerConfig();

            m_config.DocumentRoot = Environment.CurrentDirectory;
            m_config.LocalIP      = System.Net.IPAddress.Parse("0.0.0.0");
            m_config.Port         = 8080;
            m_config.DefaultDocuments.Add("default.aspx");
        }
Example #2
0
 /// <summary>
 /// Forces the server to reload the configuration settings from the Padarn configuration settings XML file
 /// </summary>
 public void Reload()
 {
     ConfigurationSettings.Reload();
     m_instance = ConfigurationSettings.GetConfig("WebServer") as ServerConfig;
 }
Example #3
0
 internal static void SetConfig(ServerConfig config)
 {
     m_instance = config;
 }
Example #4
0
        internal static ServerConfig GetConfig(ILogProvider provider, bool cache)
        {
            ServerConfig config = null;

            if (m_instance == null)
            {
                if (provider != null)
                {
                    provider.LogRuntimeInfo(ZoneFlags.Startup, "Loading WebServer config node");
                }

                config = ConfigurationSettings.GetConfig("WebServer") as ServerConfig;

                if (config == null)
                {
                    if (provider != null)
                    {
                        provider.LogRuntimeInfo(ZoneFlags.Startup, "Unable to locate WebServer config node");
                    }
                    throw new ConfigurationException("Unable to load 'WebServer' configuration node");
                }

                if (provider != null)
                {
                    provider.LogRuntimeInfo(ZoneFlags.Startup, "Config.DocumentRoot: " + config.DocumentRoot);
                }

                if (string.IsNullOrEmpty(config.DocumentRoot))
                {
                    throw new ConfigurationException("Empty DocumentRoot is invalid");
                }

                if (!System.IO.Directory.Exists(config.DocumentRoot))
                {
                    if (provider != null)
                    {
                        provider.LogRuntimeInfo(ZoneFlags.Startup, "Creating DocumentRoot at " + config.DocumentRoot);
                    }
                    System.IO.Directory.CreateDirectory(config.DocumentRoot);
                    // TODO: Should we dump in a standard "default" web page (pulled from an embedded resource), or is the 404 going to be enough?
                    // if we have a page that at least says "the server is installed an running" I think that would be useful
                }

                foreach (var assemblyName in config.AssembliesToLoad)
                {
                    string newName = Path.Combine(Path.Combine(config.DocumentRoot, "bin"), assemblyName);

                    if (provider != null)
                    {
                        provider.LogRuntimeInfo(ZoneFlags.Startup, "Loading Assembly: " + newName);
                    }

                    try
                    {
                        // try loading from the docs folder first
                        if (File.Exists(newName))
                        {
                            var a = Assembly.LoadFrom(newName);
                            config.m_loadedAssemblies.Add(a);
                            var t = a.GetTypes();
                        }
                        else
                        {
                            // try the loader path (exception will throw if it's not there)
                            Assembly.LoadFrom(assemblyName);
                        }
                    }
                    catch (Exception ex)
                    {
                        var msg = string.Format("Unable to load requested assembly '{0}': {1}", assemblyName, ex.Message);
                        Debug.WriteLine(msg);
                        if (provider != null)
                        {
                            provider.LogPadarnError(msg, null);
                        }
                    }
                }
                if (cache)
                {
                    m_instance = config;
                }
            }
            else
            {
                if (m_instance.LogFileFolder == null)
                {
                    m_instance.LogFileFolder = "\\Temp\\PadarnLogs";
                }

                config = m_instance;
            }

            return(config);
        }
        internal void Initialize()
        {
            foreach (string provider in this)
            {
                string[] assemblyNameParts = provider.Split(',');
                if (assemblyNameParts.Length < 2)
                {
                    return;
                }

                string className    = assemblyNameParts[0];
                string assemblyName = assemblyNameParts[1].Trim(' ');

                string binPath      = String.IsNullOrEmpty(ProviderPath) ? Path.Combine(ServerConfig.GetConfig().DocumentRoot, "bin") : ProviderPath;
                string assemblyPath = Path.Combine(binPath, String.Format("{0}.dll", assemblyName));

                try
                {
                    Assembly providerDll  = Assembly.LoadFrom(assemblyPath);
                    Type     providerType = providerDll.GetType(className);

                    if (providerType != null)
                    {
                        VirtualPathProvider providerInst = Activator.CreateInstance(providerType) as VirtualPathProvider;
                        HostingEnvironment.RegisterVirtualPathProvider(providerInst);
                    }
                }
                catch (FileNotFoundException)
                {
                    // Should we log this?
                }
            }
        }