コード例 #1
0
ファイル: Settings.cs プロジェクト: mikec85/HAILogger
        private static MailAddress[] ValidateMailTo(NameValueCollection settings, string section)
        {
            try
            {
                if (settings[section] == null)
                {
                    return new MailAddress[] {}
                }
                ;

                string[]      emails    = settings[section].Split(',');
                MailAddress[] addresses = new MailAddress[emails.Length];

                for (int i = 0; i < emails.Length; i++)
                {
                    addresses[i] = new MailAddress(emails[i]);
                }

                return(addresses);
            }
            catch
            {
                Event.WriteError("Settings", "Invalid email specified for " + section);
                throw;
            }
        }
コード例 #2
0
ファイル: WebNotification.cs プロジェクト: pdb0102/HAILogger
        static void client_UploadStringCompleted(object sender, UploadStringCompletedEventArgs e)
        {
            if (e.Error != null)
            {
                Event.WriteError("WebNotification", "An error occurred sending notification to " + e.UserState.ToString() + "\r\n" + e.Error.Message);

                lock (subscriptions_lock)
                    subscriptions.Remove(e.UserState.ToString());
            }
        }
コード例 #3
0
ファイル: Settings.cs プロジェクト: mikec85/HAILogger
 private static bool ValidateBool(NameValueCollection settings, string section)
 {
     try
     {
         return(Boolean.Parse(settings[section]));
     }
     catch
     {
         Event.WriteError("Settings", "Invalid bool specified for " + section);
         throw;
     }
 }
コード例 #4
0
ファイル: Settings.cs プロジェクト: mikec85/HAILogger
 private static int ValidateInt(NameValueCollection settings, string section)
 {
     try
     {
         return(Int32.Parse(settings[section]));
     }
     catch
     {
         Event.WriteError("Settings", "Invalid integer specified for " + section);
         throw;
     }
 }
コード例 #5
0
ファイル: Settings.cs プロジェクト: mikec85/HAILogger
 private static MailAddress ValidateMailFrom(NameValueCollection settings, string section)
 {
     try
     {
         return(new MailAddress(settings[section]));
     }
     catch
     {
         Event.WriteError("Settings", "Invalid email specified for " + section);
         throw;
     }
 }
コード例 #6
0
ファイル: Settings.cs プロジェクト: mikec85/HAILogger
        private static NameValueCollection LoadCollection(string sFile)
        {
            NameValueCollection settings = new NameValueCollection();

            try
            {
                FileStream   fs = new FileStream(sFile, FileMode.Open, FileAccess.Read);
                StreamReader sr = new StreamReader(fs);

                while (true)
                {
                    string line = sr.ReadLine();

                    if (line == null)
                    {
                        break;
                    }

                    if (line.StartsWith("#"))
                    {
                        continue;
                    }

                    int pos = line.IndexOf('=', 0);

                    if (pos == -1)
                    {
                        continue;
                    }

                    string key   = line.Substring(0, pos).Trim();
                    string value = line.Substring(pos + 1).Trim();

                    settings.Add(key, value);
                }

                sr.Close();
                fs.Close();
            }
            catch (FileNotFoundException)
            {
                Event.WriteError("Settings", "Unable to parse settings file " + sFile);
                throw;
            }

            return(settings);
        }
コード例 #7
0
ファイル: Settings.cs プロジェクト: mikec85/HAILogger
        private static string ValidateDirectory(NameValueCollection settings, string section)
        {
            try
            {
                if (!Directory.Exists(settings[section]))
                {
                    Directory.CreateDirectory(settings[section]);
                }

                return(settings[section]);
            }
            catch
            {
                Event.WriteError("Settings", "Invalid directory specified for " + section);
                throw;
            }
        }
コード例 #8
0
ファイル: Settings.cs プロジェクト: mikec85/HAILogger
        private static string[] ValidateMultipleStrings(NameValueCollection settings, string section)
        {
            try
            {
                if (settings[section] == null)
                {
                    return new string[] { }
                }
                ;

                return(settings[section].Split(','));
            }
            catch
            {
                Event.WriteError("Settings", "Invalid string specified for " + section);
                throw;
            }
        }
コード例 #9
0
ファイル: Settings.cs プロジェクト: mikec85/HAILogger
        private static int ValidatePort(NameValueCollection settings, string section)
        {
            try
            {
                int port = Int32.Parse(settings[section]);

                if (port < 1 || port > 65534)
                {
                    throw new Exception();
                }

                return(port);
            }
            catch
            {
                Event.WriteError("Settings", "Invalid port specified for " + section);
                throw;
            }
        }
コード例 #10
0
ファイル: WebService.cs プロジェクト: pdb0102/HAILogger
        public void Start()
        {
            Uri uri = new Uri("http://0.0.0.0:" + Global.webapi_port + "/");

            host = new WebServiceHost(typeof(HAIService), uri);

            try
            {
                ServiceEndpoint ep = host.AddServiceEndpoint(typeof(IHAIService), new WebHttpBinding(), "");
                host.Open();

                Event.WriteInfo("WebService", "Listening on " + uri.ToString());
            }
            catch (CommunicationException ex)
            {
                Event.WriteError("WebService", "An exception occurred: " + ex.Message);
                host.Abort();
            }
        }
コード例 #11
0
ファイル: Settings.cs プロジェクト: mikec85/HAILogger
 private static bool ValidateYesNo(NameValueCollection settings, string section)
 {
     if (settings[section] == null)
     {
         return(false);
     }
     if (string.Compare(settings[section], "yes", true) == 0)
     {
         return(true);
     }
     else if (string.Compare(settings[section], "no", true) == 0)
     {
         return(false);
     }
     else
     {
         Event.WriteError("Settings", "Invalid yes/no specified for " + section);
         throw new Exception();
     }
 }
コード例 #12
0
ファイル: Settings.cs プロジェクト: mikec85/HAILogger
        private static IPAddress ValidateIP(NameValueCollection settings, string section)
        {
            if (settings[section] == "*")
            {
                return(IPAddress.Any);
            }

            if (settings[section] == "")
            {
                return(IPAddress.None);
            }

            try
            {
                return(IPAddress.Parse(section));
            }
            catch
            {
                Event.WriteError("Settings", "Invalid IP specified for " + section);
                throw;
            }
        }
コード例 #13
0
ファイル: WebNotification.cs プロジェクト: pdb0102/HAILogger
        public static void Send(string type, string body)
        {
            string[] send;
            lock (subscriptions_lock)
                send = subscriptions.ToArray();

            foreach (string subscription in send)
            {
                WebClient client = new WebClient();
                client.Headers.Add(HttpRequestHeader.ContentType, "application/json");
                client.Headers.Add("type", type);
                client.UploadStringCompleted += client_UploadStringCompleted;

                try
                {
                    client.UploadStringAsync(new Uri(subscription), "POST", body, subscription);
                }
                catch (Exception ex)
                {
                    Event.WriteError("WebNotification", "An error occurred sending notification to " + subscription + "\r\n" + ex.ToString());
                    subscriptions.Remove(subscription);
                }
            }
        }
コード例 #14
0
ファイル: Prowl.cs プロジェクト: pdb0102/HAILogger
 static void client_UploadStringCompleted(object sender, UploadStringCompletedEventArgs e)
 {
     if(e.Error != null)
         Event.WriteError("ProwlNotification", "An error occurred sending notification\r\n" + e.Error.Message);
 }