/// <summary>
 /// Return all items in the Repository
 /// </summary>
 /// <returns></returns>
 public IList<Speaker> GetAll()
 {
     using (var context = new CodemashContext())
     {
         return context.Speakers.ToList();
     }
 }
 /// <summary>
 /// Return all items in the Repository
 /// </summary>
 /// <returns></returns>
 public IList <Session> GetAll()
 {
     using (var context = new CodemashContext())
     {
         return(context.Sessions.ToList());
     }
 }
Example #3
0
 /// <summary>
 /// Return all items in the repository matching the given condition
 /// </summary>
 /// <param name="condition">A condition passed as a lambda predicate</param>
 /// <returns></returns>
 public IList <Change> GetAll(Func <Change, bool> condition)
 {
     using (var context = new CodemashContext())
     {
         return(GetAll(context, condition));
     }
 }
 /// <summary>
 /// Return all items in the Repository
 /// </summary>
 /// <returns></returns>
 public IList <Speaker> GetAll()
 {
     using (var context = new CodemashContext())
     {
         return(context.Speakers.ToList());
     }
 }
Example #5
0
 /// <summary>
 /// Return the first instance of T which makes the given condition
 /// </summary>
 /// <param name="condition">The condition passed as a lambda predicate</param>
 /// <returns></returns>
 public Change Get(Func <Change, bool> condition)
 {
     using (var context = new CodemashContext())
     {
         return(context.Changes.FirstOrDefault(condition));
     }
 }
