public void CumulativeReportGeneration()
        {
            // Create new log for a vending machine that sells only coke
            TransLog log  = new TransLog();
            Item     coke = new Item("Coca Cola", "drink", 2.35m, "A2", 1);

            log.ItemsSold.Add(coke.Name, 0); // starts with 0 sold

            // log a sale
            decimal balance = 10.00m;

            log.LogPurchase(balance, coke);

            // Clear files before writing
            File.Delete(log.LogPath); // don't need the log file for this test
            if (File.Exists(log.ReportPath))
            {
                File.Delete(log.ReportPath);
            }

            // generate the report
            log.GenerateReport();

            // Does the report exist?
            Assert.IsTrue(File.Exists(log.ReportPath), "Report file should be created.");

            // Does it have the expected info and formatting inside?
            string expected = "Coca Cola|1";

            using (StreamReader sr = new StreamReader(log.ReportPath))
            {
                Assert.AreEqual(expected, sr.ReadLine(), "Report should contain the expected output.");
            }
            File.Delete(log.ReportPath);
        }
        public static TransLog GetTransLog(string activity_Id)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("SELECT  activity_id, trans_alias_id, trans_type_cd, trans_reason_cd, trans_type_sub_cd ");
            sb.Append("FROM  TransLog ");
            sb.Append("WHERE activity_id = '" + activity_Id + "' ");

            DataTable dt = new DataTable();

            using (var conn = new SqlConnection(GlobalSettings.SqlConnectionString()))
                using (var cmd = new SqlCommand(sb.ToString(), conn))
                    using (var da = new SqlDataAdapter(cmd))
                    {
                        cmd.CommandType = CommandType.Text;
                        da.Fill(dt);
                    }
            TransLog transLog = null;

            if (dt.Rows.Count > 0)
            {
                transLog = LoadTransLog(dt.Rows[0]);
            }
            return(transLog);
        }
        public void WritingToFile()
        {
            // Make a new log file and write to it
            TransLog log = new TransLog();

            if (File.Exists(log.LogPath))
            {
                File.Delete(log.LogPath);
            }
            Assert.IsFalse(File.Exists(log.LogPath), "No log file should exist yet at the target location.");
            string sampleTextA = "Hello, world!";

            log.Writer(sampleTextA, log.LogPath);

            // Does it have the expected text?
            using (StreamReader sr = new StreamReader(log.LogPath))
            {
                while (!sr.EndOfStream)
                {
                    Assert.AreEqual(sampleTextA, sr.ReadLine(), "File should contain: Hello, world!");
                }
            }

            // Can new text append?
            string sampleTextB = "My name is Log.txt, nice to meet you.";

            log.Writer(sampleTextB, log.LogPath);
            using (StreamReader sr = new StreamReader(log.LogPath))
            {
                Assert.AreEqual(sampleTextA, sr.ReadLine(), "File should have sampleTextA on first line");
                Assert.AreEqual(sampleTextB, sr.ReadLine(), "File should have sampleTextB on second line");
            }

            File.Delete(log.LogPath);
        }
Exemple #4
0
        public static TransLog GetTransLog(string activity_Id)
        {
            DateTime      todayDt = DateTime.Today;
            StringBuilder sb      = new StringBuilder();

            sb.Append("SELECT  activity_id, trans_alias_id, trans_type_cd, trans_reason_cd, trans_type_sub_cd ");
            sb.Append("FROM  BAR_TransLog ");
            sb.Append("WHERE activity_id = " + long.Parse(activity_Id) + " ");
            sb.Append("AND active_ind = '1' ");
            sb.Append("AND END_EFFECTIVE_DT_TM > '" + todayDt + "'");

            DataTable dt = new DataTable();

            using (var conn = new SqlConnection(GlobalSettings.SqlConnectionString()))
                using (var cmd = new SqlCommand(sb.ToString(), conn))
                    using (var da = new SqlDataAdapter(cmd))
                    {
                        cmd.CommandType = CommandType.Text;
                        da.Fill(dt);
                    }
            TransLog transLog = null;

            if (dt.Rows.Count > 0)
            {
                transLog = LoadTransLog(dt.Rows[0]);
            }
            dt.Dispose();
            return(transLog);
        }
        private static TransLog LoadTransLog(DataRow row)
        {
            TransLog transLog = new TransLog();

            transLog.Activity_Id       = row["activity_id"].ToString();
            transLog.Trans_Alias_Id    = row["trans_alias_id"].ToString();
            transLog.Trans_Reason_Cd   = row["trans_Reason_Cd"].ToString();
            transLog.Trans_Type_Cd     = row["trans_Type_Cd"].ToString();
            transLog.Trans_Type_Sub_Cd = row["trans_Type_Sub_Cd"].ToString();
            return(transLog);
        }
 public void AddDownloadSize(int size)
 {
     if (sizeDownloadList.Count == 2)
     {
         sizeDownloadList[1] = new TransLog(size, DateTime.Now);
     }
     else
     {
         sizeDownloadList.Add(new TransLog(size, DateTime.Now));
     }
     sizeDownload += size;
 }
