//--------------------------------------------------------------------------------------------------------------------- /// <summary>Opens the execution environment context and other resources required by the background agent.</summary> /// <remarks>The <see cref="Terradue.Portal.IfyLocalContext"/> subclass and the database connection string are obtained from the web application's web.config file.</remarks> public void Open() { // Configuration file is ../web.config string binDir; DirectoryInfo dirInfo = new DirectoryInfo(Environment.GetCommandLineArgs()[0]); binDir = Regex.Replace(dirInfo.FullName, @"[^\\/]*$", ""); string configFile = Regex.Replace(binDir, @"([\\/])bin[\\/]$", @"$1web.config"); if (!File.Exists(configFile)) { throw new Exception("File not found: " + configFile); } XmlDocument configDoc = new XmlDocument(); configDoc.Load(configFile); XmlElement key; key = configDoc.SelectSingleNode("/configuration/appSettings/add[@key='LocalContextClass']") as XmlElement; if (key != null && key.HasAttribute("value")) { className = key.Attributes["value"].Value; } key = configDoc.SelectSingleNode("/configuration/appSettings/add[@key='DatabaseConnection']") as XmlElement; if (key != null && key.HasAttribute("value")) { connectionString = key.Attributes["value"].Value; } else { throw new Exception("No connection string found in web.config"); } context = IfyContext.GetLocalContext(className, connectionString, console); context.Open(); context.AccessLevel = EntityAccessLevel.Administrator; autoEvent = new AutoResetEvent(false); timer = new Timer(new TimerCallback(OnTimer), autoEvent, 0, 1000 * interval); }