Пример #1
0
        private byte[] GetUploadFileBytes(AppendedResults singleResult, UploadContext uploadContext)
        {
            var jsonBytes = Encoding.UTF8.GetBytes(singleResult.ToJson());

            if (!uploadContext.HasAttachments)
            {
                return(jsonBytes);
            }

            using (var stream = new MemoryStream())
            {
                using (var archive = new ZipArchive(stream, ZipArchiveMode.Update, true))
                {
                    AddArchiveEntry(archive, new Attachment
                    {
                        Content       = jsonBytes,
                        Path          = uploadContext.UploadedFilename,
                        LastWriteTime = DateTimeOffset.UtcNow,
                        ByteSize      = jsonBytes.Length
                    });

                    foreach (var attachment in uploadContext.Attachments)
                    {
                        AddArchiveEntry(archive, attachment);
                    }
                }

                stream.Position = 0;

                var zipBytes = stream.GetBuffer();

                return(zipBytes);
            }
        }
Пример #2
0
        private string SaveLargeVisits(AppendedResults appendedResults, List <FieldVisitInfo> largeVisits, string path)
        {
            var largePath = Path.Combine(
                // ReSharper disable once AssignNullToNotNullAttribute
                Path.GetDirectoryName(path),
                $"{Path.GetFileNameWithoutExtension(path)}.LargeDuration.json");

            var largeResults = new AppendedResults
            {
                PluginAssemblyQualifiedTypeName = appendedResults.PluginAssemblyQualifiedTypeName,
                FrameworkAssemblyQualifiedName  = appendedResults.FrameworkAssemblyQualifiedName,
                AppendedVisits = largeVisits
            };

            Log.Info($"Saving {largeResults.AppendedVisits.Count} visits data to '{largePath}'");

            File.WriteAllText(largePath, largeResults.ToJson().IndentJson());

            return(largePath);
        }