コード例 #1
0
 /// <summary>
 /// Stores a ticket and adds it to the scheduler
 /// </summary>
 /// <param name="ticket">The ticket to be stored</param>
 /// <param name="failureReason">Reason why the method failed</param>
 /// <returns>Whether the ticket was successfully stored</returns>
 public bool storeTicket(Ticket ticket, out string failureReason)
 {
     //Set addedTicket = true
     //create folder with given ticketId as name
     if (Directory.Exists(folderRoot + ticket.ticketID))
     {
         failureReason = "Ticket directory already exists, maybe the ticket exists?";
         return(false);
     }
     else
     {
         try {
             string fullPath = null;
             if (Extensions.IsLinux)
             {
                 fullPath = Directory.CreateDirectory(folderRoot + ticket.ticketID).FullName + '/';
             }
             else
             {
                 fullPath = Directory.CreateDirectory(folderRoot + ticket.ticketID).FullName + '\\';
             }
             File.WriteAllText(fullPath + "ticket.json", JsonConvert.SerializeObject(ticket));
             ticketDirectory.ticketCount = ticketDirectory.ticketCount + 1;
             string relativeFolder = "./" + ticket.ticketID + '/';
             //relativeFolder = relativeFolder;
             StoredDetails detail = new StoredDetails("./" + ticket.ticketID,
                                                      relativeFolder + "ticket.json",
                                                      relativeFolder + "status.json",
                                                      ticket.ticketID);
             //detail = detail;
             TicketStatus status = new TicketStatus();
             ticketDirectory.tickets.Add(ticket.ticketID, detail);
             tickets.Add(ticket.ticketID, new Tuple <Ticket, TicketStatus>(ticket, status));
             updateStatusFile(ticket.ticketID, false);
             Console.WriteLine("SCHEDULER STILL HAS TO BE IMPLEMENTED");
             scheduler.storeTicket(ticket);
             addedTicket   = true;
             failureReason = null;
             WorkerThread.Interrupt();
             return(true);
         }
         catch (Exception e) {
             failureReason = e.Message;
             return(false);
         }
     }
     //System.Diagnostics.Debug.WriteLine("TicketStorage.storeTicket() has not been implemented");
 }
コード例 #2
0
        //public StoredDetails[] tickets { get; set; }
        public static TicketDirectory Deserialize(string text)
        {
            JObject jobj;

            try {
                jobj = JObject.Parse(text);
            }
            catch (Exception e) {
                Debug.WriteLine("TicketDirectory failed to deserialize with Error: " + e.Message);
                throw new Exception("Could not deserialize TicketDirectory");
            }

            TicketDirectory direct = new TicketDirectory(jobj.Property("ticketCount").Value.ToObject <int>());

            foreach (JToken token in jobj.Property("tickets").Values())
            {
                //Create StoredDetail and add to Dictionary
                //broken
                StoredDetails stored = token.ToObject <StoredDetails>();
                direct.tickets.Add(stored.id, stored);
            }
            return(direct);
        }