/**
         * Instantiate the SDSconnection, reading configuration details from the Registry. There is an
         * additional dependency on an external PKCS#12 (.pfx) file that contains the Spine endpoint
         * certificate and key.
         */
        public SDSconnection()
        {
            server = (string)Registry.GetValue(SDS_CONNECTION_REGSITRY_KEY, SDS_SERVER_REGVAL, "");
            cacheDir = (string)Registry.GetValue(SDS_CONNECTION_REGSITRY_KEY, SDS_CACHE_FILE_REGVAL, "");
            certificateFile = (string)Registry.GetValue(SDS_CONNECTION_REGSITRY_KEY, SDS_CERT_FILE_REGVAL, "");
            urlResolverFile = (string)Registry.GetValue(SDS_CONNECTION_REGSITRY_KEY, URL_RESOLVER_FILE, "");
            myAsid = (string)Registry.GetValue(SDS_CONNECTION_REGSITRY_KEY, MY_ASID, "");
            myPartyKey = (string)Registry.GetValue(SDS_CONNECTION_REGSITRY_KEY, MY_PARTY_KEY, "");
            EbXmlHeader.setMyPartyKey(myPartyKey);

            string s = (string)Registry.GetValue(SDS_CONNECTION_REGSITRY_KEY, SDS_REFRESH_PERIOD_REGVAL, "");
            loadUrlResolver();

            if (s.Length > 0)
            {
                try
                {
                    cacheRefreshPeriod = Int32.Parse(s);
                }
                catch (Exception)
                {
                    EventLog logger = new EventLog("Application");
                    logger.Source = LOGSOURCE;
                    StringBuilder sb = new StringBuilder("Registry entry ");
                    sb.Append(SDS_REFRESH_PERIOD_REGVAL);
                    sb.Append(" has invalid non-integer value '");
                    sb.Append(s);
                    sb.Append("'. Using default value ");
                    sb.Append(DEFAULT_REFRESH_PERIOD);
                    sb.Append(" hours instead");
                    logger.WriteEntry(sb.ToString(), EventLogEntryType.Warning);
                }
            }
            s = (string)Registry.GetValue(SDS_CONNECTION_REGSITRY_KEY, SDS_OPENTEST_REGVAL, "");
            opentest = (s.ToUpper().StartsWith("Y"));
            serviceRoot = (opentest) ? OPENTEST_SERVICES_ROOT : CIS_SERVICES_ROOT;
            if (server.Length == 0)
            {
                if (cacheDir.Length == 0)
                {
                    EventLog logger = new EventLog("Application");
                    logger.Source = LOGSOURCE;
                    logger.WriteEntry("Neither LDAP server name nor cache file registry entries are set - cannot resolve anything!", EventLogEntryType.Error);
                }
                else
                {
                    cache = new SDScache(cacheDir, cacheRefreshPeriod);
                }
            }
            else
            {
                if (cacheDir.Length == 0)
                {
                    EventLog logger = new EventLog("Application");
                    logger.Source = LOGSOURCE;
                    logger.WriteEntry("Cache file registry entry not set: all queries will be resolved directly from SDS and this MAY impact performance", EventLogEntryType.Warning);
                }
                else
                {
                    cache = new SDScache(cacheDir, cacheRefreshPeriod);
                }
            }
            if (certificateFile.Length > 0)
            {
                try
                {
                    String certPass = (string)Registry.GetValue(SDS_CONNECTION_REGSITRY_KEY, SDS_CERT_PASS_REGVAL, "");
                    certificate = new X509Certificate(certificateFile, certPass);
                }
                catch (Exception e)
                {
                    EventLog logger = new EventLog("Application");
                    logger.Source = LOGSOURCE;
                    StringBuilder sb = new StringBuilder("Certificate ");
                    sb.Append(certificateFile);
                    sb.Append(" failed to load: ");
                    sb.Append(e.ToString());
                    sb.Append(" - no lookups can be made against SDS");
                    logger.WriteEntry(sb.ToString(), EventLogEntryType.Error);
                }
            }
            else
            {
                EventLog logger = new EventLog("Application");
                logger.Source = LOGSOURCE;
                logger.WriteEntry("No certificate provided - queries will be resolved from cache only", EventLogEntryType.Warning);
            }
        }
