丢失有关Hangfire执行的数据

时间:2017-09-05 14:59:05

标签: c# asp.net-mvc kendo-asp.net-mvc hangfire

我有一个hangfire作业,它丢失了作为参数传递的对象中包含的LinkedList的数据。

用户输入一个分隔文件,该文件被解析为一个对象,该对象存储另一个对象的LinkedList中的每一行。然后我将一个hangfire作业,并作为参数传递给对象。作业执行时,链接列表中的所有数据都为空。该列表仍包含正确数量的元素,每个元素都是空的。任何想法?

此处的对象定义。

public class ExternalScanDTO : BaseDTO
{
    [Key]
    public int ScanHeaderID { get; set; }

    public int? ScannerID { get; set; }

    public string DeviceIdentifier { get; set; }

    public int? RFIDInputID { get; set; }

    //this is the list losing data
    [SuppressMessageAttribute("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
    public LinkedList<ScanLineDTO> ScanLineDTOs { get; set; }

    public DbGeography Location { get; set; }

    public Guid GlobalUID { get; set; }

    public int? UserID { get; set; }

    public int StatusCodeRecordTypeID { get; set; }
    public string StatusCodeRecordTypeName { get; set; }
}

我解析文件并将作业排入队列

 public ActionResult ParseCS4070CSVScanFile([DataSourceRequest] DataSourceRequest kendoRequest, ScanFileImportModel import)
    {
        try
        {
            int count = 0;
            import.ParsingErrors = new List<ParsingError>();
            var parser = new TextFieldParser(import.File.InputStream);
            parser.TextFieldType = FieldType.Delimited;
            parser.Delimiters = new string[] { "," };

            var result = new ExternalScanDTO()
            {
                ScannerID = import.ScannerID,
                StatusCodeRecordTypeID = (int)StatusCodeEnums.ScanHeaderRecordTypes.Barcode,
                ScanLineDTOs = new LinkedList<ScanLineDTO>(),
            };

            // Build parsed list of Scan Lines:
            while (!parser.EndOfData)
            {
                count++;
                var rowValues = parser.ReadFields();

                if (!isValidScanLine(import, rowValues, count))
                    continue;

                var addedLine = new ScanLineDTO
                {
                    StatusCodeID = (int)StatusCodeEnums.ScanLineStatusCodes.Valid,
                    StatusCodeScanTypeID = (int)StatusCodeEnums.ScanLineScanType.StandardOrder,
                    Barcode = rowValues[3],
                    ScanTimeStamp = DateTime.Parse(rowValues[0] + " " + rowValues[1], CultureInfo.CurrentCulture, DateTimeStyles.AssumeUniversal),
                };
                addedLine.DateCreated = DateTime.UtcNow;
                result.ScanLineDTOs.AddLast(addedLine);
            }

            if (import.ParsingErrors.Count > 0)
                throw new MyException(import.ParsingErrorsToHtml);
            if(result.ScanLineDTOs.Count == 0)
                throw new MyException("The File does not contains any lines");
            // POST LINES TO DATABASE:

            var hfj = new HFJScans();
            BackgroundJob.Enqueue(() => hfj.ProcessScanValidation(result));

            return Content(""); 

        }
        catch (Exception ex) {return AjaxErrorMessage(ex);}
    }

作业执行此方法,该方法包含在上一个方法中创建的HfjScans对象中,该方法执行一些验证检查。此时,链接列表包含空元素

   public void ProcessScanValidation(ExternalScanDTO result)
    {
        using (var wfOpr = new WFScanUploadValidate())
        {
            var resultID = wfOpr.Run(result); 
        }
    }

0 个答案:

没有答案