-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
146 lines (132 loc) · 5.59 KB
/
Copy pathProgram.cs
File metadata and controls
146 lines (132 loc) · 5.59 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
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
using System;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Threading;
namespace ConferenceDeadlineWidget
{
internal static class Program
{
[STAThread]
private static void Main(string[] args)
{
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
if (args != null && args.Any(
delegate(string argument)
{
return String.Equals(argument, "--self-test", StringComparison.OrdinalIgnoreCase);
}))
{
Environment.ExitCode = ConferenceDataService.RunSelfTest();
return;
}
if (args != null && args.Length >= 2
&& String.Equals(args[0], "--parse-file", StringComparison.OrdinalIgnoreCase))
{
string yaml = File.ReadAllText(args[1], Encoding.UTF8);
Environment.ExitCode = ConferenceDataService.RunFileTest(yaml, DateTimeOffset.Now);
return;
}
Application application = new Application();
application.ShutdownMode = ShutdownMode.OnExplicitShutdown;
bool isWindowSelfTest = args != null && args.Any(
delegate(string argument)
{
return String.Equals(argument, "--window-self-test", StringComparison.OrdinalIgnoreCase);
});
MainWindow window = new MainWindow(isWindowSelfTest);
application.MainWindow = window;
if (isWindowSelfTest)
{
window.ContentRendered += async delegate
{
await Task.Delay(5000);
string error;
if (!window.ValidateWindowBehaviorForTest(out error))
{
Console.Error.WriteLine("FAIL: " + error);
Environment.ExitCode = 1;
application.Shutdown();
return;
}
if (!window.ValidateOutsideReleaseSnapForTest(out error))
{
Console.Error.WriteLine("FAIL: " + error);
Environment.ExitCode = 1;
application.Shutdown();
return;
}
double revealedTarget;
double tuckedTarget = window.StartRightEdgeTuckTest(out revealedTarget);
await Task.Delay(450);
if (!window.IsHorizontalPositionNear(tuckedTarget))
{
Console.Error.WriteLine("FAIL: right-edge tuck animation did not reach its target.");
Environment.ExitCode = 1;
application.Shutdown();
return;
}
window.StartRevealTest();
await Task.Delay(450);
if (!window.IsHorizontalPositionNear(revealedTarget))
{
Console.Error.WriteLine("FAIL: edge reveal animation did not reach its target.");
Environment.ExitCode = 1;
application.Shutdown();
return;
}
Console.WriteLine("PASS: selection picker, sorting, four-corner dragging, outside-release snap, edge tuck, and reveal animation.");
Environment.ExitCode = 0;
application.Shutdown();
};
}
window.Show();
if (args != null && args.Length >= 2
&& String.Equals(args[0], "--render-settings-preview", StringComparison.OrdinalIgnoreCase))
{
window.ContentRendered += async delegate
{
await Task.Delay(5000);
Window settingsWindow = window.CreateConferenceSelectionWindowForTest();
settingsWindow.Show();
await Task.Delay(700);
RenderWindow(settingsWindow, args[1]);
settingsWindow.Close();
application.Shutdown();
};
}
if (args != null && args.Length >= 2
&& String.Equals(args[0], "--render-preview", StringComparison.OrdinalIgnoreCase))
{
DispatcherTimer previewTimer = new DispatcherTimer();
previewTimer.Interval = TimeSpan.FromSeconds(5);
previewTimer.Tick += delegate
{
previewTimer.Stop();
RenderWindow(window, args[1]);
application.Shutdown();
};
previewTimer.Start();
}
application.Run();
}
private static void RenderWindow(Window window, string outputPath)
{
int width = Math.Max(1, (int)Math.Ceiling(window.ActualWidth));
int height = Math.Max(1, (int)Math.Ceiling(window.ActualHeight));
RenderTargetBitmap bitmap = new RenderTargetBitmap(width, height, 96, 96, PixelFormats.Pbgra32);
bitmap.Render(window);
PngBitmapEncoder encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(bitmap));
using (FileStream stream = File.Create(outputPath))
{
encoder.Save(stream);
}
}
}
}