private void LoadAddinInAppDomain(string assemblyName, string typeName, AddinManager addinManager) { var appSetup = new AppDomainSetup() { ApplicationName = "Tangra 3", ApplicationBase = AppDomain.CurrentDomain.BaseDirectory, ConfigurationFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile, PrivateBinPath = @"Addins", }; m_DomainName = string.Format("Tangra.Addins.{0}.v{1}", m_AssemblyName.Name, m_AssemblyName.Version.ToString()); var e = new Evidence(); e.AddHostEvidence(new Zone(SecurityZone.MyComputer)); PermissionSet pset = SecurityManager.GetStandardSandbox(e); m_HostDomain = AppDomain.CreateDomain(m_DomainName, AppDomain.CurrentDomain.Evidence, appSetup, pset, null); m_HostDomain.AssemblyResolve += m_HostDomain_AssemblyResolve; m_HostDomain.ReflectionOnlyAssemblyResolve += m_HostDomain_AssemblyResolve; m_HostDomain.UnhandledException += m_HostDomain_UnhandledException; object obj = m_HostDomain.CreateInstanceAndUnwrap(assemblyName, typeName); ILease lease = (ILease)(obj as MarshalByRefObject).GetLifetimeService(); if (lease != null) { lease.Register(addinManager.RemotingClientSponsor); } m_Instance = (ITangraAddin)obj; m_Instance.Initialise(new TangraHostDelegate(typeName, addinManager)); foreach (object actionInstance in m_Instance.GetAddinActions()) { var mbrObj = actionInstance as MarshalByRefObject; if (mbrObj != null) { lease = (ILease)mbrObj.GetLifetimeService(); if (lease != null) { lease.Register(addinManager.RemotingClientSponsor); } } } }
internal Addin(string fullTypeName, AddinManager addinManager) { string[] tokens = fullTypeName.Split(new char[] { ',' }, 2); m_AssemblyName = new AssemblyName(tokens[1]); #if WIN32 if (TangraConfig.Settings.Generic.AddinIsolationLevel == TangraConfig.IsolationLevel.AppDomain) { LoadAddinInAppDomain(tokens[1], tokens[0], addinManager); } else { #endif m_HostDomain = null; string fullName = string.Format("{0}//{1}.dll", AddinManager.ADDINS_DIRECTORY, m_AssemblyName.Name); AppDomain.CurrentDomain.AssemblyResolve += m_HostDomain_AssemblyResolve; Assembly asm = Assembly.LoadFrom(fullName); Type type = asm.GetType(tokens[0]); m_Instance = (ITangraAddin)Activator.CreateInstance(type, new object[] {}); m_Instance.Initialise(new TangraHostDelegate(tokens[0], addinManager)); #if WIN32 } #endif }
internal Addin(string fullTypeName, AddinManager addinManager) { string[] tokens = fullTypeName.Split(new char[] { ',' }, 2); m_AssemblyName = new AssemblyName(tokens[1]); #if WIN32 if (TangraConfig.Settings.Generic.AddinIsolationLevel == TangraConfig.IsolationLevel.AppDomain) { LoadAddinInAppDomain(tokens[1], tokens[0], addinManager); } else { #endif m_HostDomain = null; string fullName = string.Format("{0}//{1}.dll", AddinManager.ADDINS_DIRECTORY, m_AssemblyName.Name); AppDomain.CurrentDomain.AssemblyResolve += m_HostDomain_AssemblyResolve; Assembly asm = Assembly.LoadFrom(fullName); Type type = asm.GetType(tokens[0]); m_Instance = (ITangraAddin) Activator.CreateInstance(type, new object[] {}); m_Instance.Initialise(new TangraHostDelegate(tokens[0], addinManager)); #if WIN32 } #endif }
private void LoadAddinInAppDomain(string assemblyName, string typeName, AddinManager addinManager) { var appSetup = new AppDomainSetup() { ApplicationName = "Tangra 3", ApplicationBase = AppDomain.CurrentDomain.BaseDirectory, ConfigurationFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile, PrivateBinPath = @"Addins", }; m_DomainName = string.Format("Tangra.Addins.{0}.v{1}", m_AssemblyName.Name, m_AssemblyName.Version.ToString()); var e = new Evidence(); e.AddHostEvidence(new Zone(SecurityZone.MyComputer)); PermissionSet pset = SecurityManager.GetStandardSandbox(e); m_HostDomain = AppDomain.CreateDomain(m_DomainName, AppDomain.CurrentDomain.Evidence, appSetup, pset, null); m_HostDomain.AssemblyResolve += m_HostDomain_AssemblyResolve; m_HostDomain.ReflectionOnlyAssemblyResolve += m_HostDomain_AssemblyResolve; m_HostDomain.UnhandledException += m_HostDomain_UnhandledException; object obj = m_HostDomain.CreateInstanceAndUnwrap(assemblyName, typeName); ILease lease = (ILease)(obj as MarshalByRefObject).GetLifetimeService(); if (lease != null) lease.Register(addinManager.RemotingClientSponsor); m_Instance = (ITangraAddin)obj; m_Instance.Initialise(new TangraHostDelegate(typeName, addinManager)); foreach (object actionInstance in m_Instance.GetAddinActions()) { var mbrObj = actionInstance as MarshalByRefObject; if (mbrObj != null) { lease = (ILease)mbrObj.GetLifetimeService(); if (lease != null) lease.Register(addinManager.RemotingClientSponsor); } } }
private void StartMeasurements() { #region Remove the unchecked actions if (m_AstrometryAddinActions.Count > 0) { m_AstrometryAddinActions.Clear(); foreach (AddinActionEntry selectedAction in clbAddinsToRun.CheckedItems) { m_AstrometryAddinActions.Add(selectedAction.Action); } List <string> executingActions = m_AstrometryAddinActions .Select(a => a.DisplayName) .ToList(); for (int i = m_AstrometryAddins.Count - 1; i >= 0; i--) { ITangraAddin addin = m_AstrometryAddins[i]; ITangraAddinAction[] actions = addin.GetAddinActions(); bool found = false; foreach (ITangraAddinAction action in actions) { if (executingActions.IndexOf(action.DisplayName) > -1) { found = true; break; } } if (!found) { m_AstrometryAddins.RemoveAt(i); } } } #endregion var plateConfig = m_AstrometryController.GetCurrentAstroPlate(); double pixArcsecFactor = plateConfig.GetDistanceInArcSec( plateConfig.CenterXImage, plateConfig.CenterYImage, plateConfig.CenterXImage + 1, plateConfig.CenterYImage + 1); m_MeasurementContext.MaxStdDev = pixArcsecFactor * (double)nudMaxStdDev.Value; m_MeasurementContext.FrameInterval = ucFrameInterval.Value; m_MeasurementContext.FirstFrameUtcTime = ucUtcTimePicker.DateTimeUtc; m_MeasurementContext.PerformPhotometricFit = cbxFitMagnitudes.Checked; m_MeasurementContext.ApertureSize = (float)nudAperture.Value; m_MeasurementContext.AnnulusInnerRadius = ((float)nudGap.Value + (float)nudAperture.Value) / (float)nudAperture.Value; m_MeasurementContext.AnnulusMinPixels = (int)(Math.PI * (Math.Pow((float)nudAnnulus.Value + (float)nudGap.Value + (float)nudAperture.Value, 2) - Math.Pow((float)nudGap.Value + (float)nudAperture.Value, 2))); m_MeasurementContext.PhotometryReductionMethod = ComboboxIndexToPhotometryReductionMethod(); m_MeasurementContext.PhotometryBackgroundMethod = ComboboxIndexToBackgroundMethod(); m_MeasurementContext.ExportCSV = cbxExport.Checked; m_MeasurementContext.PhotometryMagOutputBand = (TangraConfig.MagOutputBand)cbxOutputMagBand.SelectedIndex; m_MeasurementContext.PhotometryCatalogBandId = ((CatalogMagnitudeBand)cbxCatalogPhotometryBand.SelectedItem).Id; m_MeasurementContext.StarCatalogueFacade = m_FieldSolveContext.StarCatalogueFacade; m_MeasurementContext.AssumedTargetVRColour = TangraConfig.Settings.Astrometry.AssumedTargetVRColour; m_MeasurementContext.StopOnNoFit = cbxStopOnNoFit.Checked; m_MeasurementContext.MovementExpectation = (MovementExpectation)cbxExpectedMotion.SelectedIndex; m_MeasurementContext.ObjectExposureQuality = (ObjectExposureQuality)cbxSignalType.SelectedIndex; m_MeasurementContext.FrameTimeType = (FrameTimeType)cbxFrameTimeType.SelectedIndex; m_MeasurementContext.InstrumentalDelay = (double)nudInstrDelay.Value; m_MeasurementContext.InstrumentalDelayUnits = (InstrumentalDelayUnits)cbxInstDelayUnit.SelectedIndex; m_MeasurementContext.IntegratedFramesCount = m_AavIntegration ? 1 : (int)nudIntegratedFrames.Value; m_MeasurementContext.IntegratedExposureSeconds = m_MeasurementContext.IntegratedFramesCount / m_VideoController.VideoFrameRate; m_MeasurementContext.AavIntegration = m_AavIntegration; m_MeasurementContext.AavStackedMode = m_AavStacking; m_MeasurementContext.VideoFileFormat = m_VideoFileFormat; m_MeasurementContext.NativeVideoFormat = m_NativeFormat; m_MeasurementContext.MaxMeasurements = (int)nudNumberMeasurements.Value; // TODO: Detect the integration automatically and position to the first frame of the next interval TangraConfig.Settings.LastUsed.AstrometryPhotometryReductionMethod = ComboboxIndexToPhotometryReductionMethod(); TangraConfig.Settings.LastUsed.AstrometryPhotometryBackgroundMethod = ComboboxIndexToBackgroundMethod(); TangraConfig.Settings.LastUsed.AstrometryFitMagnitudes = cbxFitMagnitudes.Checked; TangraConfig.Settings.LastUsed.LastAstrometryUTCDate = ucUtcTimePicker.DateTimeUtc; if (cbxFitMagnitudes.Checked) { TangraConfig.Settings.LastUsed.AstrometryMagFitAperture = (float)nudAperture.Value; TangraConfig.Settings.LastUsed.AstrometryMagFitGap = (float)nudGap.Value; TangraConfig.Settings.LastUsed.AstrometryMagFitAnnulus = (float)nudAnnulus.Value; } TangraConfig.Settings.Save(); m_VideoAstrometry.StartAstrometricMeasurements(new ucAstrometryObjectInfo.StartAstrometricMeasurementsEventArgs(m_MeasurementContext)); Close(); }