예제 #1
0
        public EnumGuid Clone()
        {
            IEnumGUID ppenum = null;

            this.m_enumerator.Clone(out ppenum);
            return(new EnumGuid(ppenum));
        }
        public OpcServerCategory[] GetCategories(Guid clsid)
        {
            IEnumGUID catEnumerator = null;

            try
            {
                catEnumerator = _catInformation.EnumImplCategoriesOfClass(clsid);

                var catids = new Guid[MaxItemsPerRequest];
                int fetched;
                var result = new List <OpcServerCategory>();
                do
                {
                    catEnumerator.Next(catids.Length, catids, out fetched);
                    for (var i = 0; i < fetched; i++)
                    {
                        var catid             = catids[i];
                        var opcServerCategory = OpcServerCategory.Get(catid);
                        if (opcServerCategory != null)
                        {
                            result.Add(opcServerCategory);
                        }
                    }
                } while (fetched != 0);

                return(result.ToArray());
            }
            finally
            {
                if (catEnumerator != null)
                {
                    Marshal.ReleaseComObject(catEnumerator);
                }
            }
        }
예제 #3
0
        // Token: 0x0600022D RID: 557 RVA: 0x00019B88 File Offset: 0x00018B88
        public EnumGuid Clone()
        {
            IEnumGUID server = null;

            this.m_enumerator.Clone(out server);
            return(new EnumGuid(server));
        }
예제 #4
0
        /// <summary>
        /// clones the enumerator.
        /// </summary>
        public EnumGuid Clone()
        {
            IEnumGUID enumerator = null;

            m_enumerator.Clone(out enumerator);
            return(new EnumGuid(enumerator));
        }
예제 #5
0
 private void Dispose(bool disposing)
 {
     if (ComServer != null)
     {
         Marshal.ReleaseComObject(ComServer);
         ComServer = null;
     }
 }
예제 #6
0
 private void Dispose(bool disposing)
 {
     if (ComServer != null)
     {
         Marshal.ReleaseComObject(ComServer);
         ComServer = null;
     }
 }
예제 #7
0
        internal EnumGuid(IEnumGUID comServer)
        {
            if (comServer == null)
            {
                throw new ArgumentNullException("comServer");
            }

            ComServer = comServer;
        }
예제 #8
0
        private SERVERPARAM[] GetServerParam(IOPCServerList svrList, Guid catid)
        {
            // get list of servers in the specified specification.
            IEnumGUID enumeratorObject = null; //enumeratorObject has been changed from object to IEnumGUID

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

            ArrayList prms = new ArrayList();

            IEnumGUID enumerator = enumeratorObject;

            int fetched = 0;

            Guid[]      buffer = new Guid[100];
            SERVERPARAM prm;

            do
            {
                IntPtr _buffer = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(Guid)) * 100);                //alloc
                try
                {
                    enumerator.Next(100, buffer, out fetched);

                    IntPtr pPos = _buffer;
                    for (int i = 0; i < fetched; i++)
                    {
                        prm.clsid = (Guid)Marshal.PtrToStructure(pPos, typeof(Guid));
                        pPos      = (IntPtr)(pPos.ToInt64() + Marshal.SizeOf(typeof(Guid)));
                        //prm.clsid = bufferPtr[i];
                        svrList.GetClassDetails(
                            ref prm.clsid,
                            out prm.progID,
                            out prm.description);
                        prms.Add(prm);
                    }
                }
                catch
                {
                    break;
                }
                finally
                {
                    Marshal.FreeCoTaskMem(_buffer);//alloc�� ���� Ǯ��д�.
                }
            }while (fetched > 0);

            return((SERVERPARAM[])prms.ToArray(typeof(SERVERPARAM)));
        }
