/// <summary> /// Creates the directory. /// </summary> /// <param name="sourceDirPath">The source dir path.</param> /// <param name="overwrite">if set to <c>true</c> [overwrite].</param> /// <param name="logger">The logger.</param> /// <exception cref="System.ArgumentNullException">sourceDirPath;@Please provide a valid source directory path.</exception> public static void CreateDirectory(string sourceDirPath, bool overwrite = false, ILogWriter logger = null) { if (string.IsNullOrEmpty(sourceDirPath)) { throw new ArgumentNullException("sourceDirPath", @"Please provide a valid source directory path."); } var directory = new DirectoryInfo(sourceDirPath); if (directory.Exists && overwrite) { // Delete all non-read only directories Parallel.ForEach(directory.GetDirectories(), dir => { try { if (!dir.Attributes.HasFlag(FileAttributes.ReadOnly)) { dir.Delete(true); } else { dir.Attributes = FileAttributes.Normal; dir.Delete(true); } } catch (Exception exc) { logger?.Write(exc); } }); // Retrieve the rest of the files var files = directory.GetFiles("*", SearchOption.AllDirectories).ToList(); // Delete existing files Parallel.ForEach(files, file => Task.Factory.StartNew(() => { try { file.IsReadOnly = false; file.Delete(); } catch (Exception exc) /*Don't care if it fails*/ { logger?.Write(exc); } })); directory.Create(); logger?.Information("Creating output directory: \"" + directory.Name + "\"", Category.Exception, Priority.High); } if (!directory.Exists) { directory.Create(); logger?.Information("Creating output directory: \"" + directory.Name + "\"", Category.Exception, Priority.High); } }
private void RunPendingStatements() { //var session = SessionLocator.For(_baseType); try { IDomainSessionFactoryProvider provider = ServiceLocator.Current.GetInstance <IDomainSessionFactoryProvider>(); using (var session = provider.SessionFactory.OpenStatelessSession()) { //using(var connection = session.Connection;) foreach (var sqlStatement in _sqlStatements.Distinct()) { Logger.Debug(sqlStatement); session.CreateSQLQuery(sqlStatement) .SetTimeout((int)Math.Round(MonahrqConfiguration.SettingsGroup .MonahrqSettings().LongTimeout.TotalSeconds)) .ExecuteUpdate(); _reportsCoordinator.Information("Data Migration{0}\tExecuting SQL Query: {1}", System.Environment.NewLine, String.Format("{0}", sqlStatement)); } } } finally { _sqlStatements.Clear(); } }
/// <summary> /// Configurations the debug log. /// </summary> /// <param name="method">The method.</param> /// <param name="message">The message.</param> static internal void ConfigDebugLog(String method, String message) { if (Logger == null) { return; } Logger.Information("MonahrqConfig::{0}(): {1}", method, message); }
private OleDbConnection GetSourceConnection(string path) { var workingPath = this.GetWorkingPath(path); var conn = this.OpenConnection(workingPath); // identify source schema version this.DetectImportConfiguration(conn); this.progressCallbackAction("Detected schema version: " + this.config.SchemaVersion); Logger.Information("CMS Dataset AccessDBSchemaVersion: {0}", this.config.SchemaVersion); if (!this.config.IsValidSchemaVersion) { conn.Dispose(); throw new Exception("Unsupported data source format"); } return(conn); }