Exemplo n.º 1
0
 public void SendObject()
 {
     if (ChatClient.ClientForm.serverBusy == true)
     {
         return;
     }
     try
     {
         ChatClient.ClientForm.serverBusy = true;
         IPAddress[] ipAddress = Dns.GetHostAddresses("localhost");
         IPEndPoint  ipEnd     = new IPEndPoint(IPAddress.Parse(IP), int.Parse(PORT));
         TcpClient   client    = new TcpClient();
         client.Connect(ipEnd);
         NetworkStream           stream    = client.GetStream();
         IFormatter              formatter = new BinaryFormatter();
         SerializableSeismicCube scube     = new SerializableSeismicCube((SeismicCube)obj);
         formatter.Serialize(stream, scube);
         client.Close();
         MessageBox.Show("The file has been transferred successfully.", "File transferred.",
                         MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
     catch (Exception ex)
     {
         MessageBox.Show("File Sending Failed!" + ex.Message, "File Transfer",
                         MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     ChatClient.ClientForm.serverBusy = false;
     return;
 }
Exemplo n.º 2
0
        public void StartServer()
        {
            if (ChatClient.ClientForm.serverBusy == true)
            {
                return;
            }
            try
            {
                ChatClient.ClientForm.serverBusy = true;
                listener.Start();
                TcpClient     client    = listener.AcceptTcpClient();
                NetworkStream stream    = client.GetStream();
                IFormatter    formatter = new BinaryFormatter();
                switch (objType)
                {
                case OBJTYPE.SIESMIC_CUBE:
                    SerializableSeismicCube scube = (SerializableSeismicCube)formatter.Deserialize(stream);
                    using (ITransaction t = DataManager.NewTransaction())
                    {
                        t.Lock(parent);
                        SeismicCollection c = (SeismicCollection)parent;
                        if (scube == null)
                        {
                            MessageBox.Show("Error in transmission!");
                        }
                        else
                        {
                            SeismicCube cube = scube.cube;

                            if (c.CanCreateSeismicCube(cube))
                            {
                                c.CreateSeismicCube(cube, cube.PropertyVersion);
                            }
                            else
                            {
                                MessageBox.Show("Unable to create the Seismic Cube");
                            }
                        }
                    }
                    break;
                }
                client.Close();
                listener.Stop();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Object Recieving Failed!" + ex.Message, "File Transfer",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            ChatClient.ClientForm.serverBusy = false;
        }