Beispiel #1
0
        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                //timer.Enabled = false;
                logger.Log("Process Started : " + DateTime.Now.ToString(), LogLevel.INFORMATION);


                string checkStatus = string.Empty;

                checkStatus = stProcessor.CheckLastRunStatus();

                if (checkStatus == "1" || checkStatus == "2")
                {
                    //for (int j = 0; j < 3; j++)
                    //{
                    //    try
                    //    {
                    //        DownloadFileFromServer();
                    //        break;
                    //    }
                    //    catch (Exception ex)
                    //    {
                    //        if (j == 2)
                    //        {
                    //            //label1.Text = "Could not download the file 3rd time.";
                    //            logger.Log(ex.Message, LogLevel.ERR);
                    //            stProcessor.SendMail(ex.Message, ex.StackTrace);
                    //            //updateLastRun
                    //            objdataaccess.updateLastRunForFailure();
                    //        }
                    //    }
                    //}

                    //Execute the below process 3 times in case of any failure
                    //But if not succesful even on third attempt,then exception is thrown and mail is sent

                    for (int i = 0; i < 3; i++)
                    {
                        try
                        {
                            if (checkStatus == "1")
                            {
                                fileName = objdataaccess.GetOnlyFileName();
                                DownloadFileFromServer(fileName);
                            }


                            if (checkStatus == "2")
                            {
                                fileName = objdataaccess.GetOnlyFileName_IOMATERIALCOST();
                                DownloadFileFromServer(fileName);
                            }

                            //DownloadFileFromServer();
                            //stProcessor.ReadFileContent();
                            stProcessor.ReadFileContent(fileName);
                            stProcessor.updateProductTable(fileName);
                            stProcessor.moveFileToProcessedPath(fileName);
                            break;
                        }
                        catch (Exception ex)
                        {
                            if (i == 2)
                            {
                                stProcessor.SendMail(fileName, ex.Message, ex.StackTrace);
                                objdataaccess.updateLastRunForFailure(fileName);

                                //if (stProcessor.checkDownloadedFile() == "1")   // 1 - Present
                                //{
                                //    stProcessor.moveFileToFailurePath();
                                //}

                                if (stProcessor.checkDownloadedFile(fileName) == "1")   // 1 - Present
                                {
                                    stProcessor.moveFileToFailurePath(fileName);
                                }
                            }
                        }
                    }
                }

                else
                {
                    // logger.Log("Already Updated. Updation is done once for every 12hrs " + DateTime.Now.ToString(), LogLevel.INFORMATION);
                }
            }
            catch (Exception ex)
            {
                logger.Log(ex.Message, LogLevel.ERR);
                stProcessor.SendMail(fileName, ex.Message, ex.StackTrace);

                //if (stProcessor.checkDownloadedFile() == "1")  // 1 - Present  //25Mar2019
                if (stProcessor.checkDownloadedFile(fileName) == "1")  // 1 - Present
                {
                    stProcessor.moveFileToFailurePath(fileName);
                }
            }

            finally
            {
                logger.Log("Process Completed : " + DateTime.Now.ToString(), LogLevel.INFORMATION);
                // timer.Enabled = true;
            }
        }
        protected void OnTimer(object source, ElapsedEventArgs e)
        {
            try
            {
                timer.Enabled = false;
                logger.Log("Process Started : " + DateTime.Now.ToString(), LogLevel.INFORMATION);


                // 1 - FILE1.TXT
                // 2 - FILE2



                string checkStatus = stProcessor.CheckLastRunStatus();


                if (checkStatus == "1" || checkStatus == "2")
                {
                    //Execute the below process 3 times in case of any failure
                    //But if not succesful even on third attempt,then exception is thrown and mail is sent

                    for (int i = 0; i < 3; i++)
                    {
                        try
                        {
                            if (checkStatus == "1")
                            {
                                //fileName = FILE1;
                                fileName = objdataaccess.GetOnlyFileName();
                                DownloadFileFromServer(fileName);
                            }


                            if (checkStatus == "2")
                            {
                                //fileName = FILE2;
                                fileName = objdataaccess.GetOnlyFileName_IOMATERIALCOST();
                                DownloadFileFromServer(fileName);
                            }

                            //DownloadFileFromServer();
                            //stProcessor.ReadFileContent();
                            stProcessor.ReadFileContent(fileName);
                            stProcessor.updateProductTable(fileName);
                            stProcessor.moveFileToProcessedPath(fileName);
                            break;
                        }
                        catch (Exception ex)
                        {
                            if (i == 2)
                            {
                                stProcessor.SendMail(fileName, ex.Message, ex.StackTrace);
                                objdataaccess.updateLastRunForFailure(fileName);

                                //if (stProcessor.checkDownloadedFile() == "1")   // 1 - Present
                                //{
                                //    stProcessor.moveFileToFailurePath();
                                //}

                                if (stProcessor.checkDownloadedFile(fileName) == "1")   // 1 - Present
                                {
                                    stProcessor.moveFileToFailurePath(fileName);
                                }
                            }
                        }
                    }
                }

                else
                {
                    // logger.Log("Already Updated. Updation is done once for every 12hrs " + DateTime.Now.ToString(), LogLevel.INFORMATION);
                }
            }
            catch (Exception ex)
            {
                logger.Log(ex.Message, LogLevel.ERR);
                stProcessor.SendMail(fileName, ex.Message, ex.StackTrace);

                //if (stProcessor.checkDownloadedFile() == "1")  // 1 - Present  //25Mar2019
                if (stProcessor.checkDownloadedFile(fileName) == "1")  // 1 - Present
                {
                    stProcessor.moveFileToFailurePath(fileName);
                }
            }

            finally
            {
                logger.Log("Process Completed : " + DateTime.Now.ToString(), LogLevel.INFORMATION);
                timer.Enabled = true;
            }
        }