예제 #1
0
 public static IQueryable <QCEvent> Project(
     this IQueryable <QCEvent> query, QCEventQueryProjection projection)
 {
     foreach (var f in projection.GetFieldsArr())
     {
         if (QCEventQueryProjection.MAPS.ContainsKey(f))
         {
             foreach (var prop in QCEventQueryProjection.MAPS[f])
             {
                 query = prop.Compile()(query);
             }
         }
     }
     return(query);
 }
예제 #2
0
        public IDictionary <string, object> GetQCEventDynamic(
            QCEvent row, QCEventQueryProjection projection,
            QCEventQueryOptions options, string qcFolderPath, IFileService fileService)
        {
            var obj = new Dictionary <string, object>();

            foreach (var f in projection.GetFieldsArr())
            {
                switch (f)
                {
                case QCEventQueryProjection.INFO:
                {
                    var entity = row;
                    obj["id"] = entity.Id;
                    var details = entity.Details.Select(o => new
                        {
                            id             = o.Id,
                            defect_type_id = o.DefectTypeId,
                            defect_type    = new
                            {
                                id   = o.DefectType.Id,
                                code = o.DefectType.Code,
                                name = o.DefectType.Name
                            }
                        }).ToList();
                    obj["details"]             = details;
                    obj["description"]         = entity.Description;
                    obj["production_batch_id"] = entity.ProductionBatchId;
                    obj["qc_device_id"]        = entity.QCDeviceId;
                    var time = entity.CreatedTime
                               .ToDefaultTimeZone();
                    var timeStr = time.ToString(options.date_format);
                    obj["created_time"] = new
                    {
                        display = timeStr,
                        iso     = $"{time.ToUniversalTime():s}Z"
                    };
                    time = entity.LastUpdated
                           .ToDefaultTimeZone();
                    timeStr             = time.ToString(options.date_format);
                    obj["last_updated"] = new
                    {
                        display = timeStr,
                        iso     = $"{time.ToUniversalTime():s}Z"
                    };
                    obj["seen"] = entity.Seen;
                }
                break;

                case QCEventQueryProjection.BATCH:
                {
                    var entity = row.Batch;
                    if (entity != null)
                    {
                        obj["batch"] = new
                        {
                            id   = entity.Id,
                            code = entity.Code,
                        }
                    }
                    ;
                }
                break;

                case QCEventQueryProjection.IMAGE:
                {
                    if (!options.single_only)
                    {
                        throw new Exception("Only single option can query image field");
                    }
                    var entity = row;
                    if (entity.LeftImage != null)
                    {
                        var finalPath = Path.Combine(qcFolderPath, entity.LeftImage);
                        if (File.Exists(finalPath))
                        {
                            var img   = File.ReadAllBytes(finalPath);
                            var img64 = Convert.ToBase64String(img);
                            obj["left_image"] = img64;
                        }
                    }
                    if (entity.RightImage != null)
                    {
                        var finalPath = Path.Combine(qcFolderPath, entity.RightImage);
                        if (File.Exists(finalPath))
                        {
                            var img   = File.ReadAllBytes(finalPath);
                            var img64 = Convert.ToBase64String(img);
                            obj["right_image"] = img64;
                        }
                    }
                    if (entity.SideImages != null)
                    {
                        var sideImages    = JsonConvert.DeserializeObject <IEnumerable <string> >(entity.SideImages);
                        var sideImagesB64 = new List <string>();
                        obj["side_images"] = sideImagesB64;
                        foreach (var iPath in sideImages)
                        {
                            var fullPath = fileService.GetFilePath(qcFolderPath, null, iPath).Item2;
                            if (File.Exists(fullPath))
                            {
                                var img   = File.ReadAllBytes(fullPath);
                                var img64 = Convert.ToBase64String(img);
                                sideImagesB64.Add(img64);
                            }
                        }
                    }
                }
                break;
                }
            }
            return(obj);
        }