Example #1
0
        private void SetLocationInfo(CallingLocation loc)
        {
            int rc = NativeMethods.lineSetCurrentLocation(_mgr.LineHandle, (loc != null) ? loc.Id : 0);

            if (rc != 0)
            {
                throw new TapiException("lineSetCurrentLocation failed", rc);
            }
        }
Example #2
0
        private void ReadCallingLocations()
        {
            var ltc = new LINETRANSLATECAPS();

            int rc, neededSize = 4092;

            do
            {
                ltc.dwTotalSize = neededSize;
                IntPtr pLtc = Marshal.AllocHGlobal(neededSize);
                Marshal.StructureToPtr(ltc, pLtc, true);
                rc = NativeMethods.lineGetTranslateCaps(_mgr.LineHandle, (int)TapiVersion.V21, pLtc);
                Marshal.PtrToStructure(pLtc, ltc);
                if (ltc.dwNeededSize > neededSize)
                {
                    neededSize = ltc.dwNeededSize;
                    rc         = NativeMethods.LINEERR_STRUCTURETOOSMALL;
                }
                else if (rc == NativeMethods.LINEERR_OK)
                {
                    var rawBuffer = new byte[ltc.dwUsedSize];
                    Marshal.Copy(pLtc, rawBuffer, 0, ltc.dwUsedSize);
                    for (int i = 0; i < ltc.dwNumCards; i++)
                    {
                        _cards.Add(ReadCallingCard(ltc, rawBuffer, i));
                    }
                    for (int i = 0; i < ltc.dwNumLocations; i++)
                    {
                        _clocations.Add(ReadLocationEntry(ltc, rawBuffer, i));
                    }
                }
                Marshal.FreeHGlobal(pLtc);
            }while (rc == NativeMethods.LINEERR_STRUCTURETOOSMALL);

            // Assign the current country
            for (int index = 0; index < _clocations.Count; index++)
            {
                var location = _clocations[index];
                if (ltc.dwCurrentLocationID == location.Id)
                {
                    _currLocation = location;
                    break;
                }
            }
        }