-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStreamerAppBaseClasses.cs
More file actions
129 lines (118 loc) · 4.23 KB
/
StreamerAppBaseClasses.cs
File metadata and controls
129 lines (118 loc) · 4.23 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
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
namespace StreamStartingTimer {
public enum ConnectStatus {
Disabled = -1,
Disconnected = 0,
Connecting = 1,
Error = 2,
Connected = 3
}
public enum MIUPlatforms {
Twitch = 0,
YouTube = 1,
Trovo = 2
}
public enum EventType {
None = -1,
VNyan = 0,
MixItUp = 1,
EXE = 2
}
public static class StatusColors {
public static readonly Color Connecting = Color.Goldenrod;
public static readonly Color Error = Color.Red;
public static readonly Color Connected = Color.Green;
public static readonly Color Disabled = SystemColors.Control;
}
public abstract class Connector : INotifyPropertyChanged {
public event PropertyChangedEventHandler PropertyChanged;
public void RaisePropertyChanged(string propertyName) {
var handler = PropertyChanged;
if (handler != null) {
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
public void NotifyStatusChange() {
RaisePropertyChanged("Enabled");
RaisePropertyChanged("StatusColor");
}
protected static ConnectStatus _Status = ConnectStatus.Disabled;
protected static Color _StatusColor = StatusColors.Disabled;
protected static bool _Enabled = false;
public ConnectStatus Status {
get { return _Status; }
set { _Status = value; }
}
public Color StatusColor {
get { return _StatusColor; }
set { _StatusColor = value; }
}
public bool Enabled {
get { return _Enabled; }
set {_Enabled = value; }
}
protected abstract Task _Connect();
protected abstract Task _Disconnect();
public void Connect() {
Task.Run(() => _Connect());
}
public void Disconnect() {
Task.Run(() => _Disconnect());
}
}
public abstract class TimerEvent {
[CategoryAttribute("Timing"), DescriptionAttribute("Will this event fire")]
public bool Enabled { get; set; }
[CategoryAttribute("Event"), DescriptionAttribute("What to run")]
public abstract string Payload { get; set; }
[CategoryAttribute("Timing"), DescriptionAttribute("If timer is increased, will this fire a second (or more) time?")]
public bool Refire { get; set; }
[CategoryAttribute("Timing"), DescriptionAttribute("Remaining time when this event fires")]
public TimeSpan Time { get; set; }
public bool HasFired;
public abstract EventType EventType { get; }
protected abstract void _Fire();
public void Fire() {
Task.Run(() => _Fire());
}
public virtual void TestFire() {
Task.Run(() => _Fire());
}
[Browsable(false)]
public abstract JObject JSON { get; }
[Browsable(false)]
public string[] Columns {
get {
string[] Result = new string[3];
Result[0] = Time.ToString(Shared.TimeFormat);
Result[1] = EventType.ToString();
Result[2] = Payload;
return Result;
}
}
protected void SetEnabled(dynamic JSON) {
bool tempEnabled = false;
try { bool.TryParse(JSON.Enabled.ToString(), out tempEnabled); } catch { }
Enabled = tempEnabled;
}
protected void SetRefire(dynamic JSON) {
bool tempRefire = false;
try { bool.TryParse(JSON.ReFire.ToString(), out tempRefire); } catch { }
Refire = tempRefire;
}
protected void SetTime(dynamic JSON) {
Int32 tempTime = 0;
if (!(Int32.TryParse(JSON.Time.ToString(), out tempTime))) { tempTime = 0; }
Time = TimeSpan.FromSeconds(tempTime);
}
protected void SetPayload(dynamic JSON) {
try { Payload = JSON.Payload.ToString(); } catch { Payload = ""; }
}
}
}