private void OpenLogFiles()
        {
            string   path;
            DateTime currentTime;

            currentTime = DateTime.Now;

            path = LogManager.MakeLogName(config.LogPath, ExternalEdgeLogPrefix);

            try {
                externalEdgeLog = new LogManager(config, path);
            } catch (Exception e) {
                throw new EnhancedAllowListException(
                          String.Format(SipStringManager.GetString("LogOpenFailure"), path, e.GetType().ToString(), e.Message));
            }

            path = LogManager.MakeLogName(config.LogPath, InternalEdgeLogPrefix);

            try {
                internalEdgeLog = new LogManager(config, path);
            } catch (Exception e) {
                throw new EnhancedAllowListException(
                          String.Format(SipStringManager.GetString("LogOpenFailure"), path, e.GetType().ToString(), e.Message));
            }
        }
 private void RaiseConfigFileWriteFailureEvent(string message)
 {
     configFileWriteFailureThrottle.LogError(
         String.Format(
             SipStringManager.GetString("ConfigFileWriteFailure"), config.EnhancedAllowListPath, message)
         );
 }
        public static void Unregister()
        {
            string guid = AppGuid;

            try {
                WMIRegistrationHelper regHelper = new WMIRegistrationHelper(AppName, AppUri, ref guid);
                regHelper.Unregister();
            }
            catch (Exception e) {
                Config.AppEventLog.Log(EventLogEntryType.Error,
                                       String.Format(SipStringManager.GetString("WMIUnregisterFailed"), e.Message, e.GetType().ToString()));
            }
        }
        /// <summary>
        /// Core stop functionality.
        /// </summary>
        private void RealStopService()
        {
            Monitor.Enter(serviceLock);

            try {
                int retries = 0;

                //
                // If service is starting, wait until the startup thread exists.
                //

                while (startPending && retries < 20)
                {
                    cancelStart = true;
                    Monitor.Exit(serviceLock);
                    Thread.Sleep(100);
                    Monitor.Enter(serviceLock);
                    retries++;
                }


                //
                // We can safely stop the service now.
                //

                if (policyManager != null)
                {
                    try {
                        policyManager.Stop();
                    }
                    catch {
                    }

                    policyManager.Dispose();
                }

                policyManager = null;
            } finally {
                Monitor.Exit(serviceLock);
                Config.AppEventLog.LogInfo(SipStringManager.GetString("ServiceStopped"));
            }
        }
Example #5
0
 private void RaiseLogFileFullEvent()
 {
     logFileFullEvent.LogWarning(String.Format(SipStringManager.GetString("LogFileFull"), path));
 }
 private void RaiseConfigFileFullEvent()
 {
     configFileFullThrottle.LogWarning(
         String.Format(SipStringManager.GetString("ConfigFileFull"), config.EnhancedAllowListPath)
         );
 }
        private void ReloadEnhancedAllowList()
        {
            StreamReader sr = null;
            Hashtable    tempAllowList;
            string       str;

            string[] tokens;
            string   name, value = null;

            tempAllowList = new Hashtable();

            try {
                sr = new StreamReader(config.EnhancedAllowListPath);

                while ((str = sr.ReadLine()) != null)
                {
                    str    = str.Trim();
                    tokens = str.Split(new char[] { ' ', '\t' });

                    if (tokens.Length > 0)
                    {
                        name = tokens[0];

                        for (int i = 1; i < tokens.Length; i++)
                        {
                            if (tokens[i].Length > 0)
                            {
                                value = tokens[i];
                                break;
                            }
                        }

                        if (name != null && value != null)
                        {
                            if (tempAllowList.Contains(name))
                            {
                                throw new EnhancedAllowListException(
                                          String.Format(SipStringManager.GetString("ConfigFileParseError"),
                                                        config.EnhancedAllowListPath));
                            }
                            else
                            {
                                tempAllowList.Add(name.ToLower(), value);
                                currentDomains += 1;
                            }
                        }
                    } // tokens.Length > 0
                }     // while

                lock (this.SyncRoot) {
                    if (allowList != null)
                    {
                        allowList.Clear();
                    }
                    allowList = tempAllowList;
                }
            }
            catch (EnhancedAllowListException e1) {
                throw e1;
            }
            catch (Exception e) {
                throw new EnhancedAllowListException(
                          String.Format(SipStringManager.GetString("ConfigFileOpenFailure"),
                                        config.EnhancedAllowListPath, e.GetType().ToString(), e.Message));
            }
            finally {
                if (sr != null)
                {
                    sr.Close();
                }
            }
        }
        /// <summary>
        /// This routine implements application startup. This is to be executed
        /// usually in a thread pool thread (so that the main thread can wait for stop
        /// events - from SCM or from console).
        /// </summary>
        private void RealStartService(object unused)
        {
            int i, maxRetries = 10;

            try {
                for (i = 0; i < maxRetries; i++)
                {
                    lock (serviceLock) {
                        if (cancelStart)
                        {
                            Config.AppEventLog.LogInfo(
                                SipStringManager.GetString("ServiceStartupAbort"));
                            return;
                        }
                    }

                    try {
                        ServerAgent.WaitForServerAvailable(10);
                        break;
                    }
                    catch {
                        if ((i % 2) == 0)
                        {
                            Config.AppEventLog.LogError(
                                SipStringManager.GetString("ServiceStartPending"));
                        }
                        continue;
                    }
                }

                if (i == maxRetries)
                {
                    Config.AppEventLog.LogError(
                        SipStringManager.GetString("ServerUnreachable"));
                    Environment.Exit(1);
                }

                lock (serviceLock) {
                    if (cancelStart)
                    {
                        Config.AppEventLog.LogInfo(
                            SipStringManager.GetString("ServiceStartupAbort"));
                        return;
                    }

                    policyManager = new PolicyManager();

                    try {
                        //
                        // Read settings.
                        //

                        NameValueCollection properties;
                        Config config = null;

                        try {
                            properties = ConfigurationManager.AppSettings;

                            config = new Config(properties);
                        }
                        catch (Exception e) {
                            Config.AppEventLog.LogError(
                                String.Format(SipStringManager.GetString("AppConfigFileParseError"), e.GetType().ToString(), e.Message));
                            Environment.Exit(1);
                        }

                        //
                        // See if a working directory has been specified.
                        //

                        if (config.WorkingDirectory != null)
                        {
                            try {
                                Environment.CurrentDirectory = config.WorkingDirectory;
                            }
                            catch {
                                Config.AppEventLog.LogError(
                                    String.Format(SipStringManager.GetString("InvalidWorkingDirectory"), config.WorkingDirectory));
                                Environment.Exit(1);
                            }
                        }

                        policyManager.Start(config);
                    }
                    catch (Exception e) {
                        Config.AppEventLog.LogError(
                            String.Format(SipStringManager.GetString("AppException"),
                                          e.Message, e.GetType().ToString(), e.StackTrace));

                        Console.WriteLine("Got exception: " + e.Message);
                        if (e.InnerException != null)
                        {
                            Console.WriteLine("Inner exception: " + e.InnerException.Message);
                        }

                        Environment.Exit(1);
                    }

                    Config.AppEventLog.LogInfo(SipStringManager.GetString("ServiceStarted"));
                }
            }
            finally {
                lock (serviceLock) {
                    startPending = false;
                }
            }
        }