Exemplo n.º 1
0
        public void InitializeFileTab()
        {
            OptionsLoader ol     = new OptionsLoader();
            string        path   = ol.Path;
            FileLister    lister = new FileLister(path, "", false);

            lister.InitandFillListView(this.lstLibrary);
        }
Exemplo n.º 2
0
        private void InitializeOptions()
        {
            OptionsLoader ol = new OptionsLoader();

            this.txtPath.Text       = ol.Path;
            this.txtPort.Text       = ol.Port.ToString();
            this.txtConnection.Text = ol.Connection;
            this.txtURL.Text        = ol.ServiceUrl;
        }
Exemplo n.º 3
0
        protected void SaveValues()
        {
            OptionsLoader ol = new OptionsLoader();

            ol.Port       = txtPort.Text.ToInt32();
            ol.Path       = txtPath.Text;
            ol.Connection = txtConnection.Text;
            ol.ServiceUrl = this.txtURL.Text;
            ol.Update();
        }
Exemplo n.º 4
0
        public void DownloadToClient(String server, string remotefilename, string localfilename)
        {
            try
            {
                TCPClient tcpc = new TCPClient();
                Byte[]    read = new Byte[1024];

                OptionsLoader ol   = new OptionsLoader();
                int           port = 0;
                if (ol.Port > 0)
                {
                    port = ol.Port;
                }
                else
                {
                    // The default in case nothing else is set
                    port = 8081;
                }


                // Try to connect to the server
                IPAddress  adr = new IPAddress(server);
                IPEndPoint ep  = new IPEndPoint(adr, port);
                if (tcpc.Connect(ep) == -1)
                {
                    throw new Exception("Unable to connect to " + server + " on port " + port);
                }

                // Get the stream
                Stream s = tcpc.GetStream();
                Byte[] b = Encoding.ASCII.GetBytes(remotefilename.ToCharArray());
                s.Write(b, 0, b.Length);
                int          bytes;
                FileStream   fs = new FileStream(localfilename, FileMode.OpenOrCreate);
                BinaryWriter w  = new BinaryWriter(fs);

                // Read the stream and convert it to ASII
                while ((bytes = s.Read(read, 0, read.Length)) != 0)
                {
                    w.Write(read, 0, bytes);
                    read = new Byte[1024];
                }

                tcpc.Close();
                w.Close();
                fs.Close();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.ToString());
            }
        }
Exemplo n.º 5
0
        protected void btnDownload_Click(object sender, System.EventArgs e)
        {
            Cursor = Cursors.WaitCursor;
            string remoteFile     = null;
            string server         = null;
            string remotePath     = null;
            string fullRemotePath = null;


            for (int i = 0; i < this.lstResults.ListItems.Count; i++)
            {
                if (this.lstResults.ListItems[i].Selected == true)
                {
                    remotePath     = this.lstResults.ListItems[i].SubItems[0];
                    remoteFile     = this.lstResults.ListItems[i].Text;
                    fullRemotePath = remotePath + "\\" + remoteFile;
                    server         = this.lstResults.ListItems[i].SubItems[3];
                }
            }

            if (server == null)
            {
                MessageBox.Show("Please select a file to be downloaded", "ShareBaby", MessageBox.IconExclamation);
                Cursor = Cursors.Default;
                return;
            }


            if (server != this.GlobalIPAddress)
            {
                try
                {
                    OptionsLoader ol   = new OptionsLoader();
                    string        path = ol.Path;

                    string   localFile = path + "\\" + remoteFile;                   // Name the two files the same, change the paths
                    Transfer trans     = new Transfer();
                    trans.DownloadToClient(server, fullRemotePath, localFile);
                    MessageBox.Show("Successfully transferred " + localFile, "Download Complete", MessageBox.IconInformation);
                }
                catch (Exception exc)
                {
                    MessageBox.Show(exc.ToString(), "Error Tranferring File", MessageBox.IconError);
                }
            }
            else
            {
                MessageBox.Show("This is a local file and does not need to be downloaded", "ShareBaby", MessageBox.IconExclamation);
            }
            Cursor = Cursors.Default;
        }
