/// <summary> /// Initializes a new instance of the <see cref="PackageAccessor"/> class. /// </summary> /// <param name="package">The package to be accessed.</param> public PackageAccessor(LightFieldPackage package) { if (package == null) { throw new ArgumentNullException("package"); } _package = package; LightFieldComponent metadata = package.GetMetadata().FirstOrDefault(); if (metadata != null) { _master = new Json.Master(); _master.LoadFromJson(metadata.GetDataAsString()); } _exceptions = new List <Exception>(); _hasContent = Initialize(); }
private string LoadFromPhase1(LightFieldPackage package, string packageReference, Dictionary <string, FlatFieldItem> items) { LightFieldComponent metadataComponent = package.GetMetadata().FirstOrDefault(); if (metadataComponent == null) { return(null); } Json.Master master = new Json.Master(); master.LoadFromJson(metadataComponent.GetDataAsString()); if (master.Files != null) { foreach (Json.File file in master.Files) { if (file.Name != null && file.Name.StartsWith(@"C:\T1CALIB\MOD_", StringComparison.OrdinalIgnoreCase)) { if (file.Name.EndsWith(".TXT", StringComparison.OrdinalIgnoreCase)) { LightFieldComponent imageMetadataComponent = package.GetComponent(file.DataRef).FirstOrDefault(); if (imageMetadataComponent != null) { Json.Root imageRoot = new Json.Root(); imageRoot.LoadFromJson(imageMetadataComponent.GetDataAsString()); if (imageRoot.Master != null && imageRoot.Master.Picture != null && imageRoot.Master.Picture.FrameArray != null && imageRoot.Master.Picture.FrameArray.Length > 0) { Json.FrameItem frameItem = imageRoot.Master.Picture.FrameArray[0]; if (frameItem != null && frameItem.Frame != null && frameItem.Frame.Metadata != null && frameItem.Frame.Metadata.Devices != null && frameItem.Frame.Metadata.Devices.Lens != null) { string imageFileName = file.Name.Substring(0, file.Name.Length - 3) + "RAW"; FlatFieldItem item; if (!items.TryGetValue(imageFileName, out item)) { items[imageFileName] = item = new FlatFieldItem(); } item.FrameImage = frameItem.Frame.Metadata.Image; item.ZoomStep = (int)frameItem.Frame.Metadata.Devices.Lens.ZoomStep; item.FocusStep = (int)frameItem.Frame.Metadata.Devices.Lens.FocusStep; if (_serialNumber == null && frameItem.Frame.PrivateMetadata != null && frameItem.Frame.PrivateMetadata.Camera != null) { _serialNumber = frameItem.Frame.PrivateMetadata.Camera.SerialNumber; } } } } } else if (file.Name.EndsWith(".RAW", StringComparison.OrdinalIgnoreCase)) { FlatFieldItem item; if (!items.TryGetValue(file.Name, out item)) { items[file.Name] = item = new FlatFieldItem(); } item.DataReference = file.DataRef; item.PackageReference = packageReference; } } } } RawPackageAccessor raw = package.AccessRaw(); if (raw.HasContent) { foreach (Json.FrameReferences frame in raw.GetFrames()) { if (frame.Metadata != null && frame.ImageRef != null) { FlatFieldItem item = new FlatFieldItem(); item.PackageReference = packageReference; item.DataReference = frame.ImageRef; item.FrameImage = frame.Metadata.Image; if (frame.Metadata.Devices != null && frame.Metadata.Devices.Lens != null) { item.ZoomStep = (int)frame.Metadata.Devices.Lens.ZoomStep; item.FocusStep = (int)frame.Metadata.Devices.Lens.FocusStep; items[frame.ImageRef] = item; } } } } return(master.NextFile); }