Beispiel #1
0
        public static bool SaveRegisteredServers(RegisteredServers regServers)
        {
            if (regServers == null)
            {
                log.LogWarning("Unable to save registered servers. \"RegisteredServers\" object is null");
                return(false);
            }

            RegisteredServerHelper.registeredServerData = regServers;
            return(SerializeRegisteredServers(regServers, RegisteredServerHelper.RegisteredServerFileName));
        }
Beispiel #2
0
        public static bool ReloadRegisteredServerData(string fileName)
        {
            registeredServerData = null;
            RegisteredServerHelper.RegisteredServerFileName = fileName;
            RegisteredServers tmp = RegisteredServerHelper.RegisteredServerData;

            RegisteredServerHelper.RegisteredServerFileName = string.Empty;
            if (tmp != null)
            {
                RegisteredServerHelper.SaveRegisteredServers(tmp);
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #3
0
        internal static bool SerializeRegisteredServers(RegisteredServers regServers, string fileName)
        {
            if (fileName == null || fileName.Length == 0)
            {
                log.LogWarning("Unable to serialize registered servers. The destination fileName is null or empty");
                return(false);
            }

            if (regServers == null)
            {
                log.LogWarning($"Unable to serialize registered servers to {fileName}. \"RegisteredServers\" object is null");
                return(false);
            }
            try
            {
                System.Xml.XmlTextWriter tw = null;
                try
                {
                    XmlSerializer xmlS = new XmlSerializer(typeof(RegisteredServers));
                    tw            = new System.Xml.XmlTextWriter(fileName, Encoding.UTF8);
                    tw.Formatting = System.Xml.Formatting.Indented;
                    xmlS.Serialize(tw, regServers);
                }
                finally
                {
                    if (tw != null)
                    {
                        tw.Close();
                    }
                }
                return(true);
            }
            catch (System.UnauthorizedAccessException exe)
            {
                log.LogError(exe, $"Unable to serialze file to {fileName}");
                return(false);
            }
        }