Example #1
0
 protected BaseProcess(AppSettingsConfiguration appSettings, ContextManagement contextManagement, Logs logs)
 {
     AppSettings       = appSettings;
     ContextManagement = contextManagement;
     ProcessType       = logs.ProcessType;
     Logs = logs;
 }
Example #2
0
        internal static FtpConfigurationModel BuildHdiFtpConfigurationModel(EnumProcessType type, HdiProcessConfiguration hdiProcessConfiguration)
        {
            FtpConfiguration configuration;

            switch (type)
            {
            case EnumProcessType.Issuance:
                configuration = hdiProcessConfiguration.IssuanceFileFtp;
                break;

            case EnumProcessType.Cancelation:
                configuration = hdiProcessConfiguration.CancelationFileFtp;
                break;

            default:
                return(null);
            }
            return(new FtpConfigurationModel(type)
            {
                IsSftp = configuration.IsSftp,
                RsaFileName = configuration.RsaFileName,
                Host = configuration.Host,
                LookUpFileName = configuration.LookUpFileName,
                Port = configuration.Port,
                RootFolder = configuration.RootFolder,
                Username = configuration.Username,
                Password = configuration.Password,
                DownloadFilesFolder = $"{FileManager.GetDownloadFolder(type, hdiProcessConfiguration.DownloadFilesFolder)}",
                LookUpCreationFileDaysInterval = configuration.LookUpCreationFileDaysInterval,
                UploadFileFolder = configuration.UploadFileFolder,
                Timeout = configuration.Timeout
            });
        }
        internal FileInfo MoveFile(FileInfo file, EnumProcessType processType, bool error = false)
        {
            string fileFolder;

            switch (processType)
            {
            case EnumProcessType.Issuance:
                fileFolder = ReturnIssuanceFolder(error);
                break;

            case EnumProcessType.Cancelation:
                fileFolder = ReturnCancelationFolder(file.Name, error);
                break;

            default:
                Logs.Add($"Não foi encontrado nenhuma configuração para o arquivo do tipo {processType.ToString()}", EnumLog.Error);
                return(null);
            }

            if (fileFolder.isNullOrEmpty())
            {
                return(null);
            }

            Files.CreateDirectory(fileFolder);
            var destinationPath = $"{fileFolder}\\{file.Name}";

            System.IO.File.Move(file.FullName, destinationPath);
            Logs.Add($"Arquivo movido com sucesso. Caminho Antigo: [{file.FullName}]  - Caminho Destino:[{destinationPath}]", EnumLog.Error);
            return(new FileInfo(destinationPath));
        }
        internal List <FileInfo> ListDownloadedFiles(EnumProcessType fileType)
        {
            var downloadFolder = GetDownloadFolder(fileType, HdiProcessConfigurations.DownloadFilesFolder);
            var filesName      = Directory.GetFiles(downloadFolder);


            return(filesName.Select(fileName => new FileInfo(fileName)).ToList());
        }
        internal void UploadFile(FileInfo fileInfo, EnumProcessType processType)
        {
            Logs.Add($"Inicio da transferencia do arquivo.");
            var ftp = new Ftp(Ftp.BuildHdiFtpConfigurationModel(processType, HdiProcessConfigurations));

            ftp.UploadFile(fileInfo);
            Logs.Add($"O Arquivo foi transferido para o servidor com sucesso.");
        }
Example #6
0
 public Field(EnumProcessType fileType, FileFieldConfiguration config)
 {
     Sequence          = config.Sequence;
     InitialPosition   = config.InitialPosition;
     Length            = config.Length;
     FileType          = fileType;
     ComplementaryChar = config.ComplementaryChar;
     DefaultValue      = config.DefaultValue;
     Alignment         = config.Alignment ?? EnumAlignment.Left;
     _value            = config.DefaultValue.isNullOrEmpty() ? string.Empty : config.DefaultValue;
 }
        internal static string GetDownloadFolder(EnumProcessType fileType, string downloadFilesFolder)
        {
            switch (fileType)
            {
            case EnumProcessType.Issuance:
                return($"{downloadFilesFolder}\\Emissoes\\");

            case EnumProcessType.Cancelation:
                return($"{downloadFilesFolder}\\Cancelamentos\\");

            default:
                throw new Exception("file_type_nao_configurado");
            }
        }
Example #8
0
        public string ReturnLogFolder(EnumProcessType fileType)
        {
            switch (fileType)
            {
            case EnumProcessType.Issuance:
                return($"{_configuration.IsuanceFileLogsFolder}");

            case EnumProcessType.Cancelation:
                return($"{_configuration.CancelationFileLogsFolder}");

            default:
                throw new Exception("Erro ao retornar pasta do log, tipo arquivo inexistente.");
            }
        }