Exemple #7
0
        public async Task <ActionResult <TransLog> > Fetch(int page, string username, int pageSize = 2)
        {
            List <TransLog> trans    = new List <TransLog>();
            List <string>   vouchers = await _tVoucherContext
                                       .tVouchers
                                       .Select(s => s.TVoucer)
                                       .Distinct()
                                       .Skip((page - 1) * pageSize)
                                       .Take(pageSize)
                                       .ToListAsync();

            foreach (string voucher in vouchers)
            {
                //判定transLog表中是否已经加载该凭证,若未加载,加载到中间表中

                TransLog translog = _transLogcontext.transLogs
                                    .Where(n => n.TVoucher == voucher)
                                    .FirstOrDefault();
                if (translog == null)
                {
                    TransLog transLog = new TransLog
                    {
                        UserName  = username,
                        TVoucher  = voucher,
                        NCVoucher = voucher,
                        ExecTime  = DateTime.Now,
                        Status    = Status.unselected
                    };
                    _transLogcontext.transLogs.Add(transLog);
                    trans.Add(transLog);
                }
                else
                {
                    trans.Add(translog);
                }
                await _transLogcontext.SaveChangesAsync();
            }

            //layui数据表格需要的数据格式
            return(Ok(new {
                code = 0,
                msg = "",
                count = _transLogcontext.transLogs.Count(),
                data = trans
            }));
        }
        public void DispenseChangeLogging()
        {
            // Setup new log and the money amounts
            TransLog log = new TransLog();

            File.Delete(log.LogPath);
            decimal balance = 10.00m;

            // Log the GIVE CHANGE operation
            DateTime time = log.Time;

            log.LogGiveChange(balance);
            using (StreamReader sr = new StreamReader(log.LogPath))
            {
                string expected = $"{time.ToString("G")} {"GIVE CHANGE:".PadRight(25)} {balance:C} - {balance:C} = {0:C}";
                Assert.AreEqual(expected, sr.ReadLine(), "Log text should match expected string.");
            }
            File.Delete(log.LogPath);
        }
        public void FeedMoneyLogging()
        {
            // Setup new log and the money amounts
            TransLog log = new TransLog();

            File.Delete(log.LogPath);
            decimal balance    = 10.00m;
            decimal moneyAdded = 5.00m;

            // Log the MONEY FED operation
            DateTime time = log.Time;

            log.LogFeedMoney(balance, moneyAdded);
            using (StreamReader sr = new StreamReader(log.LogPath))
            {
                string expected = $"{time} {"FEED MONEY:".PadRight(25)} {(balance - moneyAdded):C} + {moneyAdded:C} = {balance:C}";
                Assert.AreEqual(expected, sr.ReadLine(), "Log text should match expected string.");
            }
            File.Delete(log.LogPath);
        }
Exemple #10
0
        private TransLog FillTransLog(IMessageProp messageProp)
        {
            var transLog = new TransLog()
            {
                Id              = Guid.NewGuid().ToString("N"),
                AppID           = 37.ToString(),
                IsInbound       = true,
                LogDate         = DateTime.Now.Date.ToString(CultureInfo.InvariantCulture),
                MsgDestination  = messageProp.MessageDestination,
                MsgOrigin       = messageProp.MessageOrigin,
                TransOrigin     = messageProp.TransOrigin,
                MsgLocator      = Helper.GetLocator(),
                MsgType         = messageProp.MessageType,
                RequestMessage  = Helper.ReturnContent(isRequest: true),
                ResponseMessage = Helper.ReturnContent(isRequest: false),
                LogTime         = DateTime.Now.ToLocalTime(),
                SentTime        = DateTime.Now.ToLocalTime()
            };

            return(transLog);
        }
        public void CreateLogFile()
        {
            // Instantiate new log and clear any existing Log.txt file
            TransLog log = new TransLog();

            if (File.Exists(log.LogPath))
            {
                File.Delete(log.LogPath);
            }
            Assert.IsFalse(File.Exists(log.LogPath), "No log file should exist yet at the target location.");

            // Create a new file
            string sampleTextA = "Hello, world!";

            log.Writer(sampleTextA, log.LogPath);

            // Was the file created?
            Assert.IsTrue(File.Exists(log.LogPath), "Log file should have been created.");

            // Cleanup
            File.Delete(log.LogPath);
        }
