HamBook – Diff between revs 16 and 44

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 16 Rev 44
Line 1... Line 1...
1 using Org.BouncyCastle.Crypto.Tls; 1 using Org.BouncyCastle.Crypto.Tls;
2 using System; 2 using System;
3 using System.Collections.Generic; 3 using System.Collections.Generic;
4 using System.Linq; 4 using System.Linq;
-   5 using System.Reflection;
5 using System.Text; 6 using System.Text;
6 using System.Threading.Tasks; 7 using System.Threading.Tasks;
Line 7... Line 8...
7   8  
8 namespace HamBook.Radios.Generic 9 namespace HamBook.Radios.Generic
9 { 10 {
10 public class MemoryRadioMode 11 public abstract class MemoryRadioMode
11 { 12 {
Line 12... Line 13...
12 public char Mode { get; set; } 13 public abstract char Code { get; }
13   -  
14 public MemoryRadioMode(string mode) : this() -  
15 { -  
16 Mode = Parse(mode); -  
17 } -  
18   -  
19 public MemoryRadioMode(char mode) : this() -  
20 { -  
Line 21... Line 14...
21 Mode = Parse(mode); 14  
22 } 15 public abstract string Name { get; }
Line 23... Line 16...
23   16  
Line 24... Line -...
24 public MemoryRadioMode() -  
25 { -  
26   -  
27 } -  
28   -  
29 public static bool TryParse(string mode, out MemoryRadioMode memoryRadioMode) -  
30 { -  
31 switch (mode) -  
32 { -  
33   -  
34 case "LSB": -  
35 case "USB": -  
36 case "CW": -  
37 case "FM": -  
38 case "AM": -  
39 case "RTTY-LSB": -  
40 case "CW-R": -  
41 case "DATA-LSB": -  
42 case "RTTY-USB": -  
43 case "FM-N": -  
44 case "DATA-USB": -  
45 case "AM-N": -  
46 memoryRadioMode = new MemoryRadioMode(mode); -  
47 return true; -  
48 default: -  
49 memoryRadioMode = null; -  
50 return false; -  
51 } -  
52 } -  
53   -  
54 public static bool TryParse(char mode, out MemoryRadioMode memoryRadioMode) -  
55 { -  
56 switch (mode) -  
57 { -  
58 case '1': -  
59 case '2': -  
60 case '3': -  
61 case '4': -  
62 case '5': -  
63 case '6': -  
64 case '7': -  
65 case '8': -  
66 case '9': -  
67 case 'B': -  
68 case 'C': -  
69 case 'D': -  
70 memoryRadioMode = new MemoryRadioMode(mode); -  
71 return true; -  
72 default: -  
73 memoryRadioMode = null; -  
74 return false; -  
75 } -  
76 } -  
77   -  
78 private char Parse(string mode) -  
79 { -  
80 switch (mode) -  
81 { -  
82 case "LSB": -  
83 return '1'; -  
84 case "USB": -  
85 return '2'; -  
86 case "CW": -  
87 return '3'; -  
88 case "FM": -  
89 return '4'; -  
90 case "AM": -  
91 return '5'; -  
92 case "RTTY-LSB": -  
93 return '6'; -  
94 case "CW-R": -  
95 return '7'; -  
96 case "DATA-LSB": -  
97 return '8'; -  
98 case "RTTY-USB": -  
99 return '9'; -  
100 case "FM-N": -  
101 return 'B'; -  
102 case "DATA-USB": -  
103 return 'C'; -  
104 case "AM-N": -  
105 return 'D'; -  
106 default: 17 public MemoryRadioMode()
107 throw new ArgumentException(); -  
108 } -  
109 } -  
110   -  
111 private char Parse(char mode) -  
112 { -  
113 switch (mode) -  
114 { -  
115 case '1': -  
116 case '2': -  
117 case '3': -  
118 case '4': -  
119 case '5': -  
120 case '6': -  
121 case '7': -  
122 case '8': -  
123 case '9': -  
124 case 'B': -  
125 case 'C': -  
126 case 'D': -  
Line 127... Line 18...
127 return mode; 18 {
128 default: -  
129 throw new ArgumentException(); -  
130 } -  
Line 131... Line 19...
131 } 19  
132   20 }
133 public static implicit operator MemoryRadioMode(string mode) 21  
134 { 22 public abstract string CodeToName(char code);
135 return new MemoryRadioMode(mode); -  
136 } -  
137   -  
138 public static implicit operator string(MemoryRadioMode memoryRadioMode) -  
139 { -  
140 switch (memoryRadioMode.Mode) -  
141 { -  
142 case '1': -  
143 return "LSB"; -  
144 case '2': -  
145 return "USB"; -  
146 case '3': 23  
147 return "CW"; 24 public abstract char NameToCode(string name);
148 case '4': 25  
149 return "FM"; 26 public static MemoryRadioMode Create(string radio, params object[] param)
150 case '5': 27 {
151 return "AM"; -  
-   28 foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
152 case '6': 29 {
153 return "RTTY-USB"; 30 foreach (var type in assembly.GetTypes())
154 case '7': 31 {
155 return "CW-R"; 32 if (typeof(MemoryRadioMode).IsAssignableFrom(type))
156 case '8': -  
157 return "DATA-LSB"; 33 {
158 case '9': -  
159 return "RTTY-USB"; 34 var radioAttribute = type.GetCustomAttribute<RadioAttribute>();
160 case 'B': -  
161 return "FM-N"; 35  
162 case 'C': -  
Line 163... Line -...
163 return "DATA-USB"; -  
164 case 'D': -  
165 return "AM-N"; -  
166 default: -  
167 throw new ArgumentException(); -  
168 } -  
169 } -  
170   36 if (radioAttribute != null && radioAttribute.Radio == radio)
171 public static implicit operator MemoryRadioMode(char mode) 37 {
172 { 38 return (MemoryRadioMode)Activator.CreateInstance(type, param);
173 return new MemoryRadioMode(mode); 39 }