private void PurgeOutPath(FileConnection Connection, string taskInfo) { Throw.IfNull(Connection); if (Connection.inout != InOut.both && Connection.inout != InOut.outbound || Connection.outpath == null) { return; } Directory.CreateDirectory(Connection.outpath); _logger.Log(LogLevel.Debug, $"{taskInfo} Purging outpath: {Connection.outpath}"); var files = _util.DirSearch(Connection.outpath, "*.*"); foreach (var file in files) { var attr = File.GetAttributes(file); if (attr.HasFlag(FileAttributes.Hidden)) { _logger.Log(LogLevel.Debug, $"{taskInfo} Deleting hidden file {file}."); File.Delete(file); //delete hidden files like .DS_Store continue; } var lastwritetime = File.GetLastWriteTime(file); var purgetime = DateTime.Now.AddHours(Connection.outpathRetentionHours * -1); if (lastwritetime.CompareTo(purgetime) < 0) { _logger.Log(LogLevel.Debug, $"Purging: {file}"); File.Delete(file); } } _util.CleanUpDirectory(Connection.outpath); }
internal ConnectionBase GetNextAvailable(HTTPRequest request) { int activeConnections = 0; ConnectionBase conn = null; // Check the last created connection first. This way, if a higher level protocol is present that can handle more requests (== HTTP/2) that protocol will be chosen // and others will be closed when their inactivity time is reached. for (int i = Connections.Count - 1; i >= 0; --i) { conn = Connections[i]; if (conn.State == HTTPConnectionStates.Initial || conn.State == HTTPConnectionStates.Free || conn.CanProcessMultiple) { HTTPManager.Logger.Verbose("HostConnection", string.Format("GetNextAvailable - returning with connection. state: {0}, CanProcessMultiple: {1}", conn.State, conn.CanProcessMultiple), this.Context, request.Context, conn.Context); return(conn); } activeConnections++; } if (activeConnections >= HTTPManager.MaxConnectionPerServer) { HTTPManager.Logger.Verbose("HostConnection", string.Format("GetNextAvailable - activeConnections({0}) >= HTTPManager.MaxConnectionPerServer({1})", activeConnections, HTTPManager.MaxConnectionPerServer), this.Context, request.Context); return(null); } string key = HostDefinition.GetKeyForRequest(request); conn = null; #if UNITY_WEBGL && !UNITY_EDITOR conn = new WebGLConnection(key); #else if (request.CurrentUri.IsFile) { conn = new FileConnection(key); } else { #if !BESTHTTP_DISABLE_ALTERNATE_SSL // Hold back the creation of a new connection until we know more about the remote host's features. // If we send out multiple requests at once it will execute the first and delay the others. // While it will decrease performance initially, it will prevent the creation of TCP connections // that will be unused after their first request processing if the server supports HTTP/2. if (activeConnections >= 1 && (this.ProtocolSupport == HostProtocolSupport.Unknown || this.ProtocolSupport == HostProtocolSupport.HTTP2)) { HTTPManager.Logger.Verbose("HostConnection", string.Format("GetNextAvailable - waiting for protocol support message. activeConnections: {0}, ProtocolSupport: {1} ", activeConnections, this.ProtocolSupport), this.Context, request.Context); return(null); } #endif conn = new HTTPConnection(key); HTTPManager.Logger.Verbose("HostConnection", string.Format("GetNextAvailable - creating new connection, key: {0} ", key), this.Context, request.Context, conn.Context); } #endif Connections.Add(conn); return(conn); }
public void Setup() { FileConnection = new FileConnection { Directory = @"C:\1CDatabases\" }; }
/// <summary> /// Инициализация IoC контейнера для оракла /// </summary> /// <param name="x">Инициализатор</param> /// <param name="connectionString">Строка подключения</param> private static void InitializeStructureMapForOracleFile(IInitializationExpression x, string connectionString) { var connection = new FileConnection(connectionString); var strategy = new OracleStrategy(connection); x.ForSingletonOf <IDbConnection>().Use(connection); x.ForSingletonOf <IDatabaseStrategy>().Use(strategy); x.ForSingletonOf <ISysDatabaseStrategy>().Use(new FileSysStrategy(new OracleSysStrategy(connection, strategy), connection)); }
public override void Emit(SsisEmitterContext context) { base.Emit(context); var fc = new FileConnection(Name + _relativePath, _relativePath); fc.Initialize(context); fc.Emit(context); ExecutePackageTaskObject.Connection = fc.Name; }
//数据库连接 private bool DBConnection() { try { file_conn = FileConnection.Create(dbPath); } catch (SQLiteException) { return(false); } return(true); }
// //Functions // /// <summary> /// Creates a connection to the SQLite DB /// </summary> /// <returns></returns> public bool Connect() { if (File.Exists(_sqlitePath) && FileConnection.State != ConnectionState.Open) { FileConnection.Open(); Console.WriteLine("File connection made."); return(true); } else { Console.WriteLine("File connection was not made."); return(false); } }
/// <summary> /// Safely closes connection to SQLite DB /// </summary> /// <returns></returns> public bool Disconnect() { if (File.Exists(_sqlitePath) && FileConnection.State != ConnectionState.Closed) { FileConnection.Close(); Console.WriteLine("\t\t\tDatabase successfully closed."); return(true); } else { Console.WriteLine("\t\t\t\tDatabase Was Not Able To Close."); return(false); } }
public override void Emit(SsisEmitterContext context) { base.Emit(context); _connection.Emit(context); SetProperty("Connection", _connection.Name); ExecuteSqlTask.ResultSetType = _resultSetTypeDTS; ExecuteSqlTask.SqlStatementSourceType = _sourceStatementTypeDTS; switch (_sourceStatementType) { case SqlTaskStatementType.File: string filePath; string fileName; _writeSqlToFile(context, out fileName, out filePath); var fileConnection = new FileConnection(fileName, filePath); fileConnection.Initialize(context); fileConnection.Emit(context); ExecuteSqlTask.SqlStatementSource = fileConnection.Name; break; case SqlTaskStatementType.Expression: ExecuteSqlTask.SqlStatementSource = Properties.Resources.Placeholder; SetExpression("SqlStatementSource", _body); break; default: throw new NotSupportedException(String.Format(CultureInfo.InvariantCulture, Properties.Resources.ErrorEnumerationTypeNotSupported, _sourceStatementType)); } // Parameter Binding int index = 0; foreach (ExecuteSqlParameter param in Parameters.Values) { BindParameter(param.VariableName, param.Direction, param.Name, (int)param.OleDBType, param.Length); index++; } foreach (ExecuteSqlResult executeSqlResult in Results.Values) { BindResult(executeSqlResult.Name, executeSqlResult.VariableName); } TryExecuteDuringDesignTime(); }
//数据库连接 private bool DBConnection() { try { //连接文件数据库 file_conn = FileConnection.Create(dbPath); //连接内存数据库 mem_conn = MemConnection.Create(); } catch (SQLiteException) { return(false); } return(true); }
/// <summary> /// Outgoing file, send. /// </summary> /// <param name="taskID"></param> /// <param name="fileConnection"></param> /// <param name="connectionManager"></param> /// <param name="ScanPathSignal"></param> /// <returns></returns> public async Task Scan(int taskID, FileConnection fileConnection, IConnectionRoutedCacheManager connectionManager, SemaphoreSlim ScanPathSignal) { Connection = fileConnection; var taskInfo = $"task: {taskID} connection: {Connection.name}"; _logger.Log(LogLevel.Debug, $"{taskInfo} scanpaths: {Connection.scanpaths}"); try { do { bool success = await ScanPathSignal.WaitAsync(_profileStorage.Current.KickOffInterval, _taskManager.cts.Token) .ConfigureAwait(false); // ScanPathSignal.Dispose(); // ScanPathSignal = new SemaphoreSlim(0, 1); foreach (string fileEntry in Connection.scanpaths) { await ProcessScanPath(taskID, Connection, connectionManager, fileEntry); await Task.Yield(); } //purge inpath PurgeInPath(Connection, taskInfo); //purge outpath PurgeOutPath(Connection, taskInfo); } while (Connection.responsive); } catch (TaskCanceledException) { _logger.Log(LogLevel.Information, $"Task was canceled."); } catch (Exception e) { _logger.LogFullException(e); } finally { _taskManager.Stop($"{Connection.name}.scan"); } }
/// <summary> /// Returns all data from a table and stores it in a DataSet using Control.Database.SQLite3 /// </summary> /// <param name="table"></param> /// <returns></returns> public DataSet GrabData(string table) { string _command = $"SELECT * FROM {table};"; DataSet data = new DataSet(); using (DbCommand command = FileConnection.CreateCommand()) { DatabaseProfile profile = new DatabaseProfile("sqlite", constr, "SQLite 3"); SQLiteQuery query = new SQLiteQuery(profile); command.CommandText = _command; command.CommandType = CommandType.Text; data = query.Execute(command); } Console.Clear(); return(data); }
public List <string> GetTables() { string _path; List <string> _retValue = new List <string>(); DataTable tableData = FileConnection.GetSchema("Tables"); foreach (DataRow row in tableData.Rows) { _path = Path.Combine(Directory.GetParent(Environment.CurrentDirectory).Parent.FullName, @"Data\"); _path += $@"{row[2].ToString()}\"; _retValue.Add(row[2].ToString()); if (!Directory.Exists(_path)) { Directory.CreateDirectory(_path); } } return(_retValue); }
public RealFileProducer(FileConnection connection, Func <T, ReadOnlyMemory <byte> > serializer) { this.connection = connection; this.serializer = serializer; }
public static int NOPH_Connector_openFileConnection_mode(int __name, int mode) { String name = CRunTime.charPtrToString(__name); FileConnection ret = new FileConnection(name, mode); int registeredHandle = CRunTime.registerObject(ret); return registeredHandle; }
private async Task ProcessScanPath(int taskID, FileConnection Connection, IConnectionRoutedCacheManager connectionManager, string fileEntry) { var taskInfo = $"task: {taskID} connection: {Connection.name}"; _logger.Log(LogLevel.Debug, $"{taskInfo} fileEntry: {fileEntry}"); //Expand home dir syntax ex: ~/blah string filestr = _fileExpanderService.Expand(fileEntry); _logger.Log(LogLevel.Debug, $"{taskInfo} expanded: {filestr}"); // get the file attributes for file or directory // FileAttributes attr = File.GetAttributes(fileEntry); string directory = filestr; _logger.Log(LogLevel.Debug, $"{taskInfo} create directory: {directory}"); var directoryFullPath = Path.GetDirectoryName(directory); Directory.CreateDirectory(directoryFullPath); //This may cause problems if we are specifying files instead of directories. Directory.CreateDirectory(directory); //This may cause problems if we are specifying files instead of directories. string searchPattern; if (filestr.IndexOf("*") != -1) { _logger.Log(LogLevel.Debug, $"{taskInfo} wildcard search pattern detected."); directory = Path.GetDirectoryName(filestr); searchPattern = Path.GetFileName(filestr); } else { _logger.Log(LogLevel.Debug, $"{taskInfo} using search pattern *."); searchPattern = "*"; } FileAttributes attr = File.GetAttributes(directory); if (!attr.HasFlag(FileAttributes.Directory)) { _logger.Log(LogLevel.Debug, $"{taskInfo} Sending individually specified {filestr}."); await _sendFileService.SendFile(filestr, taskID, Connection, connectionManager); return; } _logger.Log(LogLevel.Debug, $"{taskInfo} This is a directory."); var fileEntries = _util.DirSearch(directory, searchPattern); if (_profileStorage.Current.duplicatesDetectionUpload) { _logger.Log(LogLevel.Information, $"{taskInfo} toCloud: {(fileEntries == null ? 0 : fileEntries.Count)} files to be send to cloud (before duplicates elimination)."); } else { _logger.Log(LogLevel.Information, $"{taskInfo} toCloud: {(fileEntries == null ? 0 : fileEntries.Count)} files to be send to cloud."); } foreach (string file in fileEntries) { _logger.Log(LogLevel.Debug, $"{taskInfo} Found {file}."); try { attr = File.GetAttributes(file); if (!attr.HasFlag(FileAttributes.Hidden)) { var newTaskID = _taskManager.NewTaskID(); await _sendFileService.SendFile(file, newTaskID, Connection, connectionManager); } else { _logger.Log(LogLevel.Debug, $"{taskInfo} Deleting hidden file {file}."); File.Delete(file); //delete hidden files like .DS_Store } } catch (FileNotFoundException e) { _logger.Log(LogLevel.Debug, $"Retrieve Exception: {e.Message} {e.StackTrace}"); //eat it if not found, it's already gone } } //cleanup empty directories. _logger.Log(LogLevel.Debug, $"{taskInfo} Cleaning Empty Directories {directory}."); _util.CleanUpDirectory(directory); }
public static int NOPH_Connector_openFileConnection_mode(int __name, int mode) { function_info fi = new function_info("NOPH_Connector_openFileConnection_mode"); String name = CRunTime.charPtrToString(__name); FileConnection ret = new FileConnection(name, mode); int registeredHandle = CRunTime.registerObject(ret); fis.Add(fi.setFinishTime()); return registeredHandle; }
/// <summary> /// Create an IProducer<typeparamref name="T"/> /// </summary> /// <param name="fileName">The file to produce to. Passing this at construction /// time allows for the ability to inject a construction time value. /// Provided for simulation.</param> /// <returns></returns> public IProducer <T> Get(string fileName) { var fileConnection = new FileConnection(this.rootDirectory, fileName, this.token, this.logger); return(new RealFileProducer(fileConnection, this.serializer)); }
public string PathFormatter(RoutedItem routedItem, FileConnection connection) { Throw.IfNull(connection); //transform the inpath as needed by replacing variable names included in the inpath with the current values string path = connection.inpath; int end = 0; if (connection.inpath.Contains("{")) { do { int start = end; //we need to replace variable specifiers start = connection.inpath.IndexOf("{", start); if (start == -1) { break; } end = connection.inpath.IndexOf("}", start); if (end == -1) { break; } var variable = connection.inpath.Substring(start + 1, end - start - 1); RoutedItem.PropertyNames name; if (System.Enum.TryParse(variable, out name)) { switch (name) { case RoutedItem.PropertyNames.type: path = path.Replace("{type}", _util.RemoveInvalidPathAndFileCharacters(routedItem.type.ToString("G"))); break; case RoutedItem.PropertyNames.AccessionNumber: path = path.Replace("{AccessionNumber}", _util.RemoveInvalidPathAndFileCharacters(routedItem.AccessionNumber)); break; case RoutedItem.PropertyNames.InstanceID: path = path.Replace("{InstanceID}", _util.RemoveInvalidPathAndFileCharacters($"{routedItem.InstanceID}")); break; case RoutedItem.PropertyNames.PatientID: path = path.Replace("{PatientID}", _util.RemoveInvalidPathAndFileCharacters($"{routedItem.PatientID}")); break; case RoutedItem.PropertyNames.PatientIDIssuer: path = path.Replace("{PatientIDIssuer}", _util.RemoveInvalidPathAndFileCharacters(routedItem.PatientIDIssuer)); break; case RoutedItem.PropertyNames.Series: path = path.Replace("{Series}", _util.RemoveInvalidPathAndFileCharacters(routedItem.Series)); break; case RoutedItem.PropertyNames.Sop: path = path.Replace("{Sop}", _util.RemoveInvalidPathAndFileCharacters(routedItem.Sop)); break; case RoutedItem.PropertyNames.Study: path = path.Replace("{Study}", _util.RemoveInvalidPathAndFileCharacters(routedItem.Study)); break; case RoutedItem.PropertyNames.creationTimeUtc: path = path.Replace("{creationTimeUtc}", _util.RemoveInvalidPathAndFileCharacters($"{routedItem.creationTimeUtc}")); break; case RoutedItem.PropertyNames.error: path = path.Replace("{error}", _util.RemoveInvalidPathAndFileCharacters(routedItem.Error)); break; case RoutedItem.PropertyNames.fromConnection: path = path.Replace("{fromConnection}", _util.RemoveInvalidPathAndFileCharacters(routedItem.fromConnection)); break; case RoutedItem.PropertyNames.lastAccessTimeUtc: path = path.Replace("{lastAccessTimeUtc}", _util.RemoveInvalidPathAndFileCharacters($"{routedItem.lastAccessTimeUtc}")); break; case RoutedItem.PropertyNames.lastWriteTimeUtc: path = path.Replace("{lastWriteTimeUtc}", _util.RemoveInvalidPathAndFileCharacters($"{routedItem.lastWriteTimeUtc}")); break; case RoutedItem.PropertyNames.length: path = path.Replace("{length}", _util.RemoveInvalidPathAndFileCharacters($"{routedItem.length}")); break; case RoutedItem.PropertyNames.name: path = path.Replace("{name}", _util.RemoveInvalidPathAndFileCharacters(routedItem.name)); break; case RoutedItem.PropertyNames.priority: path = path.Replace("{priority}", _util.RemoveInvalidPathAndFileCharacters($"{routedItem.priority}")); break; case RoutedItem.PropertyNames.status: path = path.Replace("{status}", _util.RemoveInvalidPathAndFileCharacters($"{routedItem.status}")); break; case RoutedItem.PropertyNames.taskID: path = path.Replace("{taskID}", _util.RemoveInvalidPathAndFileCharacters($"{routedItem.TaskID}")); break; default: break; } } } while (true); } return(path); }
public async Task SendFile(string filePath, int taskID, FileConnection connection, IConnectionRoutedCacheManager connectionManager) { Connection = connection; _logger.Log(LogLevel.Debug, $"Sending {filePath}"); RoutedItem routedItem = new RoutedItem(fromConnection: Connection.name, sourceFileName: filePath, taskID: taskID) { type = RoutedItem.Type.FILE }; try { routedItem.type = RoutedItem.Type.FILE; _routedItemManager.Init(routedItem); _routedItemManager.Enqueue(Connection, Connection.toRules, nameof(Connection.toRules)); await _rulesManager.SendToRules(routedItem, _routedItemManager, connectionManager); //await LITE.profile.rules.SendToRules(routedItem); _routedItemManager.Dequeue(Connection, Connection.toRules, nameof(Connection.toRules)); if (Connection.outpath != null && File.Exists(filePath)) { var expandedOutPath = _fileExpanderService.Expand(Connection.outpath); // collapse the duplicate part of the path, prob more simple way of thinking about this. string dir = $"{expandedOutPath}{filePath.Substring(0, filePath.LastIndexOf(Path.DirectorySeparatorChar)).Replace(_fileExpanderService.Expand("~"), "")}"; string file = $"{expandedOutPath}{filePath.Replace(_fileExpanderService.Expand("~"), "")}"; _logger.Log(LogLevel.Debug, $"Moving {filePath} to {file}"); Directory.CreateDirectory(dir); //await Task.Yield(); if (File.Exists(file)) { var orgFileDateTime = File.GetLastWriteTime(file).ToString() .Replace(Path.DirectorySeparatorChar, '-').Replace(":", "-"); var destinationBackupFileName = $"{file}.{orgFileDateTime}"; // Remove the file to guarantee the move works //File.Delete(file); File.Replace(filePath, file, destinationBackupFileName, true); } else { File.Move(filePath, file); } _logger.Log(LogLevel.Debug, $"Moved {filePath} to {file}"); } else { _logger.Log(LogLevel.Debug, $"outpath is null."); } } catch (TaskCanceledException) { _logger.Log(LogLevel.Information, $"Task was canceled."); } catch (Exception e) { _logger.LogFullException(e); _routedItemManager.Init(routedItem); _routedItemManager.Dequeue(Connection, Connection.toRules, nameof(Connection.toRules), error: true); } }