Exemplo n.º 6
0
        public void DownloadToClient(String server, string remotefilename, string localfilename)
        {
            try
            {
                TCPClient tcpc = new TCPClient();
                Byte[] read = new Byte[1024];

                OptionsLoader ol = new OptionsLoader();
                int port = 0;
                if (ol.Port > 0)
                {
                    port = ol.Port;
                }
                else
                {
                    // The default in case nothing else is set
                    port = 8081;
                }

                // Try to connect to the server
                IPAddress adr = new IPAddress(server);
                IPEndPoint ep = new IPEndPoint(adr, port);
                if (tcpc.Connect(ep) == -1)
                {
                    throw new Exception("Unable to connect to " + server + " on port " + port);
                }

                // Get the stream
                Stream s = tcpc.GetStream();
                Byte[] b = Encoding.ASCII.GetBytes(remotefilename.ToCharArray());
                s.Write( b, 0,  b.Length );
                int bytes;
                FileStream fs = new FileStream(localfilename, FileMode.OpenOrCreate);
                BinaryWriter w = new BinaryWriter(fs);

                // Read the stream and convert it to ASII
                while( (bytes = s.Read(read, 0, read.Length)) != 0)
                {
                    w.Write(read, 0, bytes);
                    read = new Byte[1024];
                }

                tcpc.Close();
                w.Close();
                fs.Close();
            }
            catch(Exception ex)
            {
                throw new Exception(ex.ToString());
            }
        }
Exemplo n.º 7
0
        protected void btnFind_Click_1(object sender, System.EventArgs e)
        {
            Cursor = Cursors.WaitCursor;
            Pinger ping = new Pinger();

            if (txtSearch.Text != "")
            {
                lstResults.ListItems.Clear();
                P2PService    p  = new P2PService();
                OptionsLoader ol = new OptionsLoader();
                p.Url = ol.ServiceUrl;
                PeerFile[] FoundFiles = p.FindPeersWithFiles(txtSearch.Text);
                this.LogOnToService();                 // Update the file info
                int    PingTime  = 0;
                string pingEntry = null;
                if (null != FoundFiles)
                {
                    foreach (PeerFile file in FoundFiles)
                    {
                        PingTime = ping.GetPingTime(file.IpAddress);
                        if (PingTime <= 10)
                        {
                            pingEntry = "< 10 ms";
                        }
                        else
                        {
                            pingEntry = Convert.ToString(PingTime) + " ms";
                        }
                        string[] Entry = new string[5];
                        Entry[0] = file.Path;
                        Entry[1] = file.Size;
                        Entry[2] = file.Connection;
                        Entry[3] = file.IpAddress;
                        Entry[4] = pingEntry;
                        lstResults.InsertItem(0, file.Name, 0, Entry);
                    }
                }
                else                 //prepare default entry
                {
                    string[] Entry = new string[5];
                    Entry[0] = "n/a";
                    Entry[1] = "n/a";
                    Entry[2] = "n/a";
                    Entry[3] = "n/a";
                    Entry[4] = "n/a";
                    lstResults.InsertItem(0, "No Results Found", 0, Entry);
                }
            }
            Cursor = Cursors.Default;
        }
Exemplo n.º 8
0
        protected void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            if (ServiceAvailable)
            {
                P2PService    p  = new P2PService();
                OptionsLoader ol = new OptionsLoader();
                p.Url = ol.ServiceUrl;
                p.ClearEntriesForPeer(GlobalIPAddress);
            }

            GlobalThread.Abort();
            GlobalTransfer.TransferShutdown();
            SaveValues();
            EnableListen = false;
        }
Exemplo n.º 9
0
        public Transfer()
        {
            OptionsLoader ol = new OptionsLoader();
            int port = 8081;
            if (ol.Port > 0)
            {
                port = ol.Port;
            }
            else
            {
                // The default in case nothing else is set
                port = 8081;
            }

            this.tcpl = new MyTcpListener(port);
        }
Exemplo n.º 10
0
        public Transfer()
        {
            OptionsLoader ol   = new OptionsLoader();
            int           port = 8081;

            if (ol.Port > 0)
            {
                port = ol.Port;
            }
            else
            {
                // The default in case nothing else is set
                port = 8081;
            }

            this.tcpl = new MyTcpListener(port);
        }