Example #9
0
        public static string KeyTransformation(string baseKey, int index, EnumProcessType processType)
        {
            //56 bit'lik Key 28 er iki diziye ayrılır
            string leftBinaryString  = baseKey.Substring(0, baseKey.Length / 2);
            string rightBinaryString = baseKey.Substring(baseKey.Length / 2);

            leftBinaryString  = CircularLeftShift(leftBinaryString, index, processType);
            rightBinaryString = CircularLeftShift(rightBinaryString, index, processType);

            /*Bu diziler birleştirilip sonrasında compression işlemi uygulanarak
             * 56 bitten 48 bit elde edilir
             */

            var transformedKey = CompressionPermutation(leftBinaryString + rightBinaryString);


            return(transformedKey);
        }
        internal void DownloadFiles(EnumProcessType processType)
        {
            var ftp       = new Ftp(Ftp.BuildHdiFtpConfigurationModel(processType, HdiProcessConfigurations));
            var filesName = ftp.ListFilesNameFromServer();

            if (filesName.Any())
            {
                foreach (var fileName in filesName)
                {
                    if (!FileExists(fileName))
                    {
                        try
                        {
                            ftp.DownloadFile(fileName);
                            var filePath = $"{GetDownloadFolder(processType, HdiProcessConfigurations.DownloadFilesFolder)}\\{ fileName}";

                            Logs.Add($"O Download do arquivo {fileName} foi concluido.");
                            Files.UnzipDeleteZipFile($"{filePath}");
                            if (fileName.Contains(".zip"))
                            {
                                Logs.Add($"O arquivo foi extraido para { filePath.Replace(".zip", ".txt")}");
                            }
                        }
                        catch (Exception ex)
                        {
                            Logs.Add($"Não foi possível realizar o download do arquivo:[{fileName}]", EnumLog.Error);
                            Logs.Add($"[Exception Message]:{ex.Message}", EnumLog.Error);
                            Logs.Add($"[Exception StackTrace]:{ex.StackTrace}", EnumLog.Error);
                        }
                    }
                    else
                    {
                        Logs.Add($"O download do arquivo:[{fileName.Replace(".zip", ".txt")}]  não foi realizado, pois o mesmo já existe");
                    }
                }
            }
            else
            {
                Logs.Add($"Não existe nenhum arquivo para ser baixado no servidor.", EnumLog.Information);
            }
        }
Example #11
0
        /// <summary>
        /// anahtar oluşturma için laydırma işlemi
        /// Circular Left shift
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static string CircularLeftShift(string key, int index, EnumProcessType processType)
        {
            char[] resultChars = new char[key.Length];

            int shift;

            if (processType == EnumProcessType.ENCRYPTION)
            {
                shift = Data.CircularLeftshiftTable[index];
            }
            else
            {
                shift = Data.CircularLeftshiftTable.Reverse().ToArray()[index];
            }

            for (int keyCharIndex = 0; keyCharIndex < key.Length; keyCharIndex++)
            {
                if (processType == EnumProcessType.ENCRYPTION)
                {
                    resultChars[(keyCharIndex + shift) % (key.Length)] = key[keyCharIndex];
                }
                else
                {
                    resultChars[(keyCharIndex - shift + key.Length) % (key.Length)] = key[keyCharIndex];
                }
            }

            string result = "";

            foreach (var resultChar in resultChars)
            {
                result += resultChar;
            }

            return(result);
        }
Example #12
0
        public APOLICE_PROCESSAMENTO_DADOS CreatePolicyProcessData(APOLICE_PROCESSAMENTO policyProcess, EnumProcessType processType, string dsProposal,
                                                                   string dsPolicy, string dsIdentifier, EnumPolicyProcessDataStatus policyProcessDataStatus = EnumPolicyProcessDataStatus.PendingProcess, string customerDocument = "", string vehicleChassi = "")
        {
            try
            {
                policyProcess.NR_REGISTROS++;
                var policyProcessData = new APOLICE_PROCESSAMENTO_DADOS
                {
                    APOLICE_PROCESSAMENTO = policyProcess,
                    DS_PROPOSTA           = dsProposal,
                    DS_APOLICE            = dsPolicy,
                    DS_CI            = dsIdentifier,
                    NR_TIPO_REGISTRO = processType.ToInt(),
                    NR_STATUS        = policyProcessDataStatus.ToInt(),
                    NR_CNPJ_CPF      = customerDocument,
                    DS_CHASSI        = vehicleChassi,
                    DT_CRIACAO       = DateTime.Now
                };
                Context.PolicyProcessData.Add(policyProcessData);
                Context.SaveChanges();

                Logs.Add($"Registro na tabela APOLICE_PROCESSAMENTO_DADOS criado. ID:{policyProcess.CD_APOLICE_PROCESSAMENTO}");
                Logs.Add($"Campo NR_REGISTROS incrementado na tabela APOLICE_PROCESSAMENTO. ID:{policyProcess.CD_APOLICE_PROCESSAMENTO}   NR_REGISTROS_ATUALIZADO:{policyProcess.NR_REGISTROS}");

                return(policyProcessData);
            }
            catch (Exception ex)
            {
                Logs.Add($"[Exception] A aplicação gerou uma exceção não tratada ao tentar criar um registro na tabela APOLICE_PROCESSAMENTO_DADOS.", EnumLog.Error);
                Logs.Add($"- [ExceptionMessage] - {ex.Message}", EnumLog.Error);
                if (ex.InnerException != null)
                {
                    Logs.Add($"- [InnerException] - {ex.InnerException.Message}", EnumLog.Error);
                }
                Logs.Add($"- [StackTrace] - {ex.StackTrace}", EnumLog.Error);
                return(null);
            }
        }
