Exemplo n.º 1
0
        private void tsbSaveAsPlugInDefFile_Click(object sender, EventArgs e)
        {
            using (SaveFileDialog dialog = new SaveFileDialog())
            {
                dialog.Filter           = "plg files (*.plg)|*.plg";
                dialog.FilterIndex      = 1;
                dialog.RestoreDirectory = true;
                dialog.InitialDirectory = ChoApplication.ApplicationBaseDirectory;

                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    PlugInDefFilePath = ChoPath.ChangeExtension(dialog.FileName, ChoReservedFileExt.PLG);
                    Save(PlugInDefFilePath);
                }
            }
        }
Exemplo n.º 2
0
        private bool Save(string filePath)
        {
            if (!SyncData())
            {
                return(false);
            }
            ApplyPlugInGroupChanges(_prevPlugInsGroupName, _plugInBuilderList.ToArray());

            try
            {
                if (filePath.IsNullOrWhiteSpace())
                {
                    using (SaveFileDialog dialog = new SaveFileDialog())
                    {
                        dialog.Filter           = "plg files (*.plg)|*.plg";
                        dialog.FilterIndex      = 1;
                        dialog.RestoreDirectory = true;
                        dialog.InitialDirectory = ChoApplication.ApplicationBaseDirectory;

                        if (dialog.ShowDialog() == DialogResult.OK)
                        {
                            filePath = PlugInDefFilePath = ChoPath.ChangeExtension(dialog.FileName, ChoReservedFileExt.PLG);
                        }
                        else
                        {
                            return(true);
                        }
                    }
                }

                _plugInsDefManager.Save(filePath);

                IsDirty = false;
                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error while saving changes to '{0}'. {1}".FormatString(filePath, ex.Message),
                                Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return(false);
            }
        }
Exemplo n.º 3
0
        protected string GetFullPath(string filePath)
        {
            if (filePath.IsNullOrEmpty())
            {
                return(filePath);
            }
            if (!Path.IsPathRooted(filePath))
            {
                filePath = Path.Combine(Path.GetDirectoryName(ChoGlobalApplicationSettings.Me.ApplicationConfigFilePath), ChoPath.ChangeExtension(filePath, ChoReservedFileExt.Xml));
            }

            filePath = ChoPath.GetFullPath(filePath);

            return(filePath);
        }
