Exemple #1
0
        /// <summary>
        /// Check for old files to be deleted
        /// </summary>
        public void DeleteFilesTracking(Business.Entities.ScheduledJob.ScheduledJob scheduledJob)
        {
            List <FilesEff>       filesEff       = scheduledJob.FilesEff;
            List <DeleteTracking> deleteTracking = scheduledJob.DeleteTracking;

            foreach (DeleteTracking deleteTrack in deleteTracking)
            {
                DirectoryInfo directory = new DirectoryInfo(deleteTrack.FolderPath);
                FileInfo[]    files     = directory.GetFiles("*.eff"); //Getting Text files

                foreach (FileInfo file in files)
                {
                    TimeSpan dateDiff = file.LastWriteTimeUtc - DateTime.UtcNow;
                    if (dateDiff.Days > deleteTrack.Days)
                    {
                        if (deleteTrack.FolderPath == scheduledJob.LocalPath)
                        {
                            foreach (FilesEff fileEff in filesEff)
                            {
                                if (fileEff.FileName == file.Name && fileEff.ProcessState == Business.Enums.ScheduledJob.ProcessState.Completed)
                                {
                                    file.Delete();
                                    break;
                                }
                            }
                        }
                        else
                        {
                            file.Delete();
                        }
                    }
                }
            }
        }
Exemple #2
0
        private bool ProcessExistsFIle(Business.Entities.ScheduledJob.ScheduledJob scheduledJob, FilesEff sourceFileEff)
        {
            foreach (FilesEff fileEff in scheduledJob.FilesEff)
            {
                fileEff.ScheduledJob = scheduledJob;
                if (sourceFileEff.FileName == fileEff.FileName)
                {
                    if (sourceFileEff.LastUpdated.Subtract(DateTime.MinValue).TotalSeconds <= fileEff.LastUpdated.Subtract(DateTime.MinValue).TotalSeconds)
                    {
                        if (fileEff.ProcessState == Business.Enums.ScheduledJob.ProcessState.Failed)
                        {
                            ReadFile(fileEff);
                        }
                    }
                    else
                    {
                        File.Copy(Path.Combine(scheduledJob.SourcePath, sourceFileEff.FileName), Path.Combine(scheduledJob.LocalPath, sourceFileEff.FileName), true);
                        fileEff.LastUpdated = sourceFileEff.LastUpdated;
                        ReadFile(fileEff);
                    }

                    return(true);
                }
            }

            return(false);
        }
Exemple #3
0
        /// <summary>
        /// Read all files
        /// </summary>
        /// <returns></returns>
        public void ReadFiles(Business.Entities.ScheduledJob.ScheduledJob scheduledJob)
        {
            try
            {
                if (!Directory.Exists(scheduledJob.SourcePath))
                {
                    throw new Exception($"Directory don't exist: {scheduledJob.SourcePath}");
                }

                if (!Directory.Exists(scheduledJob.LocalPath))
                {
                    throw new Exception($"Directory don't exist: {scheduledJob.LocalPath}");
                }

                DirectoryInfo sourceDirectory = new DirectoryInfo(scheduledJob.SourcePath);
                FileInfo[]    sourcFiles      = sourceDirectory.GetFiles("*.eff"); //Getting Text files

                //copy all files to be processing
                foreach (FileInfo sourceFile in sourcFiles)
                {
                    FilesEff sourceFileEff = new FilesEff
                    {
                        FileName     = sourceFile.Name,
                        ProcessState = Business.Enums.ScheduledJob.ProcessState.Loading,
                        LastUpdated  = sourceFile.LastWriteTimeUtc,
                        ScheduledJob = scheduledJob
                    };

                    if (!ProcessExistsFIle(scheduledJob, sourceFileEff))
                    {
                        sourceFile.CopyTo(Path.Combine(scheduledJob.LocalPath, sourceFileEff.FileName), true);
                        ReadFile(HandlerEffBLO.CreateFile(sourceFileEff));
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }