Beispiel #1
0
        /// <inheritdoc/>
        public ReadOnlyCollection <MixpanelBatchMessageTest> SendTest(IEnumerable <MixpanelMessage> messages)
        {
            var batchMessageWrapper = new BatchMessageWrapper(messages);

            // Concatenate both 'TrackMessages' and 'EngageMessages' in one list
            List <List <MixpanelMessage> > batchMessages =
                (batchMessageWrapper.TrackMessages ?? new List <List <MixpanelMessage> >(0))
                .Concat(batchMessageWrapper.EngageMessages ?? new List <List <MixpanelMessage> >(0))
                .ToList();

            var testMessages = new List <MixpanelBatchMessageTest>(batchMessages.Count);

            foreach (List <MixpanelMessage> batchMessage in batchMessages)
            {
                var batchMessageBuildResult = new BatchMessageBuildResult(batchMessage);
                var testMessage             = new MixpanelBatchMessageTest {
                    Data = batchMessageBuildResult.Message
                };

                try
                {
                    testMessage.Json   = ToJson(testMessage.Data);
                    testMessage.Base64 = ToBase64(testMessage.Json);
                }
                catch (Exception e)
                {
                    testMessage.Exception = e;
                }

                testMessages.Add(testMessage);
            }

            return(testMessages.AsReadOnly());
        }
        /// <summary>
        /// Returns a collection of <see cref="MixpanelBatchMessageTest"/>. Each item represents a
        /// batch that contains all steps (message data, JSON, base64) of building a batch message. 
        /// If some error occurs during the process of creating a batch it can be found in 
        /// <see cref="MixpanelMessageTest.Exception"/> property.
        /// The messages will NOT be sent to Mixpanel.
        /// </summary>
        /// <param name="messages">List of <see cref="MixpanelMessage"/> to test.</param>
        public ReadOnlyCollection<MixpanelBatchMessageTest> SendTest(IEnumerable<MixpanelMessage> messages)
        {
            var batchMessageWrapper = new BatchMessageWrapper(messages);

            // Concatenate both 'TrackMessages' and 'EngageMessages' in one list
            var batchMessages =
                (batchMessageWrapper.TrackMessages ?? new List<List<MixpanelMessage>>(0))
                .Concat(((batchMessageWrapper.EngageMessages ?? new List<List<MixpanelMessage>>(0))))
                .ToList();

            var testMessages = new List<MixpanelBatchMessageTest>(batchMessages.Count);

            foreach (var batchMessage in batchMessages)
            {
                var testMessage = new MixpanelBatchMessageTest { Data = GetBatchMessageData(batchMessage) };

                try
                {
                    testMessage.Json = ToJson(testMessage.Data);
                    testMessage.Base64 = ToBase64(testMessage.Json);
                }
                catch (Exception e)
                {
                    testMessage.Exception = e;
                }

                testMessages.Add(testMessage);
            }

            return testMessages.AsReadOnly();
        }