private void OnFileCreated(object sender, FileSystemEventArgs e) { var attr = File.GetAttributes(e.FullPath); // is directory if ((attr & FileAttributes.Directory) == FileAttributes.Directory) { return; } var filePath = e.FullPath; var file = new LocalFile(new FileInfo(filePath)); try { using (var stream = file.ReadFile()) { var imgInput = System.Drawing.Image.FromStream(stream); } } catch (Exception) { if (!Directory.Exists(_badFilesDirectory)) { Directory.CreateDirectory(_badFilesDirectory); } File.Move(filePath, Path.Combine(_badFilesDirectory, Path.GetFileName(filePath))); } FileCreated?.Invoke(this, new FileEventArgs(file)); }
private void processCreatedEntry(Entry <Metadata> entry) { ProcessingCreatedEntry?.Invoke(this, entry); switch (entry) { case RootEntry <Metadata> _: throw new InvalidOperationException($"processing {entry.GetType()} entry is not supported"); case FileEntry <Metadata> file: FileCreated?.Invoke(this, file); break; case DirectoryEntry <Metadata> directory: scanDirectory(directory); break; case UnclassifiedEntry <Metadata> unclassified: classifyEntry(unclassified); break; default: throw new InvalidOperationException($"processing {entry.GetType()} entry is not supported"); } }
private void Apply(FileCreated obj) { this.AggregateId = obj.AggregateId; this.Name = obj.Name; this.Md5Hash = obj.Md5Hash; this.Size = obj.Size; this.Extension = obj.Extension; }
private Task <Unit> OnCreated(FileSystemEventArgs eventArgs, CancellationToken cancellationToken) { _logger.LogTrace("Publishing created event"); var @event = new FileCreated { Path = eventArgs.Name }; return(Publish(_publisher, @event, cancellationToken)); }
void fileWatcher_Created(object sender, FileSystemEventArgs e) { ThreadManager.invoke(() => { if (FileCreated != null) { FileCreated.Invoke(e.Name, false); } }); }
/// <summary> /// Manually forces to create the completed file. /// Warning: If not all chunks have been written, it will crash! (See Options.AutoCreate) /// </summary> public void Create() { lock (lockStream) { if (Created) { return; } FileCreating?.Invoke(this, EventArgs.Empty); using (FileStream fs = File.Open(Path.Combine(Options.Folder, Filename), FileMode.CreateNew)) { if (Size > 0) { byte[] buffer = new byte[Options.FirstChunksize]; ReadChunk(0, 0, buffer, 0, Options.FirstChunksize); fs.Write(buffer, 0, buffer.Length); if (ChunksTotal > 1) { buffer = new byte[Chunksize]; for (int i = 1; i < MapChunkIdToChunkPos.Count - 1; i++) { ReadChunk(i, 0, buffer, 0, Chunksize); fs.Write(buffer, 0, buffer.Length); } buffer = new byte[Options.LastChunksize]; ReadChunk(ChunksTotal - 1, 0, buffer, 0, Options.LastChunksize); fs.Write(buffer, 0, buffer.Length); } } } fileStream.Close(); fileStream = null; Created = true; if (Options.DeletePartOnCreate) { File.Delete(Path.Combine(Options.PartFolder, Filename + Options.PartExtension)); } FileCreated?.Invoke(this, EventArgs.Empty); if (Options.StayAlive) { fileStream = File.Open(Path.Combine(Options.Folder, Filename), FileMode.Open, FileAccess.Read, FileShare.Read); } else { Dispose(); } } }
protected virtual void File_Created(object sender, FileSystemEventArgs e) { _logger.Log(string.Format(FoldersListenerResource.FileCreatedEventLogMessage, e.Name, File.GetCreationTime(e.FullPath).ToString(Thread.CurrentThread.CurrentUICulture.DateTimeFormat))); FileCreated?.Invoke(this, new FileCreatedEventArgs { FileName = e.Name, Path = e.FullPath, CreationDate = File.GetCreationTime(e.FullPath) }); }
private void ProcessNewFile(FileCreated message) { if (!message.Path.EndsWith("zip")) return; Directory dir = new ZipFileDirectory(PathName.GetPathName(message.Path)); try { _actionToTake(dir); } catch (Exception ex) { string msg = "There was an error processing the stream package '{0}'".FormatWith(message.Path); throw new StreamPackageException(msg, ex); } }
void ProcessNewFile(FileCreated message) { if (message.Path.EndsWith("bottle")) { Directory dir = new ZipFileDirectory(PathName.GetPathName(message.Path)); try { _actionToTake(dir); } catch (Exception ex) { string msg = "There was an error processing the bottle '{0}'".FormatWith(message.Path); throw new BottleException(msg, ex); } } }
private void Apply(FileCreated e) { Bucket = e.Bucket; BlobId = e.BlobId; OwnedBy = e.UserId; CreatedBy = e.UserId; CreatedDateTime = e.TimeStamp; UpdatedBy = e.UserId; UpdatedDateTime = e.TimeStamp; ParentId = e.ParentId; FileName = e.FileName; Length = e.Length; Status = e.FileStatus; Md5 = e.Md5; Type = e.FileType; }
private void OnCreated(object source, FileSystemEventArgs e) { if (FileCreated != null) { DateTime lastWriteTime = new DateTime(); if (e.FullPath.IsFile()) { lastWriteTime = new FileInfo(e.FullPath).LastWriteTime; } else if (e.FullPath.IsFolder()) { lastWriteTime = new DirectoryInfo(e.FullPath).LastWriteTime; } FileCreated.Invoke(e.FullPath); ChangeTimes[e.FullPath] = lastWriteTime; } }
private async void Watcher_Created(object sender, FileSystemEventArgs e) { try { logger.LogInformation($"Received created event of '{e.Name}'."); if (Directory.Exists(e.FullPath)) { logger.LogInformation($"Ignore folder '{e.Name}' creation."); } else { if (!File.Exists(e.FullPath)) { logger.LogWarning($"Cannot see file '{e.Name}'. Wait for 1s..."); await Task.Delay(1000).ConfigureAwait(false); } if (File.Exists(e.FullPath)) { // Wait for file to complete writing await Task.Delay(500); while (!IsAvailableForReading(e.FullPath)) { logger.LogInformation("File is not available for reading. Wait for 1s..."); await Task.Delay(1000); } FileCreated?.Invoke(this, new FileCreatedEventArgs(e.FullPath)); } } } catch (Exception ex) { logger.LogError(ex, $"Cannot upload file {e.Name}!"); } }
internal void OnFileCreated(FileEventArgs args) { FileCreated?.Invoke(this, args); }
private void fileCreatead(object sender, FileEntry <Metadata> file) { FileCreated?.Invoke(this, file); addDelayedTask(file); }
public void CreateFile(string path) { FileCreated?.Invoke(path); }
protected virtual void OnFileCreated() { FileCreated?.Invoke(this); }
/// <summary> /// Fired when a file is created in the watched directory. /// </summary> /// <param name="e"></param> protected virtual void OnFileCreated(FileSystemEventArgs e) { FileCreated?.Invoke(this, e); }
private void TimerTriggered(object sender, ElapsedEventArgs e) { lock (_lock) { foreach (var kvp in _debouncedFileEvents) { var fileEvent = kvp.Value; var fileInfo = new FileInfo(kvp.Value.Filename); if (fileEvent.Created.HasValue) { if (fileEvent.Created.Value.AddMilliseconds(MilliSecondsSinceLastChange) > DateTime.Now) { break; } if (fileEvent.Changed.HasValue && fileEvent.Changed.Value.AddMilliseconds(MilliSecondsSinceLastChange) > DateTime.Now) { break; } if (_requireExclusiveAccess && FileUtil.WhoIsLocking(fileInfo.FullName).Any()) { _log.Debug("Waiting for exclusive file access before triggering FileCreated for {path}", kvp.Key); break; } var args = new FileSystemEventArgs(WatcherChangeTypes.Created, _path, kvp.Key); fileEvent.Created = null; _log.Debug("Triggering FileCreated for {path}", kvp.Key); FileCreated?.Invoke(this, args); } if (fileEvent.Changed.HasValue) { if (fileEvent.Changed.Value.AddMilliseconds(MilliSecondsSinceLastChange) > DateTime.Now) { break; } if (_requireExclusiveAccess && FileUtil.WhoIsLocking(fileInfo.FullName).Any()) { _log.Debug("Waiting for exclusive file access before triggering FileChanged for {path}", kvp.Key); break; } var args = new FileSystemEventArgs(WatcherChangeTypes.Created, _path, kvp.Key); fileEvent.Changed = null; _log.Debug("Triggering FileChanged for {path}", kvp.Key); FileChanged?.Invoke(this, args); } } var keysToRemove = _debouncedFileEvents.Where(kvp => !kvp.Value.Created.HasValue && !kvp.Value.Changed.HasValue).Select(kvp => kvp.Key).ToArray(); if (keysToRemove.Length > 0) { _log.Debug("Removing {count} finished events.", keysToRemove.Length); } foreach (var key in keysToRemove) { _debouncedFileEvents.Remove(key); } } }
private void OnCreated(object sender, FileSystemEventArgs eventArgs) { FileCreated?.Invoke(sender, eventArgs); }
protected void OnCreateFiles(object sender, FileArgs e) { FileCreated.Invoke(sender, e); }
private void Watcher_Created(object sender, FileSystemEventArgs e) => FileCreated?.Invoke(e.FullPath);
private void FileSystemWatcherOnCreated(object sender, FileSystemEventArgs e) { var args = new FileCreatedEventArgs(e.FullPath); FileCreated.Raise(this, args); }
private FileAggregateRoot(Guid fileId, string name, long size, string md5Hash, string extension) : this() { var creationEvent = new FileCreated(fileId, name, size, md5Hash, extension); this.RaiseEvent(creationEvent); }
public void InvokeCreateFile(File file) { FileCreated?.Invoke(file); }