/// <summary>
        /// Add a new server to the list of available servers.
        /// </summary>
        /// <param name="HostName"></param>
        /// <param name="Port"></param>
        /// <param name="Protocol"></param>
        /// <returns></returns>
        public bool RegisterServer(String HostName, String Port, String Protocol, String Description)
        {
            //
            // Check to see if we already have this server registered
            if (m_Servers.ContainsKey(HostName + Port))
            {
                return(true);
            }

            //
            // Make sure the Protocol channel has been successfully registered
            if (Protocol.ToUpper() == GPEnums.CHANNEL_TCP && !m_TcpRegistered)
            {
                return(false);
            }
            if (Protocol.ToUpper() == GPEnums.CHANNEL_HTTP && !m_HttpRegistered)
            {
                return(false);
            }

            //
            // Obtain the IGPServer interface
            String CompleteHost = Protocol.ToLower() + "://" + HostName + ":" + Port + "/" + GPEnums.SERVER_SOAPNAME;
            object obj          = Activator.GetObject(
                typeof(IGPServer),
                CompleteHost);

            IGPServer iGPServer = (IGPServer)obj;

            //
            // Validate this server is available
            if (!ValidateServer(iGPServer))
            {
                return(false);
            }

            //
            // Assign a sponsor for the remote object
            GPServerClientSponsor Sponsor = fmMain.SponsorServer.Create("GPServer Singleton");
            ILease LeaseInfo = (ILease)((MarshalByRefObject)iGPServer).GetLifetimeService();

            LeaseInfo.Register(Sponsor);
            m_Sponsors.Add(HostName + Port, Sponsor);

            //
            // Add this server interface to our singleton
            m_Servers.Add(HostName + Port, iGPServer);
            m_Descriptions.Add(HostName + Port, Description);

            return(true);
        }
        /// <summary>
        /// Call the Validate() method for IGPServer to find out if this server
        /// is actually up and running.
        /// </summary>
        /// <param name="iGPServer">Interface to the server to test</param>
        /// <returns>True/False upon success or failure</returns>
        private bool ValidateServer(IGPServer iGPServer)
        {
            try
            {
                if (iGPServer.Validate() != GPEnums.SERVER_VERSION)
                {
                    return(false);
                }
            }
            catch
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets the settings for an individual modeler prepared.  This function is
        /// intended to be called asynchronously.
        /// </summary>
        /// <param name="iServer"></param>
        /// <param name="iModeler"></param>
        /// <param name="Training"></param>
        /// <returns></returns>
        private bool InitializeModeler(IGPServer iServer, IGPModeler iModeler, GPModelingData Training)
        {
            //
            // The data we want to send is data appropriate for modeling.  Time Series
            // data needs to be transformed for the modeler.
            if (m_DELReportStatus != null)
            {
                m_DELReportStatus("Loading training data...");
            }
            iModeler.Training = Training.TrainingForModeling(
                m_Profile.ModelType.InputDimension,
                m_Profile.ModelType.PredictionDistance);

            //
            // Prepare the function set for each server
            if (m_DELReportStatus != null)
            {
                m_DELReportStatus("Transmitting user defined functions...");
            }
            IGPFunctionSet iFunctionSet = iServer.FunctionSet;
            //
            // Use a client side sponsor for this function set
            // TODO: This sponsor should really come from the server we obtained
            // the function set interface from.  The reason it currently isn't, is
            // because the whole "lease lifetime" thing isn't fully thought out yet
            // in this application.
            ILease LeaseInfo = (ILease)((MarshalByRefObject)iFunctionSet).GetLifetimeService();

            LeaseInfo.Register(m_FunctionSetSponsor);

            //
            // Let's go ahead and assign the same lease sponsor to the modeler
            LeaseInfo = (ILease)((MarshalByRefObject)iModeler).GetLifetimeService();
            LeaseInfo.Register(m_ModelerSponsor);

#if GPLOG
            GPLog.ReportLine("Loading UDFs...", true);
#endif

            foreach (string FunctionName in m_Profile.FunctionSet)
            {
#if GPLOG
                GPLog.ReportLine("   UDF: " + FunctionName, false);
#endif
                //
                // Load the Function from the database
                short  FunctionArity      = 0;
                bool   TerminalParameters = false;
                String FunctionCode       = "";
                if (GPDatabaseUtils.LoadFunctionFromDB(FunctionName, ref FunctionArity, ref TerminalParameters, ref FunctionCode, GPEnums.LANGUAGEID_CSHARP))
                {
                    //
                    // Add it to the function set
                    iFunctionSet.AddFunction(FunctionName, FunctionArity, TerminalParameters, FunctionCode);
                }
            }
            iFunctionSet.UseMemory = m_Profile.ModelingProfile.UseMemory;

            //
            // Assign it to the modeler
            iModeler.FunctionSet = iFunctionSet;

#if GPLOG
            GPLog.Report("Transmitting fitness function...", true);
#endif

            //
            // Pass the fitness function to each modeler
            if (m_DELReportStatus != null)
            {
                m_DELReportStatus("Transmitting fitness function...");
            }
            String FitnessFunction = GPDatabaseUtils.FieldValue(m_Profile.FitnessFunctionID, "tblFitnessFunction", "Code");
            iModeler.FitnessFunction = FitnessFunction;

#if GPLOG
            GPLog.ReportLine("...Complete", false);
#endif

            //
            // Transmit the profile/modeling settings
            if (m_DELReportStatus != null)
            {
                m_DELReportStatus("Transmitting modeling parameters...");
            }
            iModeler.Profile = m_Profile.ModelingProfile;
            //
            // Send over which ADF and ADLs to evolve
            foreach (byte adf in m_Profile.m_ADFSet)
            {
                iModeler.AddADF(adf);
            }
            foreach (byte adl in m_Profile.m_ADLSet)
            {
                iModeler.AddADL(adl);
            }
            foreach (byte adr in m_Profile.m_ADRSet)
            {
                iModeler.AddADR(adr);
            }

            return(true);
        }