Ejemplo n.º 2
0
        /**
         * Instantiate the SDSconnection, reading configuration details from the Registry. There is an
         * additional dependency on an external PKCS#12 (.pfx) file that contains the Spine endpoint
         * certificate and key.
         */
        public SDSconnection()
        {
            server          = (string)Registry.GetValue(SDS_CONNECTION_REGSITRY_KEY, SDS_SERVER_REGVAL, "");
            cacheDir        = (string)Registry.GetValue(SDS_CONNECTION_REGSITRY_KEY, SDS_CACHE_FILE_REGVAL, "");
            certificateFile = (string)Registry.GetValue(SDS_CONNECTION_REGSITRY_KEY, SDS_CERT_FILE_REGVAL, "");
            urlResolverFile = (string)Registry.GetValue(SDS_CONNECTION_REGSITRY_KEY, URL_RESOLVER_FILE, "");
            myAsid          = (string)Registry.GetValue(SDS_CONNECTION_REGSITRY_KEY, MY_ASID, "");
            myPartyKey      = (string)Registry.GetValue(SDS_CONNECTION_REGSITRY_KEY, MY_PARTY_KEY, "");
            EbXmlHeader.setMyPartyKey(myPartyKey);

            string s = (string)Registry.GetValue(SDS_CONNECTION_REGSITRY_KEY, SDS_REFRESH_PERIOD_REGVAL, "");

            loadUrlResolver();

            if (s.Length > 0)
            {
                try
                {
                    cacheRefreshPeriod = Int32.Parse(s);
                }
                catch (Exception)
                {
                    EventLog logger = new EventLog("Application");
                    logger.Source = LOGSOURCE;
                    StringBuilder sb = new StringBuilder("Registry entry ");
                    sb.Append(SDS_REFRESH_PERIOD_REGVAL);
                    sb.Append(" has invalid non-integer value '");
                    sb.Append(s);
                    sb.Append("'. Using default value ");
                    sb.Append(DEFAULT_REFRESH_PERIOD);
                    sb.Append(" hours instead");
                    logger.WriteEntry(sb.ToString(), EventLogEntryType.Warning);
                }
            }
            s           = (string)Registry.GetValue(SDS_CONNECTION_REGSITRY_KEY, SDS_OPENTEST_REGVAL, "");
            opentest    = (s.ToUpper().StartsWith("Y"));
            serviceRoot = (opentest) ? OPENTEST_SERVICES_ROOT : CIS_SERVICES_ROOT;
            if (server.Length == 0)
            {
                if (cacheDir.Length == 0)
                {
                    EventLog logger = new EventLog("Application");
                    logger.Source = LOGSOURCE;
                    logger.WriteEntry("Neither LDAP server name nor cache file registry entries are set - cannot resolve anything!", EventLogEntryType.Error);
                }
                else
                {
                    cache = new SDScache(cacheDir, cacheRefreshPeriod);
                }
            }
            else
            {
                if (cacheDir.Length == 0)
                {
                    EventLog logger = new EventLog("Application");
                    logger.Source = LOGSOURCE;
                    logger.WriteEntry("Cache file registry entry not set: all queries will be resolved directly from SDS and this MAY impact performance", EventLogEntryType.Warning);
                }
                else
                {
                    cache = new SDScache(cacheDir, cacheRefreshPeriod);
                }
            }
            if (certificateFile.Length > 0)
            {
                try
                {
                    String certPass = (string)Registry.GetValue(SDS_CONNECTION_REGSITRY_KEY, SDS_CERT_PASS_REGVAL, "");
                    certificate = new X509Certificate(certificateFile, certPass);
                }
                catch (Exception e)
                {
                    EventLog logger = new EventLog("Application");
                    logger.Source = LOGSOURCE;
                    StringBuilder sb = new StringBuilder("Certificate ");
                    sb.Append(certificateFile);
                    sb.Append(" failed to load: ");
                    sb.Append(e.ToString());
                    sb.Append(" - no lookups can be made against SDS");
                    logger.WriteEntry(sb.ToString(), EventLogEntryType.Error);
                }
            }
            else
            {
                EventLog logger = new EventLog("Application");
                logger.Source = LOGSOURCE;
                logger.WriteEntry("No certificate provided - queries will be resolved from cache only", EventLogEntryType.Warning);
            }
        }