private static async Task Main(string[] args) { using var client = new SafeZoneClient(new SafeZoneClientSettings(UserName, Password)); client.Connect(); var tags = new XTags { // report on check-ins for every region XTag.Build.RegionTag(string.Empty) }; var regionNames = new ConcurrentDictionary <XStringId, string>(); var userNames = new ConcurrentDictionary <XAccountId, string>(); var results = client.CheckInClient.GetSessions(SafeZoneId, ReportStartTime, ReportEndTime, tags, MaxResultsPerPage); await results.ForEachPageAsync(async page => { foreach (var session in page) { if (!regionNames.TryGetValue(session.RegionId, out var regionName)) { try { var region = await client.CoreClient.GetRegionAsync(SafeZoneId, session.RegionId, AsyncOptions.None); regionNames[session.RegionId] = regionName = region.DisplayNameOrId; } catch (XStanzaErrorException) { regionNames[session.RegionId] = regionName = (string)session.RegionId; } } if (!userNames.TryGetValue(session.UserId, out var userName)) { try { var user = await client.UserClient.GetUserAsync(SafeZoneId, session.UserId, AsyncOptions.None); userNames[session.UserId] = userName = user.Fields.DisplayName ?? user.Fields.GivenFamilyName; } catch (XStanzaErrorException) { userNames[session.UserId] = userName = (string)session.UserId; } } if (session.ExitedTimestamp == null) { Console.WriteLine($"{userName} is currently checked in at {regionName} since {session.EnteredTimestamp.Value.ToLocalTime():g}"); } else { Console.WriteLine($"{userName} was checked in at {regionName} between {session.EnteredTimestamp.Value.ToLocalTime():g} and {session.ExitedTimestamp.Value.ToLocalTime():g}"); } } }, AsyncOptions.None); }
public static void CreateEntry(WikiEntry entry) { foreach (var item in entry.Categories) { string categoryId = ""; // Category exists if (XCategories.Any(c => c.Attribute("Text").Value == item.Text)) { continue; } else { // Generate new Category categoryId = (Convert.ToInt32(XCategories.Last().Attribute("Id").Value) + 1).ToString(); XCategory.Add( new XElement("Category", new XAttribute("Id", categoryId), new XAttribute("Text", item.Text)) ); } } foreach (var item in entry.Tags) { string tagId = ""; // Tag exists if (XTags.Any(c => c.Attribute("Text").Value == item.Text)) { continue; } else { // Generate new Tag tagId = (Convert.ToInt32(XTags.Last().Attribute("Id").Value) + 1).ToString(); XTag.Add ( new XElement("Tag", new XAttribute("Id", tagId), new XAttribute("Text", item.Text)) ); } } XElement wikiEntry = new XElement("WikiEntry", new XAttribute("Id", Guid.NewGuid()), new XAttribute("CreatedBy", "*****@*****.**"), new XAttribute("CreatedAt", DateTimeOffset.UtcNow.ToString()), new XAttribute("UpdatedBy", "*****@*****.**"), new XAttribute("UpdatedAt", DateTimeOffset.UtcNow.ToString()), new XAttribute("CategoryIds", string.Join(",", from x in entry.Categories select x.Id)), new XAttribute("TagIds", string.Join(",", from x in entry.Tags select x.Id)), new XElement("Title", entry.Title), new XElement("Content", new XCData(entry.Content)) ); XWikiEntries.Add(wikiEntry); xDoc.Save(file); }