public override void ImplementedPostData(string user, byte[] data) { if (!user.Equals(MachineInfo.GetJustIP())) { return; } }
/// <summary> /// It handles the formclosing event /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Server_FormClosing(object sender, FormClosingEventArgs e) { try { if (MessageBox.Show("Are you sure ? ", "Exit", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != System.Windows.Forms.DialogResult.Yes) { e.Cancel = true; } else { XmlDocument doc = new XmlDocument(); doc.Load("MyConfig.xml"); XmlElement root = doc.DocumentElement; string userName = root.Attributes["username"].Value; int port = int.Parse(root.Attributes["port"].Value); string ip = root.Attributes["ip"].Value; DBServiceClient srv = new DBServiceClient(); srv.removeUserFromOnlineUsersTable(userName, port, ip); if (Server != null) { Server.Disconnect(MachineInfo.GetJustIP()); } e.Cancel = false; } } catch (Exception ex) { MessageBox.Show(ex.Message, "FTP File Sharing", MessageBoxButtons.OK, MessageBoxIcon.Error); e.Cancel = false; } }
/// <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); }
public override void ImplementedUpdate(string user) { if (user.Equals(MachineInfo.GetJustIP())) { return; } if (RefreshList != null) { RefreshList(this, null); } }
/// <summary> /// It handles the ShareFolder button's click event /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ShareFolder_Click(object sender, EventArgs e) { try { OpenFileDialog open = new OpenFileDialog(); open.Filter = "All|*.*"; open.Multiselect = true; open.Title = "It selects the share folder for the FTP server."; if (open.ShowDialog() != System.Windows.Forms.DialogResult.Cancel) { List <UploadData> upload = new List <UploadData>(); foreach (string file in open.FileNames) { if ((new System.IO.FileInfo(file)).Length > 100000000) { MessageBox.Show("The file '" + file + "' size is more than 100MB, Please select a smaller file.", "FTP File Sharing", MessageBoxButtons.OK, MessageBoxIcon.Warning); continue; } UploadData data = new UploadData(); data.Filename = file.Split('\\')[file.Split('\\').Length - 1]; data.File = System.IO.File.ReadAllBytes(file); upload.Add(data); } Server.Upload(MachineInfo.GetJustIP(), upload); } } catch (RemotingException re) { MessageBox.Show(re.Message, "FTP File Sharing", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception ex) { MessageBox.Show(ex.Message, "FTP File Sharing", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { Refresh_Click(null, null); } }
/// <summary> /// It handles the formclosing event /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Server_FormClosing(object sender, FormClosingEventArgs e) { try { if (MessageBox.Show("Are you sure ? ", "Exit", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != System.Windows.Forms.DialogResult.Yes) { e.Cancel = true; } else { if (Server != null) { Server.Disconnect(MachineInfo.GetJustIP()); } e.Cancel = false; } } catch (Exception ex) { MessageBox.Show(ex.Message, "FTP File Sharing", MessageBoxButtons.OK, MessageBoxIcon.Error); e.Cancel = false; } }
/// <summary> /// It handles the double click of ServerFile List view control event /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ServerFileListView_DockChanged(object sender, EventArgs e) { if (ServerFileListView.SelectedItems.Count < 1) { return; } byte[] file; Server.Download(MachineInfo.GetJustIP(), ServerFileListView.SelectedItems[0].SubItems[2].Text, out file); SaveFileDialog save = new SaveFileDialog(); save.Title = "It saves the downloaded file."; save.SupportMultiDottedExtensions = false; save.Filter = "All|*.*"; save.FileName = ServerFileListView.SelectedItems[0].SubItems[2].Text; if (save.ShowDialog() != System.Windows.Forms.DialogResult.Cancel) { System.IO.File.WriteAllBytes(save.FileName, file); MessageBox.Show(ServerFileListView.SelectedItems[0].SubItems[2].Text + " has been downloaded.", "FTP File Sharing", MessageBoxButtons.OK, MessageBoxIcon.Information); } save.Dispose(); }
/// <summary> /// Default Constructor /// </summary> public Server() { InitializeComponent(); ServerIPValue.Text = MachineInfo.GetJustIP(); }