Exemple #12
0
        /// <summary>
        /// 将一个qf保存至outfile. 其中outfile为完整路径。
        /// </summary>
        /// <param name="qf"></param>
        /// <param name="outfile"></param>
        /// <returns></returns>
        public bool SaveDfq(QFile qf, string outfile)
        {
            outfile = ProcessOutputFileNameIfRepeated(outfile);

            string outdir = Path.GetDirectoryName(outfile);

            if (!Directory.Exists(outdir))
            {
                Directory.CreateDirectory(outdir);
            }

            TransLog log = null;

            try
            {
                if (qf.SaveToFile(outfile))
                {
                    LastOutputDfqFile = outfile;
                    log = new TransLog(CurrentInFile, outfile, "保存成功", LogType.Success);
                }
                else
                {
                    LastOutputDfqFile = null;
                    log = new TransLog(CurrentInFile, outfile, "保存失败,原因路径不存在,或者没有写入权限。", LogType.Fail);
                }
            }
            catch (Exception ex)
            {
                log = new TransLog(CurrentInFile, outfile, "保存失败,原因:" + ex.Message, LogType.Fail);
            }
            if (log.LogType != LogType.Success)
            {
                LogList.Add(log);
            }

            return(log.LogType == LogType.Success);
        }
        public void PurchaseLogging()
        {
            // Setup new log and the money amounts
            TransLog log = new TransLog();

            File.Delete(log.LogPath);
            decimal balance = 10.00m;

            // Add a coke to the log inventory
            Item coke = new Item("Coca Cola", "drink", 2.35m, "A2", 1);

            log.ItemsSold.Add(coke.Name, 0); // starts with 0 sold

            // Log the GIVE CHANGE operation
            DateTime time = log.Time;

            log.LogPurchase(balance, coke);
            using (StreamReader sr = new StreamReader(log.LogPath))
            {
                string expected = $"{time} {coke.Name.PadRight(22)} {coke.Slot} {(balance + coke.Price):C} - {coke.Price:C} = {balance:C}";
                Assert.AreEqual(expected, sr.ReadLine(), "Log text should match expected string.");
            }
            File.Delete(log.LogPath);
        }
