forked from dougforpres/NINASonyCameraPlugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSonyCameraPlugin.cs
More file actions
140 lines (121 loc) · 6.89 KB
/
Copy pathSonyCameraPlugin.cs
File metadata and controls
140 lines (121 loc) · 6.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
using NINA.RetroKiwi.Plugin.SonyCamera.Properties;
using NINA.Core.Model;
using NINA.Core.Utility;
using NINA.Image.ImageData;
using NINA.Plugin;
using NINA.Plugin.Interfaces;
using NINA.Profile;
using NINA.Profile.Interfaces;
using NINA.WPF.Base.Interfaces.Mediator;
using NINA.WPF.Base.Interfaces.ViewModel;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Composition;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using Settings = NINA.RetroKiwi.Plugin.SonyCamera.Properties.Settings;
namespace NINA.RetroKiwi.Plugin.SonyCamera {
/// <summary>
/// This class exports the IPluginManifest interface and will be used for the general plugin information and options
/// The base class "PluginBase" will populate all the necessary Manifest Meta Data out of the AssemblyInfo attributes. Please fill these accordingly
///
/// An instance of this class will be created and set as datacontext on the plugin options tab in N.I.N.A. to be able to configure global plugin settings
/// The user interface for the settings will be defined by a DataTemplate with the key having the naming convention "SonyCameraPlugin_Options" where SonyCameraPlugin corresponds to the AssemblyTitle - In this template example it is found in the Options.xaml
/// </summary>
[Export(typeof(IPluginManifest))]
public class SonyCamera : PluginBase, INotifyPropertyChanged {
private readonly IPluginOptionsAccessor pluginSettings;
private readonly IProfileService profileService;
private readonly IImageSaveMediator imageSaveMediator;
// Implementing a file pattern
// private readonly ImagePattern exampleImagePattern = new ImagePattern("$$EXAMPLEPATTERN$$", "An example of an image pattern implementation", "Sony Camera Plugin");
[ImportingConstructor]
public SonyCamera(IProfileService profileService, IOptionsVM options, IImageSaveMediator imageSaveMediator) {
if (Settings.Default.UpdateSettings) {
Settings.Default.Upgrade();
Settings.Default.UpdateSettings = false;
CoreUtil.SaveSettings(Settings.Default);
}
// This helper class can be used to store plugin settings that are dependent on the current profile
this.pluginSettings = new PluginOptionsAccessor(profileService, Guid.Parse(this.Identifier));
this.profileService = profileService;
// React on a changed profile
profileService.ProfileChanged += ProfileService_ProfileChanged;
// Hook into image saving for adding FITS keywords or image file patterns
this.imageSaveMediator = imageSaveMediator;
// Run these handlers when an image is being saved
this.imageSaveMediator.BeforeImageSaved += ImageSaveMediator_BeforeImageSaved;
this.imageSaveMediator.BeforeFinalizeImageSaved += ImageSaveMediator_BeforeFinalizeImageSaved;
// Register a new image file pattern for the Options > Imaging > File Patterns area
// options.AddImagePattern(exampleImagePattern);
}
public override Task Teardown() {
// Make sure to unregister an event when the object is no longer in use. Otherwise garbage collection will be prevented.
profileService.ProfileChanged -= ProfileService_ProfileChanged;
imageSaveMediator.BeforeImageSaved -= ImageSaveMediator_BeforeImageSaved;
imageSaveMediator.BeforeFinalizeImageSaved -= ImageSaveMediator_BeforeFinalizeImageSaved;
return base.Teardown();
}
private void ProfileService_ProfileChanged(object sender, EventArgs e) {
// Rase the event that this profile specific value has been changed due to the profile switch
RaisePropertyChanged(nameof(ProfileSpecificNotificationMessage));
}
private Task ImageSaveMediator_BeforeImageSaved(object sender, BeforeImageSavedEventArgs e) {
// Insert the example FITS keyword of a specific data type into the image metadata object prior to the file being saved
// FITS keywords have a maximum of 8 characters. Comments are options. Comments that are too long will be truncated.
/*
string exampleKeywordComment = "This is a {0} keyword";
// string
string exampleStringKeywordName = "STRKEYWD";
string exampleStringKeywordValue = "Example";
e.Image.MetaData.GenericHeaders.Add(new StringMetaDataHeader(exampleStringKeywordName, exampleStringKeywordValue, string.Format(exampleKeywordComment, "string")));
// integer
string exampleIntKeywordName = "INTKEYWD";
int exampleIntKeywordValue = 5;
e.Image.MetaData.GenericHeaders.Add(new IntMetaDataHeader(exampleIntKeywordName, exampleIntKeywordValue, string.Format(exampleKeywordComment, "integer")));
// double
string exampleDoubleKeywordName = "DBLKEYWD";
double exampleDoubleKeywordValue = 1.3d;
e.Image.MetaData.GenericHeaders.Add(new DoubleMetaDataHeader(exampleDoubleKeywordName, exampleDoubleKeywordValue, string.Format(exampleKeywordComment, "double")));
// Classes also exist for other data types:
// BoolMetaDataHeader()
// DateTimeMetaDataHeader()
*/
return Task.CompletedTask;
}
private Task ImageSaveMediator_BeforeFinalizeImageSaved(object sender, BeforeFinalizeImageSavedEventArgs e) {
/* // Populate the example image pattern with data. This can provide data that may not be immediately available
e.AddImagePattern(new ImagePattern(exampleImagePattern.Key, exampleImagePattern.Description, exampleImagePattern.Category) {
Value = $"{DateTime.Now:yyyy-MM-ddTHH:mm:ss.ffffffK}"
});
*/
return Task.CompletedTask;
}
public string DefaultNotificationMessage {
get {
return Settings.Default.DefaultNotificationMessage;
}
set {
Settings.Default.DefaultNotificationMessage = value;
CoreUtil.SaveSettings(Settings.Default);
RaisePropertyChanged();
}
}
public string ProfileSpecificNotificationMessage {
get {
return pluginSettings.GetValueString(nameof(ProfileSpecificNotificationMessage), string.Empty);
}
set {
pluginSettings.SetValueString(nameof(ProfileSpecificNotificationMessage), value);
RaisePropertyChanged();
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected void RaisePropertyChanged([CallerMemberName] string propertyName = null) {
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}