Exemplo n.º 11
0
        public void LogOnToService()
        {
            this.pnlNumUsers.Text = " Logging on to the ShareBaby service...";
            if (ServiceAvailable)
            {
                OptionsLoader ol = new OptionsLoader();
                P2PService    p  = new P2PService();
                p.Url = ol.ServiceUrl;
                int NumUsers = p.GetNumUsers();
                this.pnlNumUsers.Text = " You are now logged into the ShareBaby service - " + NumUsers + " Users sharing files";
                int NumFiles = p.GetNumFiles();
                this.pnlTotalData.Text = " A total of " + NumFiles + " files are currently being shared on the service";
            }
            else
            {
                this.pnlNumUsers.Text  = " Unable to log in to the ShareBaby service";
                this.pnlTotalData.Text = " No files are being shared on the ShareBaby service at this time";
            }

            return;
        }
Exemplo n.º 12
0
        public void PublishFiles()
        {
            OptionsLoader ol         = new OptionsLoader();
            string        Connection = "LAN";

            Connection = ol.Connection;

            // Make sure the user wants these files published and the service is available
            if (ServiceAvailable)
            {
                this.pnlNumUsers.Text = " Publishing content list to the ShareBaby service...";
                string[,] z           = FileLister.GetFileList(this.lstLibrary);
                P2PService p = new P2PService();
                p.Url = ol.ServiceUrl;
                p.ClearEntriesForPeer(GlobalIPAddress);

                for (int i = 0; i <= z.GetUpperBound(1); i++)
                {
                    p.RegisterFile(GlobalIPAddress, z[0, i], Connection, z[1, i], z[2, i]);
                }
            }
        }
Exemplo n.º 13
0
 protected void SaveValues()
 {
     OptionsLoader ol = new OptionsLoader();
     ol.Port = txtPort.Text.ToInt32();
     ol.Path = txtPath.Text;
     ol.Connection = txtConnection.Text;
     ol.ServiceUrl = this.txtURL.Text;
     ol.Update();
 }
Exemplo n.º 14
0
        public void LogOnToService()
        {
            this.pnlNumUsers.Text = " Logging on to the ShareBaby service...";
            if(ServiceAvailable)
            {
                OptionsLoader ol = new OptionsLoader();
                P2PService p = new P2PService();
                p.Url = ol.ServiceUrl;
                int NumUsers = p.GetNumUsers();
                this.pnlNumUsers.Text = " You are now logged into the ShareBaby service - " + NumUsers + " Users sharing files";
                int NumFiles = p.GetNumFiles();
                this.pnlTotalData.Text = " A total of " + NumFiles + " files are currently being shared on the service";
            }
            else
            {
                this.pnlNumUsers.Text = " Unable to log in to the ShareBaby service";
                this.pnlTotalData.Text = " No files are being shared on the ShareBaby service at this time";
            }

            return;
        }
Exemplo n.º 15
0
 public void InitializeFileTab()
 {
     OptionsLoader ol = new OptionsLoader();
     string path = ol.Path;
     FileLister lister = new FileLister(path, "",false);
     lister.InitandFillListView(this.lstLibrary);
 }
Exemplo n.º 16
0
        public void PublishFiles()
        {
            OptionsLoader ol = new OptionsLoader();
            string Connection = "LAN";
            Connection = ol.Connection;

            // Make sure the user wants these files published and the service is available
            if(ServiceAvailable)
            {
                this.pnlNumUsers.Text = " Publishing content list to the ShareBaby service...";
                string[,] z = FileLister.GetFileList(this.lstLibrary);
                P2PService p = new P2PService();
                p.Url = ol.ServiceUrl;
                p.ClearEntriesForPeer(GlobalIPAddress);

                for (int i =0 ; i <= z.GetUpperBound(1) ; i++)
                {
                    p.RegisterFile(GlobalIPAddress, z[0, i], Connection, z[1, i], z[2, i]);
                }
            }
        }
