Exemplo n.º 1
0
        /// <summary>  Initialize the Adk to use the specified version of SIF.
        ///
        /// Calling this method when the Adk has already been initialized has no effect.
        ///
        /// This method must be called at agent startup to initialize
        /// various resources of the Adk, establish global settings for the
        /// class framework, and set the default version of SIF to which
        /// all messages originating from the agent will conform.
        ///
        /// Beginning with Adk 1.5.0, this method also configures the global
        /// Adk <c>ServerLog</c> instance with a logging module that
        /// will be inherited by the ServerLog of all zones. It installs a
        /// single logging module implementation: <c>DefaultServerLogModule</c>.
        /// The behavior of this module is to report SIF_LogEntry objects to
        /// the zone integration server via an Add SIF_Event message whenever
        /// <c>ServerLog.reportLogEntry</c> is called on a zone and
        /// the agent is running in SIF 1.5 or later. DefaultServerLogModule
        /// also echos server log messages to the zone's local logging framework Category
        /// so that agents do not need to duplicate logging to both the server
        /// and local agent log. If you want to install a custom <i>ServerLogModule</i>
        /// implementation -- or need to adjust the settings of the default
        /// module installed when the Adk is initialized -- call the
        /// <c>Adk.getServerLog</c> method to obtain a reference to the
        /// root of the <c>ServerLog</c> chain, then call its methods
        /// to add and remove modules. Refer to the ServerLog class for more
        /// information on server logging.
        ///
        /// </summary>
        /// <param name="version">The version of SIF that will be used by the agent this
        /// session. Supported versions are enumerated by constants of the
        /// <see cref="OpenADK.Library.SifVersion"/> class. Once initialized,
        /// the version cannot be changed.
        /// </param>
        /// <param name="sdoLibraries">One or more of the constants defined by the SdoLibrary
        /// class, identifying the SIF Data Object libraries to be loaded into
        /// memory (e.g. SdoLibraryType.STUDENT | SdoLibraryType.HR )
        ///
        /// </param>
        /// <exception cref="AdkException">If the ADK cannot be initialized</exception>
        /// <exception cref="OpenADK.Library.AdkNotSupportedException"> AdkNotSupportedException is thrown if the specified SIF
        /// version is not supported by the Adk, or if the <i>sdoLibraries</i>
        /// parameter is invalid
        /// </exception>
        public static void Initialize(SifVersion version, SIFVariant dataModel,
                                      int sdoLibraries)
        {
            if (Initialized)
            {
                return;
            }

            //	TODO: This code could be done in more of a modular way so that it
            //	doesn't need to be hand-edited each time a new SIFVariant is added.
            if (dataModel == SIFVariant.SIF_US)
            {
                sDtd = new OpenADK.Library.us.SifDtd();
            }
            else if (dataModel == SIFVariant.SIF_UK)
            {
                sDtd = new OpenADK.Library.uk.SifDtd();
            }
            else if (dataModel == SIFVariant.SIF_AU)
            {
                sDtd = new OpenADK.Library.au.SifDtd();
            }

            //if (dataModel == null)
            //{
            //    Console.Out.WriteLine("ERROR - No variant DTD loaded");
            //}
            //else
            //{
            Console.Out.WriteLine("Using datamodel - " + dataModel.ToString("G"));
            //}

            try
            {
                InitLogging();
            }
            catch (Exception e)
            {
                Console.Out.WriteLine(e);
            }


            if (version == null)
            {
                throw new ArgumentException("SifVersion cannot be null");
            }

            sSingleton = new Adk();

            // the default formatter for String APIs in the ADK is the SIF 1.x formatter
            // for backwards compatibility
            sSingleton.fDefaultFormatter = SifDtd.SIF_1X_FORMATTER;

            //
            //	Set up the ServerLog
            //

            ServerLog sl = ServerLog;

            if (sl != null)
            {
                sl.AddLogger(new DefaultServerLogModule());
            }

            //  HTTP and HTTPS transports always available
            TransportPlugin tp = new HttpTransportPlugin();

            sSingleton.fTransports[tp.Protocol] = tp;

            tp = new HttpsTransportPlugin();
            sSingleton.fTransports[tp.Protocol] = tp;

            if (Debug != AdkDebugFlags.None)
            {
                sLog.Debug("Using Adk " + AdkVersion);
            }

            sSingleton.fVersion = version;

            //Dtd.LoadLibraries(sdoLibraries);
            ((DTDInternals)Dtd).LoadLibraries((int)sdoLibraries);
        }