Exemple #1
0
        private CallingLocation ReadLocationEntry(LINETRANSLATECAPS lcl, byte[] rawBuffer, int pos)
        {
            var lce  = new LINELOCATIONENTRY();
            int size = Marshal.SizeOf(lce);

            pos = lcl.dwLocationListOffset + (pos * size);
            IntPtr pLce = Marshal.AllocHGlobal(size);

            Marshal.Copy(rawBuffer, pos, pLce, size);
            Marshal.PtrToStructure(pLce, lce);
            Marshal.FreeHGlobal(pLce);

            // Locate the country
            Country locCountry = _countries.FirstOrDefault(country => country.Id == lce.dwCountryID);

            // Locate the default calling card (if any)
            CallingCard card = null;

            if (lce.dwPreferredCardID < _cards.Count)
            {
                card = _cards[lce.dwPreferredCardID];
            }

            return(new CallingLocation(lce.dwPermanentLocationID, card,
                                       NativeMethods.GetString(rawBuffer, lce.dwLocationNameOffset, lce.dwLocationNameSize, NativeMethods.STRINGFORMAT_UNICODE), locCountry,
                                       NativeMethods.GetString(rawBuffer, lce.dwCityCodeOffset, lce.dwCityCodeSize, NativeMethods.STRINGFORMAT_UNICODE),
                                       NativeMethods.GetString(rawBuffer, lce.dwLocalAccessCodeOffset, lce.dwLocalAccessCodeSize, NativeMethods.STRINGFORMAT_UNICODE),
                                       NativeMethods.GetString(rawBuffer, lce.dwLongDistanceAccessCodeOffset, lce.dwLongDistanceAccessCodeSize, NativeMethods.STRINGFORMAT_UNICODE),
                                       NativeMethods.GetString(rawBuffer, lce.dwTollPrefixListOffset, lce.dwTollPrefixListSize, NativeMethods.STRINGFORMAT_UNICODE),
                                       NativeMethods.GetString(rawBuffer, lce.dwCancelCallWaitingOffset, lce.dwCancelCallWaitingSize, NativeMethods.STRINGFORMAT_UNICODE), lce.dwOptions));
        }
Exemple #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;
                }
            }
        }
Exemple #3
0
        private static CallingCard ReadCallingCard(LINETRANSLATECAPS lcl, byte[] rawBuffer, int pos)
        {
            var lce  = new LINECARDENTRY();
            int size = Marshal.SizeOf(lce);

            pos = lcl.dwCardListOffset + (pos * size);
            IntPtr pLce = Marshal.AllocHGlobal(size);

            Marshal.Copy(rawBuffer, pos, pLce, size);
            Marshal.PtrToStructure(pLce, lce);
            Marshal.FreeHGlobal(pLce);

            return(new CallingCard(lce.dwPermanentCardID,
                                   NativeMethods.GetString(rawBuffer, lce.dwCardNameOffset, lce.dwCardNameSize, NativeMethods.STRINGFORMAT_UNICODE), lce.dwCardNumberDigits,
                                   NativeMethods.GetString(rawBuffer, lce.dwSameAreaRuleOffset, lce.dwSameAreaRuleSize, NativeMethods.STRINGFORMAT_UNICODE),
                                   NativeMethods.GetString(rawBuffer, lce.dwLongDistanceRuleOffset, lce.dwLongDistanceRuleSize, NativeMethods.STRINGFORMAT_UNICODE),
                                   NativeMethods.GetString(rawBuffer, lce.dwInternationalRuleOffset, lce.dwInternationalRuleSize, NativeMethods.STRINGFORMAT_UNICODE), lce.dwOptions));
        }