Пример #1
0
        //internal string ConnectionString;
        /// <summary>
        /// Opens and manages its own connection to the Oyster Database
        /// ALL Instances of the Functions Class use the same Connection
        /// Always returns True
        /// </summary>
        /// 
        internal Functions()
        {
            //
            // TODO: Add constructor logic here
            //
            try
            {
                if (RF == null)
                {

                    try
                    {
                        RegistryKey RK;
                        //RK = Registry.LocalMachine.OpenSubKey("Software\\VSC\\CardVideo");
                        //UseExternalDatabase = 0;
                        RK = CarverLab.Utility.Registry.DefaultProductKey;
                        if(RK != null)
                        {
                            ServerAddress = Convert.ToString((object)RK.GetValue("OysterMediaServerAddr",""));
                            ServerPort = Convert.ToInt32((object)RK.GetValue("OysterDatabasePort",""));
                        }
                    }
                    catch(Exception Err)
                    {
                        string p = Err.Message;
                    }
                    try
                    {
                        if(chan==null)
                        {
                            chan = new TcpChannel();
                            ChannelServices.RegisterChannel(chan);
                        }
                    }
                    catch(Exception Err)
                    {
                        string p = Err.Message;
                    }
                    // Create an instance of the remote object
                    try
                    {

                        RF = (OysterDataBaseService.RemoteFunctions) Activator.GetObject(
                            typeof(OysterDataBaseService.RemoteFunctions),
                            "tcp://" + ServerAddress + ":" + ServerPort.ToString() +"/ODS_Functions" );
                        // Use the object
                        if( RF.Equals(null) )
                        {
                            RF = null;
                            chan = null;
                            throw new Exception("Unable to connect to Oyster Server");
                        }
                    }
                    catch(Exception Err)
                    {
                        string sErrorMessage = Err.Message;
                        RF = null;
                        chan = null;
                        throw new Exception("Unable to connect to Oyster Server");
                    }
                }
            }
            catch(Exception Err)
            {
                throw new Exception(Err.Message,Err.InnerException);
            }
        }
Пример #2
0
        internal Functions(string Server_Address,int Server_Port)
        {
            //
            // TODO: Add constructor logic here
            //
            try
            {
                if((RF ==null)||(Server_Address != ServerAddress)||(Server_Port != ServerPort))
                {
                    RF = null;
                    if(chan != null)
                    {
                        ChannelServices.UnregisterChannel(chan);
                        chan = null;
                    }
                    try
                    {
                        chan = new TcpChannel();
                        ChannelServices.RegisterChannel(chan);
                    }
                    catch(Exception Err)
                    {
                        string sPeek = Err.Message;
                        throw new Exception("Server not located");
                    }
                    // Create an instance of the remote object
                    RF = (OysterDataBaseService.RemoteFunctions) Activator.GetObject(
                        typeof(OysterDataBaseService.RemoteFunctions),
                        "tcp://" + Server_Address + ":" + Server_Port.ToString() +"/ODS_Functions" );

                    // Use the object
                    if( RF.Equals(null) )
                    {
                        throw new Exception("Unable to connect to Oyster Database Service!");
                    }
                    ServerAddress = Server_Address;
                    ServerPort = Server_Port;
                }
            }
            catch(Exception Err)
            {
                RF = null;
                throw new Exception(Err.Message,Err.InnerException);
            }
        }