示例#1
0
        /// <summary>
        /// It gets the available connection
        /// </summary>
        private bool GetConnection()
        {
            bool connected = true;

            SoapServerFormatterSinkProvider   soap   = new SoapServerFormatterSinkProvider();
            BinaryServerFormatterSinkProvider binary = new BinaryServerFormatterSinkProvider();

            soap.TypeFilterLevel   = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
            binary.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
            soap.Next = binary;

            Hashtable table = new Hashtable();

            table.Add("port", "0");

            TcpChannel channel = new TcpChannel(table, null, soap);

            ChannelServices.RegisterChannel(channel, false);

            try
            {
                Server = (IFTPServer)Activator.GetObject(typeof(IFTPServer), string.Format("tcp://{0}:{1}/FTPServerAPP/ftpserver.svr", ServerIPValue.Text, ServerPortValue.Text));
            }
            catch (Exception ex)
            {
                connected = false;
                EventLogger.Logger(ex, "Client - GetConnection");
            }

            if (Server == null)
            {
                connected = false;
                ChannelServices.UnregisterChannel(channel);
                MessageBox.Show("Cannot Connect to the Server", "FTP File Sharing", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(connected);
            }

            try
            {
                PostedData handler = new PostedData();
                handler.RefreshList += new EventHandler(handler_RefreshList);

                Server.PostedData += new PostedDataHandler(handler.Server_PostData);
                Server.Update     += new UpdateHandler(handler.Server_Update);

                Server.Connect(MachineInfo.GetJustIP());
            }
            catch (Exception ex)
            {
                connected = false;
                ChannelServices.UnregisterChannel(channel);
                MessageBox.Show(ex.Message, "FTP File Sharing", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            return(connected);
        }