Rayburn Davis
2014-09-15 fb4519e5c864e7c153b6bafcf79275ed36a9bda3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using System;
using System.Collections.Generic;
using System.Text;
using System.Net.Sockets;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Threading;
using DupliDelete.Duplicate_Search_Engine;
 
namespace DupliDelete
{
    public class NetworkServer
    {
        public bool Listen = true;
        byte[] socketData = new byte[262144];
        TcpListener serverSocket;
        NetworkStream networkStream=null;
        //public IList<ArraySegment<byte>> data 
 
        public void InitServer()
        {
            while (Listen == true)
            {
                serverSocket = new TcpListener(System.Net.IPAddress.Parse("127.0.0.1"), 80);
                serverSocket.Start(1);
 
                TcpClient client = serverSocket.AcceptTcpClient();
 
                networkStream = client.GetStream();
 
                IFormatter formatter = new BinaryFormatter();
 
                NetworkCommand command = (NetworkCommand)formatter.Deserialize(networkStream);
 
                // we got a command to scan for duplicates; start the scan
                if (command is NetworkDuplicateScanCommand)
                {
                    NetworkDuplicateScanCommand duplicateScanCommand = (NetworkDuplicateScanCommand)command;
 
                    List<Folder> folders = new List<Folder>();
 
                    foreach(string folder in duplicateScanCommand.Folders)
                    {
                        folders.Add(new Folder(Folder.Location.Local, "", folder));
                    }
 
                    DuplicateFinder networkFinder = new DuplicateFinder(folders.ToArray());
                    networkFinder.ScanComplete += new DuplicateFinder.ScanCompleteDelegate(networkFinder_ScanComplete);
                    networkFinder.IncludeSubfolders = true;
                    networkFinder.IgnoreLinks = false;
                    networkFinder.ScanMode = duplicateScanCommand.ScanMode;
                    networkFinder.FindThread();
                }
 
                if (command is NetworkTestCommand)
                {
                    System.Windows.Forms.MessageBox.Show(((NetworkTestCommand)command).Data);
                }
 
                //serverSocket.Server.BeginReceive(socketData,0, 262144, SocketFlags.None, new AsyncCallback(dataReceived), new Object());
            }
        }
 
        public void dataReceived(IAsyncResult state)
        {
           
        }
 
        void networkFinder_ScanComplete(DuplicateFinder.ScanCompleteArgs e)
        {
            IFormatter scanResultsFormatter = new BinaryFormatter();
            scanResultsFormatter.Serialize(networkStream, GlobalBuffers.Duplicates);
        }
    }
}