public SnapshotItem(Page parentPage)
        {
            Init();

            ParentPage = parentPage;
            ParentSnapshot = new Snapshot();
        }
        public static Configuration Read(XmlDocument configXML)
        {
            var result = new Configuration();

            XmlNodeList nodes = configXML.SelectNodes("//SnapshotData");

            // Test old version of 'SnapShot' instead of 'Snapshot'
            if (nodes != null && nodes.Count == 0) nodes = configXML.SelectNodes("//GeneratedData/SnapShotData");

            if (nodes != null)
            {
                if (nodes.Count > 0)
                {

                    XmlNode node = nodes[0];

                    foreach (XmlNode child in node.ChildNodes)
                    {
                        if (child.NodeType == XmlNodeType.Element)
                        {

                            Type snapshotSetting = typeof(Configuration);
                            PropertyInfo snapshotinfo = snapshotSetting.GetProperty(child.Name);

                            if (snapshotinfo != null)
                            {
                                Type t = snapshotinfo.PropertyType;
                                snapshotinfo.SetValue(result, Convert.ChangeType(child.InnerText, t), null);
                            }
                            else if (child.Attributes != null)
                            {
                                if (child.Attributes["name"] != null && child.Attributes["link"] != null)
                                {
                                    var item = new Snapshot();

                                    string type = child.Name.ToLower();
                                    switch (type)
                                    {
                                        case "collected": item.Type = SnapshotType.Collected; break;
                                        case "generated": item.Type = SnapshotType.Generated; break;
                                        case "variable": item.Type = SnapshotType.Variable; break;
                                    }

                                    item.Name = child.Attributes["name"].Value;
                                    item.Link = child.Attributes["link"].Value;

                                    result.Snapshots.Add(item);
                                }
                            }
                        }
                    }
                }
            }

            return result;
        }
        public SnapshotItem(Page parentPage, Snapshot snapshot)
        {
            Init();

            ParentPage = parentPage;
            ParentSnapshot = snapshot;

            NameText = snapshot.Name;
            SelectedType = snapshot.Type.ToString();
            SelectedLink = snapshot.Link;
        }
        public void LoadConfiguration(DataTable dt)
        {
            LoadGeneratedEventItems(dt);

            string address = "/GeneratedData/SnapShotData/";

            string filter = "address LIKE '" + address + "*'";
            DataView dv = dt.AsDataView();
            dv.RowFilter = filter;
            DataTable temp_dt = dv.ToTable();
            temp_dt.PrimaryKey = new DataColumn[] { temp_dt.Columns["address"] };

            SnapshotItems.Clear();

            foreach (DataRow row in temp_dt.Rows)
            {
                var snapshot = new Snapshot();
                snapshot.Name = DataTable_Functions.TrakHound.GetRowAttribute("name", row);

                string type = DataTable_Functions.TrakHound.GetLastNode(row);
                if (type != null)
                {
                    switch (type.ToLower())
                    {
                        case "collected": snapshot.Type = SnapshotType.Collected; break;
                        case "generated": snapshot.Type = SnapshotType.Generated; break;
                        case "variable": snapshot.Type = SnapshotType.Variable; break;
                    }
                }

                snapshot.Link = DataTable_Functions.TrakHound.GetRowAttribute("link", row);

                var item = new Controls.SnapshotItem(this, snapshot);
                item.SettingChanged += Snapshot_SettingChanged;
                item.RemoveClicked += Snapshot_RemoveClicked;
                SnapshotItems.Add(item);
            }

            if (!Loaded) LoadCollectedItems(probeData);
        }
        private static bool ProcessVariables(Snapshot snapshot, DataTable dt)
        {
            bool result = false;

            if (dt != null)
            {
                DataRow[] rows = dt.Select("variable = '" + snapshot.Link + "'");
                if (rows != null)
                {
                    if (rows.Length > 0)
                    {
                        var val = rows[0]["value"].ToString();

                        if (snapshot.Value != val)
                        {
                            snapshot.PreviousTimestamp = snapshot.Timestamp;
                            snapshot.PreviousValue = snapshot.Value;

                            snapshot.Value = val;

                            DateTime timestamp = DateTime.MinValue;
                            DateTime.TryParse(rows[0]["timestamp"].ToString(), out timestamp);
                            if (timestamp > DateTime.MinValue) snapshot.Timestamp = timestamp;

                            result = true;
                        }
                    }
                }
            }

            return result;
        }
        private static void ProcessGenerated(Snapshot snapshot, GeneratedEvents.Configuration gec, Instance currentInstanceData, ReturnData currentData)
        {
            var e = gec.Events.Find(x => x.Name.ToLower() == snapshot.Link.ToLower());
            if (e != null)
            {
                Return returnValue = e.Process(currentInstanceData);

                if (snapshot.Value != returnValue.Value)
                {
                    if (returnValue != null)
                    {
                        var value = e.Values.Find(x => x.Result.NumVal == returnValue.NumVal);
                        if (value != null)
                        {
                            snapshot.PreviousTimestamp = GetTimestampFromCurrent(value, currentData);
                        }
                    }

                    snapshot.PreviousValue = snapshot.Value;

                    snapshot.Value = returnValue.Value;
                }

                snapshot.Timestamp = returnValue.TimeStamp;
            }
        }
        private static bool ProcessCollectedSample(Snapshot snapshot, List<DataItem> dataItems)
        {
            bool result = false;

            var dataItem = dataItems.Find(x => x.DataItemId.ToLower() == snapshot.Link.ToLower());
            if (dataItem != null)
            {
                // If first pass
                if (snapshot.PreviousValue == null)
                {
                    snapshot.PreviousTimestamp = dataItem.Timestamp;
                }

                if (snapshot.Value != dataItem.CDATA)
                {
                    snapshot.PreviousTimestamp = snapshot.Timestamp;
                    snapshot.PreviousValue = snapshot.Value;

                    snapshot.Value = dataItem.CDATA;
                }

                snapshot.Timestamp = dataItem.Timestamp;

                result = true;
            }

            return result;
        }
        private static bool ProcessCollected(Snapshot snapshot, ReturnData currentData)
        {
            bool result = false;

            if (currentData.DeviceStreams != null)
            {
                var dataItems = currentData.DeviceStreams[0].GetAllDataItems();

                bool found = false;

                // Seach Conditions
                found = ProcessCollectedCondtion(snapshot, dataItems);

                // Search Events
                if (!found) found = ProcessCollectedEvent(snapshot, dataItems);

                // Search Samples
                if (!found) found = ProcessCollectedSample(snapshot, dataItems);

                result = found;
            }

            return result;
        }
 public Snapshot Copy()
 {
     var result = new Snapshot();
     result.Timestamp = Timestamp;
     result.Name = Name;
     result.Value = Value;
     result.PreviousTimestamp = PreviousTimestamp;
     result.PreviousValue = PreviousValue;
     return result;
 }