private void TreatmentAddressFields(Address address)
 {
     // Remoção de espaço vazio
     address.PublicPlace  = UseFul.StringRemoveSpace(address.PublicPlace, true);
     address.Neighborhood = UseFul.StringRemoveSpace(address.Neighborhood, true);
     address.City         = UseFul.StringRemoveSpace(address.City, true);
     address.Number       = UseFul.StringRemoveSpace(address.Number, false);
     address.ZipCode      = UseFul.StringRemoveSpace(address.ZipCode, false);
 }
 private void TreatmentClientFields(Client client)
 {
     // Remoção de espaço vazio
     client.Name      = UseFul.StringRemoveSpace(client.Name, true);
     client.LastName  = UseFul.StringRemoveSpace(client.LastName, true);
     client.Email     = UseFul.StringRemoveSpace(client.Email, false);
     client.Cpf       = UseFul.StringRemoveSpace(client.Cpf, false);
     client.DDD       = UseFul.StringRemoveSpace(client.DDD, false);
     client.Telephone = UseFul.StringRemoveSpace(client.Telephone, false);
 }
Beispiel #3
0
        public static int GetKeyAndValueAndReturnIndentionLength(string sString, out string sKey, out string sValue)
        {
            if (sString.IndexOf(":") >= 0)
            {
                sKey   = UseFul.StringLeft(sString, sString.IndexOf(":")).Trim();
                sValue = UseFul.StringMid(sString, sString.IndexOf(":") + 1).Trim();
            }
            else
            {
                sKey   = sString.Trim();
                sValue = "";
            }

            return(IndentionLength(sString));
        }
        private bool ValidationAddressFields(Address address, bool isCreation)
        {
            TreatmentAddressFields(address);

            // Variaveis utilizadas para validação
            IDictionary <string, string> stringFields            = new Dictionary <string, string>();
            IDictionary <string, string> stringFieldsOnlyNumbers = new Dictionary <string, string>();

            stringFields.Add("PublicPlace", address.PublicPlace);
            stringFields.Add("Neighborhood", address.Neighborhood);
            stringFields.Add("City", address.City);
            stringFieldsOnlyNumbers.Add("Number", address.Number);
            stringFieldsOnlyNumbers.Add("ZipCode", address.ZipCode);

            if (!UseFul.ValidStringFill(stringFields, ref replyMessage, ref httpStatus))
            {
                return(false);
            }
            if (!ValidadeAddressStringLength(address))
            {
                return(false);
            }
            if (!UseFul.ValidStringFillOnlyNumbers(stringFieldsOnlyNumbers, ref replyMessage, ref httpStatus))
            {
                return(false);
            }
            if (new ClientDao().Read(address.IdClient) == null)
            {
                httpStatus   = HttpStatusCode.InternalServerError;
                replyMessage = "O endereço não está associação a um cliente válido";
                return(false);
            }

            if (CustomerAddressExists(address.ZipCode, address.Number, address.IdClient, address.IdAddress, isCreation))
            {
                return(false);
            }

            return(true);
        }
        private bool ValidationClientFields(Client client)
        {
            TreatmentClientFields(client);

            // Variaveis utilizadas para validação
            IDictionary <string, string> stringFields            = new Dictionary <string, string>();
            IDictionary <string, string> stringFieldsOnlyNumbers = new Dictionary <string, string>();

            stringFields.Add("Name", client.Name);
            stringFields.Add("LastName", client.LastName);
            stringFields.Add("Email", client.Email);
            stringFieldsOnlyNumbers.Add("Cpf", client.Cpf);
            stringFieldsOnlyNumbers.Add("DDD", client.DDD);
            stringFieldsOnlyNumbers.Add("Telephone", client.Telephone);

            if (!UseFul.ValidStringFill(stringFields, ref replyMessage, ref httpStatus))
            {
                return(false);
            }
            if (!ValidadeClientStringLength(client))
            {
                return(false);
            }
            if (!UseFul.ValidStringFillOnlyNumbers(stringFieldsOnlyNumbers, ref replyMessage, ref httpStatus))
            {
                return(false);
            }
            if (!UseFul.DateIsValid(client.BirthDate, "BirthDate", ref replyMessage, ref httpStatus))
            {
                return(false);
            }
            if (!VerifyExistenceCpf(client.Cpf, client.IdClient))
            {
                return(false);
            }

            return(true);
        }
