/// <summary> /// Gets the InteractionDeveiceTypeId or creates one if it does not exist. /// This method uses its own RockContext so it doesn't interfere with the Interaction. /// </summary> /// <param name="application">The application.</param> /// <param name="operatingSystem">The operating system.</param> /// <param name="clientType">Type of the client.</param> /// <param name="deviceTypeData">The device type data.</param> /// <returns>InteractionDeveiceType.Id</returns> private int GetOrCreateInteractionDeviceTypeId(string application, string operatingSystem, string clientType, string deviceTypeData) { var rockContext = new RockContext(); InteractionDeviceTypeService interactionDeviceTypeService = new InteractionDeviceTypeService(rockContext); InteractionDeviceType interactionDeviceType = interactionDeviceTypeService.Queryable() .Where(a => a.Application == application && a.OperatingSystem == operatingSystem && a.ClientType == clientType) .FirstOrDefault(); if (interactionDeviceType == null) { interactionDeviceType = new InteractionDeviceType { DeviceTypeData = deviceTypeData, ClientType = clientType, OperatingSystem = operatingSystem, Application = application, Name = string.Format("{0} - {1}", operatingSystem, application) }; interactionDeviceTypeService.Add(interactionDeviceType); rockContext.SaveChanges(); } return(interactionDeviceType.Id); }
public InteractionDeviceType GetInteractionDeviceType(string application, string operatingSystem, string clientType, string deviceTypeData) { /* * 2020-10-22 ETD * This method was used by GetInteractionDeviceTypeId(). Discussed with Mike and Nick and it was * decided to mark it as obsolete and create private method GetOrCreateInteractionDeviceTypeId() * instead. */ var rockContext = new RockContext(); InteractionDeviceTypeService interactionDeviceTypeService = new InteractionDeviceTypeService(rockContext); InteractionDeviceType interactionDeviceType = interactionDeviceTypeService.Queryable() .Where(a => a.Application == application && a.OperatingSystem == operatingSystem && a.ClientType == clientType) .FirstOrDefault(); if (interactionDeviceType == null) { interactionDeviceType = new InteractionDeviceType(); interactionDeviceType.DeviceTypeData = deviceTypeData; interactionDeviceType.ClientType = clientType; interactionDeviceType.OperatingSystem = operatingSystem; interactionDeviceType.Application = application; interactionDeviceType.Name = string.Format("{0} - {1}", operatingSystem, application); interactionDeviceTypeService.Add(interactionDeviceType); rockContext.SaveChanges(); } return(interactionDeviceType); }
/// <summary> /// Clones this InteractionDeviceType object to a new InteractionDeviceType 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 InteractionDeviceType Clone(this InteractionDeviceType source, bool deepCopy) { if (deepCopy) { return(source.Clone() as InteractionDeviceType); } else { var target = new InteractionDeviceType(); target.CopyPropertiesFrom(source); return(target); } }
/// <summary> /// Creates the interaction. /// </summary> /// <param name="interactionComponentId">The interaction component identifier.</param> /// <param name="userAgent">The user agent.</param> /// <param name="url">The URL.</param> /// <param name="ipAddress">The ip address.</param> /// <param name="browserSessionId">The browser session identifier.</param> /// <returns></returns> public Interaction CreateInteraction(int interactionComponentId, string userAgent, string url, string ipAddress, Guid?browserSessionId) { userAgent = userAgent ?? string.Empty; var deviceOs = uaParser.ParseOS(userAgent).ToString(); var deviceApplication = uaParser.ParseUserAgent(userAgent).ToString(); var deviceClientType = InteractionDeviceType.GetClientType(userAgent); var interaction = CreateInteraction(interactionComponentId, null, null, string.Empty, null, null, RockDateTime.Now, deviceApplication, deviceOs, deviceClientType, userAgent, ipAddress, browserSessionId); interaction.SetUTMFieldsFromURL(url); return(interaction); }
/// <summary> /// Copies the properties from another InteractionDeviceType object to this InteractionDeviceType object /// </summary> /// <param name="target">The target.</param> /// <param name="source">The source.</param> public static void CopyPropertiesFrom(this InteractionDeviceType target, InteractionDeviceType source) { target.Id = source.Id; target.Application = source.Application; target.ClientType = source.ClientType; target.DeviceTypeData = source.DeviceTypeData; target.ForeignGuid = source.ForeignGuid; target.ForeignKey = source.ForeignKey; target.Name = source.Name; target.OperatingSystem = source.OperatingSystem; target.CreatedDateTime = source.CreatedDateTime; target.ModifiedDateTime = source.ModifiedDateTime; target.CreatedByPersonAliasId = source.CreatedByPersonAliasId; target.ModifiedByPersonAliasId = source.ModifiedByPersonAliasId; target.Guid = source.Guid; target.ForeignId = source.ForeignId; }
/// <summary> /// Creates the interaction. /// </summary> /// <param name="interactionComponentId">The interaction component identifier.</param> /// <param name="userAgent">The user agent.</param> /// <param name="url">The URL.</param> /// <param name="ipAddress">The ip address.</param> /// <param name="browserSessionId">The browser session identifier.</param> /// <returns></returns> public Interaction CreateInteraction(int interactionComponentId, string userAgent, string url, string ipAddress, Guid?browserSessionId) { userAgent = userAgent ?? string.Empty; var deviceOs = uaParser.ParseOS(userAgent).ToString(); var deviceApplication = uaParser.ParseUserAgent(userAgent).ToString(); var deviceClientType = InteractionDeviceType.GetClientType(userAgent); var interaction = CreateInteraction(interactionComponentId, null, null, string.Empty, null, null, RockDateTime.Now, deviceApplication, deviceOs, deviceClientType, userAgent, ipAddress, browserSessionId); if (url.IsNotNullOrWhiteSpace() && url.IndexOf("utm_", StringComparison.OrdinalIgnoreCase) >= 0) { var urlParams = System.Web.HttpUtility.ParseQueryString(url); interaction.Source = urlParams.Get("utm_source").Truncate(25); interaction.Medium = urlParams.Get("utm_medium").Truncate(25); interaction.Campaign = urlParams.Get("utm_campaign").Truncate(50); interaction.Content = urlParams.Get("utm_content").Truncate(50); interaction.Term = urlParams.Get("utm_term").Truncate(50); } return(interaction); }
/// <summary> /// Gets the interaction device type. If it can't be found, a new InteractionDeviceType record will be created and returned. /// </summary> /// <param name="application">The application.</param> /// <param name="operatingSystem">The operating system.</param> /// <param name="clientType">Type of the client.</param> /// <param name="deviceTypeData">The device type data (either a plain DeviceType name or the whole useragent string).</param> /// <returns></returns> public InteractionDeviceType GetInteractionDeviceType(string application, string operatingSystem, string clientType, string deviceTypeData) { using (var rockContext = new RockContext()) { InteractionDeviceTypeService interactionDeviceTypeService = new InteractionDeviceTypeService(rockContext); InteractionDeviceType interactionDeviceType = interactionDeviceTypeService.Queryable().Where(a => a.Application == application && a.OperatingSystem == operatingSystem && a.ClientType == clientType).FirstOrDefault(); if (interactionDeviceType == null) { interactionDeviceType = new InteractionDeviceType(); interactionDeviceType.DeviceTypeData = deviceTypeData; interactionDeviceType.ClientType = clientType; interactionDeviceType.OperatingSystem = operatingSystem; interactionDeviceType.Application = application; interactionDeviceType.Name = string.Format("{0} - {1}", operatingSystem, application); interactionDeviceTypeService.Add(interactionDeviceType); rockContext.SaveChanges(); } return(interactionDeviceType); } }