예제 #1
0
 public void Unsubscribe()
 {
     try
     {
         //var result = Items.Select(i => i.DataReference).ToArray();
         DataSubscription.UnsubscribeAll();
         Items.Clear();
         _d.Invoke(() => FilteredAttributes.Clear());
     }
     catch { }
 }
예제 #2
0
        /// <summary>
        /// Sort the list of strings and convert it into Attribute objects
        /// </summary>
        /// <param name="attributes">The value of an objects _Attributes[] attribute</param>
        private void DealWithNewAttributes(List <string> attributes)
        {
            //unsubscribe all previous subscriptions
            DataSubscription.UnsubscribeAll();
            attributes.Sort();
            Dictionary <string, List <string> > uniqueAttributes = new Dictionary <string, List <string> >();
            string        previous    = "zoogabooga";//I bet nobody will call an attribute this
            List <string> currentList = new List <string>();

            for (int i = 0; i < attributes.Count; i++)
            {
                if (attributes[i].StartsWith(previous))
                {
                    currentList.Add(attributes[i]);
                }
                else
                {
                    currentList = new List <string>();
                    uniqueAttributes.Add(attributes[i], currentList);
                    previous = attributes[i];
                }
            }
            foreach (var kvp in uniqueAttributes)
            {
                Attribute a = new Attribute(kvp.Key, kvp.Value, this);
                Attributes.Add(a);
                a.PropertyChanged += Attribute_PropertyChanged;
            }
            //Filter the attributes on the GUI dispatcher
            _d.Invoke(() =>
            {
                FilteredAttributes.Clear();
                var results = from i in Attributes where (i.Flags & FilterOptions) != 0 select i;
                FilteredAttributes.AddRange(results);
            });

            //subscribe all the filtered Attributes DataItems
            foreach (var a in FilteredAttributes)
            {
                Items.AddRange(a.DataItems);
            }

            var dataSources = new List <DataReferenceSource>();

            foreach (var dataItem in Items)
            {
                dataSources.Add(
                    new DataReferenceSource(
                        dataItem.ReferenceString,
                        dataItem.OwningObject,
                        (d) =>
                {
                    dataItem.DataReference = d;
                    dataItem.DataValue     = d.VTQ.Value.RawValue;
                    dataItem.StatusSetting = d.VTQ.QualityStatus.StatusSetting;
                    dataItem.MxQuality     = d.VTQ.QualityStatus.MxQuality;
                    dataItem.OpcUaQuality  = d.VTQ.QualityStatus.OPCUAQuality;
                    dataItem.Timestamp     = d.VTQ.Timestamp;
                }));
            }
            DataSubscription.Subscribe(dataSources.ToArray());
        }