├── .gitignore
├── AssemblyDependencies1.dgml
├── Entities
├── Entities.csproj
├── File.cs
├── Peer.cs
└── Properties
│ └── AssemblyInfo.cs
├── FakeObjects
├── FakeObjects.csproj
├── FakeTransferEngine.cs
└── Properties
│ └── AssemblyInfo.cs
├── FreeFile.DownloadManager
├── Abstract
│ ├── Factory.cs
│ ├── FileSearchResult.cs
│ ├── IFileInfoServerManager.cs
│ ├── IFileProviderServer.cs
│ ├── ISearchEngine.cs
│ ├── ITransferEngine.cs
│ ├── ITransferEngineFactory.cs
│ └── Searchengine.cs
├── Config.cs
├── DataContainerEventArg.cs
├── FileDownloadException.cs
├── FileProviderServerManager.cs
├── FileTransferManager.cs
├── FileUtility.cs
├── FreeFile.DownloadManager.csproj
├── HostUnreachableException.cs
├── Properties
│ ├── AssemblyInfo.cs
│ └── DataSources
│ │ └── Entities.File.datasource
├── Service References
│ └── FileServer
│ │ ├── FilesService.wsdl
│ │ ├── Reference.cs
│ │ ├── Reference.svcmap
│ │ ├── configuration.svcinfo
│ │ ├── configuration91.svcinfo
│ │ ├── item.disco
│ │ ├── item.xsd
│ │ ├── item1.xsd
│ │ ├── item2.xsd
│ │ └── item3.xsd
└── app.config
├── FreeFile.LocalFileManager
├── FreeFile.LocalFileManager.csproj
├── IFileInfoServerManager.cs
└── Properties
│ └── AssemblyInfo.cs
├── FreeFiles.Server
├── FreeFiles.Server.csproj
└── Properties
│ └── AssemblyInfo.cs
├── FreeFiles.ServerSearchEngine
├── Class1.cs
├── FreeFiles.ServerSearchEngine.csproj
└── Properties
│ └── AssemblyInfo.cs
├── FreeFiles.TransferEngine.WCFPNRP
├── Config.cs
├── FileReader.cs
├── FreeFiles.TransferEngine.WCFPNRP.csproj
├── PNRPManager.cs
├── PeerInfo.cs
├── PnrpTransferEngine.cs
├── PnrpTransferEngineFactory.cs
├── Properties
│ └── AssemblyInfo.cs
├── WCFFileTransferClient
│ └── FileTransferServiceClientClass.cs
└── WCFFileTransferService
│ ├── FileTransferServiceClass.cs
│ ├── FileTransferServiceHost.cs
│ └── IFileTransferService.cs
├── FreeFiles.UI.WinForm
├── App.config
├── Form1.Designer.cs
├── Form1.cs
├── Form1.resx
├── FreeFiles.UI.WinForm.csproj
├── Program.cs
└── Properties
│ ├── AssemblyInfo.cs
│ ├── Resources.Designer.cs
│ ├── Resources.resx
│ ├── Settings.Designer.cs
│ └── Settings.settings
├── FreeFiles.sln
├── FreeFilesServerConsole
├── Abstracts
│ ├── Factory.cs
│ ├── IDataBaseAction.cs
│ ├── ORM.cs
│ └── SQLLite.cs
├── App.config
├── Config.cs
├── EF
│ ├── File.cs
│ ├── FilesModel.Context.cs
│ ├── FilesModel.Context.tt
│ ├── FilesModel.Designer.cs
│ ├── FilesModel.cs
│ ├── FilesModel.edmx
│ ├── FilesModel.edmx.diagram
│ ├── FilesModel.edmx.sql
│ ├── FilesModel.tt
│ ├── FreeFilesEntitiesContext.cs
│ ├── Peer.cs
│ └── sysdiagram.cs
├── EntityUtility.cs
├── FreeFilesServerConsole.csproj
├── IUnitOfWork.cs
├── Program.cs
├── Properties
│ └── AssemblyInfo.cs
├── Repository
│ ├── FileRepository.cs
│ ├── IFilesRepository.cs
│ └── PeerRepository.cs
├── WCFServices
│ ├── FilesService.cs
│ ├── IFileService.cs
│ ├── IServiceInitializer.cs
│ └── ServiceInitializer.cs
└── packages.config
├── FreeFilesServerWinForm
├── FreeFilesServer.Designer.cs
├── FreeFilesServer.cs
├── FreeFilesServerWinForm.csproj
├── Program.cs
└── Properties
│ ├── AssemblyInfo.cs
│ ├── Resources.Designer.cs
│ ├── Resources.resx
│ ├── Settings.Designer.cs
│ └── Settings.settings
├── LICENSE
├── README.md
├── TestConsole
├── Program.cs
├── Properties
│ └── AssemblyInfo.cs
├── Service References
│ ├── FileActionsService
│ │ ├── FilesService.disco
│ │ ├── FilesService.wsdl
│ │ ├── FilesService.xsd
│ │ ├── FilesService1.xsd
│ │ ├── FilesService2.xsd
│ │ ├── FilesService3.xsd
│ │ ├── Reference.cs
│ │ ├── Reference.svcmap
│ │ ├── TestConsole.FileActionsService.File.datasource
│ │ ├── configuration.svcinfo
│ │ └── configuration91.svcinfo
│ └── FileActionsService2
│ │ ├── FilesService.wsdl
│ │ ├── Reference.cs
│ │ ├── Reference.svcmap
│ │ ├── TestConsole.FileActionsService2.File.datasource
│ │ ├── configuration.svcinfo
│ │ ├── configuration91.svcinfo
│ │ ├── item.disco
│ │ ├── item.xsd
│ │ ├── item1.xsd
│ │ ├── item2.xsd
│ │ └── item3.xsd
├── TestConsole.csproj
└── app.config
└── UnitTest
├── DBFile.cs
├── PeersTest.cs
├── Properties
└── AssemblyInfo.cs
├── TestTransferEngine.cs
└── UnitTest.csproj
/.gitignore:
--------------------------------------------------------------------------------
1 | # Build Folders (you can keep bin if you'd like, to store dlls and pdbs)
2 | [Bb]in/
3 | [Oo]bj/
4 |
5 | # mstest test results
6 | TestResults
7 |
8 | ## Ignore Visual Studio temporary files, build results, and
9 | ## files generated by popular Visual Studio add-ons.
10 |
11 | # User-specific files
12 | *.suo
13 | *.user
14 | *.sln.docstates
15 |
16 | # Build results
17 | [Dd]ebug/
18 | [Rr]elease/
19 | x64/
20 | *_i.c
21 | *_p.c
22 | *.ilk
23 | *.meta
24 | *.obj
25 | *.pch
26 | *.pdb
27 | *.pgc
28 | *.pgd
29 | *.rsp
30 | *.sbr
31 | *.tlb
32 | *.tli
33 | *.tlh
34 | *.tmp
35 | *.log
36 | *.vspscc
37 | *.vssscc
38 | .builds
39 |
40 | # Visual C++ cache files
41 | ipch/
42 | *.aps
43 | *.ncb
44 | *.opensdf
45 | *.sdf
46 |
47 | # Visual Studio profiler
48 | *.psess
49 | *.vsp
50 | *.vspx
51 |
52 | # Guidance Automation Toolkit
53 | *.gpState
54 |
55 | # ReSharper is a .NET coding add-in
56 | _ReSharper*
57 |
58 | # NCrunch
59 | *.ncrunch*
60 | .*crunch*.local.xml
61 |
62 | # Installshield output folder
63 | [Ee]xpress
64 |
65 | # DocProject is a documentation generator add-in
66 | DocProject/buildhelp/
67 | DocProject/Help/*.HxT
68 | DocProject/Help/*.HxC
69 | DocProject/Help/*.hhc
70 | DocProject/Help/*.hhk
71 | DocProject/Help/*.hhp
72 | DocProject/Help/Html2
73 | DocProject/Help/html
74 |
75 | # Click-Once directory
76 | publish
77 |
78 | # Publish Web Output
79 | *.Publish.xml
80 |
81 | # NuGet Packages Directory
82 | packages
83 |
84 | # Windows Azure Build Output
85 | csx
86 | *.build.csdef
87 |
88 | # Windows Store app package directory
89 | AppPackages/
90 |
91 | # Others
92 | [Bb]in
93 | [Oo]bj
94 | sql
95 | TestResults
96 | [Tt]est[Rr]esult*
97 | *.Cache
98 | ClientBin
99 | [Ss]tyle[Cc]op.*
100 | ~$*
101 | *.dbmdl
102 | Generated_Code #added for RIA/Silverlight projects
103 |
104 | # Backup & report files from converting an old project file to a newer
105 | # Visual Studio version. Backup files are not needed, because we have git ;-)
106 | _UpgradeReport_Files/
107 | Backup*/
108 | UpgradeLog*.XML
109 |
--------------------------------------------------------------------------------
/Entities/Entities.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {49240D90-C088-4CEB-94ED-631F248D8BE6}
8 | Library
9 | Properties
10 | Entities
11 | Entities
12 | v4.0
13 | 512
14 |
15 |
16 | true
17 | full
18 | false
19 | bin\Debug\
20 | DEBUG;TRACE
21 | prompt
22 | 4
23 |
24 |
25 | pdbonly
26 | true
27 | bin\Release\
28 | TRACE
29 | prompt
30 | 4
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
54 |
--------------------------------------------------------------------------------
/Entities/File.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace Entities
7 | {
8 | public sealed class File
9 | {
10 | public string FileName { get; set; }
11 | public int FileSize { get; set; }
12 | public string FileType { get; set; }
13 | public Guid PeerID { get; set; }
14 | public string PeerHostName { get; set; }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/Entities/Peer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace Entities
7 | {
8 | public sealed class Peer
9 | {
10 | public Guid PeerID { get; set; }
11 | public string PeerHostName { get; set; }
12 | public string Comments { get; set; }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/Entities/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("Entities")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("Microsoft")]
12 | [assembly: AssemblyProduct("Entities")]
13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2013")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("a9a4572c-9612-40f2-9c69-fffba65c5b0e")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/FakeObjects/FakeObjects.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {4BDDF06D-0C74-4339-80DF-42B28151BF82}
8 | Library
9 | Properties
10 | FakeObjects
11 | FakeObjects
12 | v4.0
13 | 512
14 |
15 |
16 | true
17 | full
18 | false
19 | bin\Debug\
20 | DEBUG;TRACE
21 | prompt
22 | 4
23 |
24 |
25 | pdbonly
26 | true
27 | bin\Release\
28 | TRACE
29 | prompt
30 | 4
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 | {bdf446f0-3e99-4ee0-a154-ef11606794ca}
48 | FreeFile.DownloadManager
49 |
50 |
51 |
52 |
59 |
--------------------------------------------------------------------------------
/FakeObjects/FakeTransferEngine.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Linq;
5 | using System.Text;
6 | using FreeFile.DownloadManager.Abstract;
7 |
8 | namespace FakeObjects
9 | {
10 | public class FakeTransferEngine : ITransferEngine
11 | {
12 | public byte[] GetFile(string filePath, string fileName, string hostURI = "", string hash = "", long partNumber = 1)
13 | {
14 | if (!filePath.EndsWith(@"\"))
15 | {
16 | filePath += @"\";
17 | }
18 | var data=File.ReadAllBytes(filePath + fileName);
19 | return data;
20 | }
21 |
22 | public byte[] GetFile(string filename, string hash, long partNumber, string hostName)
23 | {
24 | throw new NotImplementedException();
25 | }
26 |
27 | public byte[] GetFile(string filename, long partNumber, string hostName)
28 | {
29 | throw new NotImplementedException();
30 | }
31 |
32 | public void SetupFileServer()
33 | {
34 | throw new NotImplementedException();
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/FakeObjects/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("FakeObjects")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("Microsoft")]
12 | [assembly: AssemblyProduct("FakeObjects")]
13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2013")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("e5ff1e3e-7199-4f98-b66e-459ba01d3bac")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/FreeFile.DownloadManager/Abstract/Factory.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Linq;
5 | using System.Reflection;
6 | using System.Text;
7 | using System.Windows.Forms;
8 |
9 | namespace FreeFile.DownloadManager.Abstract
10 | {
11 | public sealed class Factory
12 | {
13 | Factory()
14 | {
15 |
16 | Assembly transferEngineAssembly = Assembly.LoadFile(Path.GetDirectoryName( Application.ExecutablePath) + "\\FreeFiles.TransferEngine.WCFPNRP.dll");
17 | var tnaTypes = transferEngineAssembly.GetTypes();
18 | foreach (var item in tnaTypes)
19 | {
20 | if (item.GetInterface("ITransferEngineFactory") != null)
21 | {
22 | ITransferEngineFactory ITransferEngineFactory = Activator.CreateInstance(item) as ITransferEngineFactory;
23 | this.transferEngine = ITransferEngineFactory.CreateTransferEngine();
24 | this.fileProviderServer = this.transferEngine as IFileProviderServer;
25 | break;
26 | }
27 | }
28 | /* Create
29 | *searchEngine;
30 | */
31 | this.searchEngine = new Searchengine();
32 | }
33 | static readonly object sharedObject = new object();
34 | static Factory instance;
35 | public static Factory Instance
36 | {
37 | get
38 | {
39 | if (instance == null)
40 | {
41 | lock (sharedObject)
42 | {
43 | if (instance == null)
44 | {
45 | instance = new Factory();
46 | }
47 | }
48 | }
49 | return instance;
50 | }
51 | }
52 | ISearchEngine searchEngine;
53 | ITransferEngine transferEngine;
54 | IFileProviderServer fileProviderServer;
55 | public ISearchEngine CreateSeachEngine()
56 | {
57 | return searchEngine;
58 | }
59 | public ITransferEngine CreateTransferEngine()
60 | {
61 | return transferEngine;
62 | }
63 |
64 | public IFileProviderServer CreateFileProviderServer()
65 | {
66 | return fileProviderServer;
67 | }
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/FreeFile.DownloadManager/Abstract/FileSearchResult.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace FreeFile.DownloadManager.Abstract
7 | {
8 | public sealed class FileSearchResult
9 | {
10 | public string FileName { get; set; }
11 | public long Size { get; set; }
12 | public string Hash { get; set; }
13 | public string HostName { get; set; }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/FreeFile.DownloadManager/Abstract/IFileInfoServerManager.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace FreeFile.DownloadManager.LocalFileManagement
7 | {
8 | namespace FreeFile.DownloadManager.Abstract
9 | {
10 | public interface IFileInfoServerManager
11 | {
12 | void RegisterSharedFileInfo(string localServerName, string fileName, string hash, long size);
13 | void RemoveSharedFile(string localServerName, string fileName, string hash);
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/FreeFile.DownloadManager/Abstract/IFileProviderServer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace FreeFile.DownloadManager.Abstract
7 | {
8 | public interface IFileProviderServer
9 | {
10 | void SetupFileServer();
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/FreeFile.DownloadManager/Abstract/ISearchEngine.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace FreeFile.DownloadManager.Abstract
7 | {
8 | public interface ISearchEngine
9 | {
10 | List Search(string searchPattern);
11 | List SearchByFileHashCode(string hashCode);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/FreeFile.DownloadManager/Abstract/ITransferEngine.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace FreeFile.DownloadManager.Abstract
7 | {
8 | public interface ITransferEngine
9 | {
10 | byte[] GetFile(string filename, string hash,long partNumber,string hostName);
11 | byte[] GetFile(string filename, long partNumber, string hostName);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/FreeFile.DownloadManager/Abstract/ITransferEngineFactory.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace FreeFile.DownloadManager.Abstract
7 | {
8 | public interface ITransferEngineFactory
9 | {
10 | ITransferEngine CreateTransferEngine();
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/FreeFile.DownloadManager/Abstract/Searchengine.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using Entities;
6 |
7 | namespace FreeFile.DownloadManager.Abstract
8 | {
9 | class Searchengine:ISearchEngine
10 | {
11 | public List Search(string searchPattern)
12 | {
13 | FileServer.FilesServiceClient fileServiceClient = new FileServer.FilesServiceClient();
14 |
15 | List filesList = new List();
16 | foreach (var file in fileServiceClient.SearchAvaiableFiles(searchPattern))
17 | {
18 | Entities.File currentFile = new File();
19 | currentFile.FileName = file.FileName;
20 | currentFile.FileSize = file.FileSize;
21 | currentFile.FileType = file.FileType;
22 | currentFile.PeerID = file.PeerID;
23 | currentFile.PeerHostName = file.PeerHostName;
24 | filesList.Add(currentFile);
25 | }
26 | return filesList;
27 | //List retlist = new List();
28 | //retlist.Add(new FileSearchResult { FileName = "pooya.txt",
29 | // Hash = "BA-32-53-87-6A-ED-6B-C2-2D-4A-6F-F5-3D-84-06-C6-AD-86-41-95-ED-14-4A-B5-C8-76-21-B6-C2-33-B5-48-BA-EA-E6-95-6D-F3-46-EC-8C-17-F5-EA-10-F3-5E-E3-CB-C5-14-79-7E-D7-DD-D3-14-54-64-E2-A0-BA-B4-13",
30 | // Size = 100,
31 | // HostName = "FreeFile163b69882b3a4f18b0de878eb5f0b4b7"
32 | //});
33 | //return retlist;
34 |
35 | }
36 |
37 | public List SearchByFileHashCode(string hashCode)
38 | {
39 | return null;
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/FreeFile.DownloadManager/Config.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Linq;
5 | using System.Text;
6 | using Microsoft.Win32;
7 |
8 | namespace FreeFile.DownloadManager
9 | {
10 | public static class Config
11 | {
12 | const string FreeFileLocalHostNameKey = "FreeFileLocalHostName";
13 | const string FreeFileLocalPortKey = "FreeFileLocalPort";
14 | const string SharedFolderNameKey = "SharedFolderName ";
15 |
16 | public static string LocalHostyName
17 | {
18 | get
19 | {
20 | //var localHostName = Registry.CurrentUser.GetValue(FreeFileLocalHostNameKey);
21 | var localHostName = Registry.CurrentUser.GetValue(FreeFileLocalHostNameKey);
22 | string hostname = string.Empty;
23 | if (localHostName == null)
24 | {
25 | hostname = "FreeFile" + Guid.NewGuid().ToString().Replace("-", "");
26 | Registry.CurrentUser.SetValue(FreeFileLocalHostNameKey, hostname);
27 | }
28 | else
29 | {
30 | hostname = localHostName.ToString();
31 | }
32 | return hostname;
33 | }
34 | }
35 |
36 | public static string SharedFolder
37 | {
38 | get
39 | {
40 | var sharedFolderName = Registry.CurrentUser.GetValue(SharedFolderNameKey);
41 | string folder = string.Empty;
42 | if (sharedFolderName == null)
43 | {
44 | folder = @"C:\FreeFileDirectory"; ;
45 | Registry.CurrentUser.SetValue(SharedFolderNameKey, folder);
46 | }
47 | else
48 | {
49 | folder = sharedFolderName.ToString();
50 | }
51 | return folder;
52 | }
53 | }
54 |
55 | public static int LocalPort
56 | {
57 | get
58 | {
59 | var localPort = Registry.CurrentUser.GetValue(FreeFileLocalPortKey);
60 | int port = 20388;
61 | if (localPort == null)
62 | {
63 | Registry.CurrentUser.SetValue(FreeFileLocalPortKey, port);
64 | }
65 | return port;
66 | }
67 | }
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/FreeFile.DownloadManager/DataContainerEventArg.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace FreeFile.DownloadManager
7 | {
8 | public sealed class DataContainerEventArg:EventArgs
9 | {
10 | public DataContainerEventArg(T data) : base() { this.Data = data; }
11 | public T Data { get; set; }
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/FreeFile.DownloadManager/FileDownloadException.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace FreeFile.DownloadManager
7 | {
8 | public sealed class FileDownloadException : Exception
9 | {
10 | public long PartNumber { get; private set; }
11 | public string FileName { get; private set; }
12 | public string Host { get; private set; }
13 | public FileDownloadException(long partNumber, string FileName, string Host, Exception innerException = null)
14 | : base("Download Failed!", innerException)
15 | {
16 | this.PartNumber = PartNumber;
17 | this.FileName = FileName;
18 | this.Host = Host;
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/FreeFile.DownloadManager/FileProviderServerManager.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using FreeFile.DownloadManager.Abstract;
6 |
7 | namespace FreeFile.DownloadManager
8 | {
9 | public static class FileProviderServerManager
10 | {
11 | static IFileProviderServer FileProviderServer;
12 | public static void StartFileProviderServer()
13 | {
14 | FileProviderServer= Factory.Instance.CreateFileProviderServer();
15 | FileProviderServer.SetupFileServer();
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/FreeFile.DownloadManager/FileTransferManager.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using FreeFile.DownloadManager.Abstract;
7 |
8 | namespace FreeFile.DownloadManager
9 | {
10 | public sealed class FileTransferManager
11 | {
12 | public class FilePartData
13 | {
14 | internal FilePartData(DownloadParameter downloadParameter, byte[] data)
15 | {
16 | DownloadParameter = downloadParameter;
17 | FileBytes = data;
18 | }
19 | public DownloadParameter DownloadParameter { get; private set; }
20 | public byte[] FileBytes{ get; private set; }
21 | }
22 |
23 | public sealed class DownloadParameter
24 | {
25 |
26 | public long AllPartsCount { get; set; }
27 | public long Part { get; set; }
28 | public string Host { get; set; }
29 | public Entities.File FileSearchResult { get; set; }
30 | }
31 |
32 | const long FilePartSizeInByte = 10240;
33 |
34 | ITransferEngine transferEngine;
35 |
36 | ISearchEngine searchEngine;
37 |
38 | List resultOfSameHashSearch;
39 |
40 | public FileTransferManager()
41 | {
42 | this.transferEngine = Factory.Instance.CreateTransferEngine();
43 | this.searchEngine = Factory.Instance.CreateSeachEngine();
44 | }
45 |
46 |
47 | private void StartDownload(object state)
48 | {
49 | Entities.File fileSearchResult = state as Entities.File;
50 | //Wee need to aply multiThreading to use multi host to download diferent part of file cuncurently max number of thread could be 5 thread per host in all of the application;
51 | long partcount = fileSearchResult.FileSize / FilePartSizeInByte;
52 | long mod = fileSearchResult.FileSize % FilePartSizeInByte;
53 | if (mod > 0) partcount++;
54 | for (int i = 1; i <=partcount; i++)
55 | {
56 | downloadFilePart(new DownloadParameter { FileSearchResult = fileSearchResult, Host = fileSearchResult.PeerHostName, Part = i, AllPartsCount = partcount });
57 | }
58 |
59 |
60 | }
61 |
62 | public void CancelDownloads()
63 | {
64 | }
65 |
66 | private void downloadFilePart(DownloadParameter downloadParameter)
67 | {
68 | try
69 | {
70 | var data = transferEngine.GetFile(downloadParameter.FileSearchResult.FileName, downloadParameter.Part, downloadParameter.Host);
71 | onFilePartDownloaded(new FilePartData(downloadParameter, data));
72 | //Error
73 | }
74 | catch(Exception ex)
75 | {
76 | throw new FileDownloadException(downloadParameter.Part, downloadParameter.FileSearchResult.FileName, downloadParameter.Host, ex);
77 | }
78 | }
79 |
80 | private void searchForSameFileBaseOnHash(object state)
81 | {
82 | var fileSearchResult =state as FileSearchResult;
83 | resultOfSameHashSearch = searchEngine.SearchByFileHashCode(fileSearchResult.Hash);
84 | onSynchronizedReadOnlyCollection(resultOfSameHashSearch);
85 | }
86 |
87 | public event EventHandler>> ExtraServerHostFondBaseOnHashSearch;
88 |
89 | private void onSynchronizedReadOnlyCollection(List searchResult)
90 | {
91 | if (ExtraServerHostFondBaseOnHashSearch != null)
92 | {
93 | ExtraServerHostFondBaseOnHashSearch(this, new DataContainerEventArg>(searchResult));
94 | }
95 | }
96 |
97 | public event EventHandler> FilePartDownloaded;
98 |
99 | private void onFilePartDownloaded(FilePartData filePartData)
100 | {
101 | if (FilePartDownloaded != null)
102 | {
103 | FilePartDownloaded(this, new DataContainerEventArg(filePartData));
104 | }
105 | }
106 |
107 | public List SearchFileByName(string fileName)
108 | {
109 | return this.searchEngine.Search(fileName);
110 | }
111 |
112 | public void Download(Entities.File fileSearchResult)
113 | {
114 | //var action =new Action