Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
public class SwitchManager
{
public static void InitializeAgentWindow(AgentWindow type)
{
Dictionary<int, AgentWindow> temp = new Dictionary<int, AgentWindow>();
if (agentWindows.Count == 0)
agentWindows.Add(1, type);
else
{
temp.Add(1, type);
foreach (var window in agentWindows)
{
var t = window.Key;
temp.Add(++t, window.Value);
}
agentWindows = temp;
}
}
public static int SwitchToAgent(AgentWindow type)
{
var windowToSwitch = agentWindows.First(w => w.Value == type);
UpdateIndexesAgent(windowToSwitch);
return windowToSwitch.Key;
}
private static void UpdateIndexesAgent(KeyValuePair<int, AgentWindow> windowToSwitch)
{
Dictionary<int, AgentWindow> temp = new Dictionary<int, AgentWindow>();
agentWindows.Remove(windowToSwitch.Key);
foreach (var window in agentWindows)
{
if (window.Key < windowToSwitch.Key)
{
var t = window.Key;
temp.Add(++t, window.Value);
}
else
temp.Add(window.Key, window.Value);
}
temp.Add(1, windowToSwitch.Value);
agentWindows = temp;
}
private static Dictionary<int, AgentWindow> agentWindows = new Dictionary<int, AgentWindow>();
}
public enum AgentWindow
{
AgentA1,
AgentA2,
AgentF1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.