-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
103 lines (94 loc) · 3.89 KB
/
Program.cs
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
using System;
using System.Collections.Generic;
using System.Globalization;
namespace CoordinateUUIDConverter
{
class Program
{
static void Main(string[] args)
{
if(args.Length < 2)
{
var consoleColor = Console.ForegroundColor;
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Wrong number of parameters");
Console.ForegroundColor = consoleColor;
Environment.Exit( 0 );
}
if (args[0].ToLower() != "-touuid" && args[0].ToLower() != "-tocoordinate")
{
var consoleColor = Console.ForegroundColor;
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Wrong of parameters");
Console.ForegroundColor = consoleColor;
Environment.Exit( 0 );
}
if (args[0].ToLower() == "-touuid")
{
List<Coordinate> coordinates = new List<Coordinate>();
for (int i = 1; i < args.Length; i++)
try
{
string[] buffer = args[i].Split(',');
if (buffer.Length == 2)
coordinates.Add(new Coordinate(
float.Parse(buffer[0], CultureInfo.InvariantCulture.NumberFormat),
float.Parse(buffer[1], CultureInfo.InvariantCulture.NumberFormat),
1));
else
coordinates.Add(new Coordinate (
float.Parse(buffer[0], CultureInfo.InvariantCulture.NumberFormat),
float.Parse(buffer[1], CultureInfo.InvariantCulture.NumberFormat),
float.Parse(buffer[2], CultureInfo.InvariantCulture.NumberFormat)
));
}
catch(Exception ex)
{
var consoleColor = Console.ForegroundColor;
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("The {0} coordinate format is incorrect. {1}", i, ex.Message);
Console.ForegroundColor = consoleColor;
}
ToUUIDProcess(coordinates);
}
if (args[0].ToLower() == "-tocoordinate")
{
List<Guid> ids = new List<Guid>();
for (int i = 1; i < args.Length; i++)
try
{
ids.Add(Guid.Parse(args[i]));
}
catch
{
var consoleColor = Console.ForegroundColor;
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("UUID format is incorrect. {0}" ,args[i]);
Console.ForegroundColor = consoleColor;
}
ToCoordinateProcess(ids);
}
}
private static void ToUUIDProcess(List<Coordinate> coordinates)
{
foreach(Coordinate coordinate in coordinates)
Console.WriteLine("({0},{1},{2}): {3}",
coordinate.Latitude,
coordinate.Longitude,
coordinate.Floor,
coordinate.ToUUID());
}
private static void ToCoordinateProcess(List<Guid> ids)
{
foreach (Guid id in ids)
{
Coordinate coordinate = id.ToCoordinate();
Console.WriteLine("UUID: {0}, ({1},{2},{3})",
id.ToString(),
coordinate.Latitude,
coordinate.Longitude,
coordinate.Floor);
}
}
}
}