private static void Refresh() { try { LoadFile(); } catch (Exception ex) { ChoTrace.Error(ex); try { string newFile = ChoPath.AddExtension(MetaDataFilepath, ChoReservedFileExt.Err); if (File.Exists(newFile)) { File.Delete(newFile); } File.Move(MetaDataFilepath, newFile); ChoXmlDocument.CreateXmlFileIfEmpty(MetaDataFilepath); LoadFile(); } catch (Exception innerEx) { ChoTrace.Error(innerEx); } } }
public void Register() { if (DefaultIcon.IsNullOrWhiteSpace()) { DefaultIcon = "{0},{1}".FormatString(ChoPath.ToShortFileName(ChoApplication.EntryAssemblyLocation), DefaultIconIndex); } Registry.ClassesRoot.CreateSubKey(Extension, RegistryKeyPermissionCheck.ReadWriteSubTree).SetValue("", ProgID); if (!ProgID.IsNullOrWhiteSpace()) { using (RegistryKey key = Registry.ClassesRoot.CreateSubKey(ProgID)) { if (Description != null) { key.SetValue("", Description); } if (DefaultIcon != null) { key.CreateSubKey("DefaultIcon").SetValue("", DefaultIcon); } if (Application != null) { key.CreateSubKey(@"Shell\Open\Command").SetValue("", "{0} {1}\"%1\" {2}".FormatString(Application, DefaultArgSwitch, AdditionalArguments)); } } } }
private static void Initialize() { if (_isInitialized) { return; } lock (_padLock) { if (_isInitialized) { return; } try { MetaDataFilepath = ConfigurationManager.AppSettings[PC_METADATA_FILEPATH_TAG]; if (MetaDataFilepath.IsNullOrWhiteSpace() || !File.Exists(MetaDataFilepath)) { MetaDataFilepath = ChoPath.AddExtension(Path.ChangeExtension(Path.Combine(Path.GetDirectoryName(ChoApplication.ApplicationConfigFilePath), Path.GetFileNameWithoutExtension(ChoApplication.ApplicationConfigFilePath)), "perf"), ChoReservedFileExt.MetaData); } ChoXmlDocument.CreateXmlFileIfEmpty(MetaDataFilepath); Refresh(); } finally { _isInitialized = true; } } }
public static void AppendPrivatePath(string path) { if (String.IsNullOrEmpty(path)) { return; } path = ChoPath.GetFullPath(path); if (Path.HasExtension(path)) { path = Path.GetDirectoryName(path); } if (String.IsNullOrEmpty(AppDomain.CurrentDomain.SetupInformation.PrivateBinPath)) { AppDomain.CurrentDomain.SetupInformation.PrivateBinPath = path; } else { if (!AppDomain.CurrentDomain.SetupInformation.PrivateBinPath.Contains(path)) { AppDomain.CurrentDomain.SetupInformation.PrivateBinPath = String.Format("{0};{1}", AppDomain.CurrentDomain.SetupInformation.PrivateBinPath, path); } } AppDomain.CurrentDomain.AppendPrivatePath(path); }
internal static void OpenExeConfiguration(bool doBackup) { string prevAppConfigPath = _appConfigPath; _appConfigPath = ChoGlobalApplicationSettings.Me.ApplicationConfigFilePath; _appConfigPath = ChoPath.GetFullPath(_appConfigPath); if (_appConfigPath != prevAppConfigPath) { Trace.TraceInformation("Using AppConfigPath: {0}".FormatString(_appConfigPath)); } if (!File.Exists(_appConfigPath)) { if (!prevAppConfigPath.IsNullOrWhiteSpace() && File.Exists(prevAppConfigPath)) { File.Copy(prevAppConfigPath, _appConfigPath, true); } // else // { //// if (ChoEnvironmentSettings.CreateConfigFileIfNotExists) //// { // Directory.CreateDirectory(Path.GetDirectoryName(_appConfigPath)); // using (File.CreateText(_appConfigPath)) // { } //// } // } OpenConfiguration(_appConfigPath, false); } else { OpenConfiguration(_appConfigPath, doBackup); } }
public static string GetConfigFilePath() { if (!_configFilePath.IsNullOrWhiteSpace()) { return(_configFilePath); } else { string configFilePath; string appFrxFilePath = ChoAppFrxSettings.Me.AppFrxFilePath; if (appFrxFilePath.IsNullOrWhiteSpace()) { configFilePath = ChoPath.GetFullPath(Path.Combine(ChoReservedDirectoryName.Config, ChoReservedFileName.CoreFrxConfigFileName)); } else { appFrxFilePath = ChoString.ExpandProperties(appFrxFilePath, ChoEnvironmentVariablePropertyReplacer.Instance); if (ChoPath.IsDirectory(appFrxFilePath)) { appFrxFilePath = Path.Combine(appFrxFilePath, ChoReservedFileName.CoreFrxConfigFileName); } configFilePath = appFrxFilePath; } return(configFilePath); } }
protected override void OnAfterCommandLineArgObjectLoaded(string[] commandLineArgs) { if (!SettingsFilePath.IsNullOrWhiteSpace()) { SettingsFilePath = ChoPath.GetFullPath(SettingsFilePath); } }
public static string GetFullPath(string directory, string fileName) { ChoGuard.ArgumentNotNull(fileName, "Filename"); if (Path.IsPathRooted(fileName)) { return(fileName); } else { if (!Path.HasExtension(fileName)) { fileName = Path.ChangeExtension(fileName, ChoReservedFileExt.Log); } if (String.IsNullOrEmpty(directory)) { directory = ChoFileProfileSettings.Me.LogDirectory; } else if (!String.IsNullOrEmpty(ChoFileProfileSettings.Me.LogDirectory) && !directory.StartsWith(ChoFileProfileSettings.Me.LogDirectory)) { directory = Path.Combine(ChoFileProfileSettings.Me.LogDirectory, directory); } if (!String.IsNullOrEmpty(directory) && !Directory.Exists(directory)) { Directory.CreateDirectory(directory); } return(ChoPath.GetFullPath(Path.Combine(directory, fileName))); } }
public static string Save(object target) { ChoGuard.ArgumentNotNull(target, "Target"); string tmpPath = ChoPath.GetTempFileName(); Serialize(tmpPath, target); return(tmpPath); }
// If the type of the value to convert is string, parses the string // and returns the integer to set the value of the property to. // This example first extends the integer array that supplies the // standard values collection if the user-entered value is not // already in the array. public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { if (value != null && value is string) { return(ChoPath.GetFullPath(value as string)); } return(value); }
public ChoNACHAReader(string filePath, ChoNACHAConfiguration configuration = null) { ChoGuard.ArgumentNotNullOrEmpty(filePath, "FilePath"); Configuration = configuration; Init(); _textReader = new StreamReader(ChoPath.GetFullPath(filePath), Configuration.GetEncoding(filePath), false, Configuration.BufferSize); _closeStreamOnDispose = true; }
public bool Initialize(bool beforeFieldInit, object state) { if (!beforeFieldInit) { ChoObjConfigurable.Load <IFormatProvider>(ChoPath.AddExtension(typeof(ChoFormatProviderSettings).FullName, ChoReservedFileExt.Log), ChoType.GetTypes <IFormatProvider>(), _formatProviders, FormatProviderTypes, ChoDefaultObjectKey.Name); } //else //ChoStreamProfile.Clean(ChoReservedDirectoryName.Settings, ChoPath.AddExtension(typeof(ChoFormatProviderSettings).FullName, ChoReservedFileExt.Err)); return(false); }
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()); } } }
protected string ResolveFileText(ref string filePath) { if (DoPropertyResolve) { string tmpFileName = Path.ChangeExtension(ChoPath.GetTempFileName(), Path.GetExtension(filePath)); File.WriteAllText(tmpFileName, File.ReadAllText(filePath).ExpandProperties()); filePath = tmpFileName; ChoTrace.DebugFormat("{0}: Temp file created at '{1}'", Name, tmpFileName); return(tmpFileName); } return(null); }
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(); }
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 void Initialize() { if (ConfigurationMetaDataFilePath.IsNullOrWhiteSpace()) { OverridenConfigurationMetaDataFilePath = ChoPath.AddExtension(Path.Combine(Path.GetDirectoryName(ChoGlobalApplicationSettings.Me.ApplicationConfigFilePath), ChoReservedDirectoryName.Meta, Path.GetFileNameWithoutExtension(ChoGlobalApplicationSettings.Me.ApplicationConfigFilePath)), ChoReservedFileExt.MetaData); } else { OverridenConfigurationMetaDataFilePath = ConfigurationMetaDataFilePath; } if (PCMetaDataFilePath.IsNullOrWhiteSpace()) { OverridenPCMetaDataFilePath = ChoPath.AddExtension(Path.ChangeExtension(Path.Combine(Path.GetDirectoryName(ChoGlobalApplicationSettings.Me.ApplicationConfigFilePath), ChoReservedDirectoryName.Meta, Path.GetFileNameWithoutExtension(ChoGlobalApplicationSettings.Me.ApplicationConfigFilePath)), ChoReservedFileExt.Perf), ChoReservedFileExt.MetaData); } else { OverridenPCMetaDataFilePath = PCMetaDataFilePath; } if (ETLMetaDataFilePath.IsNullOrWhiteSpace()) { OverridenETLMetaDataFilePath = ChoPath.AddExtension(Path.ChangeExtension(Path.Combine(Path.GetDirectoryName(ChoGlobalApplicationSettings.Me.ApplicationConfigFilePath), ChoReservedDirectoryName.Meta, Path.GetFileNameWithoutExtension(ChoGlobalApplicationSettings.Me.ApplicationConfigFilePath)), ChoReservedFileExt.ETL), ChoReservedFileExt.MetaData); } else { OverridenETLMetaDataFilePath = ETLMetaDataFilePath; } if (OverridenConfigurationMetaDataFilePath.IsNullOrWhiteSpace()) { throw new ApplicationException("ConfigurationMetaDataFilePath can not be null."); } if (OverridenPCMetaDataFilePath.IsNullOrWhiteSpace()) { throw new ApplicationException("PCMetaDataFilePath can not be null."); } if (OverridenETLMetaDataFilePath.IsNullOrWhiteSpace()) { throw new ApplicationException("ETLMetaDataFilePath can not be null."); } }
public virtual void Enqueue(object obj) { if (_internalQueue.Count < _capacity) { _internalQueue.Enqueue(obj); _commonQueue.Add(obj); } else { string filePath = ChoPath.GetRandomFileName(_storageDir); ChoObject.Serialize(filePath, obj); _persistanceQueue.Enqueue(filePath); _commonQueue.Add(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); }
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); } } }
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)); } }
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); } }
public ChoQueue(int capacity, string storageDir) { if (capacity <= 0) { _internalQueue = new Queue(); } else { _capacity = capacity; _internalQueue = new Queue(capacity); } if (storageDir == null) { _storageDir = Path.Combine(ChoApplication.ApplicationBaseDirectory, ChoPath.GetRandomFileName()); } else { _storageDir = Path.Combine(storageDir, ChoPath.GetRandomFileName()); } }
public ChoQueue(int capacity, string storageDir) { if (capacity <= 0) { _internalQueue = new Queue <T>(); } else { _capacity = capacity; _internalQueue = new Queue <T>(capacity); } if (storageDir == null) { _storageDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ChoPath.GetRandomFileName()); } else { _storageDir = Path.Combine(storageDir, ChoPath.GetRandomFileName()); } }
private void Refresh() { if (ChoAppFrxSettings.Me.DisableMetaDataConfig) { return; } try { LoadFile(); } catch (ChoFatalApplicationException) { throw; } catch (Exception ex) { ChoTrace.Error(ex); try { string newFile = ChoPath.AddExtension(MetaDataFilePath, ChoReservedFileExt.Err); if (File.Exists(newFile)) { File.Delete(newFile); } File.Move(MetaDataFilePath, newFile); ChoXmlDocument.CreateXmlFileIfEmpty(MetaDataFilePath); LoadFile(); } catch (Exception innerEx) { ChoTrace.Error(innerEx); } } }
protected override object Execute(object value, out bool isHandled) { isHandled = false; if (Script.IsNullOrWhiteSpace()) { return(value); } string script = ResolveText(Script); string arguments = !Arguments.IsNullOrWhiteSpace() ? "{0} {1}".FormatString(value.ToNString(), ResolveText(Arguments)) : value.ToNString(); string workingDirectory = WorkingDirectory.IsNullOrWhiteSpace() ? ChoApplication.ApplicationBaseDirectory : ResolveText(WorkingDirectory); //Create temp script file _tmpFileName = Path.ChangeExtension(ChoPath.GetTempFileName(), ChoReservedFileExt.JS); File.WriteAllText(_tmpFileName, script); ChoTrace.DebugFormat("{0}: Temp file created at '{1}'", Name, _tmpFileName); using (ChoProcess p = new ChoProcess("cscript.exe", "{0} {1} //Nologo".FormatString(_tmpFileName, arguments))) { p.WorkingDirectory = workingDirectory; return(p.Execute().StdOut); } }
public override ChoBaseConfigurationElement GetMe(Type type) { ChoGuard.ArgumentNotNull(type, "Type"); if (_configurationElement == null) { lock (SyncRoot) { if (_configurationElement == null) { object customConfigurationSectionHandler = Activator.CreateInstance(_configurationSectionHandlerType) as IChoCustomConfigurationSectionHandler; if (customConfigurationSectionHandler == null) { throw new ChoConfigurationConstructionException(String.Format("Missing {0} custom configuration section handler.", _configurationSectionHandlerType.FullName)); } if (!(customConfigurationSectionHandler is IChoCustomConfigurationSectionHandler)) { throw new ChoConfigurationConstructionException(String.Format("Mismatched {0} custom configuration section handler type specified.", _configurationSectionHandlerType.FullName)); } _configurationElement = new ChoCustomConfigurationElement(customConfigurationSectionHandler as IChoCustomConfigurationSectionHandler, _parameters); _configurationElement.DefaultConfigSectionHandlerType = ConfigSectionHandlerType; _configurationElement.ConfigFilePath = ConfigFilePath; ChoStandardConfigurationMetaDataInfo standardConfigurationMetaDataInfo = new ChoStandardConfigurationMetaDataInfo(); standardConfigurationMetaDataInfo.BindingMode = BindingMode; if (ConfigStorageType != null) { standardConfigurationMetaDataInfo.ConfigStorageType = ConfigStorageType.AssemblyQualifiedName; } standardConfigurationMetaDataInfo.ConfigurationMetaDataLogInfo = new ChoConfigurationMetaDataLogInfo(); standardConfigurationMetaDataInfo.ConfigurationMetaDataLogInfo.LogCondition = LogCondition; standardConfigurationMetaDataInfo.ConfigurationMetaDataLogInfo.LogTimeStampFormat = LogTimeStampFormat; standardConfigurationMetaDataInfo.ConfigurationMetaDataLogInfo.LogDirectory = LogDirectory; standardConfigurationMetaDataInfo.ConfigurationMetaDataLogInfo.LogFileName = LogFileName.IsNullOrEmpty() ? ChoPath.AddExtension(type.FullName, ChoReservedFileExt.Log) : LogFileName; standardConfigurationMetaDataInfo.Defaultable = Defaultable; _configurationElement.MetaDataInfo = standardConfigurationMetaDataInfo; LoadParameters(_configurationElement); } } } return(_configurationElement); }
public ChoLoggableObject() { _logFileName = ChoPath.AddExtension(GetType().FullName, ChoReservedFileExt.Log); }
private void InitializeConfigElement(ChoBaseConfigurationElement configElement, Type type) { if (configElement == null) { return; } configElement.DefaultConfigSectionHandlerType = ConfigSectionHandlerType; configElement.ConfigFilePath = ConfigFilePath; ChoStandardConfigurationMetaDataInfo standardConfigurationMetaDataInfo = new ChoStandardConfigurationMetaDataInfo(); standardConfigurationMetaDataInfo.BindingMode = BindingMode; if (ConfigStorageType != null) { standardConfigurationMetaDataInfo.ConfigStorageType = ConfigStorageType.AssemblyQualifiedName; } standardConfigurationMetaDataInfo.ConfigurationMetaDataLogInfo = new ChoConfigurationMetaDataLogInfo(); standardConfigurationMetaDataInfo.ConfigurationMetaDataLogInfo.LogCondition = LogCondition; standardConfigurationMetaDataInfo.ConfigurationMetaDataLogInfo.LogTimeStampFormat = LogTimeStampFormat; standardConfigurationMetaDataInfo.ConfigurationMetaDataLogInfo.LogDirectory = LogDirectory; standardConfigurationMetaDataInfo.ConfigurationMetaDataLogInfo.LogFileName = LogFileName.IsNullOrEmpty() ? ChoPath.AddExtension(type.FullName, ChoReservedFileExt.Log) : LogFileName; standardConfigurationMetaDataInfo.Defaultable = Defaultable; standardConfigurationMetaDataInfo.IgnoreCase = IgnoreCase; standardConfigurationMetaDataInfo.Silent = Silent; configElement.MetaDataInfo = standardConfigurationMetaDataInfo; LoadParameters(configElement); ChoConfigurationMetaDataManager.SetDefaultMetaDataInfo(configElement); }