Example #1
0
        /// <summary>
        /// Matt Lapka
        /// Created: 2015/01/31
        //  Retrieve a list of active Event objects
        /// </summary>
        /// <returns>A List object containing Event objects retrieved from the database</returns>
        public List <Event> RetrieveEventList()
        {
            double cacheExpirationTime = 5; //how long the cache should live (minutes)
            var    now = DateTime.Now;

            try
            {
                if (DataCache._currentEventList == null)
                {
                    //data hasn't been retrieved yet. get data, set it to the cache and return the result.
                    var list = EventAccessor.GetEventList();
                    DataCache._currentEventList = list;
                    DataCache._EventListTime    = now;
                    return(list);
                }
                //check time. If less than 5 min, return cache

                if (now > DataCache._EventListTime.AddMinutes(cacheExpirationTime))
                {
                    //get new list from DB
                    var list = EventAccessor.GetEventList();
                    //set cache to new list and update time
                    DataCache._currentEventList = list;
                    DataCache._EventListTime    = now;
                    return(list);
                }
                return(DataCache._currentEventList);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #2
0
        public void OnDeleteTopic(Topic topic, IDObjects.NumberSet linksAffected, EventAccessor eventAccessor)
        {
            Monitor.Enter(linksToResolve);

            try
            { linksToResolve.Add(linksAffected); }
            finally
            { Monitor.Exit(linksToResolve); }


            // Check newTopicIDsByEndingSymbol just in case.  We don't want to leave any references to a deleted topic.

            Monitor.Enter(newTopicIDsByEndingSymbol);

            try
            {
                IDObjects.NumberSet newTopicIDs = newTopicIDsByEndingSymbol[topic.Symbol.EndingSymbol];

                if (newTopicIDs != null)
                {
                    newTopicIDs.Remove(topic.TopicID);
                }
            }
            finally
            { Monitor.Exit(newTopicIDsByEndingSymbol); }
        }
Example #3
0
        public void OnDeleteLink(Link link, EventAccessor eventAccessor)
        {
            // Just in case, so there's no hanging references

            lock (linksToResolve)
            { linksToResolve.Remove(link.LinkID); }
        }
Example #4
0
        public int CalculateAvailableTickets(Event selectedEvent)
        {
            // returns a count of available tickets
            int tickets = 0;

            int maxTickets = selectedEvent.MaxSeats;

            try
            {
                // check if there are any tickets reserved already
                if (0 != EventAccessor.RetrieveCountEventIDInRoomEvents(selectedEvent.EventID))
                {
                    // if there is, subtract that amount from the maximum amount
                    tickets = maxTickets - EventAccessor.RetrieveCountOfPurchasedTickets(selectedEvent.EventID);
                }
                else
                {
                    // none have been purchased yet, all the tickets remain
                    tickets = maxTickets;
                }
            }
            catch (Exception)
            {
                throw;
            }

            return(tickets);
        }
Example #5
0
        public void GetEvent_Invalid()
        {
            setup();
            eventToEdit.EventItemID = 9999;

            Event actual = EventAccessor.GetEvent(eventToEdit.EventItemID.ToString());
        }
Example #6
0
        /// <summary>
        /// Matt Lapka
        /// Created: 2015/01/31
        /// Retrieve a single Event object from the Data Access layer with an eventItemID
        /// </summary>
        /// <param name="eventItemID">The EventItemID to search for</param>
        /// <returns>The Event object whose ID matches the passed parameter</returns>
        public Event RetrieveEvent(string eventItemID)
        {
            var    now = DateTime.Now;
            double cacheExpirationTime = 5;

            try
            {
                if (DataCache._currentEventList == null)
                {
                    return(EventAccessor.GetEvent(eventItemID));
                }
                //check time. If less than 5 min, return event from cache
                if (now > DataCache._EventListTime.AddMinutes(cacheExpirationTime))
                {
                    //get event from DB
                    var currentEvent = EventAccessor.GetEvent(eventItemID);
                    return(currentEvent);
                }
                else
                {
                    //get event from cached list
                    var   list         = DataCache._currentEventList;
                    Event currentEvent = list.FirstOrDefault(e => e.EventItemID.ToString() == eventItemID);
                    if (currentEvent != null)
                    {
                        return(currentEvent);
                    }
                    throw new ApplicationException("Event not found.");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #7
0
        public List <Event> GetUpcomingEvents(bool active = true)
        {
            List <Event> events = null;

            // limit upcoming events to those within the next 10 days.
            DateTime limit      = DateTime.Today.AddDays(10.0);
            int      limitDay   = limit.Day;
            int      limitMonth = limit.Month;
            int      limitYear  = limit.Year;

            // make sure it is formatted for Sql
            string limitDate = limitMonth + "-" + limitDay + "-" + limitYear;

            try
            {
                events = EventAccessor.RetrieveUpcomingEvents(limitDate, active);
                formatTimeForEvents(events);
            }
            catch (Exception)
            {
                throw;
            }

            return(events);
        }
Example #8
0
        // Group: CodeDB.IChangeWatcher Functions
        // __________________________________________________________________________


        public void OnAddTopic(Topic topic, EventAccessor eventAccessor)
        {
            Monitor.Enter(newTopicIDsByEndingSymbol);

            try
            {
                if (beforeFirstResolve && EngineInstance.Config.ReparseEverything)
                {
                    // We don't need to track newTopicIDsByEndingSymbol in this case because the entire output will
                    // be reparsed and every link will be re-added.  Thus every link will be on linksToResolve and we don't
                    // need to worry about new topics causing existing links to need to be reresolved.
                }
                else
                {
                    IDObjects.NumberSet newTopicIDs = newTopicIDsByEndingSymbol[topic.Symbol.EndingSymbol];

                    if (newTopicIDs == null)
                    {
                        newTopicIDs = new IDObjects.NumberSet();
                        newTopicIDsByEndingSymbol.Add(topic.Symbol.EndingSymbol, newTopicIDs);
                    }

                    newTopicIDs.Add(topic.TopicID);
                }
            }
            finally
            {
                Monitor.Exit(newTopicIDsByEndingSymbol);
            }
        }
Example #9
0
        public void OnAddLink(Link link, EventAccessor eventAccessor)
        {
            Monitor.Enter(linksToResolve);

            try
            { linksToResolve.Add(link.LinkID); }
            finally
            { Monitor.Exit(linksToResolve); }
        }
Example #10
0
        public void DeleteEvent_InvalidEvent()
        {
            int expected = 1;

            setup();
            eventToEdit.EventItemID = 9999;
            int actual = EventAccessor.DeleteEventItem(eventToEdit);

            Assert.AreEqual(expected, actual);
        }
Example #11
0
        public void OnDeleteLink(Link link, EventAccessor eventAccessor)
        {
            // Just in case, so there's no hanging references

            Monitor.Enter(linksToResolve);

            try
            { linksToResolve.Remove(link.LinkID); }
            finally
            { Monitor.Exit(linksToResolve); }
        }
Example #12
0
 /// <summary>
 /// Bryan Hurst
 /// Created: 2015/04/03
 /// Deletes information concerning the test event
 /// </summary>
 /// <param name="testEvent"></param>
 /// <returns></returns>
 public int DeleteTestEvent(Event testEvent)
 {
     try
     {
         return(EventAccessor.DeleteEventTestItem(testEvent));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Example #13
0
        public void AddEvent_ValidEvent()
        {
            int expected = 1;

            setup();

            int actual = EventAccessor.AddEvent(eventToTest);

            EventAccessor.DeleteEventTestItem(eventToTest);

            Assert.AreEqual(expected, actual);
        }
Example #14
0
 /// <summary>
 /// Method for retrieving the test record Created: by these methods
 /// </summary>
 /// <param name="list"></param>
 /// <returns></returns>
 private Event getEventObjectID(List <Event> list)
 {
     list = EventAccessor.GetEventList();
     foreach (Event item in list)
     {
         if (item.EventItemName.Equals("TEST"))
         {
             return(item);
         }
     }
     return(new Event());
 }
Example #15
0
        public void UpdateEvent_ValidEvent()
        {
            int expected = 1;

            setup();
            EventAccessor.AddEvent(eventToTest);
            eventToTest = getEventObjectID(list);

            int actual = EventAccessor.UpdateEvent(eventToTest, eventToEdit);

            EventAccessor.DeleteEventTestItem(eventToEdit);

            Assert.AreEqual(expected, actual);
        }
Example #16
0
        public void GetEvent_Valid()
        {
            setup();

            string expected = eventToTest.EventItemName;

            EventAccessor.AddEvent(eventToTest);
            eventToEdit = getEventObjectID(list);

            Event actual = EventAccessor.GetEvent(eventToEdit.EventItemID.ToString());

            EventAccessor.DeleteEventTestItem(eventToTest);

            Assert.AreEqual(expected, actual.EventItemName);
        }
Example #17
0
        public List <Event> GetEventsByDate(string date)
        {
            // Get events by a given date
            List <Event> events;

            try
            {
                events = EventAccessor.RetrieveEventsByDate(date);
            }
            catch (Exception)
            {
                throw;
            }

            return(events);
        }
Example #18
0
        public List <Event> GetInactiveEvents()
        {
            // Retrieves and returns a list of inactive events
            List <Event> events = null;

            try
            {
                events = EventAccessor.RetrieveEventsByStatus(false);
                formatTimeForEvents(events);
            }
            catch (Exception)
            {
                throw;
            }

            return(events);
        }
Example #19
0
        public List <Event> GetAllEvents()
        {
            // Retrieves and returns a list of all events in DB
            List <Event> events = null;

            try
            {
                events = EventAccessor.RetrieveAllEvents();
                formatTimeForEvents(events);
            }
            catch (Exception)
            {
                throw;
            }

            return(events);
        }
Example #20
0
        public Event GetEventByID(int eventID)
        {
            // Find a specific event by the given ID
            Event selectedEvent = null;

            try
            {
                selectedEvent = EventAccessor.RetrieveEventByID(eventID);
            }
            catch (Exception)
            {
                throw;
            }

            formatTimeForEvent(selectedEvent);

            return(selectedEvent);
        }
Example #21
0
        public void Get_ReturnsEventDataQueryable()
        {
            // Arrange
            var mockDbSet     = Events.AsQueryable().BuildMockDbSet();
            var mockDbContext = new Mock <IEventDbContext>();

            mockDbContext
            .Setup(db => db.Events)
            .Returns(mockDbSet.Object);

            var eventAccessor = new EventAccessor(mockDbContext.Object);

            // Act
            var actualQueryable = eventAccessor.GetEventsQueryable();

            // Assert
            Assert.NotNull(actualQueryable);
            Assert.IsAssignableFrom <IQueryable <Event> >(actualQueryable);
        }
Example #22
0
        public bool AddNewEvent(Event ev)
        {
            // add a new event to the system.
            bool wasAdded = false;
            int  time     = stringTimeToInt(ev);

            try
            {
                // check if it actually was added
                if (1 == EventAccessor.InsertNewEvent(ev.Name, ev.Description, ev.Date, time, ev.Location, ev.MaxSeats, ev.Price, ev.AddedBy))
                {
                    wasAdded = true;
                }
            }
            catch (Exception)
            {
                throw;
            }

            return(wasAdded);
        }
Example #23
0
        // Group: CodeDB.IChangeWatcher Functions
        // __________________________________________________________________________


        public void OnAddTopic(Topic topic, EventAccessor eventAccessor)
        {
            // We don't need to track newTopicIDsByEndingSymbol when we're reparsing everything and nothing has been resolved
            // yet because the entire codebase will be reparsed and therefore every link will be re-added.  Every link will thus be on
            // linksToResolve and we don't need to worry about new topics causing existing links to need to be reresolved.

            if ((beforeFirstResolve && EngineInstance.Config.ReparseEverything) == false)
            {
                lock (newTopicIDsByEndingSymbol)
                {
                    IDObjects.NumberSet newTopicIDs = newTopicIDsByEndingSymbol[topic.Symbol.EndingSymbol];

                    if (newTopicIDs == null)
                    {
                        newTopicIDs = new IDObjects.NumberSet();
                        newTopicIDsByEndingSymbol.Add(topic.Symbol.EndingSymbol, newTopicIDs);
                    }

                    newTopicIDs.Add(topic.TopicID);
                }
            }
        }
Example #24
0
 /// <summary>
 /// Matt Lapka
 /// Created:  2015/01/31
 /// Edit an Event object
 /// </summary>
 /// <param name="oldEvent">The Event object to be updated</param>
 /// <param name="newEvent">The Event object with the updated information</param>
 /// <returns>An enumerated result depicting success or failure</returns>
 public EventResult EditEvent(Event oldEvent, Event newEvent)
 {
     try
     {
         if (EventAccessor.UpdateEvent(oldEvent, newEvent) == 1)
         {
             //update cache
             DataCache._currentEventList = EventAccessor.GetEventList();
             DataCache._EventListTime    = DateTime.Now;
             return(EventResult.Success);
         }
         return(EventResult.NotChanged);
     }
     catch (ApplicationException ex)
     {
         return(ex.Message == "Concurrency Violation" ? EventResult.ChangedByOtherUser : EventResult.DatabaseError);
     }
     catch (Exception)
     {
         return(EventResult.DatabaseError);
     }
 }
Example #25
0
 /// <summary>
 /// Matt Lapka
 /// Created:  2015/01/31
 /// "Delete" a single Event object (make inactive)
 /// </summary>
 /// <param name="eventToDelete">The Event object to be deleted/made inactive</param>
 /// <returns>An enumerated result depicting success or fail</returns>
 public EventResult ArchiveAnEvent(Event eventToDelete)
 {
     try
     {
         if (EventAccessor.DeleteEventItem(eventToDelete) == 1)
         {
             //update cache
             DataCache._currentEventList = EventAccessor.GetEventList();
             DataCache._EventListTime    = DateTime.Now;
             return(EventResult.Success);
         }
         return(EventResult.NotChanged);
     }
     catch (ApplicationException ex)
     {
         return(ex.Message == "Concurrency Violation" ? EventResult.ChangedByOtherUser : EventResult.DatabaseError);
     }
     catch (Exception)
     {
         return(EventResult.DatabaseError);
     }
 }
Example #26
0
        public void EventSearch_Test()
        {
            //arrange
            setup();
            String inSearch = "Boat";
            //myMan.AddNewEvent(toTest);
            List <Event> expected = new List <Event>();

            expected.Add(toTest);

            //update cache
            DataCache._currentEventList = EventAccessor.GetEventList();
            DataCache._EventListTime    = DateTime.Now;
            // act
            List <Event> myTempList = new List <Event>();

            myTempList = myMan.EventSearch(inSearch);
            Event[] myArray = myTempList.ToArray();

            //assert
            Assert.IsNotNull(myArray[0].EventItemName);
        }
Example #27
0
        public List <RoomEvent> GetEventsForRoom(string roomID)
        {
            // return a list of rooms associated with an event
            List <RoomEvent> events = null;

            try
            {
                events = EventAccessor.RetrieveEventsByRoomID(roomID);
            }
            catch (Exception)
            {
                throw;
            }

            // get the total cost calculated here. It is not stored.
            foreach (RoomEvent re in events)
            {
                re.TotalPrice = re.TicketsReserved * re.IndividualPrice;
            }

            return(events);
        }
Example #28
0
        public int ClearOldEvents()
        {
            // deactivate any events in the past.
            int rows = 0;

            int today = DateTime.Today.Day;   // current day
            int month = DateTime.Today.Month; // current month
            int year  = DateTime.Today.Year;  // current year

            // format it for Sql
            string currentDate = month + "-" + today + "-" + year;

            try
            {
                EventAccessor.DeactivateOldEvents(currentDate);
            }
            catch (Exception)
            {
                throw;
            }

            return(rows);
        }
Example #29
0
        public bool EditEvent(Event oldEvent, Event newEvent)
        {
            // update an event in the system
            bool edited  = false;
            int  oldTime = stringTimeToInt(oldEvent);
            int  newTime = stringTimeToInt(newEvent);

            try
            {
                if (1 == EventAccessor.UpdateEvent(oldEvent.EventID, oldEvent.Name, oldEvent.Description, oldEvent.Date, oldTime,
                                                   oldEvent.Location, oldEvent.MaxSeats, oldEvent.Price, oldEvent.AddedBy, oldEvent.Active,
                                                   newEvent.Name, newEvent.Description, newEvent.Date, newTime, newEvent.Location, newEvent.MaxSeats,
                                                   newEvent.Price, newEvent.AddedBy, newEvent.Active))
                {
                    edited = true;
                }
            }
            catch (Exception)
            {
                throw;
            }

            return(edited);
        }
Example #30
0
 internal static void event_accessors(this TextWriter trapFile, EventAccessor accessorKey, int type, string name, Event eventKey, EventAccessor unboundAccessor)
 {
     trapFile.WriteTuple("event_accessors", accessorKey, type, name, eventKey, unboundAccessor);
 }