public static FavoriteConfigurationElementCollection GetFavorites(bool isDatabaseFavorite) { if (!isDatabaseFavorite) { TerminalsConfigurationSection section = GetSection(); if (section != null) { return(section.Favorites); } } else { FavoriteConfigurationElementCollection collection = new FavoriteConfigurationElementCollection(); using (TerminalsObjectContext dc = TerminalsObjectContext.Create()) { if (dc == null) { return(null); } foreach (var connection in dc.Connections) { FavoriteConfigurationElement favorite = connection.ToFavorite(); collection.Add(favorite); } } return(collection); } return(null); }
internal void SaveDefaultFavorite(FavoriteConfigurationElement favorite) { FavoriteConfigurationElementCollection defaultFav = GetSection().DefaultFavorite; defaultFav.Clear(); defaultFav.Add(favorite); SaveImmediatelyIfRequested(); }
public void AddFavorite(string server, string name, int Port) { try { FavoriteConfigurationElement elm = new FavoriteConfigurationElement(); try { System.Net.IPAddress address; if (System.Net.IPAddress.TryParse(server, out address)) { name = System.Net.Dns.GetHostByAddress(address).HostName; } name = string.Format("{0}_{1}", name, Terminals.Connections.ConnectionManager.GetPortName(Port, true)); } catch (Exception exc) { //lets not log dns lookups! //Terminals.Logging.Log.Info("", exc); } elm.Name = name; elm.ServerName = server; elm.UserName = System.Environment.UserName; if (System.Environment.UserDomainName != System.Environment.MachineName) { elm.DomainName = System.Environment.UserDomainName; } else { elm.DomainName = server; } elm.Tags = "Discovered Connections"; elm.Port = Port; elm.Protocol = Terminals.Connections.ConnectionManager.GetPortName(Port, true); lock (DiscoFavs) { DiscoFavs.Add(elm); } //if(this.IsHandleCreated) this.Invoke(miv); } catch (Exception e) { Terminals.Logging.Log.Info("", e); } }
FavoriteConfigurationElementCollection IImport.ImportFavorites(string Filename) { string name = System.IO.Path.GetFileName(Filename).Replace(System.IO.Path.GetExtension(Filename),""); FavoriteConfigurationElementCollection coll = new FavoriteConfigurationElementCollection(); if(System.IO.File.Exists(Filename)) { FavoriteConfigurationElement fav = null; string[] lines = System.IO.File.ReadAllLines(Filename); fav = new FavoriteConfigurationElement(); fav.Name = name; coll.Add(fav); foreach(string line in lines) { string propertyName = line.Substring(0, line.IndexOf(":")); string pValue = line.Substring(line.LastIndexOf(":") + 1); switch(propertyName) { case "full address": fav.ServerName = pValue; break; case "server port": int p = 3389; int.TryParse(pValue, out p); fav.Port = p; break; case "username": fav.UserName = pValue; break; case "domain": fav.DomainName = pValue; break; case "session bpp": switch(pValue) { case "8": fav.Colors = Colors.Bits8; break; case "16": fav.Colors = Colors.Bit16; break; case "24": fav.Colors = Colors.Bits24; break; case "32": fav.Colors = Colors.Bits32; break; default: fav.Colors = Colors.Bit16; break; } break; case "screen mode id": fav.DesktopSize = DesktopSize.AutoScale; if(pValue == "1") fav.DesktopSize = DesktopSize.FullScreen; break; case "connect to console": fav.ConnectToConsole = false; if(pValue == "1") fav.ConnectToConsole = true; break; case "disable wallpaper": fav.DisableWallPaper = false; if(pValue == "1") fav.DisableWallPaper = true; break; case "redirectsmartcards": fav.RedirectSmartCards = false; if(pValue == "1") fav.RedirectSmartCards = true; break; case "redirectdrives": fav.RedirectDrives = false; if(pValue == "1") fav.RedirectDrives = true; break; case "redirectcomports": fav.RedirectPorts = false; if(pValue == "1") fav.RedirectPorts = true; break; case "redirectprinters": fav.RedirectPrinters = false; if(pValue == "1") fav.RedirectPrinters = true; break; case "audiomode": if(pValue == "0") fav.Sounds = RemoteSounds.Redirect; if(pValue == "1") fav.Sounds = RemoteSounds.PlayOnServer; if(pValue == "2") fav.Sounds = RemoteSounds.DontPlay; break; default: break; } } } return coll; }
FavoriteConfigurationElementCollection IImport.ImportFavorites(string Filename) { FavoriteConfigurationElementCollection coll = new FavoriteConfigurationElementCollection(); if(System.IO.File.Exists(Filename)) { FavoriteConfigurationElement fav = null; string[] lines = System.IO.File.ReadAllLines(Filename); foreach(string line in lines) { if(line.StartsWith("[") && line.EndsWith("]")) { if(fav == null) { fav = new FavoriteConfigurationElement(); fav.Name = line.Substring(1, line.Length - 2); } else { coll.Add(fav); fav = new FavoriteConfigurationElement(); } } else { if(line == "") { coll.Add(fav); fav = new FavoriteConfigurationElement(); } else { string propertyName = line.Substring(0, line.IndexOf("=")); string pValue = line.Substring(line.IndexOf("=") + 1); switch(propertyName) { case "ServerName": fav.ServerName = pValue; break; case "Port": int p = 3389; int.TryParse(pValue, out p); fav.Port = p; break; case "Username": fav.UserName = pValue; break; case "Domain": fav.DomainName = pValue; break; case "Comment": break; case "Password": break; case "DesktopWidth": fav.DesktopSize = DesktopSize.AutoScale; break; case "DesktopHeight": fav.DesktopSize = DesktopSize.AutoScale; break; case "ColorDepth": switch(pValue) { case "8": fav.Colors = Colors.Bits8; break; case "16": fav.Colors = Colors.Bit16; break; case "24": fav.Colors = Colors.Bits24; break; case "32": fav.Colors = Colors.Bits32; break; default: fav.Colors = Colors.Bit16; break; } break; case "UseSmartSizing": if(pValue == "1") fav.DesktopSize = DesktopSize.AutoScale; break; case "FullScreenMonitor": if(pValue == "1") fav.DesktopSize = DesktopSize.FullScreen; break; case "ConsoleConnection": fav.ConnectToConsole = false; if(pValue == "1") fav.ConnectToConsole = true; break; case "UseCompression": break; case "BitmapPersistence": break; case "DisableWallpaper": fav.DisableWallPaper = false; if(pValue == "1") fav.DisableWallPaper = true; break; case "DisableFullWindowDrag": break; case "DisableMenuAnimations": break; case "DisableTheming": break; case "DisableCursorShadow": break; case "DisableCursorSettings": break; case "RedirectSmartCards": fav.RedirectSmartCards = false; if(pValue == "1") fav.RedirectSmartCards = true; break; case "RedirectDrives": fav.RedirectDrives = false; if(pValue == "1") fav.RedirectDrives = true; break; case "RedirectPorts": fav.RedirectPorts = false; if(pValue == "1") fav.RedirectPorts = true; break; case "RedirectPrinters": fav.RedirectPrinters = false; if(pValue == "1") fav.RedirectPrinters = true; break; case "EnableWindowsKey": break; case "KeyboardHookMode": break; case "AudioRedirectionMode": if(pValue == "0") fav.Sounds = RemoteSounds.Redirect; if(pValue == "1") fav.Sounds = RemoteSounds.PlayOnServer; if(pValue == "2") fav.Sounds = RemoteSounds.DontPlay; break; case "AlternateShell": break; case "ShellWorkingDir": break; case "AuthenticationLevel": break; default: break; } } } } } return coll; }
FavoriteConfigurationElementCollection IImport.ImportFavorites(string Filename) { string name = System.IO.Path.GetFileName(Filename).Replace(System.IO.Path.GetExtension(Filename), ""); FavoriteConfigurationElementCollection coll = new FavoriteConfigurationElementCollection(); if (System.IO.File.Exists(Filename)) { FavoriteConfigurationElement fav = null; string[] lines = System.IO.File.ReadAllLines(Filename); fav = new FavoriteConfigurationElement(); fav.Name = name; coll.Add(fav); foreach (string line in lines) { string propertyName = line.Substring(0, line.IndexOf(":")); string pValue = line.Substring(line.LastIndexOf(":") + 1); switch (propertyName) { case "full address": fav.ServerName = pValue; break; case "server port": int p = 3389; int.TryParse(pValue, out p); fav.Port = p; break; case "username": fav.UserName = pValue; break; case "domain": fav.DomainName = pValue; break; case "session bpp": switch (pValue) { case "8": fav.Colors = Colors.Bits8; break; case "16": fav.Colors = Colors.Bit16; break; case "24": fav.Colors = Colors.Bits24; break; case "32": fav.Colors = Colors.Bits32; break; default: fav.Colors = Colors.Bit16; break; } break; case "screen mode id": fav.DesktopSize = DesktopSize.AutoScale; if (pValue == "1") { fav.DesktopSize = DesktopSize.FullScreen; } break; case "connect to console": fav.ConnectToConsole = false; if (pValue == "1") { fav.ConnectToConsole = true; } break; case "disable wallpaper": fav.DisableWallPaper = false; if (pValue == "1") { fav.DisableWallPaper = true; } break; case "redirectsmartcards": fav.RedirectSmartCards = false; if (pValue == "1") { fav.RedirectSmartCards = true; } break; case "redirectdrives": fav.RedirectDrives = false; if (pValue == "1") { fav.RedirectDrives = true; } break; case "redirectcomports": fav.RedirectPorts = false; if (pValue == "1") { fav.RedirectPorts = true; } break; case "redirectprinters": fav.RedirectPrinters = false; if (pValue == "1") { fav.RedirectPrinters = true; } break; case "audiomode": if (pValue == "0") { fav.Sounds = RemoteSounds.Redirect; } if (pValue == "1") { fav.Sounds = RemoteSounds.PlayOnServer; } if (pValue == "2") { fav.Sounds = RemoteSounds.DontPlay; } break; default: break; } } } return(coll); }
FavoriteConfigurationElementCollection IImport.ImportFavorites(string Filename) { FavoriteConfigurationElementCollection coll = new FavoriteConfigurationElementCollection(); if (System.IO.File.Exists(Filename)) { FavoriteConfigurationElement fav = null; string[] lines = System.IO.File.ReadAllLines(Filename); foreach (string line in lines) { if (line.StartsWith("[") && line.EndsWith("]")) { if (fav == null) { fav = new FavoriteConfigurationElement(); fav.Name = line.Substring(1, line.Length - 2); } else { coll.Add(fav); fav = new FavoriteConfigurationElement(); } } else { if (line == "") { coll.Add(fav); fav = new FavoriteConfigurationElement(); } else { string propertyName = line.Substring(0, line.IndexOf("=")); string pValue = line.Substring(line.IndexOf("=") + 1); switch (propertyName) { case "ServerName": fav.ServerName = pValue; break; case "Port": int p = 3389; int.TryParse(pValue, out p); fav.Port = p; break; case "Username": fav.UserName = pValue; break; case "Domain": fav.DomainName = pValue; break; case "Comment": break; case "Password": break; case "DesktopWidth": fav.DesktopSize = DesktopSize.AutoScale; break; case "DesktopHeight": fav.DesktopSize = DesktopSize.AutoScale; break; case "ColorDepth": switch (pValue) { case "8": fav.Colors = Colors.Bits8; break; case "16": fav.Colors = Colors.Bit16; break; case "24": fav.Colors = Colors.Bits24; break; case "32": fav.Colors = Colors.Bits32; break; default: fav.Colors = Colors.Bit16; break; } break; case "UseSmartSizing": if (pValue == "1") { fav.DesktopSize = DesktopSize.AutoScale; } break; case "FullScreenMonitor": if (pValue == "1") { fav.DesktopSize = DesktopSize.FullScreen; } break; case "ConsoleConnection": fav.ConnectToConsole = false; if (pValue == "1") { fav.ConnectToConsole = true; } break; case "UseCompression": break; case "BitmapPersistence": break; case "DisableWallpaper": fav.DisableWallPaper = false; if (pValue == "1") { fav.DisableWallPaper = true; } break; case "DisableFullWindowDrag": break; case "DisableMenuAnimations": break; case "DisableTheming": break; case "DisableCursorShadow": break; case "DisableCursorSettings": break; case "RedirectSmartCards": fav.RedirectSmartCards = false; if (pValue == "1") { fav.RedirectSmartCards = true; } break; case "RedirectDrives": fav.RedirectDrives = false; if (pValue == "1") { fav.RedirectDrives = true; } break; case "RedirectPorts": fav.RedirectPorts = false; if (pValue == "1") { fav.RedirectPorts = true; } break; case "RedirectPrinters": fav.RedirectPrinters = false; if (pValue == "1") { fav.RedirectPrinters = true; } break; case "EnableWindowsKey": break; case "KeyboardHookMode": break; case "AudioRedirectionMode": if (pValue == "0") { fav.Sounds = RemoteSounds.Redirect; } if (pValue == "1") { fav.Sounds = RemoteSounds.PlayOnServer; } if (pValue == "2") { fav.Sounds = RemoteSounds.DontPlay; } break; case "AlternateShell": break; case "ShellWorkingDir": break; case "AuthenticationLevel": break; default: break; } } } } } return(coll); }