Beispiel #1
0
        public async Task <IActionResult> UploadFile()
        {
            // ipResult is a list containing information requested by frontend.
            var ipResults = new List <IpResult>();

            try
            {
                var files = Request.Form.Files;
                foreach (var file in files)
                {
                    //every file is locally added in a specific folder, and it will be deleted later.
                    string       fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"');
                    MemoryStream fileData = new MemoryStream();
                    using (FileStream filestream = new FileStream(Path.Combine(Directory.GetCurrentDirectory(), "LogFilesAnalyzer", fileName), FileMode.Create, FileAccess.Write))
                    {
                        file.CopyTo(filestream);
                    }
                    // analyzes log file
                    analyzer.AnalyzeLogFile(fileName, ref ipResults);
                }

                return(Ok(ipResults));
            }

            catch (Exception exc)
            {
                Log.Error("HttpPost failed, Error: {message}", exc.Message);
                return(BadRequest(exc.Message));
            }
        }
Beispiel #2
0
        public IActionResult UploadFile()
        {
            // ipResult is a list containing information requested by frontend.
            var ipResults = new List<IpResult>();
            try
            {
                var files = Request.Form.Files;
                foreach (var file in files)
                {
                    //every file is locally added in a specific folder, and it will be deleted later.
                    var path = Path.Combine(Directory.GetCurrentDirectory(), "LogFilesAnalyzer");

                    // if two files have the same name they are treated as two files, as they are.
                    var fileName = $"{DateTime.Now.ToString("dd-MM-yyyy-HH-mm-ss")}_{ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"')}";
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }
                    using (FileStream filestream = new FileStream(Path.Combine(path, fileName), FileMode.Create, FileAccess.Write))
                    {
                        file.CopyTo(filestream);
                    }
                    // analyzes log file. It could be possible to create a thread foreach document and call 
                    // ThreadAnalyzer method 
                    // Thread will die when procedure returns.
                    analyzer.AnalyzeLogFile(Path.Combine(path, fileName), ref ipResults);
                }

                return Ok(ipResults);
            }

            catch (Exception exc)
            {
                Log.Error("HttpPost failed, Error: {message}", exc.Message);
                return BadRequest(exc.Message);
            }
        }
Beispiel #3
0
        public async Task <IActionResult> UploadFile()
        {
            // ipResult is a list containing information requested by frontend.
            var ipResults = new List <IpResult>();

            try
            {
                var files = Request.Form.Files;
                foreach (var file in files)
                {
                    //every file is locally added in a specific folder, and it will be deleted later.
                    string fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"');
                    var    path     = Path.Combine(Directory.GetCurrentDirectory(), "LogFilesAnalyzer");
                    if (!System.IO.Directory.Exists(path))
                    {
                        System.IO.Directory.CreateDirectory(path);
                    }
                    using (FileStream filestream = new FileStream(Path.Combine(path, fileName), FileMode.Create, FileAccess.Write))
                    {
                        file.CopyTo(filestream);
                    }
                    // analyzes log file. It could be possible to create a thread foreach document and call
                    // ThreadAnalyzer method
                    // Thread will die when procedure returns.
                    analyzer.AnalyzeLogFile(fileName, ref ipResults);
                }

                return(Ok(ipResults));
            }

            catch (Exception exc)
            {
                Log.Error("HttpPost failed, Error: {message}", exc.Message);
                return(BadRequest(exc.Message));
            }
        }
Beispiel #4
0
 public void AnalyzeFile(string fileName, ref List <IpResult> ipResults)
 {
     Console.WriteLine("ANalyzing file....");
     analyzer.AnalyzeLogFile(fileName, ref ipResults);
 }
 /// possible way to implement a thred that analyzes a single file.
 public void AnalyzeFile(string fileName, ref List <IpResult> ipResults)
 {
     Log.Information("Analyzing file....");
     analyzer.AnalyzeLogFile(fileName, ref ipResults);
 }