Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 正在丢失执行Hangfire的数据_C#_Asp.net Mvc_Kendo Asp.net Mvc_Hangfire - Fatal编程技术网

C# 正在丢失执行Hangfire的数据

C# 正在丢失执行Hangfire的数据,c#,asp.net-mvc,kendo-asp.net-mvc,hangfire,C#,Asp.net Mvc,Kendo Asp.net Mvc,Hangfire,我有一个hangfire作业,它正在丢失作为参数传递的对象中包含的LinkedList中的数据 用户输入一个带分隔符的文件,该文件被解析为一个对象,该对象将每一行存储在另一个对象的LinkedList中。然后我创建一个hangfire作业,并将对象作为参数传入。当作业执行时,链接列表中的所有数据都为空。列表仍然包含正确数量的元素,只是每个元素都是空的。有什么想法吗 这里是对象定义 public class ExternalScanDTO : BaseDTO { [Key] pub

我有一个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; }
}

测试Newtonsoft.Json序列化如何与LinkedList和ScanLineDTO一起工作。我认为hangfire会自动进行序列化/反序列化。在将参数传递给hangfire之前,我已经尝试序列化对象,然后像您建议的那样在运行时进行序列化。序列化的json字符串在列表中也存储了空对象。我认为数据在序列化过程中丢失了,所以您的意思是我需要使用链表之外的东西。我不知道最初的作者为什么使用链表。我认为在我们的场景中没有任何好处,这很可能会解决您的问题。另一个选项是创建一个新类型,它是ExternalScanDTO的副本,但使用List而不是LinkedList。然后,您需要在序列化之前将ExternalScanDTO对象转换为这种新类型,并将使用反序列化ExternalScanDTO对象的所有代码修改为这种新类型。如果您想变得更聪明,可以使用这个新的List属性创建一个externalscando的派生类型,该属性在填充或创建列表时重建LinkedList。
 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);}
    }
   public void ProcessScanValidation(ExternalScanDTO result)
    {
        using (var wfOpr = new WFScanUploadValidate())
        {
            var resultID = wfOpr.Run(result); 
        }
    }