Exemplo n.º 1
0
        public static Time24Hours stringTo24HTime(String toConvert, char splitBy)
        {
            if (toConvert == null)
            {
                return(null);
            }

            String[] split = toConvert.Split(splitBy);
            int[]    data  = new int[3] {
                0, 0, 0
            };

            if (split.Length != 3)
            {
                return(null);
            }

            if (!int.TryParse(split[0], out data[0]) || !int.TryParse(split[1], out data[1]) || !int.TryParse(split[2], out data[2]))
            {
                return(null);
            }

            Time24Hours toReturn = new Time24Hours();

            toReturn.Hours   = data[0];
            toReturn.Minutes = data[1];
            toReturn.Seconds = data[2];

            if (!toReturn.isValid())
            {
                return(null);
            }

            return(toReturn);
        }
Exemplo n.º 2
0
        public static BrightnessRequest fromString(int orderN, String toConvert)
        {
            if (toConvert == null)
            {
                return(null);
            }

            BrightnessRequest toReturn = new BrightnessRequest();

            toReturn.orderNum = orderN;

            String[] split = toConvert.Split(';');

            if (split.Length != 3)
            {
                return(null);
            }

            Time24Hours startT = Time24Hours.stringTo24HTime(split[0], ',');
            Time24Hours endT   = Time24Hours.stringTo24HTime(split[1], ',');
            int         lightL = 1; //We never want the light level to default to 0%

            if (!int.TryParse(split[2], out lightL))
            {
                return(null);
            }
            if (lightL < 0 || lightL > 100)
            {
                return(null);
            }
            if (startT == null || endT == null)
            {
                return(null);
            }
            if (!startT.isValid() || !endT.isValid())
            {
                return(null);
            }

            toReturn.startTime  = startT;
            toReturn.endTime    = endT;
            toReturn.brightness = lightL;

            return(toReturn);
        }