Esempio n. 1
0
		public AllPageCameraDef(CameraSpec cs)
		{
			id = cs.id;
			name = cs.name;
			if (cs.type == CameraType.ThirdPartyHosted)
			{
				if (string.IsNullOrWhiteSpace(cs.path_3rdpartyimgzippedURL))
					imageUrl = cs.path_3rdpartyimg.Replace("%TIME%", TimeUtil.GetTimeInMsSinceEpoch().ToString());
				nameLink = cs.path_3rdpartynamelink;
				imageLink = cs.path_3rdpartyimglink;
			}
			allPageOverlayMessage = cs.allPageOverlayMessage;
			DateTime timeObj;
			try
			{
				Navigation.GetLatestImagePath(cs, out string timeHtml, out timeObj);
			}
			catch (NavigationException)
			{
				timeObj = DateTime.Now;
			}
			date = TimeUtil.GetTimeInMsSinceEpoch(timeObj);
		}
Esempio n. 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;
                                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);
        }