Exemplo n.º 1
0
        /// <summary>
        /// Fetch all the attributes and subscribe according to the filter
        /// </summary>
        public void SubscribeAttributes()
        {
            //just in case we are resubscribing, clear everything
            _d.Invoke(() => FilteredAttributes.Clear());
            Attributes.Clear();
            DataReferenceSource r = new DataReferenceSource(
                Name + "._Attributes[]",
                Name,
                (i) =>
            {
                //we need to start this on a new thread otherwise we can't make other calls to the RuntimeDataClient
                string[] attributes = (string[])i.VTQ.Value.Array;
                if (attributes == null)
                {
                    return;
                }
                new Thread(() =>
                {
                    Thread.CurrentThread.IsBackground = true;
                    DealWithNewAttributes(attributes.ToList <string>());
                }).Start();
            }
                );

            //just in case
            if (DataSubscription != null)
            {
                DataSubscription.Subscribe(new DataReferenceSource[] { r });
            }
        }
Exemplo n.º 2
0
 public void Unsubscribe()
 {
     try
     {
         //var result = Items.Select(i => i.DataReference).ToArray();
         DataSubscription.UnsubscribeAll();
         Items.Clear();
         _d.Invoke(() => FilteredAttributes.Clear());
     }
     catch { }
 }
Exemplo n.º 3
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());
        }