public ServerNode(ServersTree owner, ServerDescription description)
		{
			Owner = owner;
			Id = description.Id;
			Name = description.ProgramId;
			ServerName = description.Name;
			IsExpanded = true;
			Icon = "/Images/ServerOff.png";
		}
        /// <summary>
        /// Returns an enumerator to allow to determine available OPC servers.
        /// </summary>
        /// <param name="categories">OPC Server categories (OPCDA/OPCHDA etc.)</param>
        /// <returns>Enumerator to allow to determine available OPC servers.</returns>
		public IEnumerable<ServerDescription> GetEnumerator(params Guid[] categories)
		{
			IEnumGUID enumerator = null;
			IOPCEnumGUID opcEnumerator = null;
			try
			{
				var tmp = Guid.Empty;
				if(serverList2 != null)
					serverList2.EnumClassesOfCategories(
						(uint)categories.Length, 
						categories, 
						0,
						ref tmp, 
						out opcEnumerator);					
				else
					serverList.EnumClassesOfCategories(
						(uint)categories.Length, 
						categories, 
						0,
						ref tmp, 
						out enumerator);					

				while(true)
				{
                    var res = 0;
                    uint fetched = 0;
                    var ids = new Guid[1];
                    if (opcEnumerator != null)
                        res = opcEnumerator.Next((uint)ids.Length, ids, out fetched);
					else if (enumerator != null)
                        res = enumerator.Next(1, ids, out fetched);
                    if (res > 1)
                        Marshal.ThrowExceptionForHR(res);
					if(fetched == 0)
						break;

				    var id = ids[0];
				    ServerDescription serverDescription;
                    try 
					{
					    string name;
                        string programId;
                        var versionIndependentProgramId = string.Empty;
                        if (serverList2 != null)
                            serverList2.GetClassDetails(ref id, out programId, out name, out versionIndependentProgramId);
						else
							serverList.GetClassDetails(ref id, out programId, out name);
                        serverDescription = new ServerDescription(id, programId, versionIndependentProgramId, name);
					}
					catch(Exception e)
					{
                        serverDescription = new ServerDescription(id, e);
					}

                    yield return serverDescription;
				}
			}
			finally
			{
				if(enumerator != null)
					Marshal.ReleaseComObject(enumerator);
				if(opcEnumerator != null)
					Marshal.ReleaseComObject(opcEnumerator);
			}
		}
Exemple #3
0
        /// <summary>
        /// Returns an enumerator to allow to determine available OPC servers.
        /// </summary>
        /// <param name="categories">OPC Server categories (OPCDA/OPCHDA etc.)</param>
        /// <returns>Enumerator to allow to determine available OPC servers.</returns>
        public IEnumerable <ServerDescription> GetEnumerator(params Guid[] categories)
        {
            IEnumGUID    enumerator    = null;
            IOPCEnumGUID opcEnumerator = null;

            try
            {
                var tmp = Guid.Empty;
                if (serverList2 != null)
                {
                    serverList2.EnumClassesOfCategories(
                        (uint)categories.Length,
                        categories,
                        0,
                        ref tmp,
                        out opcEnumerator);
                }
                else
                {
                    serverList.EnumClassesOfCategories(
                        (uint)categories.Length,
                        categories,
                        0,
                        ref tmp,
                        out enumerator);
                }

                while (true)
                {
                    var  res     = 0;
                    uint fetched = 0;
                    var  ids     = new Guid[1];
                    if (opcEnumerator != null)
                    {
                        res = opcEnumerator.Next((uint)ids.Length, ids, out fetched);
                    }
                    else if (enumerator != null)
                    {
                        res = enumerator.Next(1, ids, out fetched);
                    }
                    if (res > 1)
                    {
                        Marshal.ThrowExceptionForHR(res);
                    }
                    if (fetched == 0)
                    {
                        break;
                    }

                    var id = ids[0];
                    ServerDescription serverDescription;
                    try
                    {
                        string name;
                        string programId;
                        var    versionIndependentProgramId = string.Empty;
                        if (serverList2 != null)
                        {
                            serverList2.GetClassDetails(ref id, out programId, out name, out versionIndependentProgramId);
                        }
                        else
                        {
                            serverList.GetClassDetails(ref id, out programId, out name);
                        }
                        serverDescription = new ServerDescription(id, programId, versionIndependentProgramId, name);
                    }
                    catch (Exception e)
                    {
                        serverDescription = new ServerDescription(id, e);
                    }

                    yield return(serverDescription);
                }
            }
            finally
            {
                if (enumerator != null)
                {
                    Marshal.ReleaseComObject(enumerator);
                }
                if (opcEnumerator != null)
                {
                    Marshal.ReleaseComObject(opcEnumerator);
                }
            }
        }