예제 #1
0
        public void Initialize()
        {
            #region Get ApplicationName

            if (ApplicationName.IsNullOrWhiteSpace())
            {
                try
                {
                    ApplicationName = System.IO.Path.GetFileName(ChoAssembly.GetEntryAssemblyLocation());
                }
                catch (System.Security.SecurityException ex)
                {
                    ChoApplication.Trace(ChoTraceSwitch.Switch.TraceError, ex.ToString());
                }
            }

            #endregion Get ApplicationName

            #region Get HostName

            // Get the DNS host name of the current machine
            try
            {
                // Lookup the host name
                if (HostName.IsNullOrWhiteSpace())
                {
                    HostName = System.Net.Dns.GetHostName();
                }
            }
            catch (System.Net.Sockets.SocketException)
            {
            }
            catch (System.Security.SecurityException)
            {
                // We may get a security exception looking up the hostname
                // You must have Unrestricted DnsPermission to access resource
            }

            // Get the NETBIOS machine name of the current machine
            if (HostName.IsNullOrWhiteSpace())
            {
                try
                {
                    HostName = Environment.MachineName;
                }
                catch (InvalidOperationException)
                {
                }
                catch (System.Security.SecurityException)
                {
                    // We may get a security exception looking up the machine name
                    // You must have Unrestricted EnvironmentPermission to access resource
                }
            }

            #endregion Get HostName

            #region Get IpAddresses

            try
            {
                IPAddress[] localIPs = Dns.GetHostAddresses(Dns.GetHostName());
                for (int i = 0; i < localIPs.Length; i++)
                {
                    IPAddresses.Add(localIPs[i].ToString());
                }
            }
            catch (System.Net.Sockets.SocketException)
            {
            }
            catch (System.Security.SecurityException)
            {
                // We may get a security exception looking up the hostname
                // You must have Unrestricted DnsPermission to access resource
            }

            #endregion Get IpAddresses

            if (ApplicationBehaviourSettings == null)
            {
                ApplicationBehaviourSettings = new ChoApplicationBehaviourSettings();
            }

            if (TrayApplicationBehaviourSettings == null)
            {
                TrayApplicationBehaviourSettings = new ChoTrayApplicationBehaviourSettings();
            }

            if (LogSettings == null)
            {
                LogSettings = new ChoLogSettings();
            }

            ChoApplication.RaiseGlobalApplicationSettingsOverrides(this);
            Merge(ChoGlobalApplicationSettings.Default);

            PostInitialize();
        }