-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
144 lines (129 loc) · 4.12 KB
/
Program.cs
File metadata and controls
144 lines (129 loc) · 4.12 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
namespace ZohoSync
{
using System;
using System.IO;
using System.Linq;
using ZohoSync.Config;
/// <summary>
/// main entry class
/// </summary>
class Program
{
/// <summary>
/// output files
/// </summary>
public static bool WriteFiles { get; set; }
/// <summary>
/// wait for key
/// </summary>
public static bool WaitForKey { get; set; }
/// <summary>
/// skip log
/// </summary>
public static bool SkipLog { get; set; }
/// <summary>
/// test only
/// </summary>
public static bool TestOnly { get; set; }
/// <summary>
/// main entry
/// </summary>
/// <param name="args">args</param>
static void Main(string[] args)
{
// write header
Console.WriteLine("Zoho Sync Tool (1.0.2)");
Console.WriteLine("© Pavel Valenta 2013-2014");
Console.WriteLine("");
if (args.Length > 0)
{
if (args.Contains("writefiles")) WriteFiles = true;
if (args.Contains("waitforkey")) WaitForKey = true;
if (args.Contains("skiplog")) SkipLog = true;
if (args.Contains("testonly")) TestOnly = true;
}
// header
if (!SkipLog)
{
using (StreamWriter writer = File.AppendText(Path.Combine(Directory.GetCurrentDirectory(), "ZohoSync.log")))
{
writer.WriteLine("");
writer.WriteLine("Sync Start On: " + DateTime.Now.ToString());
writer.Close();
}
}
// get reader & writer
var zoho = new ZohoReader();
var smart = new SmartEmailingWriter();
// get mapping
var mapping = ConfigReader.MappingSetting;
if (!zoho.Authenticate())
{
if (WaitForKey)
{
Console.WriteLine("Please press key to close.");
Console.ReadKey(true);
}
return;
}
foreach (var m in mapping.Setting)
{
var map = m as Mapping;
// get data
var response = zoho.GetData(map.ZohoTable);
// send to smart emailing
smart.SendData(map.SmartEmailList, response);
}
// footer
if (!SkipLog)
{
using (StreamWriter writer = File.AppendText(Path.Combine(Directory.GetCurrentDirectory(), "ZohoSync.log")))
{
writer.WriteLine("Sync End On: " + DateTime.Now.ToString());
writer.WriteLine("");
writer.Close();
}
}
// the end
Console.WriteLine("");
if (WaitForKey)
{
Console.WriteLine("Please press key to close.");
Console.ReadKey(true);
}
}
/// <summary>
/// output write text
/// </summary>
/// <param name="text">text</param>
public static void OutputWrite(string text)
{
Console.Write(text);
if (!SkipLog)
{
using (StreamWriter writer = File.AppendText(Path.Combine(Directory.GetCurrentDirectory(), "ZohoSync.log")))
{
writer.Write(text);
writer.Close();
}
}
}
/// <summary>
/// output write line text
/// </summary>
/// <param name="text">text</param>
public static void OutputWriteLine(string text)
{
Console.WriteLine(text);
if (!SkipLog)
{
using (StreamWriter writer = File.AppendText(Path.Combine(Directory.GetCurrentDirectory(), "ZohoSync.log")))
{
writer.WriteLine(text);
writer.Close();
}
}
}
}
}