Example #6
0
 /// <summary>
 /// Return all items in the Repository
 /// </summary>
 /// <returns></returns>
 public IList <Change> GetAll()
 {
     using (var context = new CodemashContext())
     {
         return(context.Changes.ToList());
     }
 }
 /// <summary>
 /// Return all items in the repository matching the given condition
 /// </summary>
 /// <param name="condition">A condition passed as a lambda predicate</param>
 /// <returns></returns>
 public IList <Speaker> GetAll(Func <Speaker, bool> condition)
 {
     using (var context = new CodemashContext())
     {
         return(context.Speakers.Where(condition).ToList());
     }
 }
 /// <summary>
 /// Return the first instance of T which makes the given condition
 /// </summary>
 /// <param name="condition">The condition passed as a lambda predicate</param>
 /// <returns></returns>
 public Session Get(Func <Session, bool> condition)
 {
     using (var context = new CodemashContext())
     {
         return(context.Sessions.FirstOrDefault(condition));
     }
 }
 /// <summary>
 /// Return all items in the repository matching the given condition
 /// </summary>
 /// <param name="condition">A condition passed as a lambda predicate</param>
 /// <returns></returns>
 public IList <Session> GetAll(Func <Session, bool> condition)
 {
     using (var context = new CodemashContext())
     {
         return(context.Sessions.Where(condition).ToList());
     }
 }
 /// <summary>
 /// Return all items in the repository matching the given condition
 /// </summary>
 /// <param name="condition">A condition passed as a lambda predicate</param>
 /// <returns></returns>
 public IList<Speaker> GetAll(Func<Speaker, bool> condition)
 {
     using (var context = new CodemashContext())
     {
         return context.Speakers.Where(condition).ToList();
     }
 }
 /// <summary>
 /// Return all items in the Repository
 /// </summary>
 /// <returns></returns>
 public IList<Session> GetAll()
 {
     using (var context = new CodemashContext())
     {
         return context.Sessions.ToList();
     }
 }
 /// <summary>
 /// Return all items in the repository matching the given condition
 /// </summary>
 /// <param name="condition">A condition passed as a lambda predicate</param>
 /// <returns></returns>
 public IList<Session> GetAll(Func<Session, bool> condition)
 {
     using (var context = new CodemashContext())
     {
         return context.Sessions.Where(condition).ToList();
     }
 }
 /// <summary>
 /// Return the first instance of T which makes the given condition
 /// </summary>
 /// <param name="condition">The condition passed as a lambda predicate</param>
 /// <returns></returns>
 public Session Get(Func<Session, bool> condition)
 {
     using (var context = new CodemashContext())
     {
         return context.Sessions.FirstOrDefault(condition);
     }
 }
 /// <summary>
 /// Return a client instance based on the channel URI to identify it
 /// </summary>
 /// <param name="channel">The channel URI which identifies the client</param>
 /// <returns></returns>
 public Client Get(string channel)
 {
     using (var context = new CodemashContext())
     {
         return context.Clients.FirstOrDefault(c => c.ChannelUri == channel);
     }
 }
 /// <summary>
 /// Return a client instance based on the channel URI to identify it
 /// </summary>
 /// <param name="channel">The channel URI which identifies the client</param>
 /// <returns></returns>
 public Client Get(string channel)
 {
     using (var context = new CodemashContext())
     {
         return(context.Clients.FirstOrDefault(c => c.ChannelUri == channel));
     }
 }
 /// <summary>
 /// Return the first instance of T which makes the given condition
 /// </summary>
 /// <param name="condition">The condition passed as a lambda predicate</param>
 /// <returns></returns>
 public Speaker Get(Func <Speaker, bool> condition)
 {
     using (var context = new CodemashContext())
     {
         return(context.Speakers.FirstOrDefault(condition));
     }
 }
 /// <summary>
 /// Return the first instance of T which makes the given condition
 /// </summary>
 /// <param name="condition">The condition passed as a lambda predicate</param>
 /// <returns></returns>
 public Speaker Get(Func<Speaker, bool> condition)
 {
     using (var context = new CodemashContext())
     {
         return context.Speakers.FirstOrDefault(condition);
     }
 }
 /// <summary>
 /// Return whether the current Channel URI is already registered with the service
 /// </summary>
 /// <param name="clientUri">The Channel URI identifying the client</param>
 /// <returns></returns>
 public bool IsClientRegistered(string clientUri)
 {
     using (var context = new CodemashContext())
     {
         return context.Clients.FirstOrDefault(
             c => string.Compare(c.ChannelUri, clientUri, StringComparison.OrdinalIgnoreCase) == 0) != null;
     }
 }
 /// <summary>
 /// Return whether the current Channel URI is already registered with the service
 /// </summary>
 /// <param name="clientUri">The Channel URI identifying the client</param>
 /// <returns></returns>
 public bool IsClientRegistered(string clientUri)
 {
     using (var context = new CodemashContext())
     {
         return(context.Clients.FirstOrDefault(
                    c => string.Compare(c.ChannelUri, clientUri, StringComparison.OrdinalIgnoreCase) == 0) != null);
     }
 }
        /// <summary>
        /// Commit all changes in the repository
        /// </summary>
        public void SaveRange(IEnumerable <Speaker> entityList)
        {
            using (var context = new CodemashContext())
            {
                SaveChanges(context, entityList);
                SaveRemovals(context, entityList);

                context.SaveChanges();
            }
        }
        /// <summary>
        /// Commit all changes in the repository
        /// </summary>
        public void SaveRange(IEnumerable<Speaker> entityList)
        {
            using (var context = new CodemashContext())
            {
                SaveChanges(context, entityList);
                SaveRemovals(context, entityList);

                context.SaveChanges();
            }
        }
        /// <summary>
        /// Remove the sessions in the database which do not appear in the incoming session list
        /// </summary>
        /// <param name="context"></param>
        /// <param name="sessions"></param>
        private static void SaveRemovals(CodemashContext context, IList <Session> sessions)
        {
            // first check if the session has been totally removed
            var existingSessions = context.Sessions.Select(s => s.SessionId);
            var masterSessions   = sessions.Select(s => s.SessionId);
            var sessionsToRemove = existingSessions.Where(i => !masterSessions.Contains(i)).ToList();

            // perform the mass update
            sessionsToRemove.ForEach(s => context.Sessions.Remove(context.Sessions.FirstOrDefault(se => se.SessionId == s)));
        }
 /// <summary>
 /// Update the client identified by the channel Uri to the latest changeset
 /// </summary>
 /// <param name="channelUri">The channel URI used to identify a client</param>
 /// <param name="changesetLoaded">The changeset of the most recently loaded changeset</param>
 public void UpdateClientChangeset(string channelUri, int changesetLoaded)
 {
     using (var context = new CodemashContext())
     {
         var client = context.Clients.FirstOrDefault(c => c.ChannelUri == channelUri);
         if (client != null)
         {
             client.CurrentChangeSet = changesetLoaded;
             context.SaveChanges();
         }
     }
 }
 /// <summary>
 /// Update the client identified by the channel Uri to the latest changeset
 /// </summary>
 /// <param name="channelUri">The channel URI used to identify a client</param>
 /// <param name="changesetLoaded">The changeset of the most recently loaded changeset</param>
 public void UpdateClientChangeset(string channelUri, int changesetLoaded)
 {
     using (var context = new CodemashContext())
     {
         var client = context.Clients.FirstOrDefault(c => c.ChannelUri == channelUri);
         if (client != null)
         {
             client.CurrentChangeSet = changesetLoaded;
             context.SaveChanges();
         }
     }
 }
        private void SaveRemovals(CodemashContext context, IEnumerable <Speaker> speakers)
        {
            var masterSpeakers   = speakers.Select(sp => sp.SpeakerId).ToList();
            var existingSpeakers = context.Speakers.Select(sp => sp.SpeakerId).ToList();
            var removals         = existingSpeakers.Where(sp => !masterSpeakers.Contains(sp));

            foreach (var speakerId in removals)
            {
                var speaker = context.Speakers.First(sp => sp.SpeakerId == speakerId);
                context.Speakers.Remove(speaker);
            }
        }
