public List <Features> GetFeatures(string login) { XmlDocument xmlDocument = Utility.LoadXmlWithXmlDocument(_path + login + ".xml"); if (xmlDocument == null) { return(new List <Features>()); } List <Features> listFeatures = null; if (xmlDocument != null) { XmlNodeList nodeList = xmlDocument.GetElementsByTagName("FEATURE"); listFeatures = (from XmlNode node in nodeList select new Features { Description = (EFeatures)StringValue.Parse(typeof(EFeatures), Utility.Decript(node["DESCRIPTION"].InnerText)), Permission = (EPermission)int.Parse(Utility.Decript(node["PERMISSION"].InnerText)), }).ToList(); } return(listFeatures); }
public void HandleStringParam() { var p1 = new StringValue("Hello, world"); Assert.AreEqual(@"Hello\, world", p1.ToString()); var p2 = new StringValue("Pay $300|Pay $100|"); Assert.AreEqual(@"Pay \$300\|Pay \$100\|", p2.ToString()); var p3 = StringValue.Parse(@"Pay \$300\|Pay \$100\|"); Assert.AreEqual("Pay $300|Pay $100|", p3.Value); var crit = Criterium.Parse(@"paramX=Hello\, world"); var p4 = ((UntypedValue)crit.Operand).AsStringValue(); Assert.AreEqual("Hello, world", p4.Value); }
public static Tag Parse(byte[] data, int index, out int length) { TagType id = (TagType)data[index]; length = sizeof(byte); if (id == TagType.End) { return(EndTag); } StringValue name = StringValue.Parse(data, index + sizeof(byte), out int nameLength); length += nameLength; TagValue value = TagValue.Parse(id, data, index + length, out int valueLength); length += valueLength; return(new Tag(id, name, value)); }
public LoginAuthentication LoadLogin(string login, string password, string codigoSessao) { LoginAuthentication loginAuthentication = null; ValidacaoAcessoSoapClient acessoSoapClient = Settings.DefiniServer.Instance(LanguageDefault).SetConfigValidacaoAcessoService(); //var c = acessoSoapClient.State; if (acessoSoapClient == null) { ReconnectValidation(login, password, codigoSessao); } XElement xElement; XmlDocument xmlServer = new XmlDocument(); try { xElement = acessoSoapClient.ValidarUsuario(login, password, codigoSessao); //c = acessoSoapClient.State; using (XmlReader xmlReader = xElement.CreateReader()) { xmlServer.Load(xmlReader); } acessoSoapClient.Close(); xmlServer.ChildNodes[0].InnerXml = Utility.Decript(xmlServer.ChildNodes[0].InnerXml); if (xmlServer.DocumentElement != null) { XmlNode xmlFechamento = xmlServer.DocumentElement.SelectSingleNode("FECHAMENTO"); if (xmlFechamento == null) { ReconnectValidation(login, password, codigoSessao); } XmlNode xmlStatus = xmlServer.DocumentElement.SelectSingleNode("STATUS"); XmlNode xmlIpServer = xmlServer.DocumentElement.SelectSingleNode("IPSERVER"); if ((xmlStatus != null) && (xmlStatus.HasChildNodes)) { if (xmlStatus.InnerText == "1") { XmlNode xmlCodigoSessao = xmlServer.DocumentElement.SelectSingleNode("CODIGOSESSAO"); XmlNode xmlDataExpiracao = xmlServer.DocumentElement.SelectSingleNode("DATAEXPIRACAO"); XmlNodeList acessos = xmlServer.GetElementsByTagName("ACESSO"); XmlNode xmlId = xmlServer.DocumentElement.SelectSingleNode("ID"); XmlNode xmlLogin = xmlServer.DocumentElement.SelectSingleNode("LOGIN"); XmlNode xmlSenha = xmlServer.DocumentElement.SelectSingleNode("SENHA"); XmlNode xmlNome = xmlServer.DocumentElement.SelectSingleNode("NOME"); XmlNode xmlSobreNome = xmlServer.DocumentElement.SelectSingleNode("SOBRENOME"); XmlNode xmlCpf = xmlServer.DocumentElement.SelectSingleNode("CPF"); XmlNode xmlEmail = xmlServer.DocumentElement.SelectSingleNode("EMAIL"); XmlNode xmlNascimento = xmlServer.DocumentElement.SelectSingleNode("DATANASCIMENTO"); XmlNode xmlCep = xmlServer.DocumentElement.SelectSingleNode("CEP"); XmlNode xmlEstado = xmlServer.DocumentElement.SelectSingleNode("ESTADO"); XmlNode xmlCidade = xmlServer.DocumentElement.SelectSingleNode("CIDADE"); XmlNode xmlBairro = xmlServer.DocumentElement.SelectSingleNode("BAIRRO"); XmlNode xmlLagradouro = xmlServer.DocumentElement.SelectSingleNode("LAGRADOURO"); XmlNode xmlNumero = xmlServer.DocumentElement.SelectSingleNode("NUMERO"); XmlNode xmlComplemento = xmlServer.DocumentElement.SelectSingleNode("COMPLEMENTO"); XmlNode xmlTipo = xmlServer.DocumentElement.SelectSingleNode("TIPO"); loginAuthentication = new LoginAuthentication { CodeSession = xmlCodigoSessao.InnerText, Login = login, Password = password, LastDate = DateTime.Now, LimitDate = String.IsNullOrEmpty(xmlDataExpiracao.InnerText) ? DateTime.Now.AddDays(2) : DateTime.Parse(xmlDataExpiracao.InnerText), Remember = true, Features = new List <Features>(), IpServer = xmlIpServer.InnerText, UserProfile = new UserRegister() { Id = int.Parse(xmlId.InnerText), Birthday = String.IsNullOrEmpty(xmlDataExpiracao.InnerText) ? new DateTime(1900, 1, 1) : DateTime.Parse(xmlNascimento.InnerText), CEP = xmlCep.InnerText, City = xmlCidade.InnerText, Complement = xmlComplemento.InnerText, ConfirmPassword = xmlSenha.InnerText, CPF = xmlCpf.InnerText, District = xmlBairro.InnerText, Email = xmlEmail.InnerText, FirstName = xmlNome.InnerText, LastName = xmlSobreNome.InnerText, Number = xmlNumero.InnerText, Password = xmlSenha.InnerText, State = xmlEstado.InnerText, Street = xmlLagradouro.InnerText, UserName = xmlLogin.InnerText, Tipo = (EPerfil)int.Parse(xmlTipo.InnerText) } }; foreach (Features features in from XmlNode acesso in acessos select new Features { Description = (EFeatures)StringValue.Parse(typeof(EFeatures), acesso["CODIGOACESSO"].InnerText), Permission = (EPermission)StringValue.Parse(typeof(EPermission), acesso["MODO"].InnerText) }) { loginAuthentication.Features.Add(features); } } else if (xmlStatus.InnerText == "0") { XmlNode xmlInformacao = xmlServer.DocumentElement.SelectSingleNode("INFORMACAO"); throw new Exception(xmlInformacao.InnerText); } } } } catch (Exception ex) { acessoSoapClient.Close(); throw ex; //ReconnectValidation(login, password, codigoSessao); } return(loginAuthentication); }
public LoginAuthentication LoginOffline(string login, string password, bool remember) { //Test if guest.xml exists: if (login == "guest" && Utility.Decript(password) == "123456") { if (!File.Exists(_path + login + ".xml")) { CreateDataPath(new LoginAuthentication() { CodeSession = "GUEST", Login = login, Password = password, LastDate = DateTime.Now, LimitDate = DateTime.Now.AddDays(5), Remember = false, Offline = true, Features = new List <Features>() { new Features() { Description = EFeatures.NEW_CHART, Permission = EPermission.Permitido }, new Features() { Description = EFeatures.HISTORICDATA, Permission = EPermission.Restringido } }, UserProfile = new UserRegister() { UserName = "******" } }, login); } } LoginAuthentication loginAuthentication = null; XmlDocument xmlDocument = Utility.LoadXmlWithXmlDocument(_path + login + ".xml"); XmlNodeList nodeList = xmlDocument.GetElementsByTagName("DATA"); foreach (XmlNode node in nodeList.Cast <XmlNode>().Where(node => node["LOGIN"].InnerText.Equals(Utility.Cript(login)) && node["PASSWORD"].InnerText.Equals(Utility.Cript(password)))) { loginAuthentication = new LoginAuthentication { Login = Utility.Decript(node["LOGIN"].InnerText), Password = Utility.Decript(node["PASSWORD"].InnerText), LastDate = DateTime.Now, LimitDate = DateTime.Parse(Utility.Decript(node["LIMITDATE"].InnerText), new CultureInfo("pt-BR")), Remember = remember, CodeSession = "", Features = new List <Features>(), Offline = true, UserProfile = new UserRegister() { UserName = "******" } }; EStatusAuthentication eStatusAuthentication = VerifyDate(loginAuthentication.LastDate, loginAuthentication.LimitDate); if ((eStatusAuthentication.Equals(EStatusAuthentication.Expired)) || (eStatusAuthentication.Equals(EStatusAuthentication.Blocked))) { throw new Exception("Período de login offline acabou, realize um login online para regularizar."); } XmlNodeList nodeFeatures = xmlDocument.GetElementsByTagName("FEATURE"); loginAuthentication.Features = (from XmlNode feature in nodeFeatures select new Features { Description = (EFeatures)StringValue.Parse(typeof(EFeatures), Utility.Decript(feature["DESCRIPTION"].InnerText)), Permission = (EPermission)StringValue.Parse(typeof(EPermission), Utility.Decript(feature["PERMISSION"].InnerText)), }).ToList(); node["REMEMBER"].InnerText = Utility.Cript(remember.ToString()); xmlDocument.Save(_path + login + ".xml"); xmlDocument.Save(_path + "LoginSaved.xml"); break; } return(loginAuthentication); }