Exemple #14
0
        /// <summary>
        /// 处理文件函数,包括处理前后的主要业务逻辑。
        /// </summary>
        /// <param name="infile"></param>
        /// <returns></returns>
        public virtual bool ProcessFile(string infile)
        {
            // 如果文件不存在或后缀名不匹配,就直接忽略,不产生任何记录。
            if (!File.Exists(infile) || pd.extentions.IndexOf(Path.GetExtension(infile).ToLower()) < 0)
            {
                return(false);
            }

            //当前正在转换的文件。
            CurrentInFile = infile;

            // 转换数据
            TransLog log = null;

            try
            {
                if (TransferFile(infile))
                {
                    log = new TransLog(infile, LastOutputDfqFile, "转换成功", LogType.Success);
                }
                else
                {
                    log = new TransLog(infile, LastOutputDfqFile, "转换失败,原因:未定义。", LogType.Unknown);
                }
                LogList.Add(log);
            }
            catch (Exception ex)
            {
                log = new TransLog(infile, LastOutputDfqFile, "转换失败,原因:" + ex.Message, LogType.Fail);
                LogList.Add(log);
            }


            // invoke the TransFileComplete event. Note ? denotes nullable.
            TransFileComplete.Invoke(this, log);


            // Processes input file.
            switch (pd.ProcessSourceFileType)
            {
            // move inputfile ==> backup folder.
            case 0:
                // the fileinfo of input file.
                FilenameInfo fi = FilenameInfo.Parse(infile);

                // select the backup folder according to the processing result.
                string backupFolder = log.LogType == LogType.Success ? pd.FolderForSuccessed : pd.FolderForFailed;

                // create backup directory.
                Directory.CreateDirectory(backupFolder);
                if (!Directory.Exists(backupFolder))
                {
                    LogList.Add(new TransLog(infile, backupFolder, "备份文件夹'" + backupFolder + "' 创建失败。", LogType.Backup));
                    break;
                }

                string outfile = null;
                switch (pd.KeepBackupFolderStructType)
                {
                case 0:
                    // construct outputfile with a unique file name.
                    outfile = FileHelper.AddIncreamentId(backupFolder + "\\" + fi.Filename + fi.Extention);
                    break;

                case 1:
                    outfile = FileHelper.GetOutFolder(infile,
                                                      currentInputPath.Type == 0 ? "" : currentInputPath.path,
                                                      backupFolder);
                    Directory.CreateDirectory(Path.GetDirectoryName(outfile));
                    break;
                }
                // copy file. If failed, add the error to logs.
                if (!FileHelper.CopyFile(infile, outfile))
                {
                    LogList.Add(new TransLog(infile, outfile, String.Format("复制文件 '{0}' 至 '{1}' 失败。", infile, outfile), LogType.Backup));
                    break;
                }

                // delete source file.
                if (!FileHelper.DeleteFile(infile))
                {
                    LogList.Add(new TransLog(infile, outfile, String.Format("文件 {0} 删除失败。", infile), LogType.Backup));
                }
                break;

            case 1:     // no change.
                break;

            case 2:     // delete files.
                FileHelper.DeleteFile(infile);
                break;

            case 3:     // customized.
                break;
            }

            return(log != null && log.LogType == LogType.Success);
        }
Exemple #15
0
        private void processTransducing()
        {
            int transed = 0;

            while (true)
            {
                //这三个时间分别表示当前时间,开始时间和结束时间。
                DateTime dt    = DateTime.Now;
                DateTime start = new DateTime(dt.Year, dt.Month, dt.Day, pd.StartTime.Hour, pd.StartTime.Minute, pd.StartTime.Second);
                DateTime end   = new DateTime(dt.Year, dt.Month, dt.Day, pd.EndTime.Hour, pd.EndTime.Minute, pd.EndTime.Second);

                //只有在开始和结束时间范围内才会开始下一次转换。
                if (pd.SupportAutoTransducer && !(dt >= start && dt <= end))
                {
                    Thread.Sleep(1);
                    continue;
                }

                try
                {
                    for (int i = 0; i < lvInputList.Items.Count; i++)
                    {
                        if (selectedonly && !lvInputList.Items[i].Checked)
                        {
                            continue;
                        }

                        InputPath ip = lvInputList.Items[i].Tag as InputPath;
                        lvInputList.Items[i].BackColor = Color.LightGray;

                        // process transducing.
                        trans.ProcessInput(ip);

                        lvInputList.Items[i].BackColor        = Color.White;
                        ip.LastTranducingTime                 = DateTime.Now;
                        lvInputList.Items[i].SubItems[2].Text = ip.LastTranducingTime.ToString();
                        transed += trans.LogList.Count(l => l.LogType == LogType.Success);
                        //处理完成后,把日志添加到日志列表中去。日志存放在trans.LogList中。
                        for (int j = 0; j < trans.LogList.Count; j++)
                        {
                            TransLog log = trans.LogList[j];
                            //编号,0.时间,1.事件,2.原因,3.输出文件
                            lvLogs.Items.Insert(0, new ListViewItem(log.GetStrings()));
                            //Funs.AddLog(log.LogType.ToString(), log.Content, log.Output);
                            Funs.AddLog(log);
                        }
                    }

                    Thread.Sleep(100);
                    Application.DoEvents();
                }
                catch (Exception e1)
                {
                    Funs.AddLog("TRANS", "NONE", e1.Message);
                }



                if (!pd.SupportAutoTransducer || !pd.AutoTransducerAvaliable)
                {
                    Reset();
                    MessageBox.Show("转换完成。\n共转换 " + transed + "个文件。", "转换完成", MessageBoxButtons.OK);
                    break;
                }

                trans.LogList.Clear();
                Application.DoEvents();
                Thread.Sleep(pd.getCircleInterval() * 1000);
            }
        }