예제 #1
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="ar"></param>
        private void OnFTPActionComplete(IAsyncResult ar)
        {
            string processResultMessage = "";
            try
            {
                // Retrieve the delegate.
                DoFTPActionStartDelegate dlgt = (DoFTPActionStartDelegate)ar.AsyncState;

                TransferMainService transferMainService = new TransferMainService();

                TransferWorkService transferWorkService = new TransferWorkService();

                // Look up transfer record by ID
                TransferMain tm = transferMainService.GetByTransferRefId(mWorkRefId);

                lock (this)
                {

                    // Call EndInvoke to retrieve the results.
                    processResultMessage = dlgt.EndInvoke(out processResult, out destinationRefId, ar);

                    // display or process aync results
                    LogManager.GetLogger("SiteLogger").Info("Processing Complete: " + processResult + " with result: " + processResultMessage);
                    //logger.logEntry(this.ToString(), "Processing Complete: " + processResult + " with result: " + processResultMessage, LogMsgSeverity.Information, false);

                    // update transfer record
                    /// write transfer to work table

                    TransferWork tw = transferWorkService.GetByTransferRefIdDestinationRefId(tm.TransferRefId, destinationRefId);

                    if (tw == null)
                        throw new SystemException("Unable to find transfer records for destination " + destinationRefId);

                    tw.CompletionTime = DateTime.Now;

                    if (processResult)
                        tw.StatusTypeId = (short)StatusTypeList.Complete;
                    else
                    {
                        tw.StatusTypeId = (short)StatusTypeList.Error;
                        // reset the schedule to run in 2 hours on an error
                        EventScheduler eventScheduler = new EventScheduler();
                        eventScheduler.GetSchedule((Guid)tm.ScheduleRefId).NextInvokeTime = DateTime.Now.AddHours(2);
                    }

                    tw.Retires += 1;
                    if (tw.Results == null)
                        tw.Results = processResultMessage + "\n";
                    else
                        tw.Results += processResultMessage + "\n";

                    transferWorkService.Save(tw);

                    //TODO: figure this out
                    //clean things up
                    SetFileComplete(processResultMessage, destinationRefId);
                }

            }
            catch (Exception ex)
            {
                LogManager.GetLogger("SiteLogger").Fatal("Callback method  DoFTPActionComplete(): Failed.", ex);
                //logger.logEntry(this.ToString(), "Callback method  DoFTPActionComplete(): Failed." + ex.Message, LogMsgSeverity.Critical, false);
            }
        }