Exemplo n.º 4
0
        public void Initialize()
        {
            if (ApplicationBehaviourSettings == null)
            {
                ApplicationBehaviourSettings = new ChoApplicationBehaviourSettings();
            }

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

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

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

            if (ApplicationName.IsNullOrEmpty())
            {
                ChoApplication.OnFatalApplicationException(101, "Missing ApplicationName.");
            }

            ApplicationNameWithoutExtension = Path.GetFileNameWithoutExtension(ApplicationName);

            if (EventLogSourceName.IsNullOrWhiteSpace())
            {
                EventLogSourceName = System.IO.Path.GetFileName(ChoAssembly.GetEntryAssemblyLocation());
            }
            if (LogSettings.LogTimeStampFormat.IsNullOrWhiteSpace())
            {
                LogSettings.LogTimeStampFormat = "yyyy-MM-dd hh:mm:ss.fffffff";
            }

            if (LogSettings.LogFileName.IsNullOrWhiteSpace())
            {
                LogSettings.LogFileName = ChoPath.ChangeExtension(ApplicationName, ChoReservedFileExt.Log);
            }

            LogSettings.LogFileName = ChoPath.CleanFileName(LogSettings.LogFileName);
            if (Path.IsPathRooted(LogSettings.LogFileName))
            {
                LogSettings.LogFileName = Path.GetFileName(LogSettings.LogFileName);
            }

            try
            {
                DateTime.Now.ToString(LogSettings.LogTimeStampFormat);
            }
            catch (Exception ex)
            {
                ChoApplication.Trace(ChoTrace.ChoSwitch.TraceError, "Invalid LogTimeStampFormat '{0}' configured.".FormatString(LogSettings.LogTimeStampFormat));
                ChoApplication.Trace(ChoTrace.ChoSwitch.TraceError, ex.ToString());
                LogSettings.LogTimeStampFormat = "yyyy-MM-dd hh:mm:ss.fffffff";
            }

            try
            {
                string sharedEnvConfigDir = null;

                if (!AppFrxConfigFilePath.IsNullOrEmpty())
                {
                    sharedEnvConfigDir = Path.GetDirectoryName(AppFrxConfigFilePath);
                }

                if (AppConfigFilePath.IsNullOrWhiteSpace())
                {
                    if (sharedEnvConfigDir.IsNullOrWhiteSpace())
                    {
                        ApplicationConfigFilePath = ChoPath.GetFullPath(Path.Combine(ChoReservedDirectoryName.Config, ChoPath.AddExtension(ChoPath.CleanFileName(ApplicationName), ChoReservedFileExt.Xml)));
                    }
                    else
                    {
                        ApplicationConfigFilePath = Path.Combine(sharedEnvConfigDir, ChoPath.AddExtension(ChoPath.CleanFileName(ApplicationName), ChoReservedFileExt.Xml));
                    }
                }
                else
                {
                    if (!Path.IsPathRooted(AppConfigFilePath))
                    {
                        if (sharedEnvConfigDir.IsNullOrWhiteSpace())
                        {
                            ApplicationConfigFilePath = ChoPath.GetFullPath(Path.Combine(ChoReservedDirectoryName.Config, AppConfigFilePath));
                        }
                        else
                        {
                            ApplicationConfigFilePath = Path.Combine(sharedEnvConfigDir, AppConfigFilePath);
                        }
                    }
                    else
                    {
                        ApplicationConfigFilePath = AppFrxConfigFilePath;
                    }
                }

                ApplicationConfigDirectory = Path.GetDirectoryName(ApplicationConfigFilePath);
            }
            catch (System.Security.SecurityException ex)
            {
                // This security exception will occur if the caller does not have
                // some undefined set of SecurityPermission flags.
                ChoApplication.Trace(ChoTrace.ChoSwitch.TraceError, ex.ToString());
            }

            #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 (LogSettings.TraceLevel < 0)
            {
                LogSettings.TraceLevel = 4;
            }

            if (!LogSettings.LogFolder.IsNullOrWhiteSpace())
            {
                ApplicationLogDirectory = ChoString.ExpandProperties(LogSettings.LogFolder, ChoEnvironmentVariablePropertyReplacer.Instance);
            }
            //else
            //    ApplicationLogDirectory = Path.Combine(Path.GetDirectoryName(ChoGlobalApplicationSettings.SharedEnvConfigPath), ChoReservedDirectoryName.Logs);

            if (ApplicationLogDirectory.IsNullOrWhiteSpace())
            {
                if (ChoApplication.AppEnvironment.IsNullOrWhiteSpace())
                {
                    ApplicationLogDirectory = Path.Combine(ChoPath.AssemblyBaseDirectory, ChoReservedDirectoryName.Logs);
                }
                else
                {
                    ApplicationLogDirectory = Path.Combine(ChoPath.AssemblyBaseDirectory, ChoReservedDirectoryName.Logs, ChoApplication.AppEnvironment);
                }
            }
            if (!Path.IsPathRooted(ApplicationLogDirectory))
            {
                ApplicationLogDirectory = Path.Combine(ChoPath.AssemblyBaseDirectory, ApplicationLogDirectory);
            }

            if (ChoApplication.ApplicationMode == ChoApplicationMode.Service)
            {
                TrayApplicationBehaviourSettings.TurnOn = false;
            }
        }
