Beispiel #1
0
        public static PartInfo Process(PartCountEvent partCountEvent, GeneratedEvent gEvent, long _lastSequence)
        {
            if (partCountEvent.ValueType == ValueType.CAPTURE_ITEM)
            {
                return(ProcessCaptureItemMethod(partCountEvent, gEvent, _lastSequence));
            }
            else if (partCountEvent.ValueType == ValueType.STATIC_INCREMENT)
            {
                return(ProcessStaticIncrementMethod(partCountEvent, gEvent, _lastSequence));
            }

            return(null);
        }
        public static PartInfo Process(PartCountEvent partCountEvent, GeneratedEvent gEvent, long _lastSequence)
        {
            if (partCountEvent.ValueType == ValueType.CAPTURE_ITEM)
            {
                return ProcessCaptureItemMethod(partCountEvent, gEvent, _lastSequence);
            }
            else if (partCountEvent.ValueType == ValueType.STATIC_INCREMENT)
            {
                return ProcessStaticIncrementMethod(partCountEvent, gEvent, _lastSequence);
            }

            return null;
        }
Beispiel #3
0
        private static PartInfo ProcessCaptureItemMethod(PartCountEvent partCountEvent, GeneratedEvent gEvent, long _lastSequence)
        {
            if (!string.IsNullOrEmpty(partCountEvent.CaptureItemLink))
            {
                var captureItem = gEvent.CaptureItems.Find(x => x.Name == partCountEvent.CaptureItemLink);

                if (captureItem != null && captureItem.Sequence > _lastSequence)
                {
                    int count = 0;
                    int.TryParse(captureItem.Value, out count);
                    if (count > 0)
                    {
                        DateTime timestamp = gEvent.CurrentValue.Timestamp;

                        // Create new PartInfo object
                        var info = new PartInfo();
                        info.Id        = Guid.NewGuid().ToString();
                        info.Timestamp = timestamp;
                        info.Sequence  = captureItem.Sequence;

                        // Calculate Increment Value based on CalculationType
                        if (partCountEvent.CalculationType == CalculationType.INCREMENTAL)
                        {
                            info.Count = count;
                        }
                        else if (partCountEvent.CalculationType == CalculationType.TOTAL)
                        {
                            int previousCount = 0;
                            int.TryParse(captureItem.PreviousValue, out previousCount);

                            // If Part Count is less than or equal to stored value then assume
                            // it has been reset and needs to be incremented the entire new amount
                            if (count <= previousCount)
                            {
                                info.Count = count;
                            }
                            else
                            {
                                info.Count = count - previousCount;
                            }
                        }

                        return(info);
                    }
                }
            }

            return(null);
        }