Example #26
0
        public IEnumerable <Change> GetChangesForClient(int clientId)
        {
            using (var context = new CodemashContext())
            {
                var client = context.Clients.FirstOrDefault(c => c.ClientId == clientId);
                if (client == null)
                {
                    throw new ClientNotFoundException();
                }

                return(context.Changes.Where(c => c.ChangeId > client.CurrentChangeSet).ToList());
            }
        }
        /// <summary>
        /// Register a client for push notifications
        /// </summary>
        /// <param name="client"></param>
        public void RegisterClient(Client client)
        {
            using (var context = new CodemashContext())
            {
                // determine the latest changeset number
                var changeset = 0;
                if (context.Changes.Any())
                    changeset = context.Changes.Max(c => c.Changeset);

                client.CurrentChangeSet = changeset;
                context.Clients.Add(client);
                context.SaveChanges();
            }
        }
Example #28
0
        /// <summary>
        /// Return the SessionChanges as part of the latest version of changes
        /// </summary>
        /// <returns></returns>
        public IEnumerable <Change> GetLatest()
        {
            using (var context = new CodemashContext())
            {
                // if no sessions exist, return an empty list
                if (!context.Changes.Any())
                {
                    return(new List <Change>());
                }

                // latest version is
                var version = context.Changes.Max(sc => sc.Changeset);
                return(GetAll(context, sc => sc.Changeset == version));
            }
        }
        /// <summary>
        /// Register a client for push notifications
        /// </summary>
        /// <param name="client"></param>
        public void RegisterClient(Client client)
        {
            using (var context = new CodemashContext())
            {
                // determine the latest changeset number
                var changeset = 0;
                if (context.Changes.Any())
                {
                    changeset = context.Changes.Max(c => c.Changeset);
                }

                client.CurrentChangeSet = changeset;
                context.Clients.Add(client);
                context.SaveChanges();
            }
        }
        private void SaveChanges(CodemashContext context, IEnumerable<Speaker> speakers)
        {
            foreach (var entity in speakers)
            {
                var result = context.Speakers.FirstOrDefault(sp => sp.SpeakerId == entity.SpeakerId);
                if (result == null)
                {
                    context.Speakers.Add(entity);
                    continue;
                }

                result.Biography = entity.Biography;
                result.BlogUrl = entity.BlogUrl;
                result.EmailAddress = entity.EmailAddress;
                result.Name = entity.Name;
            }
        }
        private void SaveChanges(CodemashContext context, IEnumerable <Speaker> speakers)
        {
            foreach (var entity in speakers)
            {
                var result = context.Speakers.FirstOrDefault(sp => sp.SpeakerId == entity.SpeakerId);
                if (result == null)
                {
                    context.Speakers.Add(entity);
                    continue;
                }

                result.Biography    = entity.Biography;
                result.BlogUrl      = entity.BlogUrl;
                result.EmailAddress = entity.EmailAddress;
                result.Name         = entity.Name;
            }
        }
        /// <summary>
        /// Apply the changes (add/remove) from a Master Session List
        /// </summary>
        /// <param name="masterSessionList">The session data from the master source</param>
        /// <remarks>The incoming range is expected to be the full measure of session data</remarks>
        public void SaveRange(IEnumerable<Session> masterSessionList)
        {
            var masterList = masterSessionList.ToList();
            using (var context = new CodemashContext())
            {
                // get all available speakers
                var availabelSpeakers = context.Speakers.Select(sp => sp.SpeakerId).ToArray();

                // filter the master list so that sessions which do not have a valid speaker are not included
                masterList = masterList.Where(s => availabelSpeakers.Contains(s.SpeakerId)).ToList();

                SaveChanges(context, masterList);
                SaveRemovals(context, masterList);

                context.SaveChanges();
            }
        }
 public void test_that_all_tables_are_empty()
 {
     try
     {
         using (var context = new CodemashContext())
         {
             Assert.AreEqual(0, context.Changes.Count());
             Assert.AreEqual(0, context.Sessions.Count());
             Assert.AreEqual(0, context.Speakers.Count());
             Assert.IsTrue(true);
         }
     }
     catch (Exception ex)
     {
         Assert.Fail("Exception Occured");
     }
 }
        /// <summary>
        /// Apply the changes (add/remove) from a Master Session List
        /// </summary>
        /// <param name="masterSessionList">The session data from the master source</param>
        /// <remarks>The incoming range is expected to be the full measure of session data</remarks>
        public void SaveRange(IEnumerable <Session> masterSessionList)
        {
            var masterList = masterSessionList.ToList();

            using (var context = new CodemashContext())
            {
                // get all available speakers
                var availabelSpeakers = context.Speakers.Select(sp => sp.SpeakerId).ToArray();

                // filter the master list so that sessions which do not have a valid speaker are not included
                masterList = masterList.Where(s => availabelSpeakers.Contains(s.SpeakerId)).ToList();

                SaveChanges(context, masterList);
                SaveRemovals(context, masterList);

                context.SaveChanges();
            }
        }
        /// <summary>
        /// Execute the represented process
        /// </summary>
        public void Execute()
        {
            // check each client to make sure they are at the current highest changeset
            using (var context = new CodemashContext())
            {
                var changeList = context.Changes.ToList();
                if (changeList.Count > 0)
                {
                    int currentChangeset = changeList.Max(c => c.Changeset);
                    foreach (var client in context.Clients.Where(c => c.CurrentChangeSet < currentChangeset))
                    {
                        int changesetDifference = currentChangeset - client.CurrentChangeSet;
                        var manager = NotificationManagerResolver.Resolve(client.ClientType);

                        manager.SendTileNotification(client.ChannelUri, changesetDifference);
                        manager.SendToastNotification(client.ChannelUri, changesetDifference);
                    }
                }
            }
        }
