Exemple #1
0
        private static void PublishFileByChunkMessage(IModel model, FileViewModel file)
        {
            Console.WriteLine($"File: {file.Title} - existing");
            Console.WriteLine("Starting file read operation...");
            StatusSenderService.SendStatus($"Processes the sequence - '{file.Title}'...");

            var fullName   = file.FullName;
            var fileStream = File.OpenRead(fullName);
            var fileSize   = Convert.ToInt32(new FileInfo(fullName).Length);

            var pool = ArrayPool <byte> .Shared;

            while (true)
            {
                if (fileSize <= 0)
                {
                    break;
                }

                var isFinish = IsChunkLargerFileSize(fileSize);
                var buffer   = pool.Rent(isFinish ? fileSize : Constants.DefaultChunkSize);

                var readChunkSize = GetStreamData(fileStream, buffer);
                fileSize -= readChunkSize;

                var basicProperties = BuildBasicProperties(model, file, isFinish);
                model.BasicPublish(string.Empty, Constants.Queries.DataQuery, basicProperties, buffer);
            }

            Console.WriteLine("Chunks publish is complete.");
            StatusSenderService.SendStatus($"Publish the sequence - '{file.Title}'.");
        }
Exemple #2
0
        private static void OnCreated(object sender, FileSystemEventArgs e)
        {
            Console.WriteLine("File: " + e.Name + " " + e.ChangeType);
            StatusSenderService.SendStatus($"Find new file - '{e.Name}'.");

            MessageSenderService.SendMessage(new List <FileViewModel>
            {
                new FileViewModel
                {
                    FullName = e.FullPath,
                    Title    = e.Name
                }
            });

            WaitingMessage();
        }
Exemple #3
0
        static void Main(string[] args)
        {
            string userName;

            do
            {
                Console.WriteLine("Enter your name:");
                userName = Console.ReadLine();
            }while (string.IsNullOrEmpty(userName));

            StatusSenderService.SendStatus("Starting dictionary listening...");

            CommandReceiverService.ReceiveCommandMessage(userName);

            DirectoryListenerService.FindAndPublishExistFiles();
            DirectoryListenerService.ListenDirectoryAndPublishFiles();
        }
Exemple #4
0
 private static void WaitingMessage()
 {
     StatusSenderService.SendStatus("Waiting for new files...");
 }