示例#1
0
        public SOFA()
        {
            disposedValue = false;
            StringBuilder lpszPath = new StringBuilder(260);

            TL         = new TraceLogger("", "SOFA");
            TL.Enabled = RegistryCommonCode.GetBool("Trace NOVAS", false);
            Utl        = new Util();
            string lpFileName;

            if (Is64Bit())
            {
                ASCOM.Astrometry.SOFA.SOFA.SHGetSpecialFolderPath(IntPtr.Zero, lpszPath, 44, false);
                lpFileName = lpszPath.ToString() + "\\ASCOM\\Astrometry\\SOFA11-64.dll";
            }
            else
            {
                lpFileName = Environment.GetFolderPath(Environment.SpecialFolder.CommonProgramFiles) + "\\ASCOM\\Astrometry\\SOFA11.dll";
            }
            TL.LogMessage("New", "Loading SOFA library DLL: " + lpFileName);
            SofaDllHandle = ASCOM.Astrometry.SOFA.SOFA.LoadLibrary(lpFileName);
            int lastWin32Error = Marshal.GetLastWin32Error();

            if (SofaDllHandle != IntPtr.Zero)
            {
                TL.LogMessage("New", "Loaded SOFA library OK");
                TL.LogMessage("New", "SOFA Initialised OK");
            }
            else
            {
                TL.LogMessage("New", "Error loading SOFA library: " + lastWin32Error.ToString("X8"));
                throw new HelperException("Error code returned from LoadLibrary when loading SOFA library: " + lastWin32Error.ToString("X8"));
            }
        }
示例#2
0
 public AstroUtils(int leapSeconds, IAscomDataStore store, ITraceLogger logger)
 {
     Utl          = new Util();
     Nov31        = new NOVAS31();
     Store        = store ?? (IAscomDataStore) new EntityStore();
     TL           = logger ?? new TraceLogger("", "Astrometry");
     TL.Enabled   = Store?.GetProfile <bool>("Utilities", "Trace Astro Utils", false) ?? false;
     UtcTaiOffset = Store?.GetProfile("Astrometry", "Leap Seconds", 36) ?? 36;
     TL.LogMessage("New", "AstroUtils created Utilities component OK");
     TL.LogMessage("New", $"Leap seconds: {UtcTaiOffset}");
     TL.LogMessage("New", "Finished initialisation OK");
 }
示例#3
0
        void IFileStoreProvider.SetSecurityACLs(ITraceLogger p_tl)
        {
            DirectoryInfo      directoryInfo      = new DirectoryInfo(this.ASCOMFolder);
            SecurityIdentifier securityIdentifier = new SecurityIdentifier(WellKnownSidType.BuiltinUsersSid, new SecurityIdentifier("S-1-0-0"));

            p_tl.LogMessage("  SetSecurityACLs", "Retrieving access control");
            DirectorySecurity accessControl = directoryInfo.GetAccessControl();

            p_tl.LogMessage("  SetSecurityACLs", "Adding full control access rule");
            accessControl.AddAccessRule(new FileSystemAccessRule((IdentityReference)securityIdentifier, FileSystemRights.FullControl, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow));
            p_tl.LogMessage("  SetSecurityACLs", "Setting access control");
            directoryInfo.SetAccessControl(accessControl);
            p_tl.LogMessage("  SetSecurityACLs", "Successfully set security ACL!");
        }
示例#4
0
 void IFileStoreProvider.CreateDirectory(string p_SubKeyName, ITraceLogger p_TL)
 {
     try
     {
         p_TL.LogMessage("  CreateDirectory", "Creating directory for: \"" + p_SubKeyName + "\"");
         Directory.CreateDirectory(this.CreatePath(p_SubKeyName));
         p_TL.LogMessage("  CreateDirectory", "Created directory OK");
     }
     catch (Exception ex)
     {
         //ProjectData.SetProjectError(ex);
         Exception exception = ex;
         p_TL.LogMessage("FileSystem.CreateDirectory", "Exception: " + exception.ToString());
         Interaction.MsgBox((object)("CreateDirectory Exception: " + exception.ToString()), MsgBoxStyle.OkOnly, (object)null);
         //ProjectData.ClearProjectError();
     }
 }
示例#5
0
 public static string Encrypt(this string clearText, ITraceLogger TL)
 {
     try
     {
         byte[] clearBytes     = Encoding.UTF8.GetBytes(clearText);
         byte[] entropyBytes   = Encoding.UTF8.GetBytes(GenerateEntropy());
         byte[] encryptedBytes = ProtectedData.Protect(clearBytes, entropyBytes, dataProtectionScope);
         string encryptedText  = Convert.ToBase64String(encryptedBytes);
         TL.LogMessage("Encrypt", encryptedText, false);
         return(encryptedText);
     }
     catch (Exception ex)
     {
         TL.LogMessageCrLf("Encrypt", ex.ToString());
         return("Unable to encrypt this value");
     }
 }
示例#6
0
 public static string Unencrypt(this string encryptedText, ITraceLogger TL)
 {
     try
     {
         if (encryptedText == null)
         {
             return("");                       // Deal with initial case where text has not yet been encrypted
         }
         byte[] encryptedBytes = Convert.FromBase64String(encryptedText);
         byte[] entropyBytes   = Encoding.UTF8.GetBytes(GenerateEntropy());
         byte[] clearBytes     = ProtectedData.Unprotect(encryptedBytes, entropyBytes, dataProtectionScope);
         string clearText      = Encoding.UTF8.GetString(clearBytes);
         TL.LogMessage("Unencrypt", encryptedText, false);
         return(clearText);
     }
     catch (Exception ex)
     {
         TL.LogMessageCrLf("Unencrypt", ex.ToString());
         return("Unable to decrypt this value");
     }
 }