Esempio n. 1
0
        private void CmdSaveConfig()
        {
            //Ensure session
            if (!EnsureSessionExists())
            {
                return;
            }

            //Make a copy
            if (File.Exists(cfg._savePath))
            {
                CLITools.PrintText("Backing up...");
                if (File.Exists(cfg._savePath + ".bak"))
                {
                    File.Delete(cfg._savePath + ".bak");
                }
                File.Copy(cfg._savePath, cfg._savePath + ".bak");
            }

            //Save
            CLITools.PrintText("Saving...");
            cfg.Save();
            CLITools.PrintText("Saved to disk successfully.", ConsoleColor.Green);
            unsaved = false;
        }
        public static DeltaManagerServer CreateManagerServer(string label, IPAddress address)
        {
            //Prepare
            DeltaConfigManagerServer configEntry;

            lock (cfg.registered_servers)
            {
                //Create key
                byte[] key = SecureStringTool.GenerateSecureRandomBytes(16);

                //Create ID
                short  id;
                Random rand = new Random();
                do
                {
                    id = (short)rand.Next(257, short.MaxValue - 1);
                } while (cfg.registered_servers.Where(x => x.id == id).Count() != 0);

                //Create config entry
                configEntry = new DeltaConfigManagerServer
                {
                    label   = label,
                    ip_addr = address.ToString(),
                    id      = id,
                    key     = Convert.ToBase64String(key)
                };

                //Add
                cfg.registered_servers.Add(configEntry);
                cfg.Save();
            }

            //Create instance and add it
            DeltaManagerServer server = new DeltaManagerServer(configEntry);

            lock (servers)
                servers.Add(server);

            return(server);
        }