コード例 #1
0
        public void ExtractDB()
        {
            var sourcePath = fileHelper.GetLocalFilePath(Settings.DB_SQLite_NAME);

            var databaseBackupPath = fileHelper.GetExternalFilePath(string.Format("{0}_{1}.db3", "buc_Backup", DateTime.UtcNow.Ticks));

            fileHelper.CopyFile(sourcePath, databaseBackupPath);
        }
コード例 #2
0
        public List <T> GetDataFromSource(string sourceFilePath, string destinationFilePath, bool processFullFile = false)
        {
            sourceFilePath      = string.Format(sourceFilePath, DateTime.Now.ToString("MMdd"));
            destinationFilePath = string.Format(destinationFilePath, DateTime.Now.ToString("MMdd"));
            _fileHelper.CreateDirectoryIfNotExists(destinationFilePath);

            var isNewFile = !_fileHelper.FileExists(destinationFilePath);

            if (_fileHelper.CopyFile(sourceFilePath, destinationFilePath, true))
            {
                _logger.Info($"{typeof(T).GetType().Name}: Processing delta content of file - {destinationFilePath}");
                var columnNames = string.Join(',', typeof(T).GetPropertyNames());
                var content     = _fileHelper.ReadAllText(destinationFilePath);
                var fullContent = new StringBuilder();
                fullContent.Append(columnNames + Environment.NewLine);
                fullContent.Append(content);
                var lst = fullContent.ToString().FromCsv <List <T> >();

                var lst1     = new List <dynamic>(lst);
                var finallst = new List <dynamic>();
                if (!isNewFile && !processFullFile)
                {
                    var dtInputFrom = DateTime.Now.AddMinutes(-2);
                    dtInputFrom = dtInputFrom.AddSeconds(dtInputFrom.Second * -1);
                    var dtInputTill = DateTime.Now;
                    dtInputTill = dtInputTill.AddSeconds(dtInputTill.Second * -1);
                    finallst    = lst1.Where(i => i.TradeDateTimeVal >= dtInputFrom && i.TradeDateTimeVal <= dtInputTill).ToList();
                    _logger.Info($"{typeof(T).GetType().Name}: Processing delta content of file From: {dtInputFrom.ToString("dd-MM-yyyy HH:mm:ss")} - {dtInputTill.ToString("dd-MM-yyyy HH:mm:ss")}");
                }
                else
                {
                    _logger.Info($"{typeof(T).GetType().Name}: New File has been placed, processing full file - {destinationFilePath}");
                    finallst = lst1.Where(i => i.TradeDateTimeVal >= new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day)).ToList();
                }
                return(finallst.Cast <T>().ToList());
            }
            return(default(List <T>));
        }