Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Global.asax « webcompare - github.com/mono/mono-tools.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 664e1669457c99bd09b45c5abca786841b657b83 (plain)
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<%@ Import Namespace="GuiCompare" %>
<%@ Import Namespace="System.Threading" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Collections.Specialized" %>
<%@ Import Namespace="System.Collections.Generic" %>
<%@ Assembly name="Mono.Api.Compare" %>

<script runat="server" language="c#" >

public class CompareParameters {
	static Dictionary<CompareParameters,CompareContext> compare_cache = new Dictionary<CompareParameters,CompareContext> ();
	static Dictionary<CompareParameters,DateTime> timestamp = new Dictionary<CompareParameters,DateTime> ();

	static public bool InCache (CompareParameters cp)
	{
		lock (compare_cache){
			return compare_cache.ContainsKey (cp);
		}
	}

	static public DateTime GetAssemblyTime (CompareParameters cp)
	{
		return timestamp [cp];
	}

	public CompareParameters (NameValueCollection nvc)
	{
		Assembly = nvc ["assembly"] ?? "mscorlib";
		InfoDir  = nvc ["reference"] ?? "3.5";
		string bdir = nvc ["profile"] ?? "2.0";
		Validate (bdir);

		BinDir = "binary/" + bdir;
	}

	public CompareParameters (string assembly, string infodir, string bindir)
	{
		Assembly = assembly;
		InfoDir = infodir;
		BinDir = bindir;
	}

	static void Validate (string s)
	{
		if (s.IndexOf ("..") != -1 || s.IndexOf ('/') != -1 || s.IndexOf ('%') != -1 || s.IndexOf (' ') != -1)
			throw new Exception (String.Format ("Invalid parameter: {0}", s));
	}

	string assembly;
	public string Assembly { 
		get { return assembly; }
		private set { 
			Validate (value);
			assembly = value;
		}
	}

	string infodir;
	public string InfoDir { 
		get { return infodir; }
		private set { 
			Validate (value);
			infodir = value;
		}
	}

	public string BinDir {  get; private set; } 

	public override int GetHashCode ()
	{
		return Assembly.GetHashCode ();
	}

	public override bool Equals (object obj)
	{
		if (obj == null)
			return false;
		CompareParameters other = obj as CompareParameters;
		if (other == null)
			return false;

		return other.Assembly == Assembly && other.InfoDir == InfoDir && other.BinDir == BinDir;
		
	}

	public CompareContext GetCompareContext ()
	{
		CompareContext cc;

		lock (compare_cache){
			DateTime stamp = new FileInfo (DllFile).LastWriteTimeUtc;

			if (!compare_cache.TryGetValue (this, out cc) || timestamp [this] != stamp){
				cc = MakeCompareContext ();
				compare_cache [this] = cc;
				timestamp [this] = stamp;
			}
		}
		return cc;
	}

	string DllFile {
	       	get {
	       		return Path.Combine (HttpRuntime.AppDomainAppPath, Path.Combine (BinDir, Assembly) + ".dll");
		}
	}

	CompareContext MakeCompareContext ()
	{
		string info_file = Path.Combine (HttpRuntime.AppDomainAppPath, Path.Combine (Path.Combine ("masterinfos", InfoDir), Assembly) + ".xml");
		string dll_file = DllFile;

		using (var sw = File.AppendText ("/tmp/mylog")){
			sw.WriteLine ("{2} Comparing {0} and {1}", info_file, dll_file, DateTime.Now);
			sw.Flush ();

			if (!File.Exists (info_file)) 
				throw new Exception (String.Format ("File {0} does not exist", info_file));
			if (!File.Exists (dll_file))
				throw new Exception (String.Format ("File {0} does not exist", dll_file));
	
			CompareContext cc = new CompareContext (
				() => new MasterAssembly (info_file),
			     	() => new CecilAssembly (dll_file));

			cc.ProgressChanged += delegate (object sender, CompareProgressChangedEventArgs a){
				sw.WriteLine (a.Message);
				sw.Flush ();
			};
			ManualResetEvent r = new ManualResetEvent (false);
			cc.Finished += delegate { r.Set (); };
			cc.Compare ();
			r.WaitOne ();
			cc.Comparison.PropagateCounts ();
	
			sw.Flush ();

			return cc;
		}
	}
}

void Application_Start ()
{
}

</script>