Example #1
0
        public void WriteTo(ITabularWriter writer, String8Block block, int id, WebRequestWriteMode mode)
        {
            if (writer.RowCountWritten == 0)
            {
                List <string> columnNames = new List <string>(new string[] {
                    "ID",
                    "EventTime",
                    "DataCenter",
                    "ServerName",
                    "ServerPort",
                    "HttpMethod",
                    "HttpStatus",
                    "RequestBytes",
                    "ResponseBytes",
                    "TimeTakenMs",
                    "Protocol",
                    "WasEncrypted",
                    "WasCachedResponse",

                    "ClientRegion",
                    "ClientBrowser",
                    "ClientOs",
                });


                if (mode != WebRequestWriteMode.Minimal)
                {
                    columnNames.Add("ClientIP");
                    columnNames.Add("UriStem");
                    columnNames.Add("UserID");

                    if (mode != WebRequestWriteMode.UserIdentityOnly)
                    {
                        columnNames.AddRange(new string[] {
                            "UserEmailAddress",
                            "UserGuid",
                            "IsPremiumUser",
                            "JoinDate"
                        });
                    }
                }

                writer.SetColumns(columnNames);
            }

            block.Clear();

            writer.Write(id);
            writer.Write(this.EventTime);
            writer.Write(block.GetCopy(this.DataCenter));
            writer.Write(block.GetCopy(this.ServerName));
            writer.Write(this.ServerPort);
            writer.Write(block.GetCopy(this.HttpMethod));
            writer.Write(this.HttpStatus);
            if (this.RequestBytes.HasValue)
            {
                writer.Write(this.RequestBytes.Value);
            }
            else
            {
                writer.Write(String8.Empty);
            }
            writer.Write(this.ResponseBytes);
            writer.Write((int)this.TimeTakenMs);
            writer.Write(block.GetCopy(this.Protocol));
            writer.Write(this.WasEncrypted);
            writer.Write(this.WasCachedResponse);

            writer.Write(block.GetCopy(this.User.Region));
            writer.Write(block.GetCopy(this.User.Browser));
            writer.Write(block.GetCopy(this.User.OS));

            if (mode != WebRequestWriteMode.Minimal)
            {
                writer.Write(this.ClientIP);
                writer.Write(block.GetCopy(this.UriStem));

                if (this.IsAnonymous)
                {
                    writer.Write(String8.Empty);
                }
                else
                {
                    writer.Write(this.User.ID);
                }

                if (mode != WebRequestWriteMode.UserIdentityOnly)
                {
                    if (this.IsAnonymous)
                    {
                        writer.Write(String8.Empty);
                    }
                    else
                    {
                        writer.Write(block.GetCopy(this.User.EmailAddress));
                    }
                    if (this.IsAnonymous)
                    {
                        writer.Write(String8.Empty);
                    }
                    else
                    {
                        writer.Write(block.GetCopy(this.User.Guid.ToString()));
                    }
                    if (this.IsAnonymous)
                    {
                        writer.Write(String8.Empty);
                    }
                    else
                    {
                        writer.Write(this.User.IsPremiumUser);
                    }
                    if (this.IsAnonymous)
                    {
                        writer.Write(String8.Empty);
                    }
                    else
                    {
                        writer.Write(this.User.JoinDate);
                    }
                }
            }

            writer.NextRow();
        }
Example #2
0
        private static void BuildWebRequests(string basePath, string fileNamePrefix, WebRequestGenerator generator, int eventCount, WebRequestWriteMode mode)
        {
            DateTime     asOfDate = generator.Current;
            String8Block block    = new String8Block();

            string path = Path.Combine(basePath, $"{fileNamePrefix}.{asOfDate:yyyyMMdd}.r5.{eventCount}.csv");

            Console.WriteLine($"Writing {path}...");

            using (ITabularWriter writer = TabularFactory.BuildWriter(path))
            {
                for (int i = 0; i < eventCount; ++i)
                {
                    WebRequest request = generator.Next();
                    request.WriteTo(writer, block, i, mode);
                }
            }

            File.SetLastWriteTimeUtc(path, asOfDate);
        }