Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="fileURI"></param>
        protected void processOrderFile(string inFileURI)
        {
            bool added = false;
            WebOrderDBAccessProcess process = web_order_db_manager.AddProcess(out added);

            //....................................................

            WebOrder webOrder;
            string   orderHandle = readOrderFromFile(inFileURI, out webOrder);

            process.OrderURI = inFileURI;
            process.WebOrder = webOrder;

            process.HasCompleted += dbAccessProcessComplete;
            process.HasFailed    += dbAccessProcessFailed;
            process.DeadLock     += dbAccessDeadLock;

            //....................................................

            removeCompleteOrder(process.WebOrder);

            System.Reflection.MethodBase currentMethod = System.Reflection.MethodBase.GetCurrentMethod();
            ServiceLogger.LogWithMethod(currentMethod, @": Complete order file has been removed from folder");

            //....................................................

            if (added)
            {
                web_order_db_manager.StartProcess(process);
            }
            else
            {
                web_order_db_manager.AddProcessToPoll(process);
            }
        }
Пример #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        protected void dbAccessDeadLock(object sender, WebOrderDBAccessEventArgs args)
        {
            WebOrderDBAccessProcess process = (WebOrderDBAccessProcess)sender;

            ServiceLogger.Log(String.Format("Failed to load XML order:{0}. {1}", process.OrderURI, args.ErrorMessage));

            web_order_db_manager.SetDeadLockPause();
        }
Пример #3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="inProcess"></param>
 public void TerminateProcess(WebOrderDBAccessProcess inProcess)
 {
     try
     {
         // Removes process from the queue
         process_threads.Remove(inProcess);
     }
     catch
     {
     }
 }
Пример #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="inProcess"></param>
        public void StartProcess(WebOrderDBAccessProcess inProcess)
        {
            try
            {
                Thread thread = process_threads[inProcess];

                thread.Start();
            }
            catch
            {
            }
        }
Пример #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        protected void dbAccessProcessComplete(object sender, WebOrderDBAccessEventArgs args)
        {
            WebOrderDBAccessProcess process = (WebOrderDBAccessProcess)sender;

            System.Reflection.MethodBase currentMethod = System.Reflection.MethodBase.GetCurrentMethod();
            ServiceLogger.LogWithMethod(currentMethod, string.Format(@": Completing order: {0}", process.WebOrder.Handle));

            moveToSucessfulOrder(process.WebOrder);
            ServiceLogger.LogWithMethod(currentMethod, @": Complete order file has been moved from succesful folder");

            web_order_db_manager.TerminateProcess(process);

            ServiceLogger.LogWithMethod(currentMethod, string.Format(@": Order {0} has been completed", process.WebOrder.Handle));
        }
Пример #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        protected void dbAccessProcessFailed(object sender, WebOrderDBAccessEventArgs args)
        {
            WebOrderDBAccessProcess process = (WebOrderDBAccessProcess)sender;

            System.Reflection.MethodBase currentMethod = System.Reflection.MethodBase.GetCurrentMethod();
            ServiceLogger.LogWithMethod(currentMethod, string.Format(@": Finishing failed order: {0}", process.WebOrder.Handle));

            ServiceLogger.Log(String.Format("Failed to load XML order:{0}. {1}", process.OrderURI, args.ErrorMessage));

            moveToFailedOrder(process.WebOrder, args.ErrorMessage);
            ServiceLogger.LogWithMethod(currentMethod, @": Complete order file has been moved from failed folder");

            web_order_db_manager.TerminateProcess(process);

            ServiceLogger.LogWithMethod(currentMethod, string.Format(@": Failed order {0} has been finished", process.WebOrder.Handle));
        }
Пример #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="inFileURI"></param>
        /// <returns></returns>
        public WebOrderDBAccessProcess AddProcess(out bool outAdded)
        {
            WebOrderDBAccessProcess result = new WebOrderDBAccessProcess();

            //::::::::::::::::::::::::::::::::::::::::::

            outAdded = false;

            if (!tooManyProcesses())
            {
                Thread thread = createProcessThread(result);

                process_threads.Add(result, thread);
                outAdded = true;
            }

            //::::::::::::::::::::::::::::::::::::::::::

            return(result);
        }
Пример #8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="source"></param>
        /// <param name="e"></param>
        protected void onTimeOutEvent(Object source, ElapsedEventArgs e)
        {
            //ServiceLogger.Log(@"WebOrderDBAccessProcess.onTimeOutEvent(Object source, ElapsedEventArgs e) BEGIN");

            System.Timers.Timer timer = (System.Timers.Timer)source;
            timer.Enabled = false;

            //:::::::::::::::::::::::::::::::::::::::::

            foreach (KeyValuePair <WebOrderDBAccessProcess, Thread> pair in process_threads.OrderBy(key => key.Key.StartTime))
            {
                WebOrderDBAccessProcess process = pair.Key;
                Thread thread = pair.Value;

                DateTime now = DateTime.Now;
                //TimeSpan elapsedTime = now.Subtract(process.StartTime);

                long elapsedMinutes = totalMinutesElapsed(process.StartTime);

                //if (elapsedTime.TotalMinutes >= 1) // 1 min
                if (process.Started && (elapsedMinutes >= 1))
                {
                    TerminateProcess(process);
                }
                else if (elapsedMinutes < 1)
                {
                    break;
                }
            }

            //:::::::::::::::::::::::::::::::::::::::::

            timer.Enabled = true;

            //ServiceLogger.Log(@"WebOrderDBAccessProcess.onTimeOutEvent(Object source, ElapsedEventArgs e) END");
        }
Пример #9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="inProcess"></param>
        public void AddProcessToPoll(WebOrderDBAccessProcess inProcess)
        {
            Thread thread = createProcessThread(inProcess);

            process_threads_poll.Add(inProcess, thread);
        }
Пример #10
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="inProcess"></param>
 /// <returns></returns>
 private Thread createProcessThread(WebOrderDBAccessProcess inProcess)
 {
     return(new Thread(inProcess.Start));
 }