Beispiel #6
0
        private static cYAMLMapping GetYAMLMappings(List <string> sLines, ref int iLineIndex, cYAMLMapping Parent, string sMappingName, int iParentIndention)
        {
            string sKey;
            string sValue;

            cYAMLMapping YAMLMapping = new cYAMLMapping();

            YAMLMapping.sMappingName = sMappingName;
            YAMLMapping.Parent       = Parent;

            while (iLineIndex < sLines.Count)
            {
                if (sLines[iLineIndex].Contains("Detector forced on/off"))
                {
                }

                // Comments?
                if (UseFul.StringLeft(sLines[iLineIndex], 2) == " #")
                {
                    iLineIndex++;
                    continue;
                }

                int iLineIndention = IndentionLength(sLines[iLineIndex]);

                // Back to previous level
                if (iLineIndention < iParentIndention)
                {
                    break;
                }

                // New section on same level?
                if (iLineIndention == iParentIndention && sLines[iLineIndex].IndexOf(":") == sLines[iLineIndex].Length - 1 && sLines[iLineIndex].Length > 0)
                {
                    break;
                }

                // New scalar on same level?
                if (iLineIndention == iParentIndention && sLines[iLineIndex].IndexOf(": ") > 0)
                {
                    break;
                }

                if (sLines[iLineIndex].IndexOf(": ") >= 0)
                {
                    sKey   = UseFul.StringLeft(sLines[iLineIndex], sLines[iLineIndex].IndexOf(": ")).Trim(new char[] { ' ', '\'', '\"' });
                    sValue = UseFul.StringMid(sLines[iLineIndex], sLines[iLineIndex].IndexOf(": ") + 2).Trim(new char[] { ' ', '\'', '\"' });
                    //        description: Traffic Light Controller is in fail safe mode; e.g. yellow flash
                    //          or dark mode

                    bool bPreserveLFs  = false;
                    bool bFoldLFs      = false;
                    bool bAddEndingLF  = false;
                    bool bTextIsQuoted = false;
                    if (UseFul.StringLeft(sValue, 1) == "|")
                    {
                        bPreserveLFs = true;
                    }
                    else if (UseFul.StringLeft(sValue, 1) == ">")
                    {
                        bFoldLFs = true;
                    }
                    if (bPreserveLFs || bFoldLFs)
                    {
                        bAddEndingLF = UseFul.StringMid(sValue, 1, 1) == "-" ? false : true;
                        sValue       = "";
                        if (iLineIndex < sLines.Count - 1)
                        {
                            bTextIsQuoted = sLines[iLineIndex + 1].StartsWith("\"") || sLines[iLineIndex + 1].StartsWith("'");
                        }
                    }
                    else
                    {
                        bTextIsQuoted = sValue.StartsWith("\"") || sValue.StartsWith("'");
                    }
                    if (bTextIsQuoted)
                    {
                    }
                    while (iLineIndex < sLines.Count - 1)
                    {
                        // Buggish YAML could contain empty line in text flow?
                        if (iLineIndention >= IndentionLength(sLines[iLineIndex + 1]) && sLines[iLineIndex + 1].Length > 0)
                        {
                            break;
                        }
                        if (bTextIsQuoted == false)
                        {
                            if (sLines[iLineIndex + 1].IndexOf(": ") >= 0)
                            {
                                //  break;
                            }
                        }
                        else
                        {
                        }

                        iLineIndex++;
                        if (sLines[iLineIndex].Trim() == "")
                        {
                            sValue += "\n";
                        }
                        else
                        {
                            if (UseFul.StringRight(sValue, 1) != "\n")
                            {
                                sValue += " ";
                            }
                            sValue += sLines[iLineIndex].Trim();
                            if (bPreserveLFs)
                            {
                                sValue += "\n";
                            }
                        }
                    }
                    sValue = sValue.Trim(new char[] { '\"', ' ', '\n', '\'' });
                    if (bAddEndingLF)
                    {
                        sValue += "\n";
                    }
                    if (YAMLMapping.YAMLScalars.ContainsKey(sKey) == false)
                    {
                        YAMLMapping.YAMLScalars.Add(sKey, sValue);
                    }
                    else
                    {
                        Debug.WriteLine("Key already exists in section: " + YAMLMapping.GetFullPath() + ": " + sLines[iLineIndex].Trim());
                    }
                    iLineIndex++;
                }
                else if (sLines[iLineIndex].IndexOf(":") == sLines[iLineIndex].Length - 1 && sLines[iLineIndex].Length > 0)
                {
                    string sChildSectionName = UseFul.StringLeft(sLines[iLineIndex], sLines[iLineIndex].IndexOf(":")).Trim();
                    iLineIndex++;
                    cYAMLMapping YAMLChildSection = GetYAMLMappings(sLines, ref iLineIndex, YAMLMapping, sChildSectionName, iLineIndention);
                    if (YAMLMapping.YAMLMappings.ContainsKey(sChildSectionName) == false)
                    {
                        YAMLMapping.YAMLMappings.Add(sChildSectionName, YAMLChildSection);
                    }
                    else
                    {
                        Debug.WriteLine("Key already exists in section: " + YAMLMapping.GetFullPath() + ": " + sLines[iLineIndex].Trim());
                    }
                }
                else if (iLineIndention == 0 && sLines[iLineIndex] == "---")
                {
                    iLineIndex++;
                }
                else
                {
                    Debug.WriteLine("Invalid line: " + iLineIndex.ToString() + ": " + sLines[iLineIndex].Trim());
                    iLineIndex++;
                }
            }

            return(YAMLMapping);
        }