예제 #1
0
        public static Value Read(XmlNode node)
        {
            var result = new Value();
            result.Triggers = new List<Trigger>();
            result.MultiTriggers = new List<MultiTrigger>();

            foreach (XmlNode childNode in node.ChildNodes)
            {
                if (childNode.NodeType == XmlNodeType.Element)
                {
                    switch (childNode.Name.ToLower())
                    {
                        case "triggers":

                            foreach (XmlNode triggerNode in childNode)
                            {
                                if (triggerNode.NodeType == XmlNodeType.Element)
                                {

                                    switch (triggerNode.Name.ToLower())
                                    {

                                        case "trigger":

                                            var trigger = Trigger.Read(triggerNode);
                                            if (trigger != null) result.Triggers.Add(trigger);

                                            break;

                                        case "multitrigger":

                                            var multiTrigger = MultiTrigger.Read(triggerNode);
                                            if (multiTrigger != null) result.MultiTriggers.Add(multiTrigger);

                                            break;
                                    }
                                }
                            }

                            break;

                        case "result":

                            var returnResult = new Return();
                            returnResult.Id = "DEFAULT_ID";

                            if (childNode.Attributes != null)
                                if (childNode.Attributes["numval"] != null)
                                    returnResult.NumVal = Convert.ToInt16(childNode.Attributes["numval"].Value);

                            returnResult.Value = childNode.InnerText;

                            result.Result = returnResult;

                            break;
                    }
                }
            }

            return result;
        }
예제 #2
0
        private static DateTime GetTimestampFromCurrent(Value value, ReturnData currentData)
        {
            var result = DateTime.MinValue;

            var dataItems = currentData.DeviceStreams[0].GetAllDataItems();

            foreach (var trigger in value.Triggers)
            {
                var timestamp = GetTimestampFromTrigger(trigger, dataItems);
                if (timestamp > result) result = timestamp;
            }

            foreach (var multitrigger in value.MultiTriggers)
            {
                foreach (var trigger in multitrigger.Triggers)
                {
                    var timestamp = GetTimestampFromTrigger(trigger, dataItems);
                    if (timestamp > result) result = timestamp;
                }
            }

            return result;
        }