static void Main() { Console.WriteLine("Loading sample dataset:"); var ws = SampleDataResources.CreateXmlWorkspace(); foreach (var doc in ws.Documents) { Console.WriteLine($"{doc.Filepath} ({doc.Kind})"); } Console.WriteLine("Compiling sample dataset:"); var sampleCompilation = RosterState.CreateFromNodes(ws.Documents.Select(x => x.GetRootAsync().Result !)).Compilation; foreach (var diagnostic in sampleCompilation.GetDiagnostics()) { Console.WriteLine(diagnostic.ToString()); } Console.WriteLine("Finished processing sample dataset."); Console.WriteLine("-----------------------------------"); Console.WriteLine(); Console.WriteLine(">>> Building dataset."); // create var rosterState = RosterState.CreateFromNodes(GetDataset()); Console.WriteLine(">>> Compilation created, creating global namespace."); var globalNamespace = rosterState.Compilation.GlobalNamespace; Console.WriteLine(">>> Global namespace retrieved."); Console.WriteLine(">>> Testing gamesystem binding in Catalogue symbol."); var gamesystem = globalNamespace.Catalogues.Where(x => !x.IsGamesystem).First().Gamesystem; Console.WriteLine(">>> Catalogue symbol has bound to gamesystem symbol: " + gamesystem.Name); Console.WriteLine(">>> Testing publication binding."); var forceEntry1 = globalNamespace.RootCatalogue.AllItems.OfType <IForceEntrySymbol>().First(); Console.WriteLine($">>> Force '{forceEntry1.Name}' publication bound to '{forceEntry1.PublicationReference?.Publication.Name}'"); Console.WriteLine(">>> Testing diagnostic listing."); var diagnostics = rosterState.Compilation.GetDiagnostics(); foreach (var diag in diagnostics) { Console.WriteLine(diag.ToString()); } Console.WriteLine($">>> Diagnostics printed (count: {diagnostics.Length})."); // roster modifications var printer = new RosterPrinter(); var rosterEditor = new RosterEditor(rosterState); rosterEditor.ApplyOperation(RosterOperations.CreateRoster() with { Name = "Test Marine Strike Force" });
protected virtual void OnContactListChannelReady(object sender, EventArgs args) { uint [] contacts = contact_list.GetContacts(); //Log.DebugFormat ("Account {0} has {1} contacts", conn.AccountId, contacts.Length); presence = DBusUtility.GetProxy <ISimplePresence> (conn.Bus, conn.BusName, conn.ObjectPath); GetPresenceInfo(contacts); presence.PresencesChanged += OnPresencesChanged; state = RosterState.Loaded; OnRosterStateChanged(new RosterEventArgs(state)); }
public void Load() { if (state != RosterState.Unloaded) { return; } state = RosterState.Loading; contact_list = new ContactListChannel(this.Connection, "subscribe"); contact_list.ChannelReady += OnContactListChannelReady; contact_list.MembersAdded += OnMembersAdded; contact_list.MembersRemoved += OnMembersRemoved; contact_list.Request(); }
private void UpdateTimer_Elapsed(object sender, EventArgs e) { if (this._rosterEnabled) { if (this._rosterInterval < 1) { return; } if (DateTime.Now > this._lastUpdated.AddHours(this._rosterInterval)) { if (this._state != RosterState.Idle) { return; } string[] removed; string[] added; RichTextWindow window; this._state = RosterState.FetchingMembers; try { if (this.UpdateRoster(out removed, out added, out window)) { if (removed.Length > 0 || added.Length > 0) { string[] pages = window.ToStrings(); Int32 i = 0; foreach (string page in pages) { i++; string count = string.Empty; if (pages.Length > 1) { count = " (" + i + " of " + pages.Length + ")"; } this._bot.SendOrganizationMessage(this._bot.ColorHighlight + "Roster Update Report »» " + page + count); } } } this._lastUpdated = DateTime.Now; } catch { } this._state = RosterState.Idle; } } }
private void OnRosterUpdateCommand(BotShell bot, CommandArgs e) { if (this._state != RosterState.Idle) { bot.SendReply(e, "Roster update is currently in progress. Please try again later"); return; } bot.SendReply(e, "Updating Roster... (This may take several minutes)"); string[] removed; string[] added; RichTextWindow window; this._state = RosterState.FetchingMembers; try { if (this.UpdateRoster(out removed, out added, out window)) { string[] pages = window.ToStrings(); Int32 i = 0; foreach (string page in pages) { i++; string count = string.Empty; if (pages.Length > 1) { count = " (" + i + " of " + pages.Length + ")"; } bot.SendReply(e, "Roster Update Report »» " + page + count); } this._lastUpdated = DateTime.Now; } else { bot.SendReply(e, "An error has occured while trying to update the roster. Please try again later"); } } catch { } this._state = RosterState.Idle; }
public override async Task Handle(HandlerContext <Command> context) { // TODO might be comma-separated values Roster roster = CompositionRoot.DocumentSession.LoadEx <Roster>(context.Payload.RosterKey); AuditLogEntry auditLogEntry = roster.AuditLogEntries.Single(x => x.CorrelationId == context.CorrelationId); RosterState before = (RosterState)auditLogEntry.Before; RosterState after = (RosterState)auditLogEntry.After; HashSet <string> affectedPlayers = new(before.Players.Concat(after.Players)); // find user who did the last edit-players action AuditLogEntry?editPlayersAction = roster.AuditLogEntries.LastOrDefault( x => x.Action == Roster.ChangeType.EditPlayers.ToString()); if (editPlayersAction == null) { throw new Exception($"No edit-players action found in roster {roster.Id}"); } Dictionary <string, Player> playersDict = CompositionRoot.DocumentSession.Load <Player>(affectedPlayers) .ToDictionary(x => x.Id); Player?editPlayer = CompositionRoot.DocumentSession.Load <Player>(editPlayersAction.UserId); User? editUser = CompositionRoot.DocumentSession.FindUserByEmail(editPlayersAction.UserId); string replyToEmail = editPlayer?.Email ?? editUser?.Email ?? throw new Exception($"Unable to find edit-players action user with id '{editPlayersAction.UserId}'"); if (editPlayer is not null) { _ = affectedPlayers.Add(editPlayer.Id); playersDict[editPlayer.Id] = editPlayer; } // only send to players that have accepted email, or have not yet decided string[] propertyKeys = affectedPlayers.Select(UserSettings.GetKey).ToArray(); Dictionary <string, UserSettings> properties = Enumerable.ToDictionary( await context.Databases.Snittlistan.KeyValueProperties.Where( x => propertyKeys.Contains(x.Key)) .ToArrayAsync(), x => x.Key, x => (UserSettings)x.Value); foreach (string playerId in affectedPlayers) { Player player = playersDict[playerId]; do { if (properties.TryGetValue( UserSettings.GetKey(playerId), out UserSettings? settings)) { Logger.InfoFormat( "found user settings for {playerId} {@settings}", playerId, settings); } else { Logger.InfoFormat( "no user settings found for {playerId}", playerId); } if (string.IsNullOrEmpty(player.Email)) { Logger.InfoFormat("no email set for player {playerId}", playerId); break; } if ((settings?.RosterMailEnabled ?? true) == false) { Logger.InfoFormat("roster mail disabled for player {playerId}", playerId); break; } PublishRosterMailTask message = new( context.Payload.RosterKey, player.Id, player.Email, player.Nickname ?? player.Name, replyToEmail, context.Payload.RosterLink, context.Payload.UserProfileLink); context.PublishMessage(message); }while (false); } RosterMail rosterMail = await context.Databases.Snittlistan.RosterMails.SingleAsync( x => x.RosterKey == context.Payload.RosterKey && x.PublishedDate == null); rosterMail.MarkPublished(DateTime.Now); }
public RosterEventArgs(RosterState action) { this.action = action; }
public RosterEventArgs(RosterState action) { this.action = action; }
protected Roster() { state = RosterState.Unloaded; }
private bool UpdateRoster(out string[] removed, out string[] added, out RichTextWindow window) { this._state = RosterState.FetchingMembers; removed = new string[0]; added = new string[0]; window = null; DateTime startTime = DateTime.Now; List <string> oldMembers = new List <string>(); List <string> newMembers = new List <string>(); using (IDbCommand command = this._database.Connection.CreateCommand()) { command.CommandText = "SELECT ID FROM organizations"; IDataReader reader = command.ExecuteReader(); while (reader.Read()) { try { int id = (int)reader.GetInt64(0); OrganizationResult org = XML.GetOrganization(id, this._bot.Dimension, false, true); if (org == null || org.Members == null || org.Members.Items == null || org.Members.Items.Length == 0) { throw new Exception(); } foreach (OrganizationMember member in org.Members.Items) { newMembers.Add(member.Nickname); } } catch { reader.Close(); return(false); } } reader.Close(); } using (IDbCommand command = this._database.Connection.CreateCommand()) { command.CommandText = "SELECT Username FROM members"; IDataReader reader = command.ExecuteReader(); while (reader.Read()) { try { string name = reader.GetString(0); oldMembers.Add(name); } catch { } } reader.Close(); } this._state = RosterState.CrossCheckingMembers; this._progressMax = newMembers.Count + oldMembers.Count; this._progressValue = 0; List <string> addMembers = new List <string>(); List <string> removeMembers = new List <string>(); foreach (string member in newMembers) { if (!oldMembers.Contains(member)) { addMembers.Add(member); this._bot.GetMainBot().SendNameLookup(member); } this._progressValue++; } foreach (string member in oldMembers) { if (!newMembers.Contains(member)) { removeMembers.Add(member); } this._progressValue++; } this._state = RosterState.RemovingMembers; this._progressMax = removeMembers.Count; this._progressValue = 0; foreach (string member in removeMembers) { this._bot.Users.RemoveUser(member); this._bot.Users.RemoveAlt(member); this._bot.FriendList.Remove("notify", member); this._database.ExecuteNonQuery("DELETE FROM members WHERE Username = '******'"); this._progressValue++; } this._state = RosterState.AddingMembers; this._progressMax = addMembers.Count; this._progressValue = 0; List <string> failed = new List <string>(); foreach (string member in addMembers) { if (this._bot.Users.AddUser(member, UserLevel.Member)) { this._bot.FriendList.Add("notify", member); this._database.ExecuteNonQuery("INSERT INTO members VALUES ('" + member + "', 0)"); } else { failed.Add(member); } this._progressValue++; } foreach (string member in failed) { addMembers.Remove(member); } added = addMembers.ToArray(); removed = removeMembers.ToArray(); TimeSpan elapsed = DateTime.Now - startTime; window = new RichTextWindow(this._bot); window.AppendTitle("Roster Update Report"); window.AppendHighlight("Processing Time: "); window.AppendNormal(String.Format("{0:00}:{1:00}:{2:00}", Math.Floor(elapsed.TotalHours), elapsed.Minutes, elapsed.Seconds)); window.AppendLineBreak(); window.AppendHighlight("Members Added: "); window.AppendNormal(added.Length.ToString()); window.AppendLineBreak(); window.AppendHighlight("Members Removed: "); window.AppendNormal(removed.Length.ToString()); window.AppendLineBreak(); if (added.Length > 0) { window.AppendLineBreak(); window.AppendHeader("Added Members"); foreach (string member in added) { window.AppendHighlight(member); window.AppendLineBreak(); } } if (removed.Length > 0) { window.AppendLineBreak(); window.AppendHeader("Removed Members"); foreach (string member in removed) { window.AppendHighlight(member); window.AppendLineBreak(); } } this._state = RosterState.Idle; return(true); }