예제 #9
0
        public void ListAllServer(Guid catid, out OPCServers[] serverslist)
        {
            serverslist = null;
            this.Dispose();
            Guid clsid         = new Guid("13486D51-4821-11D2-A494-3CB306C10000");
            Type typeFromCLSID = Type.GetTypeFromCLSID(clsid);

            this.OPCObjList          = Activator.CreateInstance(typeFromCLSID);
            this.interfaceServerList = (IOPCServerList)this.OPCObjList;
            if (this.interfaceServerList == null)
            {
                Marshal.ThrowExceptionForHR(-2147467260);
            }
            this.interfaceServerList.EnumClassesOfCategories(1, ref catid, 0, ref catid, out this.enumObject);
            if (this.enumObject == null)
            {
                Marshal.ThrowExceptionForHR(-2147467260);
            }
            this.interfaceEnumGUID = (IEnumGUID)this.enumObject;
            if (this.interfaceEnumGUID == null)
            {
                Marshal.ThrowExceptionForHR(-2147467260);
            }
            int    celt         = 300;
            IntPtr rgelt        = Marshal.AllocCoTaskMem(celt * 0x10);
            int    pceltFetched = 0;

            this.interfaceEnumGUID.Next(celt, rgelt, out pceltFetched);
            if (pceltFetched < 1)
            {
                Marshal.FreeCoTaskMem(rgelt);
            }
            else
            {
                serverslist = new OPCServers[pceltFetched];
                byte[] destination = new byte[0x10];
                int    num3        = (int)rgelt;
                for (int i = 0; i < pceltFetched; i++)
                {
                    serverslist[i] = new OPCServers();
                    Marshal.Copy((IntPtr)num3, destination, 0, 0x10);
                    serverslist[i].classID = new Guid(destination);
                    this.interfaceServerList.GetClassDetails(ref serverslist[i].classID, out serverslist[i].programID, out serverslist[i].serverName);
                    num3 += 0x10;
                }
                Marshal.FreeCoTaskMem(rgelt);
                this.Dispose();
            }
        }
예제 #10
0
        /*------------------------------------------------------
        *  Get Server Parameter
        *
        *  ------------------------------------------------------*/
        private SERVERPARAM[] GetServerParam(IOPCServerList svrList, Guid catid, out int nServerCnt)
        {
            // Get Server List
            IEnumGUID enumeratorObject = null;

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

            ArrayList prms = new ArrayList();

            IEnumGUID enumerator = enumeratorObject;

            int fetched = 0;

            Guid[]      buffer = new Guid[100];
            SERVERPARAM prm;

            nServerCnt = 0;
            do
            {
                IntPtr _buffer = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(Guid)) * 100);
                try
                {
                    enumerator.Next(100, buffer, out fetched);
                    IntPtr pPos = _buffer;
                    for (int i = 0; i < fetched; i++)
                    {
                        prm.clsid       = (Guid)Marshal.PtrToStructure(pPos, typeof(Guid));
                        pPos            = (IntPtr)(pPos.ToInt64() + Marshal.SizeOf(typeof(Guid)));
                        prm.progID      = "";
                        prm.description = "";
                        svrList.GetClassDetails(ref prm.clsid, out prm.progID, out prm.description);
                        prms.Add(prm);
                        nServerCnt++;
                    }
                }
                catch
                {
                    break;
                }
                finally
                {
                    Marshal.FreeCoTaskMem(_buffer);
                }
            }while (fetched > 0);

            return((SERVERPARAM[])prms.ToArray(typeof(SERVERPARAM)));
        }
예제 #11
0
        public void Dispose()
        {
            int num;

            this.interfaceEnumGUID = null;
            if (this.enumObject != null)
            {
                num             = Marshal.ReleaseComObject(this.enumObject);
                this.enumObject = null;
            }
            this.interfaceServerList = null;
            if (this.OPCObjList != null)
            {
                num             = Marshal.ReleaseComObject(this.OPCObjList);
                this.OPCObjList = null;
            }
        }
예제 #12
0
        void IOPCServerList.EnumClassesOfCategories([In] int cImplemented, [In] ref Guid catidImpl, [In] int cRequired, [In] ref Guid catidReq, [MarshalAs(UnmanagedType.IUnknown)] out object ppUnk)
        {
            string currentMethod = Dottest.Framework.Stubs.CurrentTestMethod.Name;

            if (currentMethod.Equals("TestListAllServer04"))
            {
                ppUnk = null;
            }
            else if (currentMethod.Equals("TestListAllServer05"))
            {
                IEnumGUID e = null;
                ppUnk = e;
                //ppUnk = new object();
            }
            else
            {
                ppUnk = new EnumGUID();
            }
        }
예제 #13
0
        // Token: 0x0600000A RID: 10 RVA: 0x000024D4 File Offset: 0x000006D4
        private DxpSimpleClass.SERVERPARAM[] GetServerParam(IOPCServerList svrList, Guid catid, out int nServerCnt)
        {
            IEnumGUID enumGUID = null;

            svrList.EnumClassesOfCategories(1, new Guid[]
            {
                catid
            }, 0, null, out enumGUID);
            ArrayList arrayList = new ArrayList();
            int       num       = 0;

            Guid[] array = new Guid[100];
            nServerCnt = 0;
            do
            {
                try
                {
                    enumGUID.Next(array.Length, array, out num);
                    for (int i = 0; i < num; i++)
                    {
                        DxpSimpleClass.SERVERPARAM serverparam;
                        serverparam.clsid = array[i];
                        svrList.GetClassDetails(ref serverparam.clsid, out serverparam.progID, out serverparam.description);
                        arrayList.Add(serverparam);
                        nServerCnt++;
                    }
                }
                catch
                {
                    break;
                }
            }while (num > 0);
            Marshal.ReleaseComObject(enumGUID);
            enumGUID = null;
            return((DxpSimpleClass.SERVERPARAM[])arrayList.ToArray(typeof(DxpSimpleClass.SERVERPARAM)));
        }