Example #13
0
 public Logs(LogsConfiguration configuration, EnumProcessType processType)
 {
     Log            = new List <LogModel>();
     _configuration = configuration;
     ProcessType    = processType;
 }
Example #14
0
 public PolicyService(EnumProcessType processType) : base(processType)
 {
 }
 public FtpConfigurationModel(EnumProcessType fileType)
 {
     FileType = fileType;
 }
Example #16
0
        public static string Crypt(string binaryData, string hexKey, EnumProcessType processType)
        {
            //hexKey bit string'e dönüşütürülür
            string bitKey = BinaryHelper.GetBitsFromHex(hexKey);

            //Key 64 bit'ten 56 bit'e dönüştürülür
            bitKey = CompressionPermutationKeyInit(bitKey);

            string result = "";

            List <int> roundIndexes = new List <int>();

            for (int index = 0; index < ((decimal)binaryData.Length / (decimal)64); index++)
            {
                roundIndexes.Add(index);
            }

            //On decrpytion, rounds are reversed
            if (processType == EnumProcessType.DECRYPTION)
            {
                roundIndexes.Reverse();
            }


            foreach (int index in roundIndexes)
            {
                bool finished = false;

                string currentBinaryString = binaryData.Substring(index * 64);

                if (currentBinaryString.Length > 64)
                {
                    currentBinaryString = currentBinaryString.Substring(0, 64);

                    finished = processType == EnumProcessType.DECRYPTION && index == 0;
                }
                else
                {
                    finished = processType == EnumProcessType.ENCRYPTION ||  (processType == EnumProcessType.DECRYPTION && index == 0);
                }

                currentBinaryString = InitialPermutation(currentBinaryString);

                //32'şer bit olarak data ikiye ayrılır
                string leftBinaryString  = currentBinaryString.Substring(0, currentBinaryString.Length / 2);
                string rightBinaryString = currentBinaryString.Substring(currentBinaryString.Length / 2);

                var cryptIndexes = new List <int>();
                for (int cryptIndex = 0; cryptIndex < 16; cryptIndex++)
                {
                    cryptIndexes.Add(cryptIndex);
                }

                if (processType == EnumProcessType.DECRYPTION)
                {
                    cryptIndexes.Reverse();
                }

                //cryp işlemleri 16 kez tekrarlanır. Her adımda data çaprazlanır
                foreach (int cryptIndex in cryptIndexes)
                {
                    //Bu adım için 56 bitlik Key'den 48 bitlik yeni key üretilir
                    var transformedKey = KeyTransformation(bitKey, cryptIndex, processType);

                    //FUNCTION çalıştırılır
                    var expandedRightBinaryString = MainFunction(rightBinaryString, transformedKey);

                    //leftBinaryString (48bit) ve expandedRightBinaryString (48bit) XOR'lanır (her bit ikilik sistemde toplanıp mod2'si alınır)
                    leftBinaryString = XORArray(leftBinaryString, expandedRightBinaryString);

                    //left ve right'ın yerleri değiştirilerek yeni adıma hazırlanır. (çaprazlama)
                    string prevLeftBinaryString = leftBinaryString;
                    leftBinaryString  = rightBinaryString;
                    rightBinaryString = prevLeftBinaryString;
                }

                //sonuçta elde edilen left ve right birbirine eklenerek 64 bitlik data elde edilir
                var resultBinary = leftBinaryString + rightBinaryString;
                resultBinary = FinalPermutation(resultBinary);
                result      += resultBinary;

                if (finished)
                {
                    break;
                }
            }

            return(result);
        }
Example #17
0
 protected HdiFile(TConfigurationFile configuration, EnumProcessType processType)
 {
     Configuration = configuration;
     ProcessType   = processType;
 }
 public static int ToInt(this EnumProcessType processType) => (int)processType;
 protected BaseServices(EnumProcessType processType)
 {
     Services    = new ServiceCollection();
     ProcessType = processType;
     ConfigureServices();
 }