Exemplo n.º 5
0
        internal void PostInitialize()
        {
            if (ApplicationName.IsNullOrEmpty())
            {
                ChoEnvironment.Exit(101, "Missing ApplicationName.");
            }

            if (EventLogSourceName.IsNullOrWhiteSpace())
            {
                EventLogSourceName = System.IO.Path.GetFileName(ChoAssembly.GetEntryAssemblyLocation());
            }
            if (LogSettings.LogTimeStampFormat.IsNullOrWhiteSpace())
            {
                LogSettings.LogTimeStampFormat = "yyyy-MM-dd hh:mm:ss.fffffff";
            }

            if (LogSettings.LogFileName.IsNullOrWhiteSpace())
            {
                LogSettings.LogFileName = ChoPath.ChangeExtension(ApplicationName, ChoReservedFileExt.Log);
            }

            LogSettings.LogFileName = ChoPath.CleanFileName(LogSettings.LogFileName);
            if (Path.IsPathRooted(LogSettings.LogFileName))
            {
                LogSettings.LogFileName = Path.GetFileName(LogSettings.LogFileName);
            }

            try
            {
                DateTime.Now.ToString(LogSettings.LogTimeStampFormat);
            }
            catch (Exception ex)
            {
                ChoApplication.Trace(ChoTraceSwitch.Switch.TraceError, "Invalid LogTimeStampFormat '{0}' configured.".FormatString(LogSettings.LogTimeStampFormat));
                ChoApplication.Trace(ChoTraceSwitch.Switch.TraceError, ex.ToString());
                LogSettings.LogTimeStampFormat = "yyyy-MM-dd hh:mm:ss.fffffff";
            }

            try
            {
                string sharedEnvConfigDir = null;

                if (!AppFrxConfigFilePath.IsNullOrEmpty())
                {
                    sharedEnvConfigDir = Path.GetDirectoryName(ChoPath.GetFullPath(AppFrxConfigFilePath));
                }

                if (AppConfigFilePath.IsNullOrWhiteSpace())
                {
                    if (sharedEnvConfigDir.IsNullOrWhiteSpace())
                    {
                        ApplicationConfigFilePath = ChoPath.GetFullPath(Path.Combine(ChoReservedDirectoryName.Config, ChoPath.AddExtension(ChoPath.CleanFileName(ApplicationName), ChoReservedFileExt.Xml)));
                    }
                    else
                    {
                        ApplicationConfigFilePath = Path.Combine(sharedEnvConfigDir, ChoPath.AddExtension(ChoPath.CleanFileName(ApplicationName), ChoReservedFileExt.Xml));
                    }
                }
                else
                {
                    if (!Path.IsPathRooted(AppConfigFilePath))
                    {
                        if (sharedEnvConfigDir.IsNullOrWhiteSpace())
                        {
                            ApplicationConfigFilePath = ChoPath.GetFullPath(Path.Combine(ChoReservedDirectoryName.Config, AppConfigFilePath));
                        }
                        else
                        {
                            ApplicationConfigFilePath = Path.Combine(sharedEnvConfigDir, AppConfigFilePath);
                        }
                    }
                    else
                    {
                        ApplicationConfigFilePath = AppConfigFilePath;
                    }
                }

                ApplicationConfigDirectory = Path.GetDirectoryName(ChoPath.GetFullPath(ApplicationConfigFilePath));
                AppFrxConfigFilePath       = Path.Combine(ApplicationConfigDirectory, ChoReservedFileName.CoreFrxConfigFileName);
            }
            catch (System.Security.SecurityException ex)
            {
                // This security exception will occur if the caller does not have
                // some undefined set of SecurityPermission flags.
                ChoApplication.Trace(ChoTraceSwitch.Switch.TraceError, ex.ToString());
            }

            if (!LogSettings.LogFolder.IsNullOrWhiteSpace())
            {
                ApplicationLogDirectory = ChoString.ExpandProperties(LogSettings.LogFolder, ChoEnvironmentVariablePropertyReplacer.Instance);
            }

            if (ApplicationLogDirectory.IsNullOrWhiteSpace())
            {
                if (ChoApplication.AppEnvironment.IsNullOrWhiteSpace())
                {
                    ApplicationLogDirectory = Path.Combine(ChoPath.AssemblyBaseDirectory, ChoReservedDirectoryName.Logs);
                }
                else
                {
                    ApplicationLogDirectory = Path.Combine(ChoPath.AssemblyBaseDirectory, ChoReservedDirectoryName.Logs, ChoApplication.AppEnvironment);
                }
            }
            if (!Path.IsPathRooted(ApplicationLogDirectory))
            {
                ApplicationLogDirectory = Path.Combine(ChoPath.AssemblyBaseDirectory, ApplicationLogDirectory);
            }

            if (ChoApplication.ApplicationMode == ChoApplicationMode.Service)
            {
                TrayApplicationBehaviourSettings.TurnOn = false;
            }
        }