예제 #14
0
        internal EnumGuid(IEnumGUID comServer)
        {
            if (comServer == null) throw new ArgumentNullException("comServer");

            ComServer = comServer;
        }
예제 #15
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);
                }
            }
        }
예제 #16
0
        /// <summary>
        /// Fetches the classes in the specified categories.
        /// </summary>
        public static List <Guid> EnumClassesInCategories(params Guid[] categories)
        {
            ICatInformation manager = (ICatInformation)CreateLocalServer(CLSID_StdComponentCategoriesMgr);

            object unknown = null;

            try
            {
                manager.EnumClassesOfCategories(
                    1,
                    categories,
                    0,
                    null,
                    out unknown);

                IEnumGUID enumerator = (IEnumGUID)unknown;

                List <Guid> classes = new List <Guid>();

                Guid[] buffer = new Guid[10];

                while (true)
                {
                    int fetched = 0;

                    IntPtr pGuids = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(Guid)) * buffer.Length);

                    try
                    {
                        enumerator.Next(buffer.Length, pGuids, out fetched);

                        if (fetched == 0)
                        {
                            break;
                        }

                        IntPtr pos = pGuids;

                        for (int ii = 0; ii < fetched; ii++)
                        {
                            buffer[ii] = (Guid)Marshal.PtrToStructure(pos, typeof(Guid));
                            pos        = (IntPtr)(pos.ToInt64() + Marshal.SizeOf(typeof(Guid)));
                        }
                    }
                    finally
                    {
                        Marshal.FreeCoTaskMem(pGuids);
                    }

                    for (int ii = 0; ii < fetched; ii++)
                    {
                        classes.Add(buffer[ii]);
                    }
                }

                return(classes);
            }
            finally
            {
                ReleaseServer(unknown);
                ReleaseServer(manager);
            }
        }
예제 #17
0
 public void Release()
 {
     Interop.ReleaseServer(this.m_enumerator);
     this.m_enumerator = null;
 }
예제 #18
0
        public void GetServerList(Guid[] catList, out string[] Servers, out Guid[] ClsIDs)
        {
            object obj2;

            Servers = null;
            ClsIDs  = null;
            if (this.ifSrvList == null)
            {
                throw new Exception(String.Format("GetServerList failed with error code {hr}", -2147467262));
            }
            this.ifSrvList.EnumClassesOfCategories(catList.Length, catList, 0, null, out obj2);
            if (obj2 != null)
            {
                IEnumGUID o = (IEnumGUID)obj2;
                obj2 = null;
                o.Reset();
                int    index     = 0;
                Guid   rgelt     = this.CLSID_OPCEnum;
                Guid[] guidArray = new Guid[50];

                int pceltFetched = 0;

                do
                {
                    o.Next(1, ref rgelt, out pceltFetched);
                    if (pceltFetched > 0)
                    {
                        guidArray[index] = rgelt;
                        index++;
                    }
                }while ((pceltFetched > 0) && (index < guidArray.Length));

                Marshal.ReleaseComObject(o);
                o = null;
                string[] strArray   = new string[index];
                Guid[]   guidArray2 = new Guid[index];
                int      num3       = 0;
                for (int i = 0; i < index; i++)
                {
                    string ppszProgID   = null;
                    string ppszUserType = null;
                    try
                    {
                        this.ifSrvList.GetClassDetails(ref guidArray[i], out ppszProgID, out ppszUserType);
                        strArray[num3]   = ppszProgID;
                        guidArray2[num3] = guidArray[i];
                        num3++;
                    }
                    catch
                    {
                    }
                }
                if (num3 > 0)
                {
                    Servers = new string[num3];
                    ClsIDs  = new Guid[num3];
                    for (int j = 0; j < num3; j++)
                    {
                        Servers[j] = strArray[j];
                        ClsIDs[j]  = guidArray2[j];
                    }
                }
                strArray   = null;
                guidArray2 = null;
            }
        }
예제 #19
0
 /// <summary>
 /// Saves a reference to the COM server.
 /// </summary>
 public EnumGuid(object server)
 {
     m_enumerator = (IEnumGUID)server;
 }
