Exemple #1
0
        public static List <PTZProfile> GetPtzProfiles()
        {
            List <PTZProfile> profiles = new List <PTZProfile>();
            DirectoryInfo     di       = new DirectoryInfo(CameraProxyGlobals.PTZProfilesDirectoryBase);

            if (di.Exists)
            {
                FileInfo[] files = di.GetFiles("*.xml");
                foreach (FileInfo fi in files)
                {
                    PTZProfile p = new PTZProfile();
                    p.Load(fi.FullName);
                    profiles.Add(p);
                }
                profiles.Sort(new ComparisonComparer <PTZProfile>((p1, p2) => { return(p1.name.CompareTo(p2.name)); }));
            }
            return(profiles);
        }
Exemple #2
0
        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);
        }