Exemplo n.º 17
0
        protected void btnDownload_Click(object sender, System.EventArgs e)
        {
            Cursor = Cursors.WaitCursor;
            string remoteFile = null;
            string server = null;
            string remotePath = null;
            string fullRemotePath = null;

            for( int i = 0; i < this.lstResults.ListItems.Count; i++)
            {
                if(this.lstResults.ListItems[i].Selected == true )
                {
                    remotePath = this.lstResults.ListItems[i].SubItems[0];
                    remoteFile =  this.lstResults.ListItems[i].Text;
                    fullRemotePath = remotePath + "\\" + remoteFile;
                    server = this.lstResults.ListItems[i].SubItems[3];
                }
            }

            if(server == null)
            {
                MessageBox.Show("Please select a file to be downloaded","ShareBaby", MessageBox.IconExclamation);
                Cursor = Cursors.Default;
                return;
            }

            if(server != this.GlobalIPAddress)
            {
                try
                {
                    OptionsLoader ol = new OptionsLoader();
                    string path = ol.Path;

                    string localFile = path + "\\" + remoteFile; // Name the two files the same, change the paths
                    Transfer trans = new Transfer();
                    trans.DownloadToClient(server, fullRemotePath, localFile);
                    MessageBox.Show("Successfully transferred " + localFile, "Download Complete", MessageBox.IconInformation);
                }
                catch(Exception exc)
                {
                    MessageBox.Show(exc.ToString(), "Error Tranferring File", MessageBox.IconError);
                }
            }
            else
            {
                MessageBox.Show("This is a local file and does not need to be downloaded","ShareBaby", MessageBox.IconExclamation);
            }
            Cursor = Cursors.Default;
        }
Exemplo n.º 18
0
        protected void btnFind_Click_1(object sender, System.EventArgs e)
        {
            Cursor = Cursors.WaitCursor;
            Pinger ping = new Pinger();

            if( txtSearch.Text != "")
            {
                lstResults.ListItems.Clear();
                P2PService p = new P2PService();
                OptionsLoader ol = new OptionsLoader();
                p.Url = ol.ServiceUrl;
                PeerFile[] FoundFiles = p.FindPeersWithFiles(txtSearch.Text);
                this.LogOnToService(); // Update the file info
                int PingTime = 0;
                string pingEntry = null;
                if (null != FoundFiles)
                {
                    foreach (PeerFile file in FoundFiles)
                    {
                        PingTime = ping.GetPingTime(file.IpAddress);
                        if(PingTime <=10)
                        {
                            pingEntry = "< 10 ms";
                        }
                        else
                        {
                            pingEntry = Convert.ToString(PingTime) + " ms";
                        }
                        string[] Entry = new string[5];
                        Entry[0] = file.Path;
                        Entry[1] = file.Size;
                        Entry[2] = file.Connection;
                        Entry[3] = file.IpAddress;
                        Entry[4] = pingEntry;
                        lstResults.InsertItem(0,file.Name,0,Entry);
                    }
                }
                else //prepare default entry
                {
                    string[] Entry = new string[5];
                    Entry[0] = "n/a";
                    Entry[1] = "n/a";
                    Entry[2] = "n/a";
                    Entry[3] = "n/a";
                    Entry[4] = "n/a";
                    lstResults.InsertItem(0,"No Results Found",0,Entry);
                }
            }
            Cursor = Cursors.Default;
        }
Exemplo n.º 19
0
 private void InitializeOptions()
 {
     OptionsLoader ol = new OptionsLoader();
     this.txtPath.Text = ol.Path;
     this.txtPort.Text = ol.Port.ToString();
     this.txtConnection.Text = ol.Connection;
     this.txtURL.Text = ol.ServiceUrl;
 }
Exemplo n.º 20
0
        protected void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            if(ServiceAvailable)
            {
                P2PService p = new P2PService();
                OptionsLoader ol = new OptionsLoader();
                p.Url = ol.ServiceUrl;
                p.ClearEntriesForPeer(GlobalIPAddress);
            }

            GlobalThread.Abort();
            GlobalTransfer.TransferShutdown();
            SaveValues();
            EnableListen = false;
        }