Skip to content

Instantly share code, notes, and snippets.

@VasylBakalets
Created October 5, 2015 13:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VasylBakalets/9940023abd33c885e9fd to your computer and use it in GitHub Desktop.
Save VasylBakalets/9940023abd33c885e9fd to your computer and use it in GitHub Desktop.
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