summaryrefslogtreecommitdiff
path: root/Codemerx/Gestor.Model/Model.Domain.Ferramentas/Credencial.cs
blob: a6e7464c75e51104f050beada1f154869179ff5f (plain)
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
using Gestor.Model.Attributes;
using Gestor.Model.Common;
using Gestor.Model.Domain.Generic;
using Gestor.Model.Domain.Seguros;
using Gestor.Model.Helper;
using Gestor.Model.Resources;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Text.RegularExpressions;

namespace Gestor.Model.Domain.Ferramentas
{
	public class Credencial : DomainBase, IDomain
	{
		private string _descricao;

		private string _assinatura;

		private string _header;

		private string _cabecalho;

		[Description("ASSINATURA")]
		[Log(true)]
		public string Assinatura
		{
			get
			{
				return this._assinatura;
			}
			set
			{
				this._assinatura = value ?? "";
			}
		}

		public string Cabecalho
		{
			get
			{
				return this._cabecalho;
			}
			set
			{
				this._cabecalho = value ?? "";
			}
		}

		[Description("DESCRIÇÃO")]
		[Log(true)]
		public string Descricao
		{
			get
			{
				string str = this._descricao;
				if (str != null)
				{
					return str.ToUpper();
				}
				return null;
			}
			set
			{
				this._descricao = value;
			}
		}

		[Description("DOMÍNIO")]
		[Log(true)]
		public string Dominio
		{
			get;
			set;
		}

		[Description("E-MAIL")]
		[Log(true)]
		public string Email
		{
			get;
			set;
		}

		public bool Excluido
		{
			get;
			set;
		}

		[Log(true)]
		public string Header
		{
			get
			{
				return this._header;
			}
			set
			{
				this._header = value;
			}
		}

		public long IdEmpresa
		{
			get;
			set;
		}

		public long IdUsuario
		{
			get;
			set;
		}

		[Description("PORTA")]
		[Log(true)]
		public int? Porta
		{
			get;
			set;
		}

		public string Replyto
		{
			get;
			set;
		}

		[Description("SEGURO")]
		[Log(true)]
		public bool Seguro
		{
			get;
			set;
		}

		[Description("SENHA")]
		[Log(true)]
		public string Senha
		{
			get;
			set;
		}

		[Log(true)]
		public TipoEmail Tipo
		{
			get;
			set;
		}

		[Description("USUÁRIO")]
		[Log(true)]
		public string Usuario
		{
			get;
			set;
		}

		[JsonIgnore]
		public Func<List<KeyValuePair<string, string>>> ValidationEvent
		{
			get
			{
				Credencial credencial = this;
				return new Func<List<KeyValuePair<string, string>>>(credencial.Validate);
			}
		}

		public Credencial()
		{
		}

		public List<TupleList> Log()
		{
			string str;
			List<TupleList> tupleLists = new List<TupleList>();
			this.Assinatura = (new Regex("<title>.*<\\/title>")).Replace(this.Assinatura, "").Trim();
			this.Assinatura = (new Regex("(<[^>]*>)|(p\\s?{[^}]*})|(\\r)|(\\n)")).Replace(this.Assinatura, "").Trim();
			TupleList tupleList = new TupleList();
			ObservableCollection<Tuple<string, string, string>> observableCollection = new ObservableCollection<Tuple<string, string, string>>()
			{
				new Tuple<string, string, string>("DESCRIÇÃO", (string.IsNullOrWhiteSpace(this.Descricao) ? "" : this.Descricao), "")
			};
			int? porta = this.Porta;
			if (!porta.HasValue)
			{
				str = "";
			}
			else
			{
				porta = this.Porta;
				if (porta.HasValue)
				{
					str = porta.GetValueOrDefault().ToString();
				}
				else
				{
					str = null;
				}
			}
			observableCollection.Add(new Tuple<string, string, string>("PORTA", str, ""));
			observableCollection.Add(new Tuple<string, string, string>("DOMÍNIO", (string.IsNullOrWhiteSpace(this.Dominio) ? "" : this.Dominio), ""));
			observableCollection.Add(new Tuple<string, string, string>("E-MAIL", (string.IsNullOrWhiteSpace(this.Email) ? "" : this.Email), ""));
			observableCollection.Add(new Tuple<string, string, string>("LOGIN", (string.IsNullOrWhiteSpace(this.Usuario) ? "" : this.Usuario), ""));
			observableCollection.Add(new Tuple<string, string, string>("CERTIFICADO DE SEGURANÇA", (this.Seguro ? "SIM" : "NÃO"), ""));
			observableCollection.Add(new Tuple<string, string, string>("ASSINATURA", (string.IsNullOrWhiteSpace(this.Assinatura) ? "" : this.Assinatura), ""));
			tupleList.Tuples = observableCollection;
			tupleLists.Add(tupleList);
			return tupleLists;
		}

		public List<KeyValuePair<string, string>> Validate()
		{
			List<KeyValuePair<string, string>> keyValuePairs = ValidationHelper.AddValue();
			if (string.IsNullOrEmpty(this.Descricao))
			{
				keyValuePairs.AddValue<string, string>("Descricao|DESCRIÇÃO", Messages.Obrigatorio, true);
			}
			else if (this.Descricao.Length > 50)
			{
				keyValuePairs.AddValue<string, string>("Descricao|DESCRIÇÃO", string.Format(Messages.MaiorQueLimite, 50), true);
			}
			if (this.Tipo == TipoEmail.Outros)
			{
				if (!this.Porta.HasValue)
				{
					keyValuePairs.AddValue<string, string>("Porta", Messages.Invalido, true);
				}
				if (string.IsNullOrWhiteSpace(this.Dominio))
				{
					keyValuePairs.AddValue<string, string>("Dominio|DOMÍNIO", Messages.Obrigatorio, true);
				}
				else if (this.Dominio.Length > 80)
				{
					keyValuePairs.AddValue<string, string>("Dominio|DOMÍNIO", string.Format(Messages.MaiorQueLimite, 80), true);
				}
				if (string.IsNullOrEmpty(this.Usuario))
				{
					keyValuePairs.AddValue<string, string>("Usuario|USUÁRIO", Messages.Obrigatorio, true);
				}
				else if (this.Usuario.Length > 50)
				{
					keyValuePairs.AddValue<string, string>("Usuario|USUÁRIO", string.Format(Messages.MaiorQueLimite, 50), true);
				}
				if (string.IsNullOrEmpty(this.Senha))
				{
					keyValuePairs.AddValue<string, string>("Senha", Messages.Obrigatorio, true);
				}
				else if (this.Senha.Length > 50)
				{
					keyValuePairs.AddValue<string, string>("Senha", string.Format(Messages.MaiorQueLimite, 50), true);
				}
			}
			if (string.IsNullOrWhiteSpace(this.Email))
			{
				keyValuePairs.AddValue<string, string>("Email|E-MAIL", Messages.Obrigatorio, true);
			}
			else if (this.Email.Length > 80)
			{
				keyValuePairs.AddValue<string, string>("Email|E-MAIL", string.Format(Messages.MaiorQueLimite, 80), true);
			}
			else if (!this.Email.ValidacaoEmail())
			{
				keyValuePairs.AddValue<string, string>("Email|E-MAIL", Messages.Invalido, true);
			}
			if (!string.IsNullOrWhiteSpace(this.Replyto) && !this.Replyto.ValidacaoEmail())
			{
				keyValuePairs.AddValue<string, string>("Replyto|RESPONDER PARA", Messages.Obrigatorio, true);
			}
			return keyValuePairs;
		}
	}
}