Example #1
0
 public void AddFile(SharedFileInfo fileInfo)
 {
     lock (obj)
     {
         SharedFileList.Add(fileInfo);
     }
 }
Example #2
0
        private void getContext()
        {
            new Thread(() =>
            {
                while (true)
                {
                    HttpListenerContext context;
                    try
                    {
                        context = listener.GetContext();
                    }
                    catch
                    {
                        return;
                    }

                    new Thread(() =>
                    {
                        var request = context.Request;

                        string queryString            = request.RawUrl.Substring(1, request.RawUrl.Length - 1);
                        SharedFileInfo sharedFileInfo = null;;
                        lock (obj)
                        {
                            sharedFileInfo = SharedFileList.FirstOrDefault(file => file.SharePath == queryString);
                        }
                        if (sharedFileInfo != null)
                        {
                            var response         = context.Response;
                            response.SendChunked = false;
                            response.ContentType = System.Net.Mime.MediaTypeNames.Application.Octet;
                            response.AddHeader("Content-disposition", "attachment; filename=" + sharedFileInfo.Name);

                            byte[] buffer            = sharedFileInfo.Bytes;
                            response.ContentLength64 = buffer.Length;
                            Stream output            = response.OutputStream;
                            output.Write(buffer, 0, buffer.Length);
                            output.Flush();
                            output.Close();
                            output.Dispose();
                            response.StatusCode        = (int)HttpStatusCode.OK;
                            response.StatusDescription = "OK";
                            response.OutputStream.Close();
                        }
                    })
                    .Start();
                }
            })
            .Start();
        }
Example #3
0
        private void tsMenuItemAddFile_Click(object sender, EventArgs e)
        {
            var file = new OpenFileDialog();

            file.Multiselect = true;
            file.Title       = "Select Files";

            if (file.ShowDialog() == DialogResult.OK)
            {
                foreach (string fileName in file.FileNames)
                {
                    var fileInfo = new SharedFileInfo(fileName);
                    var lvi      = new ListViewItem();
                    lvi.Text = fileInfo.Name;
                    lvi.SubItems.Add("/" + fileInfo.SharePath);
                    lvi.SubItems.Add(fileInfo.Path);
                    listView.Items.Add(lvi);
                    shareEngine.AddFile(fileInfo);
                }
            }
            file.Dispose();
        }