Example #36
0
        /// <summary>
        /// Commit all changes in the repository
        /// </summary>
        public void SaveRange(IEnumerable <Change> entityList)
        {
            // establish the changeset number
            int changeset = 1;

            using (var context = new CodemashContext())
            {
                if (context.Changes.Any())
                {
                    changeset = context.Changes.Max(c => c.Changeset) + 1;
                }

                foreach (var change in entityList)
                {
                    change.Changeset = changeset;
                    context.Changes.Add(change);
                }

                context.SaveChanges();
            }
        }
        /// <summary>
        /// Save modifications to the existing session data
        /// </summary>
        /// <param name="context"></param>
        /// <param name="sessions"></param>
        private static void SaveChanges(CodemashContext context, IEnumerable <Session> sessions)
        {
            var existingSessions = context.Sessions.ToList();

            foreach (var session in sessions.ToList())
            {
                var existingSession = existingSessions.FirstOrDefault(s => s.SessionId == session.SessionId);
                if (existingSession == null)
                {
                    context.Sessions.Add(session);
                    continue;
                }

                // copy the fields to the existing object
                existingSession.Title     = session.Title;
                existingSession.Abstract  = session.Abstract;
                existingSession.Start     = session.Start;
                existingSession.End       = session.End;
                existingSession.Level     = session.Level;
                existingSession.Room      = session.Room;
                existingSession.SpeakerId = session.SpeakerId;
                existingSession.Track     = session.Track;
            }
        }
