public string SaveItem(HttpProcessor p) { bool isNew = p.GetBoolParam("new"); string originalIdNotLowerCase = p.GetPostParam("itemid"); string originalId = originalIdNotLowerCase.ToLower(); string itemtype = p.GetPostParam("itemtype"); if (itemtype == "camera") { CameraSpec cs = new CameraSpec(); string result = cs.setFieldValues(p.RawPostParams); if (result.StartsWith("0")) { return(result); } lock (this) { if (isNew) { cs.id = originalId; if (CameraIdIsUsed(cs.id)) { return("0A camera with this ID already exists."); } cameras.Add(cs); } else { if (originalId != cs.id && CameraIdIsUsed(cs.id)) { return("0A camera with this ID already exists."); } bool foundCamera = false; for (int i = 0; i < cameras.Count; i++) { if (cameras[i].id == originalId) { cs.order = cameras[i].order; foundCamera = true; MJpegServer.cm.KillCamera(originalId); cameras[i] = cs; break; } } if (!foundCamera) { cameras.Add(cs); } } MJpegServer.cm.CleanUpCameraOrder(); Save(CameraProxyGlobals.ConfigFilePath); } return(result); } else if (itemtype == "user") { Configuration.User u = new Configuration.User(); string result = u.setFieldValues(p.RawPostParams); if (result.StartsWith("0")) { return(result); } lock (this) { if (isNew) { u.name = originalId; if (UserNameIsUsed(u.name)) { return("0A user with this name already exists."); } users.Add(u); } else { if (originalId != u.name && UserNameIsUsed(u.name)) { return("0A user with this name already exists."); } bool foundUser = false; for (int i = 0; i < users.Count; i++) { if (users[i].name == originalId) { foundUser = true; users[i] = u; break; } } if (!foundUser) { users.Add(u); } } Save(CameraProxyGlobals.ConfigFilePath); } return(result); } else if (itemtype == "ptzprofile") { PTZProfile f = new PTZProfile(); int version = p.GetPostIntParam("version", 1); if (version == 1) { f.spec = new PTZSpecV1(); } string result = f.spec.setFieldValues(p.RawPostParams); if (result.StartsWith("0")) { return(result); } lock (this) { if (isNew) { f.name = originalIdNotLowerCase; if (ProfileNameIsUsed(f.name)) { return("0A PTZ Profile with this name already exists."); } f.Save(CameraProxyGlobals.PTZProfilesDirectoryBase + f.name + ".xml"); } else { if (originalId != f.name.ToLower() && ProfileNameIsUsed(f.name)) { return("0A PTZ Profile with this name already exists."); } File.Delete(CameraProxyGlobals.PTZProfilesDirectoryBase + originalId + ".xml"); f.Save(CameraProxyGlobals.PTZProfilesDirectoryBase + f.name + ".xml"); } } return(result); } return("0Invalid item type: " + itemtype); }
public string SaveItem(HttpProcessor p) { bool isNew = p.GetBoolParam("new"); string originalIdNotLowerCase = p.GetPostParam("itemid"); string originalId = originalIdNotLowerCase.ToLower(); string itemtype = p.GetPostParam("itemtype"); if (itemtype == "camera") { CameraSpec cs = new CameraSpec(); string result = cs.setFieldValues(p.RawPostParams); if (result.StartsWith("0")) { return(result); } lock (this) { if (isNew) { cs.id = originalId; if (CameraIdIsUsed(cs.id)) { return("0A camera with this ID already exists."); } cameras.Add(cs); } else { if (originalId != cs.id && CameraIdIsUsed(cs.id)) { return("0A camera with this ID already exists."); } bool foundCamera = false; for (int i = 0; i < cameras.Count; i++) { if (cameras[i].id == originalId) { cs.order = cameras[i].order; foundCamera = true; cameras[i] = cs; break; } } if (!foundCamera) { cameras.Add(cs); } } CleanUpCameraOrder(); Save(Globals.ConfigFilePath); } return(result); } else if (itemtype == "user") { Configuration.User u = new Configuration.User(); string result = u.setFieldValues(p.RawPostParams); if (result.StartsWith("0")) { return(result); } lock (this) { if (isNew) { u.name = originalId; if (UserNameIsUsed(u.name)) { return("0A user with this name already exists."); } users.Add(u); } else { if (originalId != u.name && UserNameIsUsed(u.name)) { return("0A user with this name already exists."); } bool foundUser = false; for (int i = 0; i < users.Count; i++) { if (users[i].name == originalId) { foundUser = true; users[i] = u; break; } } if (!foundUser) { users.Add(u); } } Save(Globals.ConfigFilePath); } return(result); } else if (itemtype == "globaloptions") { Configuration.TimelapseGlobalOptions o = new TimelapseGlobalOptions(); string result = o.setFieldValues(p.RawPostParams); if (result.StartsWith("0")) { return(result); } lock (this) { this.options = o; Save(Globals.ConfigFilePath); } GlobalThrottledStream.ThrottlingManager.SetBytesPerSecond(0, o.uploadBytesPerSecond); GlobalThrottledStream.ThrottlingManager.SetBytesPerSecond(1, o.downloadBytesPerSecond); GlobalThrottledStream.ThrottlingManager.BurstIntervalMs = o.throttlingGranularity; return(result); } return("0Invalid item type: " + itemtype); }