Ejemplo n.º 1
0
        public async Task <DataFileSystem> ExportSystem(PKSystem system)
        {
            // Export members
            var members   = new List <DataFileMember>();
            var pkMembers = await _members.GetBySystem(system);                // Read all members in the system

            var messageCounts = await _members.MessageCountsPerMember(system); // Count messages proxied by all members in the system

            members.AddRange(pkMembers.Select(m => new DataFileMember
            {
                Id           = m.Hid,
                Name         = m.Name,
                DisplayName  = m.DisplayName,
                Description  = m.Description,
                Birthday     = m.Birthday != null ? Formats.DateExportFormat.Format(m.Birthday.Value) : null,
                Pronouns     = m.Pronouns,
                Color        = m.Color,
                AvatarUrl    = m.AvatarUrl,
                Prefix       = m.Prefix,
                Suffix       = m.Suffix,
                Created      = Formats.TimestampExportFormat.Format(m.Created),
                MessageCount = messageCounts.Where(x => x.Member.Equals(m.Id)).Select(x => x.MessageCount).FirstOrDefault()
            }));

            // Export switches
            var switches   = new List <DataFileSwitch>();
            var switchList = await _switches.GetTruncatedSwitchList(system, Instant.FromDateTimeUtc(DateTime.MinValue.ToUniversalTime()), SystemClock.Instance.GetCurrentInstant());

            switches.AddRange(switchList.Select(x => new DataFileSwitch
            {
                Timestamp = Formats.TimestampExportFormat.Format(x.TimespanStart),
                Members   = x.Members.Select(m => m.Hid).ToList() // Look up member's HID using the member export from above
            }));

            return(new DataFileSystem
            {
                Id = system.Hid,
                Name = system.Name,
                Description = system.Description,
                Tag = system.Tag,
                AvatarUrl = system.AvatarUrl,
                TimeZone = system.UiTz,
                Members = members,
                Switches = switches,
                Created = Formats.TimestampExportFormat.Format(system.Created),
                LinkedAccounts = (await _systems.GetLinkedAccountIds(system)).ToList()
            });
        }