forked from rstropek/Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodeAnalysis.cs
More file actions
101 lines (86 loc) · 1.72 KB
/
Copy pathCodeAnalysis.cs
File metadata and controls
101 lines (86 loc) · 1.72 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
namespace CodeAnalysisDemo
{
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.IO;
public interface ISwiftItem<T>
{
string ItemName { get; }
List<T> Values { get; }
}
public interface INamedItem
{
string ItemName { get; }
}
public class SwiftItem<T> : ISwiftItem<T>
{
public string ItemName
{
get;
set;
}
public List<T> Values
{
get;
set;
}
}
public class SwiftFile
{
private Stream underlying_File;
private string fileName;
private object header;
public SwiftFile(string fileName)
{
this.underlying_File = new FileStream(fileName, FileMode.Open);
this.fileName = fileName;
this.header = new object();
}
public List<Tuple<string, object>> Settings
{
get;
set;
}
public void AddObject<T>(SwiftItem<T> newObj)
{
lock (this.header)
{
var header = string.Format("{0}: {1}", newObj.ItemName, newObj.Values.Count);
foreach (var item in newObj.Values)
{
if (item is INamedItem)
{
var namedItem = item as INamedItem;
// do something special with namedItem
}
}
// do something with newObj
}
}
public void CopyFile(string source_file_name)
{
using (var reader = new StreamReader(new FileStream(source_file_name, FileMode.Open)))
{
// TODO: copy file here
}
}
public void WriteToDatabase(SqlConnection conn, string tenant)
{
var cmd = conn.CreateCommand();
cmd.CommandText = string.Format("INSERT INTO Target ( Tenant, Data ) VALUES ( {0}, @Data )", tenant);
// Build rest of the command and execute it
}
public void Close()
{
try
{
this.underlying_File.Close();
}
catch
{
Console.WriteLine("Error");
}
}
}
}