Beispiel #4
0
        private static PartInfo ProcessStaticIncrementMethod(PartCountEvent partCountEvent, GeneratedEvent gEvent, long _lastSequence)
        {
            long sequence = gEvent.CurrentValue.ChangedSequence;

            // Create new PartInfo object
            var info = new PartInfo();

            info.Id        = Guid.NewGuid().ToString();
            info.Timestamp = gEvent.CurrentValue.Timestamp;
            info.Sequence  = sequence;

            info.Count = partCountEvent.StaticIncrementValue;

            return(info);
        }
        private static PartInfo ProcessCaptureItemMethod(PartCountEvent partCountEvent, GeneratedEvent gEvent, long _lastSequence)
        {
            if (!string.IsNullOrEmpty(partCountEvent.CaptureItemLink))
            {
                var captureItem = gEvent.CaptureItems.Find(x => x.Name == partCountEvent.CaptureItemLink);

                if (captureItem != null && captureItem.Sequence > _lastSequence)
                {
                    int count = 0;
                    int.TryParse(captureItem.Value, out count);
                    if (count > 0)
                    {
                        DateTime timestamp = gEvent.CurrentValue.Timestamp;

                        // Create new PartInfo object
                        var info = new PartInfo();
                        info.Id = Guid.NewGuid().ToString();
                        info.Timestamp = timestamp;
                        info.Sequence = captureItem.Sequence;

                        // Calculate Increment Value based on CalculationType
                        if (partCountEvent.CalculationType == CalculationType.INCREMENTAL)
                        {
                            info.Count = count;
                        }
                        else if (partCountEvent.CalculationType == CalculationType.TOTAL)
                        {
                            int previousCount = 0;
                            int.TryParse(captureItem.PreviousValue, out previousCount);

                            // If Part Count is less than or equal to stored value then assume
                            // it has been reset and needs to be incremented the entire new amount
                            if (count <= previousCount) info.Count = count;
                            else info.Count = count - previousCount;
                        }

                        return info;
                    }
                }
            }

            return null;
        }
        private static PartInfo ProcessStaticIncrementMethod(PartCountEvent partCountEvent, GeneratedEvent gEvent, long _lastSequence)
        {
            long sequence = gEvent.CurrentValue.ChangedSequence;

            // Create new PartInfo object
            var info = new PartInfo();
            info.Id = Guid.NewGuid().ToString();
            info.Timestamp = gEvent.CurrentValue.Timestamp;
            info.Sequence = sequence;

            info.Count = partCountEvent.StaticIncrementValue;

            return info;
        }
        public static Configuration Read(XmlDocument xml)
        {
            var result = new Configuration();

            XmlNodeList nodes = xml.SelectNodes("//Parts");

            if (nodes != null)
            {
                if (nodes.Count > 0)
                {
                    XmlNode node = nodes[0];

                    OldConfiguration oldConfig = null;

                    foreach (XmlNode child in node.ChildNodes)
                    {
                        if (child.NodeType == XmlNodeType.Element)
                        {
                            if (child.Name.ToLower() == "event")
                            {
                                var partCountEvent = new PartCountEvent();

                                foreach (XmlNode eventChild in child.ChildNodes)
                                {
                                    if (eventChild.NodeType == XmlNodeType.Element)
                                    {
                                        if (eventChild.Name.ToLower() == "calculationtype")
                                        {
                                            switch (eventChild.InnerText.ToLower())
                                            {
                                            case "incremental": partCountEvent.CalculationType = CalculationType.INCREMENTAL; break;

                                            case "total": partCountEvent.CalculationType = CalculationType.TOTAL; break;
                                            }
                                        }
                                        else if (eventChild.Name.ToLower() == "valuetype")
                                        {
                                            switch (eventChild.InnerText.ToLower())
                                            {
                                            case "capture_item": partCountEvent.ValueType = ValueType.CAPTURE_ITEM; break;

                                            case "static_increment": partCountEvent.ValueType = ValueType.STATIC_INCREMENT; break;
                                            }
                                        }
                                        else
                                        {
                                            var type = typeof(PartCountEvent);

                                            PropertyInfo info = type.GetProperty(eventChild.Name);
                                            if (info != null)
                                            {
                                                Type t = info.PropertyType;
                                                info.SetValue(partCountEvent, Convert.ChangeType(eventChild.InnerText, t), null);
                                            }
                                        }
                                    }
                                }

                                result.Events.Add(partCountEvent);
                            }
                            else
                            {
                                if (oldConfig == null)
                                {
                                    oldConfig = new OldConfiguration();
                                }

                                if (child.Name.ToLower() == "calculationtype") // Deprecated
                                {
                                    switch (child.InnerText.ToLower())
                                    {
                                    case "incremental": oldConfig.CalculationType = CalculationType.INCREMENTAL; break;

                                    case "total": oldConfig.CalculationType = CalculationType.TOTAL; break;
                                    }
                                }
                                else // Deprecated
                                {
                                    var type = typeof(OldConfiguration);

                                    PropertyInfo info = type.GetProperty(child.Name);
                                    if (info != null)
                                    {
                                        Type t = info.PropertyType;
                                        info.SetValue(oldConfig, Convert.ChangeType(child.InnerText, t), null);
                                    }
                                }
                            }
                        }
                    }

                    if (oldConfig != null)
                    {
                        var partCountEvent = new PartCountEvent();

                        partCountEvent.EventName       = oldConfig.PartsEventName;
                        partCountEvent.EventValue      = oldConfig.PartsEventValue;
                        partCountEvent.CaptureItemLink = oldConfig.PartsCaptureItemLink;
                        partCountEvent.CalculationType = oldConfig.CalculationType;

                        result.Events.Add(partCountEvent);
                    }
                }
            }

            return(result);
        }
        public static Configuration Read(XmlDocument xml)
        {
            var result = new Configuration();

            XmlNodeList nodes = xml.SelectNodes("//Parts");

            if (nodes != null)
            {
                if (nodes.Count > 0)
                {
                    XmlNode node = nodes[0];

                    OldConfiguration oldConfig = null;

                    foreach (XmlNode child in node.ChildNodes)
                    {
                        if (child.NodeType == XmlNodeType.Element)
                        {
                            if (child.Name.ToLower() == "event")
                            {
                                var partCountEvent = new PartCountEvent();

                                foreach (XmlNode eventChild in child.ChildNodes)
                                {
                                    if (eventChild.NodeType == XmlNodeType.Element)
                                    {
                                        if (eventChild.Name.ToLower() == "calculationtype")
                                        {
                                            switch (eventChild.InnerText.ToLower())
                                            {
                                                case "incremental": partCountEvent.CalculationType = CalculationType.INCREMENTAL; break;
                                                case "total": partCountEvent.CalculationType = CalculationType.TOTAL; break;
                                            }
                                        }
                                        else if (eventChild.Name.ToLower() == "valuetype")
                                        {
                                            switch (eventChild.InnerText.ToLower())
                                            {
                                                case "capture_item": partCountEvent.ValueType = ValueType.CAPTURE_ITEM; break;
                                                case "static_increment": partCountEvent.ValueType = ValueType.STATIC_INCREMENT; break;
                                            }
                                        }
                                        else
                                        {
                                            var type = typeof(PartCountEvent);

                                            PropertyInfo info = type.GetProperty(eventChild.Name);
                                            if (info != null)
                                            {
                                                Type t = info.PropertyType;
                                                info.SetValue(partCountEvent, Convert.ChangeType(eventChild.InnerText, t), null);
                                            }
                                        }
                                    }
                                }

                                result.Events.Add(partCountEvent);
                            }
                            else
                            {
                                if (oldConfig == null) oldConfig = new OldConfiguration();

                                if (child.Name.ToLower() == "calculationtype") // Deprecated
                                {
                                    switch (child.InnerText.ToLower())
                                    {
                                        case "incremental": oldConfig.CalculationType = CalculationType.INCREMENTAL; break;
                                        case "total": oldConfig.CalculationType = CalculationType.TOTAL; break;
                                    }
                                }
                                else // Deprecated
                                {
                                    var type = typeof(OldConfiguration);

                                    PropertyInfo info = type.GetProperty(child.Name);
                                    if (info != null)
                                    {
                                        Type t = info.PropertyType;
                                        info.SetValue(oldConfig, Convert.ChangeType(child.InnerText, t), null);
                                    }
                                }
                            }
                        }
                    }

                    if (oldConfig != null)
                    {
                        var partCountEvent = new PartCountEvent();

                        partCountEvent.EventName = oldConfig.PartsEventName;
                        partCountEvent.EventValue = oldConfig.PartsEventValue;
                        partCountEvent.CaptureItemLink = oldConfig.PartsCaptureItemLink;
                        partCountEvent.CalculationType = oldConfig.CalculationType;

                        result.Events.Add(partCountEvent);
                    }
                }
            }

            return result;
        }