예제 #20
0
        /// <summary>
        /// List all
        /// </summary>
        /// <param name="catid">Catid</param>
        public static OpcServerDefinition[] ListAll(Guid catid)
        {
            OpcServerDefinition[] serverslist = new OpcServerDefinition[0];
            object enumObj    = null;
            Type   typeOfList = Type.GetTypeFromCLSID(OpcServerListGuid);
            object listObj    = Activator.CreateInstance(typeOfList);

            try
            {
                IOPCServerList opcServerList = listObj as IOPCServerList;
                if (opcServerList == null)
                {
                    Marshal.ThrowExceptionForHR(HRESULTS.E_ABORT);
                }

                opcServerList.EnumClassesOfCategories(1, ref catid, 0, ref catid, out enumObj);
                if (enumObj == null)
                {
                    Marshal.ThrowExceptionForHR(HRESULTS.E_ABORT);
                }

                IEnumGUID ifEnum = enumObj as IEnumGUID;
                if (ifEnum == null)
                {
                    Marshal.ThrowExceptionForHR(HRESULTS.E_ABORT);
                }

                const int maxcount = 300;
                IntPtr    ptrGuid  = Marshal.AllocCoTaskMem(maxcount * 16);
                ifEnum.Next(maxcount, ptrGuid, out int count);
                if (count < 1)
                {
                    Marshal.FreeCoTaskMem(ptrGuid);
                    return(serverslist);
                }

                serverslist = new OpcServerDefinition[count];

                byte[] guidbin = new byte[16];
                int    runGuid = (int)ptrGuid;
                for (int i = 0; i < count; i++)
                {
                    serverslist[i] = new OpcServerDefinition();
                    Marshal.Copy((IntPtr)runGuid, guidbin, 0, 16);
                    serverslist[i].ClsID = new Guid(guidbin);
                    opcServerList.GetClassDetails(ref serverslist[i].ClsID,
                                                  out serverslist[i].ProgID, out serverslist[i].Name);
                    runGuid += 16;
                }

                Marshal.FreeCoTaskMem(ptrGuid);
            }
            finally
            {
                if (!(enumObj == null))
                {
                    Marshal.ReleaseComObject(enumObj);
                }
                if (!(listObj == null))
                {
                    Marshal.ReleaseComObject(listObj);
                }
            }
            return(serverslist);
        }
예제 #21
0
        public void ListAll(Guid catid,out OpcServers[] serverslist)
        {
            serverslist = null;
             Dispose();
             Guid guid = new Guid("13486D51-4821-11D2-A494-3CB306C10000");
             Type typeoflist = Type.GetTypeFromCLSID(guid);
             OPCListObj = Activator.CreateInstance(typeoflist);

             ifList = (IOPCServerList)OPCListObj;
             if (ifList == null)
            Marshal.ThrowExceptionForHR(HRESULTS.E_ABORT);

             ifList.EnumClassesOfCategories(1,ref catid,0,ref catid,out EnumObj);
             if (EnumObj == null)
            Marshal.ThrowExceptionForHR(HRESULTS.E_ABORT);

             ifEnum = (IEnumGUID)EnumObj;
             if (ifEnum == null)
            Marshal.ThrowExceptionForHR(HRESULTS.E_ABORT);

             int maxcount = 300;
             IntPtr ptrGuid = Marshal.AllocCoTaskMem(maxcount * 16);
             int count = 0;
             ifEnum.Next(maxcount,ptrGuid,out count);
             if (count < 1) { Marshal.FreeCoTaskMem(ptrGuid); return; }

             serverslist = new OpcServers[count];

             byte[] guidbin = new byte[16];
             int runGuid = (int)ptrGuid;
             for (int i = 0; i < count; i++) {
            serverslist[i] = new OpcServers();
            Marshal.Copy((IntPtr)runGuid,guidbin,0,16);
            serverslist[i].ClsID = new Guid(guidbin);
            ifList.GetClassDetails(ref serverslist[i].ClsID,
                              out serverslist[i].ProgID,out serverslist[i].ServerName);
            runGuid += 16;
            }

             Marshal.FreeCoTaskMem(ptrGuid);
             Dispose();
        }
예제 #22
0
 public void Dispose()
 {
     ifEnum = null;
      if (!(EnumObj == null)) {
     int rc = Marshal.ReleaseComObject(EnumObj);
     EnumObj = null;
     }
      ifList = null;
      if (!(OPCListObj == null)) {
     int rc = Marshal.ReleaseComObject(OPCListObj);
     OPCListObj = null;
     }
 }
예제 #23
0
 /// <summary>
 /// releases the COM server.
 /// </summary>
 public void Release()
 {
     OpcCom.Interop.ReleaseServer(m_enumerator);
     m_enumerator = null;
 }
예제 #24
0
 public OpcServerList()
 {
     OPCListObj = null;
      ifList = null;
      EnumObj = null;
      ifEnum = null;
 }