Example #1
0
 protected Subscription(SerializationInfo info, StreamingContext context)
 {
     this.m_server       = null;
     this.m_subscription = null;
     this.m_state        = new SubscriptionState();
     this.m_name         = null;
     this.m_filters      = new SubscriptionFilters();
     this.m_categories   = new CategoryCollection();
     this.m_areas        = new StringCollection();
     this.m_sources      = new StringCollection();
     this.m_attributes   = new AttributeDictionary();
     this.m_state        = (SubscriptionState)info.GetValue("ST", typeof(SubscriptionState));
     this.m_filters      = (SubscriptionFilters)info.GetValue("FT", typeof(SubscriptionFilters));
     this.m_attributes   = (AttributeDictionary)info.GetValue("AT", typeof(AttributeDictionary));
     this.m_name         = this.m_state.Name;
     this.m_categories   = new CategoryCollection(this.m_filters.Categories.ToArray());
     this.m_areas        = new StringCollection(this.m_filters.Areas.ToArray());
     this.m_sources      = new StringCollection(this.m_filters.Sources.ToArray());
 }
Example #2
0
 public Subscription(Opc.Ae.Server server, ISubscription subscription, SubscriptionState state)
 {
     this.m_server       = null;
     this.m_subscription = null;
     this.m_state        = new SubscriptionState();
     this.m_name         = null;
     this.m_filters      = new SubscriptionFilters();
     this.m_categories   = new CategoryCollection();
     this.m_areas        = new StringCollection();
     this.m_sources      = new StringCollection();
     this.m_attributes   = new AttributeDictionary();
     if (server == null)
     {
         throw new ArgumentNullException("server");
     }
     if (subscription == null)
     {
         throw new ArgumentNullException("subscription");
     }
     this.m_server       = server;
     this.m_subscription = subscription;
     this.m_state        = (SubscriptionState)state.Clone();
     this.m_name         = state.Name;
 }
        /// <summary>
        /// Returns a list of servers that support the specified specification on the specified host.
        /// </summary>
        public Opc.Server[] GetAvailableServers(Specification specification, string host, ConnectData connectData)
        {
            lock (this)
            {
                NetworkCredential credentials = (connectData != null)?connectData.GetCredential(null, null):null;

                // connect to the server.
                m_server = (IOPCServerList2)OpcCom.Interop.CreateInstance(CLSID, host, credentials);
                m_host   = host;

                try
                {
                    ArrayList servers = new ArrayList();

                    // convert the interface version to a guid.
                    Guid catid = new Guid(specification.ID);

                    // get list of servers in the specified specification.
                    IOPCEnumGUID enumerator = null;

                    m_server.EnumClassesOfCategories(
                        1,
                        new Guid[] { catid },
                        0,
                        null,
                        out enumerator);

                    // read clsids.
                    Guid[] clsids = ReadClasses(enumerator);

                    // release enumerator object.
                    OpcCom.Interop.ReleaseServer(enumerator);
                    enumerator = null;

                    // fetch class descriptions.
                    foreach (Guid clsid in clsids)
                    {
                        Factory factory = new OpcCom.Factory();

                        try
                        {
                            URL url = CreateUrl(specification, clsid);

                            Opc.Server server = null;

                            if (specification == Specification.COM_DA_30)
                            {
                                server = new Opc.Da.Server(factory, url);
                            }

                            else if (specification == Specification.COM_DA_20)
                            {
                                server = new Opc.Da.Server(factory, url);
                            }

                            else if (specification == Specification.COM_AE_10)
                            {
                                server = new Opc.Ae.Server(factory, url);
                            }

                            else if (specification == Specification.COM_HDA_10)
                            {
                                server = new Opc.Hda.Server(factory, url);
                            }

                            else if (specification == Specification.COM_DX_10)
                            {
                                server = new Opc.Dx.Server(factory, url);
                            }

                            servers.Add(server);
                        }
                        catch (Exception)
                        {
                            // ignore bad clsids.
                        }
                    }

                    return((Opc.Server[])servers.ToArray(typeof(Opc.Server)));
                }
                finally
                {
                    // free the server.
                    OpcCom.Interop.ReleaseServer(m_server);
                    m_server = null;
                }
            }
        }