public List <Ticket> GetTickets() { lock (lockObj) { IOrderedEnumerable <string> files = from file in Directory.GetFiles(PathInfo.Ticket) where DateTime.Compare(DateTime.Now.AddSeconds(-10), new FileInfo(file).LastWriteTime) > 0 orderby file ascending select file; List <Ticket> tickets = new List <Ticket>(); foreach (string file in files) { Ticket ticket = null; using (FileStream stream = new FileStream(PathInfo.CombinePath(PathInfo.Ticket, file), FileMode.Open)) { DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(Ticket)); ticket = (Ticket)serializer.ReadObject(stream); } if (ticket != null) { tickets.Add(ticket); } } return(tickets); } }
public static void WriteLog(LOGTYPE logType, string message) { string file = string.Empty; switch (logType) { default: case LOGTYPE.INFO: case LOGTYPE.SUCCESS: file = PathInfo.CombinePath(PathInfo.CurrentLog, DateTime.Now.ToString("yyyyMMddHH")) + "-access.log"; break; case LOGTYPE.ERROR: file = PathInfo.CombinePath(PathInfo.CurrentLog, DateTime.Now.ToString("yyyyMMddHH")) + "-error.log"; break; } if (!string.IsNullOrEmpty(file)) { using (StreamWriter writer = new StreamWriter(file, true)) { writer.WriteLine(string.Format("{0} {1}", DateTime.Now.ToString("u"), message)); } } }
public Queue GetQueue() { IOrderedEnumerable <string> files = GetQueueFiles(); Queue queue = new Queue(); if (files.Count() > 0) { string file = files.First(); FileInfo fileInfo = new FileInfo(file); string queueName = System.IO.Path.GetFileName(file); if (fileInfo.Length > 0) { using (FileStream stream = new FileStream(PathInfo.CombinePath(PathInfo.Queue, queueName), FileMode.Open)) { try { DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(Queue)); queue = (Queue)serializer.ReadObject(stream); } catch (Exception e) { LogProcess.Error(e); } } } else { queue = null; } RemoveQueue(queueName); } else { queue = null; } return(queue); }