예제 #1
0
        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));
        }
예제 #2
0
        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");
            }
        }
예제 #3
0
 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;
 }
예제 #4
0
        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);
         }
     });
 }
예제 #6
0
        /// <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)
     });
 }
예제 #8
0
        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);
            }
        }
예제 #9
0
 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);
         }
     }
 }
예제 #10
0
 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);
         }
     }
 }
예제 #11
0
파일: File.cs 프로젝트: xlgwr/osdr
 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;
 }
예제 #12
0
        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;
            }
        }
예제 #13
0
        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}!");
            }
        }
예제 #14
0
 internal void OnFileCreated(FileEventArgs args)
 {
     FileCreated?.Invoke(this, args);
 }
예제 #15
0
 private void fileCreatead(object sender, FileEntry <Metadata> file)
 {
     FileCreated?.Invoke(this, file);
     addDelayedTask(file);
 }
예제 #16
0
 public void CreateFile(string path)
 {
     FileCreated?.Invoke(path);
 }
예제 #17
0
 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);
 }
예제 #19
0
        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);
                }
            }
        }
예제 #20
0
 private void OnCreated(object sender, FileSystemEventArgs eventArgs)
 {
     FileCreated?.Invoke(sender, eventArgs);
 }
예제 #21
0
 protected void OnCreateFiles(object sender, FileArgs e)
 {
     FileCreated.Invoke(sender, e);
 }
 private void Watcher_Created(object sender, FileSystemEventArgs e)
 => FileCreated?.Invoke(e.FullPath);
예제 #23
0
        private void FileSystemWatcherOnCreated(object sender, FileSystemEventArgs e)
        {
            var args = new FileCreatedEventArgs(e.FullPath);

            FileCreated.Raise(this, args);
        }
예제 #24
0
        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);
 }