Esempio n. 1
0
        public static void Main(string[] args)
        {
            //File.OpenRead()
            var fullPath = ChoPath.GetFullPath("Emp.csv");

            using (var choCsvReader = new ChoCSVReader <EmployeeRec>("D:\\sourcecontrol\\repos\\ChoETLTests\\ConsoleApp1\\Emp.csv").WithFirstLineHeader()) {
                foreach (var employeeRec in choCsvReader.AsEnumerable( ))
                {
                    Console.WriteLine(employeeRec.DumpAsJson());
                }
            }
        }
        public static string GetConfigFile(XmlNode section)
        {
            string configPath = ChoConfigurationManager.AppConfigFilePath;

            if (section.Attributes[PathToken] != null)
            {
                configPath = section.Attributes[PathToken].Value;
            }

            configPath = ChoPath.GetFullPath(configPath);

            return(configPath);
        }
        public ChoNACHAWriter(string filePath, ChoNACHAConfiguration configuration = null)
        {
            ChoGuard.ArgumentNotNullOrEmpty(filePath, "FilePath");
            Configuration = configuration;
            if (Configuration == null)
            {
                Configuration = new ChoNACHAConfiguration();
            }

            _streamWriter         = new StreamWriter(ChoPath.GetFullPath(filePath), false, Configuration.Encoding, Configuration.BufferSize);
            _closeStreamOnDispose = true;

            Init();
        }
Esempio n. 4
0
        protected string GetFullPath(string filePath)
        {
            if (filePath.IsNullOrEmpty())
            {
                return(filePath);
            }
            if (!Path.IsPathRooted(filePath))
            {
                filePath = Path.Combine(Path.GetDirectoryName(ChoGlobalApplicationSettings.Me.ApplicationConfigFilePath), filePath); //ChoPath.ChangeExtension(filePath, ChoReservedFileExt.Xml));
            }
            filePath = ChoPath.GetFullPath(filePath);

            return(filePath);
        }
        public override object Load(ChoBaseConfigurationElement configElement, XmlNode node)
        {
            base.Load(configElement, node);

            ConfigurationManager.RefreshSection(APP_SETTINGS_SECTION_NAME);
            ConfigFilePath       = _configuration.FilePath;
            _appSettingsFilePath = ChoPath.GetFullPath(GetAppSettingsFilePathIfAnySpecified());
            if (!_appSettingsFilePath.IsNullOrWhiteSpace())
            {
                _hasAppSettingsFilePath = true;
            }

            ConfigSectionName = APP_SETTINGS_SECTION_NAME;
            return(ConfigurationManager.AppSettings);
        }
