/// <summary> /// Renders the specified context. /// </summary> /// <param name="context">The context.</param> /// <param name="result">The result.</param> public override void Render(Context context, TextWriter result) { // First, ensure that this command is allowed in the context. if (!LavaHelper.IsAuthorized(context, this.GetType().Name)) { result.Write(string.Format(RockLavaBlockBase.NotAuthorizedMessage, this.Name)); base.Render(context, result); return; } // Parse the Lava Command markup to retrieve paramters. var parms = new Dictionary <string, string> { { ParameterKey.Operation, "View" } }; LavaHelper.ParseCommandMarkup(_markup, context, parms); // Set local variables from parsed parameters. int?contentChannelItemId = parms.GetValueOrNull(ParameterKey.ContentChannelItemId).AsIntegerOrNull(); if (!contentChannelItemId.HasValue) { // Do nothing if a ContentChannelItem ID wasn't specified. return; } ContentChannelItem contentChannelItem = null; using (var rockContext = new RockContext()) { contentChannelItem = new ContentChannelItemService(rockContext) .Queryable("ContentChannel") .AsNoTracking() .FirstOrDefault(c => c.Id == contentChannelItemId.Value); } ContentChannel contentChannel = contentChannelItem.ContentChannel; if (contentChannelItem == null || contentChannel == null) { // The caller supplied an invalid ContentChannelItem ID; nothing to do. return; } string operation = parms.GetValueOrNull(ParameterKey.Operation); string summary = parms.GetValueOrNull(ParameterKey.Summary); string source = parms.GetValueOrNull(ParameterKey.Source); string medium = parms.GetValueOrNull(ParameterKey.Medium); string campaign = parms.GetValueOrNull(ParameterKey.Campaign); string content = parms.GetValueOrNull(ParameterKey.Content); string term = parms.GetValueOrNull(ParameterKey.Term); int?personAliasId = parms.GetValueOrNull(ParameterKey.PersonAliasId).AsIntegerOrNull(); if (!personAliasId.HasValue) { Person currentPerson = LavaHelper.GetCurrentPerson(context); personAliasId = LavaHelper.GetPrimaryPersonAliasId(currentPerson); } // Write the Interaction by way of a transaction. DefinedValueCache mediumType = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.INTERACTIONCHANNELTYPE_CONTENTCHANNEL.AsGuid()); if (mediumType == null) { return; } var info = new InteractionTransactionInfo { ChannelTypeMediumValueId = mediumType.Id, ChannelEntityId = contentChannel.Id, ChannelName = contentChannel.ToString(), ComponentEntityTypeId = contentChannel.TypeId, ComponentEntityId = contentChannelItem.Id, ComponentName = contentChannelItem.ToString(), InteractionOperation = operation, InteractionSummary = summary ?? contentChannelItem.Title, PersonAliasId = personAliasId, InteractionSource = source, InteractionMedium = medium, InteractionCampaign = campaign, InteractionContent = content, InteractionTerm = term }; var interactionTransaction = new InteractionTransaction(info); interactionTransaction.Enqueue(); }
/// <summary> /// Renders the specified context. /// </summary> /// <param name="context">The context.</param> /// <param name="result">The result.</param> public override void Render(Context context, TextWriter result) { // First, ensure that this command is allowed in the context. if (!this.IsAuthorized(context)) { result.Write(string.Format(RockLavaBlockBase.NotAuthorizedMessage, this.Name)); return; } // Parse the Lava Command markup to retrieve paramters. var parms = new Dictionary <string, string>(); LavaHelper.ParseCommandMarkup(_markup, context, parms); // Set local variables from parsed parameters. // InteractionChannel variables. int?channelTypeMediumValueId = parms.GetValueOrNull(ParameterKey.ChannelTypeMediumValueId).AsIntegerOrNull(); if (!channelTypeMediumValueId.HasValue) { // Do nothing if a ChannelTypeMediumValueId wasn't specified. return; } DefinedValueCache channelTypeMediumValue = DefinedValueCache.Get(channelTypeMediumValueId.Value); if (channelTypeMediumValue == null) { // Do nothing if an invalid ChannelTypeMediumValueId was specified. return; } int? channelEntityId = parms.GetValueOrNull(ParameterKey.ChannelEntityId).AsIntegerOrNull(); string channelName = parms.GetValueOrNull(ParameterKey.ChannelName); int?componentEntityTypeId = parms.GetValueOrNull(ParameterKey.ComponentEntityTypeId).AsIntegerOrNull(); int?interactionEntityTypeId = parms.GetValueOrNull(ParameterKey.InteractionEntityTypeId).AsIntegerOrNull(); // InteractionComponent variables. int? componentEntityId = parms.GetValueOrNull(ParameterKey.ComponentEntityId).AsIntegerOrNull(); string componentName = parms.GetValueOrNull(ParameterKey.ComponentName); // Interaction variables. int?entityId = parms.GetValueOrNull(ParameterKey.EntityId).AsIntegerOrNull(); string operation = parms.GetValueOrNull(ParameterKey.Operation); string summary = parms.GetValueOrNull(ParameterKey.Summary); string source = parms.GetValueOrNull(ParameterKey.Source); string medium = parms.GetValueOrNull(ParameterKey.Medium); string campaign = parms.GetValueOrNull(ParameterKey.Campaign); string content = parms.GetValueOrNull(ParameterKey.Content); string term = parms.GetValueOrNull(ParameterKey.Term); int?relatedEntityTypeId = parms.GetValueOrNull(ParameterKey.RelatedEntityTypeId).AsIntegerOrNull(); int?relatedEntityId = parms.GetValueOrNull(ParameterKey.RelatedEntityId).AsIntegerOrNull(); string channelCustom1 = parms.GetValueOrNull(ParameterKey.ChannelCustom1); string channelCustom2 = parms.GetValueOrNull(ParameterKey.ChannelCustom2); string channelCustomIndexed1 = parms.GetValueOrNull(ParameterKey.ChannelCustomIndexed1); int?personAliasId = parms.GetValueOrNull(ParameterKey.PersonAliasId).AsIntegerOrNull(); if (!personAliasId.HasValue) { Person currentPerson = LavaHelper.GetCurrentPerson(context); personAliasId = LavaHelper.GetPrimaryPersonAliasId(currentPerson); } string data = null; using (TextWriter twData = new StringWriter()) { base.Render(context, twData); data = twData.ToString(); } // Write the Interaction by way of a transaction. var info = new InteractionTransactionInfo { ChannelTypeMediumValueId = channelTypeMediumValueId, ChannelEntityId = channelEntityId, ChannelName = channelName, ComponentEntityTypeId = componentEntityTypeId, InteractionEntityTypeId = interactionEntityTypeId, ComponentEntityId = componentEntityId, ComponentName = componentName, InteractionEntityId = entityId, InteractionOperation = operation, InteractionSummary = summary, InteractionData = data, InteractionRelatedEntityTypeId = relatedEntityTypeId, InteractionRelatedEntityId = relatedEntityId, InteractionChannelCustom1 = channelCustom1, InteractionChannelCustom2 = channelCustom2, InteractionChannelCustomIndexed1 = channelCustomIndexed1, PersonAliasId = personAliasId, InteractionSource = source, InteractionMedium = medium, InteractionCampaign = campaign, InteractionContent = content, InteractionTerm = term }; var interactionTransaction = new InteractionTransaction(info); interactionTransaction.Enqueue(); }
private void DoTestRound(string roundName) { int[] personAliasIds = new PersonAliasService(new RockContext()).Queryable().Select(a => a.Id).ToArray(); Stopwatch stopwatch = Stopwatch.StartNew(); var pageViewTransactionList = new ConcurrentQueue <InteractionTransaction>(); var pageViewCounts = 0; Guid browserSessionId = Guid.NewGuid(); for (int i = 0; i < 100; i++) { foreach (var testPage in _allPages) { if (pageViewCounts > 10000) { break; } InteractionTransactionInfo interactionTransactionInfo = new InteractionTransactionInfo { InteractionSummary = $"Some Random Summary {pageViewCounts}", UserAgent = HttpUserAgentList[rnd.Next(HttpUserAgentList.Length)], BrowserSessionId = browserSessionId, InteractionData = $"http://localhost:12345/page/{testPage.Id}", IPAddress = $"10.{rnd.Next( 10 )}.{rnd.Next( 255 )}.{rnd.Next( 255 )}", PersonAliasId = personAliasIds[rnd.Next(personAliasIds.Length)], GetValuesFromHttpRequest = false }; if (rnd.Next(100) < 60) { // create a new session about 60% of the time browserSessionId = Guid.NewGuid(); } if (rnd.Next(11) > 5) { // have around 50% that are from an anonymous view interactionTransactionInfo.PersonAliasId = null; } var testSite = SiteCache.Get(testPage.SiteId); Stopwatch stopwatchCreate = Stopwatch.StartNew(); var pageViewTransaction = new InteractionTransaction( DefinedValueCache.Get(SystemGuid.DefinedValue.INTERACTIONCHANNELTYPE_WEBSITE), testSite, testPage, interactionTransactionInfo); pageViewTransactionList.Enqueue(pageViewTransaction); pageViewCounts++; } } stopwatch.Stop(); Debug.WriteLine($"#############{roundName}#########"); Debug.WriteLine($"{stopwatch.Elapsed.TotalMilliseconds} ms, create, pageViewCounts: {pageViewCounts}"); stopwatch.Restart(); while (pageViewTransactionList.TryDequeue(out InteractionTransaction transaction)) { transaction.Execute(); } stopwatch.Stop(); Debug.WriteLine($"{stopwatch.Elapsed.TotalMilliseconds} ms, log pageViewCounts: {pageViewCounts}"); }