예제 #1
0
        public AssetSyncMachineModule()
        {
            Get["/syncmachine"] = x => {
                var settings       = new SyncMachineConfiguration();
                var set            = settings.Get();
                var syncedMachines = set.Machines.Any() ? set.Machines : new List <SyncMachineModel>();
                var model          = new PageAssetSyncMachineModel {
                    IsActive       = set.IsActive,
                    SyncedMachines = syncedMachines.OrderBy(_ => _.MachineAddress)
                };
                return(JsonConvert.SerializeObject(model));
            };

            Post["/syncmachine/set"] = x => {
                var syncmachineConfiguration = new SyncMachineConfiguration();
                syncmachineConfiguration.Set();
                return(HttpStatusCode.OK);
            };

            Post["/syncmachine/restart"] = x => {
                var syncmachineConfiguration = new SyncMachineConfiguration();
                syncmachineConfiguration.Start();
                return(HttpStatusCode.OK);
            };

            Post["/syncmachine/stop"] = x => {
                var syncmachineConfiguration = new SyncMachineConfiguration();
                syncmachineConfiguration.Stop();
                return(HttpStatusCode.OK);
            };

            Post["/syncmachine/enable"] = x => {
                var dhcpdConfiguration = new SyncMachineConfiguration();
                dhcpdConfiguration.Enable();
                dhcpdConfiguration.Start();
                return(HttpStatusCode.OK);
            };

            Post["/syncmachine/disable"] = x => {
                var dhcpdConfiguration = new SyncMachineConfiguration();
                dhcpdConfiguration.Disable();
                dhcpdConfiguration.Stop();
                return(HttpStatusCode.OK);
            };

            Post["/syncmachine/machine"] = x => {
                string machineAddress = Request.Form.MachineAddress;
                var    model          = new SyncMachineModel {
                    MachineAddress = machineAddress
                };
                var syncmachineConfiguration = new SyncMachineConfiguration();
                syncmachineConfiguration.AddResource(model);
                return(HttpStatusCode.OK);
            };

            Post["/syncmachine/machine/del"] = x => {
                string guid = Request.Form.Guid;
                var    syncmachineConfiguration = new SyncMachineConfiguration();
                syncmachineConfiguration.RemoveResource(guid);
                return(HttpStatusCode.OK);
            };

            Post["Accept Configuration", "/syncmachine/accept"] = x => {
                string file    = Request.Form.File;
                string content = Request.Form.Content;
                if (File.Exists(file))
                {
                    File.Copy(file, $"{file}.sbck", true);
                }
                File.WriteAllText(file, content);
                //todo restart service to apply changes
                return(HttpStatusCode.OK);
            };
        }