Esempio n. 6
0
        public static string GetFullPath(string name, string path)
        {
            if (path == null || path.Trim().Length == 0)
            {
                return(path);
            }

            path = path.Trim();

            if (_files[name] != null)
            {
                return(System.IO.Path.Combine(System.IO.Path.GetDirectoryName(_files[name]), path));
            }
            else
            {
                return(ChoPath.GetFullPath(path));
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Initialize the object memeber. Called by Constructors
        /// </summary>
        /// <param name="fileName">Log file name</param>
        /// <param name="maxFileSize">Max file size</param>
        /// <param name="maxFileCount">Max file count</param>
        /// <param name="mode">Log file mode</param>
        /// <param name="cyclic"></param>
        /// <param name="autoBackup">Auto backup flag</param>
        /// <param name="allowSplitMsg">Auto backup flag</param>
        void Init(string fileName, long maxFileSize, int maxFileCount, FileMode mode, bool cyclic, bool autoBackup, bool allowSplitMsg)
        {
            _lastBackupTime = DateTime.Today;

            if (maxFileSize <= 0)
            {
                throw new ArgumentOutOfRangeException("Invalid maximum file length.");
            }
            if (maxFileCount <= 0)
            {
                throw new ArgumentOutOfRangeException("Invalid maximum file count.");
            }

            _maxFileSize   = maxFileSize;
            _maxFileCount  = maxFileCount;
            _allowSplitMsg = allowSplitMsg;
            _autoBackup    = autoBackup;
            _cyclic        = cyclic;

            //check and set autobackup to true, if cyclic option is on
            if (cyclic)
            {
                _autoBackup = true;
            }

            string fullPath = ChoPath.GetFullPath(fileName);

            _fileDir  = Path.GetDirectoryName(fullPath);
            _fileBase = Path.GetFileNameWithoutExtension(fullPath);
            _fileExt  = Path.GetExtension(fullPath);

            //Calculate file decimals
            _fileDecimals = 1;
            int decimalBase = 10;

            while (decimalBase < _maxFileCount)
            {
                ++_fileDecimals;
                decimalBase *= 10;
            }

            switch (mode)
            {
            case FileMode.Create:
            case FileMode.CreateNew:
            case FileMode.Truncate:
                // Delete old files
                for (int fileIndex = 0; fileIndex < _maxFileCount; ++fileIndex)
                {
                    string file = GetBackupFileName(fileIndex);
                    if (File.Exists(file))
                    {
                        File.Delete(file);
                    }
                }
                break;

            default:
                // Position file pointer to the last backup file
                for (int fileIndex = 0; fileIndex < _maxFileCount; ++fileIndex)
                {
                    if (File.Exists(GetBackupFileName(fileIndex)))
                    {
                        _nextFileIndex = fileIndex + 1;
                    }
                    else
                    {
                        break;
                    }
                }

                //if the file count reaches the max file count, back those up
                if (_nextFileIndex == _maxFileCount)
                {
                    BackupAllFiles();
                }
                else
                {
                    Seek(0, SeekOrigin.End);

                    if (_autoBackup && Position > 0)
                    {
                        BackupAndResetStream();
                        BackupAllFiles();
                    }
                }

                Seek(0, SeekOrigin.End);
                break;
            }
        }
Esempio n. 8
0
        public object Create(object parent, object configContext, XmlNode section)
        {
            XPathNavigator navigator = section.CreateNavigator();

            string path = (string)navigator.Evaluate("string(@path)");

            if (path != null && path.Length > 0)
            {
                bool envFriendly = false;
                try
                {
                    envFriendly = Boolean.Parse((string)navigator.Evaluate("string(@envFriendly)"));
                }
                catch { }

                if (envFriendly)
                {
                    path = ChoEnvironmentSettings.ToEnvSpecificConfigFile(path);
                }

                path = ChoPath.GetFullPath(path);
                if (!File.Exists(path))
                {
                    throw new ApplicationException(String.Format(CultureInfo.InvariantCulture, Resources.ES1002, path));
                }

                XmlDocument document = new XmlDocument();
                document.Load(path);

                section   = document.DocumentElement;
                navigator = section.CreateNavigator();
            }

            string typename = (string)navigator.Evaluate("string(@type)");

            if (typename == null || typename.Trim().Length == 0)
            {
                throw new ApplicationException(String.Format(CultureInfo.InvariantCulture, Resources.ES1003, section.Name));
            }

            Type type = Type.GetType(typename);

            if (type == null)
            {
                type = ChoType.GetType(typename);
            }

            if (type == null)
            {
                throw new ApplicationException(String.Format(CultureInfo.InvariantCulture, Resources.ES1004, typename));
            }

            ChoConfigFilesMapper.Add(section.Name, path);

            XmlSerializer serializer = new XmlSerializer(type);

            try
            {
                return(serializer.Deserialize(new XmlNodeReader(section)));
            }
            catch
            {
                if (section.Name != type.Name && section.Name.ToUpper() == type.Name.ToUpper())
                {
                    XmlNode newSection = new XmlDocument().CreateElement(type.Name);
                    newSection.InnerXml = section.InnerXml;
                    section             = newSection;
                }
                return(serializer.Deserialize(new XmlNodeReader(section)));
            }
        }
        private void LoadXml(XmlDocument doc)
        {
            if (doc == null)
            {
                return;
            }

            XmlNode rootNode = doc.SelectSingleNode("//sharedEnvironment");

            if (rootNode != null)
            {
                if (rootNode.Attributes["baseAppSharedConfigDirectory"] != null)
                {
                    BaseAppConfigDirectory = ChoPath.GetFullPath(ChoString.ExpandProperties(rootNode.Attributes["baseAppSharedConfigDirectory"].Value, ChoEnvironmentVariablePropertyReplacer.Instance));
                }
                if (BaseAppConfigDirectory.IsNullOrWhiteSpace())
                {
                    BaseAppConfigDirectory = ChoPath.AssemblyBaseDirectory;
                }

                if (rootNode.Attributes["defaultEnvironment"] != null)
                {
                    DefaultEnvironment = rootNode.Attributes["defaultEnvironment"].Value;
                }

                XmlNodeList envNodes = rootNode.SelectNodes("environment");
                if (envNodes != null)
                {
                    List <ChoEnvironmentDetails> environmentDetailList = new List <ChoEnvironmentDetails>();
                    foreach (XmlNode envNode in envNodes)
                    {
                        ChoEnvironmentDetails environmentDetails = new ChoEnvironmentDetails();

                        if (envNode.Attributes["name"] != null)
                        {
                            environmentDetails.Name = envNode.Attributes["name"].Value;

                            if (!environmentDetails.Name.IsNullOrWhiteSpace())
                            {
                                if (envNode.Attributes["freeze"] != null)
                                {
                                    Boolean.TryParse(envNode.Attributes["freeze"].Value, out environmentDetails.Freeze);
                                }

                                if (envNode.Attributes["appFrxFilePath"] != null)
                                {
                                    environmentDetails.AppFrxFilePath = envNode.Attributes["appFrxFilePath"].Value;
                                    if (!environmentDetails.AppFrxFilePath.IsNullOrWhiteSpace())
                                    {
                                        if (!Path.IsPathRooted(environmentDetails.AppFrxFilePath))
                                        {
                                            environmentDetails.AppFrxFilePath = ChoString.ExpandProperties(environmentDetails.AppFrxFilePath, ChoEnvironmentVariablePropertyReplacer.Instance);

                                            if (!Path.IsPathRooted(environmentDetails.AppFrxFilePath))
                                            {
                                                environmentDetails.AppFrxFilePath = Path.Combine(BaseAppConfigDirectory, environmentDetails.AppFrxFilePath);
                                            }

                                            if (ChoPath.IsDirectory(environmentDetails.AppFrxFilePath))
                                            {
                                                environmentDetails.AppFrxFilePath = Path.Combine(environmentDetails.AppFrxFilePath, ChoReservedFileName.CoreFrxConfigFileName);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        environmentDetails.AppFrxFilePath = Path.Combine(BaseAppConfigDirectory, environmentDetails.Name, ChoReservedFileName.CoreFrxConfigFileName);
                                    }
                                }
                                else
                                {
                                    environmentDetails.AppFrxFilePath = Path.Combine(BaseAppConfigDirectory, environmentDetails.Name, ChoReservedFileName.CoreFrxConfigFileName);
                                }

                                XmlNodeList machineNodes = envNode.SelectNodes("machine");
                                if (machineNodes != null)
                                {
                                    List <string> machines = new List <string>();
                                    foreach (XmlNode machineNode in machineNodes)
                                    {
                                        machines.Add(machineNode.InnerText);
                                    }
                                    environmentDetails.Machines = machines.ToArray();
                                }

                                environmentDetailList.Add(environmentDetails);
                            }
                        }
                    }

                    EnvironmentDetails = environmentDetailList.ToArray();

                    foreach (ChoEnvironmentDetails environmentDetail in EnvironmentDetails)
                    {
                        environmentDetail.Parent = this;
                    }
                }
            }
        }
Esempio n. 10
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;
            }
        }
Esempio n. 11
0
 public static void OpenConfiguration(string appConfigPath)
 {
     OpenConfiguration(ChoPath.GetFullPath(appConfigPath), true);
 }
Esempio n. 12
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;
            }
        }
        /// <summary>
        /// <para>Returns the <see cref="DateTime"/> of the last change of the information watched</para>
        /// <para>The information is retrieved using the watched file modification timestamp</para>
        /// </summary>
        /// <returns>The <see cref="DateTime"/> of the last modificaiton, or <code>DateTime.MinValue</code> if the information can't be retrieved</returns>
        protected override DateTime GetCurrentLastWriteTime()
        {
            lock (_padLock)
            {
                DateTime lastWriteTime;
                DateTime createdTime;
                ChoConfigurationChangeAction configurationChangeAction = ChoConfigurationChangeAction.Changed;

                if (File.Exists(_configFilePath))
                {
                    lastWriteTime = File.GetLastWriteTime(_configFilePath);
                    createdTime   = File.GetCreationTime(_configFilePath);
                }
                else
                {
                    lastWriteTime = DateTime.MinValue;
                    createdTime   = DateTime.MinValue;
                }

                try
                {
                    if (lastWriteTime == DateTime.MinValue)
                    {
                        if (_lastWriteTime == DateTime.MinValue)
                        {
                        }
                        else
                        {
                            configurationChangeAction = ChoConfigurationChangeAction.Deleted;
                        }
                    }
                    else
                    {
                        if (_lastWriteTime == DateTime.MinValue)
                        {
                            configurationChangeAction = ChoConfigurationChangeAction.Created;
                        }
                        else
                        {
                            if (_lastWriteTime != lastWriteTime)
                            {
                                configurationChangeAction = ChoConfigurationChangeAction.Changed;
                            }
                        }
                    }
                }
                finally
                {
                    if (_configurationChangeAction != configurationChangeAction)
                    {
                        _configurationChangeAction         = configurationChangeAction;
                        _configurationFileChangedEventArgs = new ChoConfigurationFileChangedEventArgs(this.SectionName, ChoPath.GetFullPath(_configFilePath), _configurationChangeAction, _lastWriteTime);
                    }
                    _lastWriteTime = lastWriteTime;
                    _createdTime   = createdTime;
                }

                return(_lastWriteTime);
            }
        }
        /// <summary>
        /// <para>Initialize a new <see cref="ChoConfigurationChangeFileWatcher"/> class with the path to the configuration file and the name of the section</para>
        /// </summary>
        /// <param name="_configFilePath">
        /// <para>The full path to the configuration file.</para>
        /// </param>
        /// <param name="_configurationSectionName">
        /// <para>The name of the configuration section to watch.</para>
        /// </param>
        public ChoConfigurationChangeFileWatcher(string configurationSectionName, string configFilePath)
            : base(configurationSectionName)
        {
            if (string.IsNullOrEmpty(configFilePath))
            {
                throw new ArgumentException(Resources.ExceptionStringNullOrEmpty, "configFilePath");
            }

            this._configFilePath = configFilePath;
            _configurationFileChangedEventArgs = new ChoConfigurationFileChangedEventArgs(configurationSectionName, ChoPath.GetFullPath(_configFilePath), _configurationChangeAction, DateTime.MinValue);
        }
Esempio n. 15
0
 public static ChoHL7Message Parse(string filePath, ChoHL7Configuration configuration = null)
 {
     configuration = configuration ?? ChoHL7Configuration.Instance;
     return(Parse(new StreamReader(ChoPath.GetFullPath(filePath), configuration.GetEncoding(filePath), false, configuration.BufferSize), configuration));
 }