Exemplo n.º 6
0
        private void Load(string sharedEnvironmentConfigFilePath)
        {
            if (sharedEnvironmentConfigFilePath.IsNullOrWhiteSpace())
            {
                sharedEnvironmentConfigFilePath = SharedEnvironmentConfigFilePath;
            }

            BaseAppConfigDirectory = null;
            DefaultEnvironment     = null;
            EnvironmentDetails     = null;
            string backupSharedEnvironmentConfigFilePath = null;

            XmlDocument doc = new XmlDocument();

            if (!String.IsNullOrEmpty(sharedEnvironmentConfigFilePath) &&
                File.Exists(sharedEnvironmentConfigFilePath))
            {
                ChoApplication.Trace(true, "Using shared environment config file: {0}".FormatString(sharedEnvironmentConfigFilePath));
                //backupSharedEnvironmentConfigFilePath = "{0}.{1}".FormatString(sharedEnvironmentConfigFilePath, ChoReservedFileExt.Cho);

                try
                {
                    //if (File.Exists(backupSharedEnvironmentConfigFilePath))
                    //    File.SetAttributes(backupSharedEnvironmentConfigFilePath, FileAttributes.Archive);
                    using (ChoXmlDocument xmlDoc = new ChoXmlDocument(sharedEnvironmentConfigFilePath))
                    {
                        doc = xmlDoc.XmlDocument;
                    }
                    //doc.Load(sharedEnvironmentConfigFilePath);
                    //doc.Save(backupSharedEnvironmentConfigFilePath);
                    //if (File.Exists(backupSharedEnvironmentConfigFilePath))
                    //    File.SetAttributes(backupSharedEnvironmentConfigFilePath, FileAttributes.Hidden);
                }
                catch (Exception ex)
                {
                    ChoApplication.Trace(true, "Error loading shared environment config file: {0}.".FormatString(sharedEnvironmentConfigFilePath));
                    ChoApplication.Trace(true, ex.ToString());

                    //doc = LoadBackupSharedEnvironmentConfigFile(backupSharedEnvironmentConfigFilePath);
                }
            }
            else if (ChoApplication.GetSharedEnvironmentConfigXml != null)
            {
                string xml = ChoApplication.GetSharedEnvironmentConfigXml();
                backupSharedEnvironmentConfigFilePath = ChoPath.ChangeExtension(ChoReservedFileName.SharedEnvironmentConfigFileName, ChoReservedFileExt.Cho);

                if (!xml.IsNullOrWhiteSpace())
                {
                    ChoApplication.Trace(true, "Using shared environment xml:");
                    ChoApplication.Trace(true, xml);

                    try
                    {
                        doc.LoadXml(xml);
                        doc.Save(backupSharedEnvironmentConfigFilePath);
                    }
                    catch (Exception ex)
                    {
                        ChoApplication.Trace(true, "Error loading shared environment config xml.");
                        ChoApplication.Trace(true, ex.ToString());

                        doc = LoadBackupSharedEnvironmentConfigFile(backupSharedEnvironmentConfigFilePath);
                    }
                }
            }
            LoadXml(doc);
        }