-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLoadExcecoes.cs
156 lines (149 loc) · 5.61 KB
/
LoadExcecoes.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
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
145
146
147
148
149
150
151
152
153
154
155
156
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web.Script.Serialization;
namespace Holtz_Compactador
{
public class LoadExcecoes
{
private static List<string> ExtensoesN = new List<string>();
private static List<string> PastasN = new List<string>();
private static string CaminhoArquivoExt = Path.GetDirectoryName(System.AppDomain.CurrentDomain.BaseDirectory);
public static void ClearAll()
{
ExtensoesN.Clear();
PastasN.Clear();
}
public static void LoadAll()
{
CarregaExtensoesN();
CarregaPastasN();
}
public static List<string> ParExtensoesN
{
get { return ExtensoesN; }
set { ExtensoesN = value; }
}
public static void ParAddExtensaoN(string Item)
{
ExtensoesN.Add(Item);
}
public static void ParAddPastaN(string Item)
{
PastasN.Add(Item);
}
public static List<string> ParPastasN
{
get { return PastasN; }
set { PastasN = value; }
}
public static void Start()
{
ClearAll();
CarregaExtensoesN();
CarregaPastasN();
}
private static void CarregaExtensoesN()
{
ExtensoesN.Clear();
string caminhoArquivo = Directory.GetParent(Directory.GetParent(CaminhoArquivoExt).FullName).FullName;
caminhoArquivo += @"\Extensoes.json";
if (!File.Exists(caminhoArquivo)) //Caso não tenha o Config.json
{
using (FileStream fs = File.Create(caminhoArquivo)) { }
}
else //só carrega se já tinha o Extensoes.json
{
JavaScriptSerializer serializer = new JavaScriptSerializer();
using (StreamReader sr = File.OpenText(caminhoArquivo))
{
string json = sr.ReadToEnd();
if (json.Length > 2) //evitar que o json esteja vazio
{
dynamic resultado = serializer.DeserializeObject(json);
foreach (KeyValuePair<string, object> entry in resultado)
{
var key = entry.Key;
var value = entry.Value as string;
ExtensoesN.Add(value);
}
}
sr.Close();
sr.Dispose();
}
}
}
private static void CarregaPastasN()
{
PastasN.Clear();
string caminhoArquivo = Directory.GetParent(Directory.GetParent(CaminhoArquivoExt).FullName).FullName;
caminhoArquivo += @"\Pastas.json";
if (!File.Exists(caminhoArquivo))
{
using (FileStream fs = File.Create(caminhoArquivo)) { }
}
else //só carrega se já tinha o Pastas.json
{
JavaScriptSerializer serializer = new JavaScriptSerializer();
using (StreamReader sr = File.OpenText(caminhoArquivo))
{
string json = sr.ReadToEnd();
if (json.Length > 2) //evitar que o json esteja vazio
{
dynamic resultado = serializer.DeserializeObject(json);
foreach (KeyValuePair<string, object> entry in resultado)
{
var key = entry.Key;
var value = entry.Value as string;
PastasN.Add(value);
}
}
sr.Close();
sr.Dispose();
}
}
}
public static void GravaJsonExtensoes() //grava no arquivo físico
{
string caminhoArquivo = Directory.GetParent(Directory.GetParent(CaminhoArquivoExt).FullName).FullName;
caminhoArquivo += @"\Extensoes.json";
//serialize vai por aspas duplas : "valor"
JavaScriptSerializer serializer = new JavaScriptSerializer();
string json = "{";
int count = 0;
foreach (var item in ExtensoesN)
{
string itemSerializer = serializer.Serialize(item);
count += 1;
if (count > 1) { json += ","; }
json += "\"ExtN" + count.ToString() + "\": " + itemSerializer;
}
json += "}";
using (StreamWriter sr = new StreamWriter(caminhoArquivo))
{
sr.Write(json);
}
}
public static void GravaJsonPastas() //grava no arquivo físico
{
string caminhoArquivo = Directory.GetParent(Directory.GetParent(CaminhoArquivoExt).FullName).FullName;
caminhoArquivo += @"\Pastas.json";
//serialize vai por aspas duplas : "valor"
JavaScriptSerializer serializer = new JavaScriptSerializer();
string json = "{";
int count = 0;
foreach (var item in PastasN)
{
string itemSerializer = serializer.Serialize(item);
count += 1;
if (count > 1) { json += ","; }
json += "\"ExtN" + count.ToString() + "\": " + itemSerializer;
}
json += "}";
using (StreamWriter sr = new StreamWriter(caminhoArquivo))
{
sr.Write(json);
}
}
}
}