private void ProcessGeneratedEvents(EventData data)
        {
            var gEventItems = (List <GeneratedEvent>)data.Data02;

            gEventItems = gEventItems.OrderBy(o => o.CurrentValue.Timestamp).ToList();

            var pc = Configuration.Get(configuration);

            if (pc != null)
            {
                var infos = new List <PartInfo>();

                foreach (var partCountEvent in pc.Events)
                {
                    var matchedItems = gEventItems.FindAll(x => x.EventName == partCountEvent.EventName && x.CurrentValue != null && x.PreviousValue != null);
                    foreach (var gEvent in matchedItems)
                    {
                        // Test if current event value matches configured EventName
                        if (gEvent.CurrentValue != null && gEvent.CurrentValue.Value == String_Functions.UppercaseFirst(partCountEvent.EventValue.Replace('_', ' ')))
                        {
                            bool match = true;

                            // Test if previous event value matches configured PreviousEventName
                            if (!string.IsNullOrEmpty(partCountEvent.PreviousEventValue))
                            {
                                match = gEvent.PreviousValue.Value == String_Functions.UppercaseFirst(partCountEvent.PreviousEventValue.Replace('_', ' '));
                            }

                            if (match)
                            {
                                lock (_lock)
                                {
                                    var partInfo = PartInfo.Process(partCountEvent, gEvent, lastSequence);
                                    if (partInfo != null)
                                    {
                                        infos.Add(partInfo);

                                        lastSequence = partInfo.Sequence;
                                        SaveStoredSequence(configuration, lastSequence);
                                    }
                                }
                            }
                        }
                    }

                    if (infos.Count > 0)
                    {
                        SendPartInfos(infos);
                    }
                }
            }
        }
Example #2
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);
        }
Example #3
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;
        }