public Model() { _objects = new ObservableCollection <ObjectModel>(); _managers = new List <NikonManager>(); string[] md3s = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.md3", SearchOption.AllDirectories); if (md3s.Length == 0) { Log.GetInstance().WriteLine("Couldn't find any MD3 files in " + Directory.GetCurrentDirectory()); Log.GetInstance().WriteLine("Download MD3 files from Nikons SDK website: https://sdk.nikonimaging.com/apply/"); } foreach (string md3 in md3s) { const string requiredDllFile = "NkdPTP.dll"; string requiredDllPath = Path.Combine(Path.GetDirectoryName(md3), requiredDllFile); if (!File.Exists(requiredDllPath)) { Log.GetInstance().WriteLine("Warning: Couldn't find " + requiredDllFile + " in " + Path.GetDirectoryName(md3) + ". The library will not work properly without it!"); } Log.GetInstance().WriteLine("Opening " + md3); NikonManager manager = new NikonManager(md3); manager.DeviceAdded += new DeviceAddedDelegate(_manager_DeviceAdded); manager.DeviceRemoved += new DeviceRemovedDelegate(_manager_DeviceRemoved); _objects.Add(new ObjectModel(manager)); _managers.Add(manager); } }
public void Start() { try { _object.Start(_cap.ulID); } catch (NikonException ex) { Log.GetInstance().WriteLine("Failed to start " + _cap.ulID.ToString() + ", " + ex.ToString()); } }
public void StartLiveView() { try { NikonDevice device = _object as NikonDevice; if (device != null) { device.LiveViewEnabled = true; _timer.Start(); } } catch (NikonException ex) { Log.GetInstance().WriteLine("Failed to start live view: " + ex.ToString()); } }
void _timer_Tick(object sender, EventArgs e) { NikonDevice device = _object as NikonDevice; Debug.Assert(device != null); NikonLiveViewImage liveViewImage = null; try { liveViewImage = device.GetLiveViewImage(); } catch (NikonException ex) { Log.GetInstance().WriteLine("Failed to get live view image: " + ex.ToString()); } if (liveViewImage == null) { _timer.Stop(); return; } // Note: Decode the live view jpeg image on a seperate thread to keep the UI responsive ThreadPool.QueueUserWorkItem(new WaitCallback((o) => { Debug.Assert(liveViewImage != null); JpegBitmapDecoder decoder = new JpegBitmapDecoder( new MemoryStream(liveViewImage.JpegBuffer), BitmapCreateOptions.None, BitmapCacheOption.OnLoad); Debug.Assert(decoder.Frames.Count > 0); BitmapFrame frame = decoder.Frames[0]; Dispatcher.CurrentDispatcher.Invoke((Action)(() => { SetLiveViewImage(frame); })); })); }
public void StopLiveView() { try { NikonDevice device = _object as NikonDevice; if (device != null) { _timer.Stop(); device.LiveViewEnabled = false; SetLiveViewImage(null); } } catch (NikonException ex) { Log.GetInstance().WriteLine("Failed to stop live view: " + ex.ToString()); } }
void Save(byte[] buffer, string file) { string path = Path.Combine( System.Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), file); Log.GetInstance().WriteLine("Saving: " + path); try { using (FileStream stream = new FileStream(path, FileMode.Create, FileAccess.Write)) { stream.Write(buffer, 0, buffer.Length); } } catch (Exception ex) { Log.GetInstance().WriteLine("Failed to save file: " + path + ", " + ex.Message); } }
void device_VideoFragmentReady(NikonDevice sender, NikonVideoFragment fragment) { string path = Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.MyVideos), fragment.Filename); if (fragment.IsFirst) { Debug.Assert(_videoFile == null); _videoFile = new FileStream(path, FileMode.Create, FileAccess.Write); Log.GetInstance().WriteLine("Downloading Video..."); } Log.GetInstance().WriteLine(fragment.PercentComplete.ToString(".0") + "%"); Debug.Assert(_videoFile != null); _videoFile.Write(fragment.Buffer, 0, fragment.Buffer.Length); if (fragment.IsLast) { _videoFile.Close(); _videoFile = null; Log.GetInstance().WriteLine("Saved Video: " + path + " (" + fragment.VideoWidth + "x" + fragment.VideoHeight + ")"); } }
public LogModel() { _log = Log.GetInstance(); _log.LogChanged += new LogChangedDelegate(_log_LogChanged); }
void device_VideoRecordingInterrupted(NikonDevice sender, int error) { Log.GetInstance().WriteLine("Video Recording Interrupted (" + error.ToString() + ")"); }