示例#1
0
        //MicroService 3
        public async Task <IActionResult> ProcessDIALSDataNWriteToDB()
        {
            try
            {
                string dialsFolderPath = Path.Combine(Directory.GetCurrentDirectory(), "DIALSFiles");

                if (Directory.Exists(dialsFolderPath))
                {
                    var files = Directory.GetFiles(dialsFolderPath);

                    if (files.Length > 0)
                    {
                        foreach (string fileName in files)
                        {
                            log.Info(DateTime.Now.ToString() + " AMS-POC: DIALS file processing in progress - " + fileName);
                            FileStream fileStream = new FileStream(Path.Combine(dialsFolderPath, fileName), FileMode.Open);
                            using (BufferedStream bufferedStream = new BufferedStream(fileStream))
                            {
                                using (StreamReader streamReader = new StreamReader(bufferedStream))
                                {
                                    while (!streamReader.EndOfStream)
                                    {
                                        string dialsString = await streamReader.ReadLineAsync();

                                        //Process DIALS data
                                        var dialsObject = DIALSUtility.ProcessDIALSData(dialsString);

                                        //Store in to DB
                                        if (!string.IsNullOrEmpty(dialsObject.TrackingNumber))
                                        {
                                            SakilaContext context = HttpContext.RequestServices.GetService(typeof(SakilaContext)) as SakilaContext;
                                            context.AddNewDIALS(dialsObject);
                                        }
                                        else
                                        {
                                            log.Warn(DateTime.Now.ToString() + " AMS-POC: Tracking number not found in DIALS data.");
                                        }
                                    }
                                }
                            }
                            log.Info(DateTime.Now.ToString() + " AMS-POC: DIALS file processing completed - " + fileName);
                        }

                        log.Info(DateTime.Now.ToString() + " AMS-POC: Total DIALS files processed - " + files.Length);
                    }
                }
            }
            catch (Exception ex) {
                log.Error(DateTime.Now.ToString() + " AMS-POC: " + Convert.ToString(ex.Message));
                return(new JsonResult(new { Result = System.Net.HttpStatusCode.InternalServerError }));
            }

            return(Ok());
        }
        public IActionResult MicroServiceProcessDIALSFile(DIALS dialsObject)
        {
            try
            {
                SakilaContext context = new SakilaContext("server=127.0.01;port=3306;database=ams;user=root;password=techM@Ups1");
                context.AddNewDIALS(dialsObject);
            }
            catch (Exception ex)
            {
                log.Error(DateTime.Now.ToString() + " AMS-MicroServiceProcessOPLDNDIALSFiles: " + Convert.ToString(ex.Message));
                return(new JsonResult(new { Result = System.Net.HttpStatusCode.InternalServerError }));
            }

            return(Ok(new { Result = "Success" }));
        }
示例#3
0
        public IActionResult MicroServiceProcessDIALSFile(DIALS dialsObject)
        {
            try
            {
                SakilaContext context = HttpContext.RequestServices.GetService(typeof(SakilaContext)) as SakilaContext;
                context.AddNewDIALS(dialsObject);
            }
            catch (Exception ex)
            {
                log.Error(DateTime.Now.ToString() + " AMS-MicroServiceProcessOPLDNDIALSFiles: " + Convert.ToString(ex.Message));
                return(new JsonResult(new { Result = System.Net.HttpStatusCode.InternalServerError }));
            }

            return(Ok(new { Result = "Success" }));
        }
        public IActionResult MicroServiceProcessDIALSFile(DIALS dialsObject)
        {
            try
            {
                SakilaContext context = new SakilaContext("server=techm.cooavdyjxzoz.us-east-1.rds.amazonaws.com;port=3306;database=sakila;user=root;password=Password123");
                context.AddNewDIALS(dialsObject);
            }
            catch (Exception ex)
            {
                log.Error(DateTime.Now.ToString() + " AMS-MicroServiceProcessOPLDNDIALSFiles: " + Convert.ToString(ex.Message));
                return(new JsonResult(new { Result = System.Net.HttpStatusCode.InternalServerError }));
            }

            return(Ok(new { Result = "Success" }));
        }
        //MicroService 3
        public async Task <IActionResult> ProcessDIALSDataNWriteToDB()
        {
            try
            {
                string dialsFolderPath = Path.Combine(Directory.GetCurrentDirectory(), "DIALSFiles");

                if (Directory.Exists(dialsFolderPath))
                {
                    var files = Directory.GetFiles(dialsFolderPath);

                    if (files.Length > 0)
                    {
                        foreach (string fileName in files)
                        {
                            FileStream fileStream = new FileStream(Path.Combine(dialsFolderPath, fileName), FileMode.Open);
                            using (BufferedStream bufferedStream = new BufferedStream(fileStream))
                            {
                                using (StreamReader streamReader = new StreamReader(bufferedStream))
                                {
                                    while (!streamReader.EndOfStream)
                                    {
                                        string dialsString = await streamReader.ReadLineAsync();

                                        //Process DIALS data
                                        var dialsObject = DIALSUtility.ProcessDIALSData(dialsString);

                                        //Store in to DB
                                        if (!string.IsNullOrEmpty(dialsObject.TrackingNumber))
                                        {
                                            SakilaContext context = HttpContext.RequestServices.GetService(typeof(SakilaContext)) as SakilaContext;
                                            context.AddNewDIALS(dialsObject);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch {
                return(new JsonResult(new { Result = System.Net.HttpStatusCode.InternalServerError }));
            }

            return(Ok());
        }