public void Test_TryGetShiftMode()
        {
            int result = SRHelper.TryGetShiftMode("111");

            Assert.AreEqual(111, result);

            result = SRHelper.TryGetShiftMode(@".\ShiftModeAttr");
            Assert.AreEqual(-1, result);
        }
        public void Test_GetWorkShift()
        {
            int workShift = SRHelper.GetWorkShift(DateTime.Parse("2021.04.22 23:30:00"), 3, -60);

            Assert.AreEqual(1, workShift);

            workShift = SRHelper.GetWorkShift(DateTime.Parse("2021.04.23 07:30:00"), 3, -60);
            Assert.AreEqual(2, workShift);

            workShift = SRHelper.GetWorkShift(DateTime.Parse("2021.04.22 15:30:00"), 3, -60);
            Assert.AreEqual(3, workShift);
        }
        private void ProcessAttributes(AFAttributeTemplates attributes, string prefix)
        {
            foreach (AFAttributeTemplate attr in attributes)
            {
                if (attr == dataReference.Attribute)
                {
                    continue;
                }

                string attrName = prefix + "|" + attr.Name;

                if (SRHelper.IsIntVal(attr.Type))
                {
                    txtShiftMode.Items.Add(attrName);
                }

                ProcessAttributes(attr.AttributeTemplates, attrName);
            }
        }
        public void Test_GetWorkShiftParams()
        {
            double[] wsParams;
            DateTime dtx;

            dtx      = ParseDT("2021.04.22 23:30:00");
            wsParams = SRHelper.GetWorkShiftParams(dtx, 3, -60);
            Assert.AreEqual(1.00d, wsParams[0]);
            Assert.AreEqual(new AFTime("2021.04.22 23:00:00"), new AFTime(wsParams[1]));
            Assert.AreEqual(new AFTime("2021.04.23 07:00:00"), new AFTime(wsParams[2]));

            dtx      = ParseDT("2021.04.23 08:30:00");
            wsParams = SRHelper.GetWorkShiftParams(dtx, 3, -60);
            Assert.AreEqual(2.00d, wsParams[0]);
            Assert.AreEqual(new AFTime("2021.04.23 07:00:00"), new AFTime(wsParams[1]));
            Assert.AreEqual(new AFTime("2021.04.23 15:00:00"), new AFTime(wsParams[2]));

            dtx      = ParseDT("2021.04.22 21:30:00");
            wsParams = SRHelper.GetWorkShiftParams(dtx, 3, -60);
            Assert.AreEqual(3.00d, wsParams[0]);
            Assert.AreEqual(new AFTime("2021.04.22 15:00:00"), new AFTime(wsParams[1]));
            Assert.AreEqual(new AFTime("2021.04.22 23:00:00"), new AFTime(wsParams[2]));
        }
        // 2 shifts (2), 3 shifts (3), Unknown (0), Day (-1), Month (-2), Year (-3)
        public override AFValue GetValue(object context, object timeContext, AFAttributeList inputAttributes, AFValues inputValues)
        {
            AFTime time;

            if (timeContext is AFTime)
            {
                time = (AFTime)timeContext;
            }
            else if (timeContext is AFTimeRange)
            {
                var timeRange = (AFTimeRange)timeContext;
                time = (Attribute.Element is AFEventFrame) ? timeRange.StartTime : timeRange.EndTime;
            }
            else if (timeContext is DateTime)
            {
                time = new AFTime((DateTime)timeContext);
            }
            else
            {
                time = AFTime.NowInWholeSeconds;
            }

            int shiftMode = SRHelper.TryGetShiftMode(fShiftMode);

            if (shiftMode == 0)
            {
                try {
                    var attr = AFAttribute.FindAttribute(fShiftMode, Attribute);
                    if (attr == null)
                    {
                        throw new ArgumentException(string.Format(Resources.ERR_AttributeHasNotBeenFound, ShiftMode));
                    }
                    else
                    {
                        object val = attr.GetValue().Value;
                        if (SRHelper.IsIntVal(val))
                        {
                            shiftMode = (int)SRHelper.ConvertToType(val, TypeCode.Int32);
                        }
                        else
                        {
                            shiftMode = 0;
                        }
                    }
                } catch {
                    shiftMode = 0;
                }
            }

            if (shiftMode == 0)
            {
                throw new ArgumentException(Resources.ERR_SourceAttributeMustBeAnIntegerType);
            }

            DateTime localTime = time.LocalTime;

            string[] wsParams;
            if (shiftMode < 0)
            {
                wsParams = SRHelper.GetWorkMacroParams(localTime, shiftMode, fStartOffset);
            }
            else
            {
                wsParams = SRHelper.GetWorkShiftParams(localTime, shiftMode, fStartOffset);
            }
            wsParams[3] = SRHelper.GetPITimeStampStr(localTime);

            return(new AFValue(base.Attribute, wsParams, time, Attribute.DefaultUOM));
        }