public Ticket SaveTicket(Ticket ticket) { lock (lockObj) { ticket.FileName = DateTime.Now.ToString("yyyyMMddHHmmss") + "_" + Guid.NewGuid().ToString("N").Substring(0, 16) + ".ticket"; try { using (FileStream stream = new FileStream(System.IO.Path.Combine(PathInfo.Ticket, ticket.FileName), FileMode.CreateNew)) { DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(Ticket)); ticket.Source = ticket.Source.EncryptedSource; serializer.WriteObject(stream, ticket); } return(ticket); } catch (Exception e) { LogProcess.Error(e); return(null); } } }
public bool RemoveTicket(Ticket ticket) { lock (lockObj) { try { File.Move( System.IO.Path.Combine(PathInfo.Ticket, ticket.FileName), System.IO.Path.Combine(PathInfo.Trash, ticket.FileName) ); return(true); } catch (Exception e) { LogProcess.Error(e); } return(false); } }
public bool EmptyTicket() { try { foreach (Ticket ticket in GetTickets()) { lock (lockObj) { File.Delete(System.IO.Path.Combine(PathInfo.Ticket, ticket.FileName)); } } return(true); } catch (Exception e) { LogProcess.Error(e); } return(false); }
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); }
public void BuildQueueFromTicket(TicketProcess ticketProcess, int blobkCount) { if (blobkCount <= 0) { blobkCount = BLOCKCOUNT; } List <Ticket> tickets = ticketProcess.GetTickets(); if (tickets.Count() == 0) { return; } Ticket ticket = tickets[0]; Source source = ticket.Source; try { source = source.DecryptedSource; string value = source.Value; string connectionString = source.ConnectionString; if (source.Provider == "System.Data.SqlClient") { Database db = new SqlDatabase(source.ConnectionString); DataSet ds = db.ExecuteDataSet(CommandType.Text, source.Value); if (ds != null && ds.Tables.Count > 0) { QueueProcess queueProcess = new QueueProcess(); List <Recipient> recipients = new List <Recipient>(); foreach (DataRow dr in ds.Tables[0].Rows) { string address = dr["address"].ToString(); string name = dr["name"].ToString(); try { recipients.Add(new Recipient(name, address)); } catch (Exception e) { LogProcess.Error(e, address + ", " + name); continue; } if (recipients.Count >= blobkCount) { queueProcess.SaveQueue(new Queue() { RecipientData = recipients.ToArray(), TicketData = ticket }); recipients = new List <Recipient>(); } } if (recipients.Count() > 0) { queueProcess.SaveQueue(new Queue() { RecipientData = recipients.ToArray(), TicketData = ticket }); recipients = new List <Recipient>(); } } } else if (source.Provider == "System.String[]") { QueueProcess queueProcess = new QueueProcess(); List <Recipient> recipients = new List <Recipient>(); foreach (string recipient in source.Value.Trim().Split(new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries)) { string address = recipient.Trim(); recipients.Add(new Recipient(address, address)); if (recipients.Count >= blobkCount) { queueProcess.SaveQueue(new Queue() { RecipientData = recipients.ToArray(), TicketData = ticket }); recipients = new List <Recipient>(); } } queueProcess.SaveQueue(new Queue() { RecipientData = recipients.ToArray(), TicketData = ticket }); recipients = new List <Recipient>(); } else { throw new NotSupportedException(); } } catch (Exception e) { LogProcess.Error(e); } ticketProcess.RemoveTicket(ticket); }