/// <summary>
        /// Gets the interaction session. If browserSessionId isn't specified, or it can't be found, a new InteractionSession record will be created and returned.
        /// </summary>
        /// <param name="browserSessionId">The browser session identifier (RockSessionId).</param>
        /// <param name="ipAddress">The ip address.</param>
        /// <param name="interactionDeviceTypeId">The interaction device type identifier.</param>
        /// <returns></returns>
        public InteractionSession GetInteractionSession(Guid?browserSessionId, string ipAddress, int?interactionDeviceTypeId)
        {
            using (var rockContext = new RockContext())
            {
                InteractionSessionService interactionSessionService = new InteractionSessionService(rockContext);
                InteractionSession        interactionSession        = null;

                // if we have a browser session id, see if a session record was already created
                if (browserSessionId.HasValue)
                {
                    interactionSession = interactionSessionService.Queryable().Where(a => a.Guid == browserSessionId.Value).FirstOrDefault();
                }

                if (interactionSession == null)
                {
                    interactionSession = new InteractionSession();
                    interactionSession.DeviceTypeId = interactionDeviceTypeId;
                    interactionSession.IpAddress    = ipAddress;
                    interactionSession.Guid         = browserSessionId ?? Guid.NewGuid();
                    interactionSessionService.Add(interactionSession);
                    rockContext.SaveChanges();
                }

                return(interactionSession);
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Clones this InteractionSession object to a new InteractionSession object
 /// </summary>
 /// <param name="source">The source.</param>
 /// <param name="deepCopy">if set to <c>true</c> a deep copy is made. If false, only the basic entity properties are copied.</param>
 /// <returns></returns>
 public static InteractionSession Clone(this InteractionSession source, bool deepCopy)
 {
     if (deepCopy)
     {
         return(source.Clone() as InteractionSession);
     }
     else
     {
         var target = new InteractionSession();
         target.CopyPropertiesFrom(source);
         return(target);
     }
 }
Esempio n. 3
0
 /// <summary>
 /// Copies the properties from another InteractionSession object to this InteractionSession object
 /// </summary>
 /// <param name="target">The target.</param>
 /// <param name="source">The source.</param>
 public static void CopyPropertiesFrom(this InteractionSession target, InteractionSession source)
 {
     target.Id                      = source.Id;
     target.DeviceTypeId            = source.DeviceTypeId;
     target.ForeignGuid             = source.ForeignGuid;
     target.ForeignKey              = source.ForeignKey;
     target.InteractionMode         = source.InteractionMode;
     target.IpAddress               = source.IpAddress;
     target.SessionData             = source.SessionData;
     target.CreatedDateTime         = source.CreatedDateTime;
     target.ModifiedDateTime        = source.ModifiedDateTime;
     target.CreatedByPersonAliasId  = source.CreatedByPersonAliasId;
     target.ModifiedByPersonAliasId = source.ModifiedByPersonAliasId;
     target.Guid                    = source.Guid;
     target.ForeignId               = source.ForeignId;
 }