Example #38
0
 /// <summary>
 /// Private version of GetAll which can receive an external context - this allows other methods with existing contexts to share
 /// this functionality
 /// </summary>
 /// <param name="context"></param>
 /// <param name="condition"></param>
 /// <returns></returns>
 private static IList <Change> GetAll(CodemashContext context, Func <Change, bool> condition)
 {
     return(context.Changes.Where(condition).ToList());
 }
        /// <summary>
        /// Remove the sessions in the database which do not appear in the incoming session list
        /// </summary>
        /// <param name="context"></param>
        /// <param name="sessions"></param>
        private static void SaveRemovals(CodemashContext context, IList<Session> sessions)
        {
            // first check if the session has been totally removed
            var existingSessions = context.Sessions.Select(s => s.SessionId);
            var masterSessions = sessions.Select(s => s.SessionId);
            var sessionsToRemove = existingSessions.Where(i => !masterSessions.Contains(i)).ToList();

            // perform the mass update
            sessionsToRemove.ForEach(s => context.Sessions.Remove(context.Sessions.FirstOrDefault(se => se.SessionId == s)));
        }
        private void SaveRemovals(CodemashContext context, IEnumerable<Speaker> speakers)
        {
            var masterSpeakers = speakers.Select(sp => sp.SpeakerId).ToList();
            var existingSpeakers = context.Speakers.Select(sp => sp.SpeakerId).ToList();
            var removals = existingSpeakers.Where(sp => !masterSpeakers.Contains(sp));

            foreach (var speakerId in removals)
            {
                var speaker = context.Speakers.First(sp => sp.SpeakerId == speakerId);
                context.Speakers.Remove(speaker);
            }
        }
        /// <summary>
        /// Save modifications to the existing session data
        /// </summary>
        /// <param name="context"></param>
        /// <param name="sessions"></param>
        private static void SaveChanges(CodemashContext context, IEnumerable<Session> sessions)
        {
            var existingSessions = context.Sessions.ToList();
            foreach (var session in sessions.ToList())
            {
                var existingSession = existingSessions.FirstOrDefault(s => s.SessionId == session.SessionId);
                if (existingSession == null)
                {
                    context.Sessions.Add(session);
                    continue;
                }

                // copy the fields to the existing object
                existingSession.Title = session.Title;
                existingSession.Abstract = session.Abstract;
                existingSession.Start = session.Start;
                existingSession.End = session.End;
                existingSession.Level = session.Level;
                existingSession.Room = session.Room;
                existingSession.SpeakerId = session.SpeakerId;
                existingSession.Track = session.Track;
            }
        }