示例#1
0
        public void BinaryPropTest()
        {
            CheckDisposed();

            // ScrImportSet::ImportSettings:Binary
            // Set class first, or it will throw an exception.
            int  hvo      = 1;
            uint clidAnal = SilDataAccess.MetaDataCache.GetClassId("ScrImportSet");

            SilDataAccess.SetInt(hvo, (int)CmObjectFields.kflidCmObject_Class, (int)clidAnal);
            int tag = (int)SilDataAccess.MetaDataCache.GetFieldId("ScrImportSet", "ImportSettings", false);

            using (ArrayPtr arrayPtr = MarshalEx.ArrayToNative(3, typeof(int)))
            {
                int    chvo;
                byte[] prgb = new byte[] { 3, 4, 5 };
                SilDataAccess.SetBinary(hvo, tag, prgb, prgb.Length);
                SilDataAccess.BinaryPropRgb(hvo, tag, arrayPtr, 3, out chvo);
                byte[] prgbNew = (byte[])MarshalEx.NativeToArray(arrayPtr, chvo, typeof(byte));
                Assert.AreEqual(prgb.Length, prgbNew.Length);
                for (int i = 0; i < prgbNew.Length; i++)
                {
                    Assert.AreEqual(prgb[i], prgbNew[i]);
                }
            }
        }
示例#2
0
        /// <summary>
        /// Override to filter the specified properties.
        /// </summary>
        public override int get_VecItem(int hvo, int tag, int index)
        {
            ITestItem tester;

            if (!m_filterFlids.TryGetValue(tag, out tester))
            {
                return(base.get_VecItem(hvo, tag, index));
            }
            int chvoReal = BaseSda.get_VecSize(hvo, tag);

            using (ArrayPtr arrayPtr = MarshalEx.ArrayToNative(chvoReal, typeof(int)))
            {
                BaseSda.VecProp(hvo, tag, chvoReal, out chvoReal, arrayPtr);
                int[] candidates = (int[])MarshalEx.NativeToArray(arrayPtr, chvoReal, typeof(int));
                int   iresult    = 0;
                for (int icandidate = 0; icandidate < candidates.Length; icandidate++)
                {
                    if (tester.Test(candidates[icandidate], BaseSda, m_validHvos))
                    {
                        if (iresult == index)
                        {
                            return(candidates[icandidate]);
                        }
                        iresult++;
                    }
                }
                throw new IndexOutOfRangeException("filtered vector does not contain that many items (wanted " + index +
                                                   " but have only " + iresult + ")");
            }
        }
示例#3
0
        public void BinaryProp()
        {
            using (ArrayPtr arrayPtr = MarshalEx.ArrayToNative <int>(10))
            {
                int chvo = 99;
                m_ISilDataAccess.BinaryPropRgb(1112, 2221, ArrayPtr.Null, 0, out chvo);
                Assert.AreEqual(0, chvo);

                byte[] prgb = new byte[] { 3, 4, 5 };
                m_IVwCacheDa.CacheBinaryProp(1112, 2221, prgb, prgb.Length);
                m_ISilDataAccess.BinaryPropRgb(1112, 2221, arrayPtr, 10, out chvo);
                byte[] prgbNew = MarshalEx.NativeToArray <byte>(arrayPtr, chvo);
                Assert.AreEqual(prgb.Length, prgbNew.Length);
                for (int i = 0; i < prgbNew.Length; i++)
                {
                    Assert.AreEqual(prgb[i], prgbNew[i]);
                }

                byte[] prgb2 = new byte[] { 6, 7, 8, 9 };
                m_IVwCacheDa.CacheBinaryProp(1112, 2221, prgb2, prgb2.Length);
                m_ISilDataAccess.BinaryPropRgb(1112, 2221, arrayPtr, 10, out chvo);
                prgbNew = MarshalEx.NativeToArray <byte>(arrayPtr, chvo);
                Assert.AreEqual(prgb2.Length, prgbNew.Length);
                for (int i = 0; i < prgbNew.Length; i++)
                {
                    Assert.AreEqual(prgb2[i], prgbNew[i]);
                }
            }
        }
示例#4
0
        /// <summary>
        /// Override to filter the specified properties.
        /// </summary>
        public override void VecProp(int hvo, int tag, int chvoMax, out int chvo, ArrayPtr rghvo)
        {
            ITestItem tester;

            if (!m_filterFlids.TryGetValue(tag, out tester))
            {
                base.VecProp(hvo, tag, chvoMax, out chvo, rghvo);
                return;
            }
            int chvoReal = BaseSda.get_VecSize(hvo, tag);

            using (ArrayPtr arrayPtr = MarshalEx.ArrayToNative(chvoReal, typeof(int)))
            {
                BaseSda.VecProp(hvo, tag, chvoReal, out chvoReal, arrayPtr);
                int[] candidates = (int[])MarshalEx.NativeToArray(arrayPtr, chvoReal, typeof(int));
                int[] results    = new int[chvoMax];
                int   iresult    = 0;
                for (int icandidate = 0; icandidate < candidates.Length; icandidate++)
                {
                    if (tester.Test(candidates[icandidate], BaseSda, m_validHvos))
                    {
                        results[iresult++] = candidates[icandidate];
                    }
                }
                chvo = iresult;
                MarshalEx.ArrayToNative(rghvo, chvoMax, results);
            }
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Used by constructor.
        /// Sets the text property vars for this proxy, from the name, type, and ws
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private void SetTextProps()
        {
            if (m_Context == ContextValues.EndMarker || m_sStyleName == null || m_sStyleName == string.Empty)
            {                   // props are not relevant for end markers or markers with no style name
                m_ttpRunProps  = m_ws == 0 ? null : StyleUtils.CharStyleTextProps(null, m_ws);
                m_rgbParaProps = null;
                return;
            }
            Debug.Assert(m_StyleType == StyleType.kstCharacter || m_StyleType == StyleType.kstParagraph);
            Debug.Assert(m_ws != 0);

            // For char style, the run props contain writing system & char style name; for para
            // style, they contain only the writing system.
            m_ttpRunProps = StyleUtils.CharStyleTextProps(
                (m_StyleType == StyleType.kstCharacter) ? m_sStyleName : null, m_ws);

            // For char style, the paragraph props are empty; for para style, they contain the
            // para style name.
            if (m_StyleType == StyleType.kstParagraph)
            {
                ITsTextProps props = StyleUtils.ParaStyleTextProps(m_sStyleName);
                using (ArrayPtr rgbFmtBufPtr = MarshalEx.ArrayToNative <byte>(kcbFmtBufMax))
                {
                    int nBytes = props.SerializeRgb(rgbFmtBufPtr, kcbFmtBufMax);
                    m_rgbParaProps = MarshalEx.NativeToArray <byte>(rgbFmtBufPtr, nBytes);
                }
            }
            else
            {
                m_rgbParaProps = null;
            }
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Get a value determining if the new writing systems should be created as a side-effect
        /// of a paste operation.
        /// </summary>
        /// <param name="wsf">writing system factory containing the new writing systems</param>
        /// <param name="destWs">The destination writing system (writing system used at the
        /// selection).</param>
        /// <returns>
        ///     an indication of how the paste should be handled.
        /// </returns>
        /// ------------------------------------------------------------------------------------
        public override PasteStatus DeterminePasteWs(ILgWritingSystemFactory wsf, out int destWs)
        {
            // Determine writing system at selection (destination for paste).
            destWs = 0;
            if (CurrentSelection != null)
            {
                destWs = CurrentSelection.GetWritingSystem(SelectionHelper.SelLimitType.Anchor);
            }
            if (destWs <= 0)
            {
                destWs = Cache.DefaultAnalWs;                 // set to default analysis, if 0.
            }
            int cws = wsf.NumberOfWs;

            using (ArrayPtr ptr = MarshalEx.ArrayToNative <int>(cws))
            {
                wsf.GetWritingSystems(ptr, cws);
                int[] vws = MarshalEx.NativeToArray <int>(ptr, cws);

                for (int iws = 0; iws < cws; iws++)
                {
                    if (vws[iws] != 0 && wsf.get_EngineOrNull(vws[iws]) == null)
                    {
                        // found corrupt writing system--don't want to use any ws in this pasted string
                        return(PasteStatus.UseDestWs);
                    }
                }
            }

            return(PasteStatus.PreserveWs);
        }
示例#7
0
        /// <summary>
        /// Override to filter the specified properties.
        /// </summary>
        public override int get_VecSize(int hvo, int tag)
        {
            ITestItem tester;

            if (!m_filterFlids.TryGetValue(tag, out tester))
            {
                return(base.get_VecSize(hvo, tag));
            }
            int chvoReal = BaseSda.get_VecSize(hvo, tag);

            using (ArrayPtr arrayPtr = MarshalEx.ArrayToNative(chvoReal, typeof(int)))
            {
                BaseSda.VecProp(hvo, tag, chvoReal, out chvoReal, arrayPtr);
                int[] candidates = (int[])MarshalEx.NativeToArray(arrayPtr, chvoReal, typeof(int));
                int   iresult    = 0;
                for (int icandidate = 0; icandidate < candidates.Length; icandidate++)
                {
                    if (tester.Test(candidates[icandidate], BaseSda, m_validHvos))
                    {
                        iresult++;
                    }
                }
                return(iresult);
            }
        }
示例#8
0
        public void StringPropWrongLengthFmtTest()
        {
            CheckDisposed();

            // Set class first, or it will throw an exception.
            int  hvo  = 1;
            uint clid = SilDataAccess.MetaDataCache.GetClassId("PhEnvironment");

            SilDataAccess.SetInt(hvo, (int)CmObjectFields.kflidCmObject_Class, (int)clid);
            int tag = (int)SilDataAccess.MetaDataCache.GetFieldId("PhEnvironment", "StringRepresentation", false);

            ITsPropsBldr propsBldr = TsPropsBldrClass.Create();

            propsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "Verse");
            ITsStrBldr strBldr = TsStrBldrClass.Create();

            // Test StringFields (which are basically the same, except that the
            // format of the parameters is different)
            strBldr.Replace(0, 0, "Third", propsBldr.GetTextProps());
            ITsString tsString = strBldr.GetString();
            int       cbFmt;

            byte[] rgbFmt;
            using (ArrayPtr arrayPtr = MarshalEx.ArrayToNative(1000, typeof(byte)))
            {
                cbFmt  = tsString.SerializeFmtRgb(arrayPtr, 1000);
                rgbFmt = (byte[])MarshalEx.NativeToArray(arrayPtr, cbFmt, typeof(byte));
            }
            VwCacheDa.CacheStringFields(hvo, tag, tsString.Text,
                                        tsString.Length, rgbFmt, cbFmt - 1);
        }
示例#9
0
        public void StringFields_Replace()
        {
            CheckDisposed();
            ITsPropsBldr propsBldr = TsPropsBldrClass.Create();

            propsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "Verse");
            ITsStrBldr strBldr = TsStrBldrClass.Create();

            // Test StringFields (which are basically the same, except that the
            // format of the parameters is different)
            strBldr.Replace(0, 0, "Third", propsBldr.GetTextProps());
            ITsString tsString = strBldr.GetString();

            using (ArrayPtr arrayPtr = MarshalEx.ArrayToNative(1000, typeof(byte)))
            {
                int    cbFmt  = tsString.SerializeFmtRgb(arrayPtr, 1000);
                byte[] rgbFmt = (byte[])MarshalEx.NativeToArray(arrayPtr, cbFmt, typeof(byte));
                m_IVwCacheDa.CacheStringFields(1118, 2228, tsString.Text,
                                               tsString.Length, rgbFmt, cbFmt);
                strBldr.Replace(0, 5, "Fourth", propsBldr.GetTextProps());
                tsString = strBldr.GetString();

                m_IVwCacheDa.CacheStringFields(1118, 2228, tsString.Text,
                                               tsString.Length, rgbFmt, cbFmt);

                ITsString tsStringNew = m_ISilDataAccess.get_StringProp(1118, 2228);

                Assert.AreEqual(tsString.Text, tsStringNew.Text);
            }
        }
示例#10
0
        public void GetFieldIdsTest()
        {
            var flidSize = m_mdc.FieldCount;

            int[] uIds;
            var   testFlidSize = flidSize - 1;

            using (var flidsPtr = MarshalEx.ArrayToNative <int>(testFlidSize))
            {
                m_mdc.GetFieldIds(testFlidSize, flidsPtr);
                uIds = MarshalEx.NativeToArray <int>(flidsPtr, testFlidSize);
                Assert.AreEqual(testFlidSize, uIds.Length, "Wrong size of fields returned.");
                foreach (var flid in uIds)
                {
                    Assert.IsTrue(flid > 0, "Wrong flid value: " + flid);
                }
            }

            testFlidSize = flidSize;
            using (var flidsPtr = MarshalEx.ArrayToNative <int>(testFlidSize))
            {
                m_mdc.GetFieldIds(testFlidSize, flidsPtr);
                uIds = MarshalEx.NativeToArray <int>(flidsPtr, testFlidSize);
                var uIdsNonCOM = m_mdc.GetFieldIds();
                Assert.AreEqual(uIds.Length, uIdsNonCOM.Length, "COM non-COM GetFieldIds different sizes.");
                for (var i = 0; i < uIdsNonCOM.Length; ++i)
                {
                    Assert.AreEqual(uIdsNonCOM[i], uIds[i], "");
                }
                Assert.AreEqual(testFlidSize, uIds.Length, "Wrong size of fields returned.");
                foreach (var flid in uIds)
                {
                    Assert.IsTrue(flid > 0, "Wrong flid value: " + flid);
                }
            }


            testFlidSize = flidSize + 1;
            using (var flidsPtr = MarshalEx.ArrayToNative <int>(testFlidSize))
            {
                m_mdc.GetFieldIds(testFlidSize, flidsPtr);
                uIds = MarshalEx.NativeToArray <int>(flidsPtr, testFlidSize);
                Assert.AreEqual(testFlidSize, uIds.Length, "Wrong size of fields returned.");
                for (var iflid = 0; iflid < uIds.Length; ++iflid)
                {
                    var flid = uIds[iflid];
                    if (iflid < uIds.Length - 1)
                    {
                        Assert.IsTrue(flid > 0, "Wrong flid value: " + flid);
                    }
                    else
                    {
                        Assert.AreEqual(0, flid, "Wrong value for flid beyond actual length.");
                    }
                }
            }
        }
示例#11
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Setups the font features.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private void SetupFontFeatures()
        {
            if (m_fontName == null || m_fontName == "")
            {
                Enabled = false;
                return;
            }
            IRenderEngine renderer;

            if (FontHasGraphiteTables(m_fontName, false, false))
            {
                renderer = FwGrEngineClass.Create();
            }
            else
            {
                renderer = UniscribeEngineClass.Create();
            }
            renderer.WritingSystemFactory = m_wsf;
            HoldDummyGraphics hdg = new HoldDummyGraphics(m_fontName, false, false, CreateGraphics());

            renderer.InitRenderer(hdg.m_vwGraphics, m_fontFeatures);
            m_featureEngine = renderer as IRenderingFeatures;
            if (m_featureEngine == null)
            {
                Enabled = false;
                hdg.Close();
                return;
            }
            int cfid;

            m_featureEngine.GetFeatureIDs(0, null, out cfid);
            if (cfid == 0)
            {
                Enabled = false;
                hdg.Close();
                return;
            }
            if (cfid == 1)
            {
                // What if it's the dummy built-in graphite feature that we ignore?
                // Get the list of features (only 1).
                using (ArrayPtr idsM = MarshalEx.ArrayToNative(cfid, typeof(int)))
                {
                    m_featureEngine.GetFeatureIDs(cfid, idsM, out cfid);
                    int [] ids = (int[])MarshalEx.NativeToArray(idsM, cfid, typeof(int));
                    if (ids[0] == kGrLangFeature)
                    {
                        Enabled = false;
                        hdg.Close();
                        return;
                    }
                }
            }
            Enabled = true;
            hdg.Close();
        }
示例#12
0
        /// <summary>
        /// Get the items from a vector property.
        /// </summary>
        private static int[] GetVector(ISilDataAccess sda, int hvo, int tag)
        {
            var chvo = sda.get_VecSize(hvo, tag);

            using (ArrayPtr arrayPtr = MarshalEx.ArrayToNative <int>(chvo))
            {
                sda.VecProp(hvo, tag, chvo, out chvo, arrayPtr);
                return(MarshalEx.NativeToArray <int>(arrayPtr, chvo));
            }
        }
示例#13
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Setups the font features.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public void SetupFontFeatures()
        {
            CheckDisposed();

            if (string.IsNullOrEmpty(m_fontName))
            {
                Enabled          = false;
                m_isGraphiteFont = false;
                return;
            }

            using (var hdg = new HoldDummyGraphics(m_fontName, false, false, this))
            {
                IRenderEngine renderer = GraphiteEngineClass.Create();
                renderer.InitRenderer(hdg.m_vwGraphics, m_fontFeatures);
                // check if the font is a valid Graphite font
                if (!renderer.FontIsValid)
                {
                    m_isGraphiteFont = false;
                    Enabled          = false;
                    return;
                }
                renderer.WritingSystemFactory = m_wsf;
                m_isGraphiteFont = true;
                m_featureEngine  = renderer as IRenderingFeatures;
                if (m_featureEngine == null)
                {
                    Enabled = false;
                    return;
                }
                int cfid;
                m_featureEngine.GetFeatureIDs(0, null, out cfid);
                if (cfid == 0)
                {
                    Enabled = false;
                    return;
                }
                if (cfid == 1)
                {
                    // What if it's the dummy built-in graphite feature that we ignore?
                    // Get the list of features (only 1).
                    using (ArrayPtr idsM = MarshalEx.ArrayToNative <int>(cfid))
                    {
                        m_featureEngine.GetFeatureIDs(cfid, idsM, out cfid);
                        int [] ids = MarshalEx.NativeToArray <int>(idsM, cfid);
                        if (ids[0] == kGrLangFeature)
                        {
                            Enabled = false;
                            return;
                        }
                    }
                }
                Enabled = true;
            }
        }
示例#14
0
        public void GetFieldsTest()
        {
            using (var flids = MarshalEx.ArrayToNative <int>(500))
            {
                var countAllFlidsOut = m_mdc.GetFields(0, true, (int)CellarPropertyTypeFilter.All, 0, flids);
                countAllFlidsOut = m_mdc.GetFields(0, true, (int)CellarPropertyTypeFilter.All, countAllFlidsOut, flids);

                MarshalEx.NativeToArray <int>(flids, countAllFlidsOut);
                Assert.AreEqual(7, countAllFlidsOut, "Wrong number of fields returned for CmObject.");
            }
        }
示例#15
0
        public void GetFieldsDoesNotIncludeBaseFields()
        {
            using (var flids = MarshalEx.ArrayToNative <int>(500))
            {
                var countAllFlidsOut = m_mdc.GetFields(MoStemAllomorphTags.kClassId, false, (int)CellarPropertyTypeFilter.All, 0, flids);
                countAllFlidsOut = m_mdc.GetFields(MoStemAllomorphTags.kClassId, false, (int)CellarPropertyTypeFilter.All, countAllFlidsOut, flids);

                var fields = new List <int>(MarshalEx.NativeToArray <int>(flids, countAllFlidsOut));
                Assert.That(fields, Has.Member(MoStemAllomorphTags.kflidPhoneEnv));       // not inherited
                Assert.That(fields, Has.No.Member(MoFormTags.kflidForm));                 // inherited
            }
        }
示例#16
0
        public override void Load(int hvo, int tag, int ws, IVwCacheDa cda)
        {
            ISilDataAccess sda  = cda as ISilDataAccess;
            int            cobj = sda.get_VecSize(hvo, m_tagReal);

            using (ArrayPtr arrayPtr = MarshalEx.ArrayToNative(cobj + 1, typeof(int)))             // one longer to leave room for dummy
            {
                sda.VecProp(hvo, m_tagReal, cobj, out cobj, arrayPtr);
                int [] rgHvo = (int[])MarshalEx.NativeToArray(arrayPtr, cobj, typeof(int));
                rgHvo[cobj] = TypeAheadSupportVc.kBaseFakeObj;
                cda.CacheVecProp(hvo, tag, rgHvo, cobj + 1);
            }
        }
示例#17
0
        /// <summary>
        /// Make one that wraps the specified cache and passes items in the specified property of the specified root object.
        /// </summary>
        public FilterSdaDecorator(ISilDataAccess domainDataByFlid, int mainFlid, int hvoRoot)
            : base(domainDataByFlid)
        {
            m_mainFlid = mainFlid;
            m_hvoRoot  = hvoRoot;
            int chvoReal = BaseSda.get_VecSize(m_hvoRoot, m_mainFlid);

            using (ArrayPtr arrayPtr = MarshalEx.ArrayToNative(chvoReal, typeof(int)))
            {
                BaseSda.VecProp(m_hvoRoot, m_mainFlid, chvoReal, out chvoReal, arrayPtr);
                m_validHvos = new Set <int>((int[])MarshalEx.NativeToArray(arrayPtr, chvoReal, typeof(int)));
            }
        }
示例#18
0
        public void BinaryProp()
        {
            CheckDisposed();
            using (ArrayPtr arrayPtr = MarshalEx.ArrayToNative(10, typeof(int)))
            {
                int chvo = 99;
                m_ISilDataAccess.BinaryPropRgb(1112, 2221, arrayPtr, 10, out chvo);
                Assert.AreEqual(0, chvo);
                Assert.IsFalse(m_ISilDataAccess.IsDirty());

                byte[] prgb = new byte[] { 3, 4, 5 };
                m_ISilDataAccess.SetBinary(1112, 2221, prgb, prgb.Length);
                m_ISilDataAccess.BinaryPropRgb(1112, 2221, ArrayPtr.Null, 0, out chvo);
                Assert.AreEqual(prgb.Length, chvo);

                m_ISilDataAccess.BinaryPropRgb(1112, 2221, arrayPtr, 10, out chvo);
                byte[] prgbNew = (byte[])MarshalEx.NativeToArray(arrayPtr, chvo, typeof(byte));
                Assert.AreEqual(prgb.Length, prgbNew.Length);
                for (int i = 0; i < prgbNew.Length; i++)
                {
                    Assert.AreEqual(prgb[i], prgbNew[i]);
                }
                Assert.IsTrue(m_ISilDataAccess.IsDirty());

                byte[] prgb2 = new byte[] { 6, 7, 8, 9 };
                m_ISilDataAccess.SetBinary(1112, 2221, prgb2, prgb2.Length);
                m_ISilDataAccess.BinaryPropRgb(1112, 2221, arrayPtr, 10, out chvo);
                prgbNew = (byte[])MarshalEx.NativeToArray(arrayPtr, chvo, typeof(byte));
                Assert.AreEqual(prgb2.Length, prgbNew.Length);
                for (int i = 0; i < prgbNew.Length; i++)
                {
                    Assert.AreEqual(prgb2[i], prgbNew[i]);
                }
                Assert.IsTrue(m_ISilDataAccess.IsDirty());

                Exception ex = null;
                try
                {
                    m_ISilDataAccess.BinaryPropRgb(1112, 2221, arrayPtr, 2, out chvo);
                }
                catch (Exception e)
                {
                    ex = e;
                }
                Assert.AreEqual(typeof(System.Runtime.InteropServices.COMException),
                                ex.GetType());
                Assert.IsTrue(m_ISilDataAccess.IsDirty());

                CheckProp(1112, 2221, prgb2, CellarModuleDefns.kcptBinary);
            }
        }
示例#19
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Return a byte array read from the specified column
 /// </summary>
 /// <param name="odc">The odc.</param>
 /// <param name="icol">ZERO-based column index.</param>
 /// <returns>null or byte array</returns>
 /// <remarks>The SQL command must NOT modify the database in any way!</remarks>
 /// ------------------------------------------------------------------------------------
 public static byte[] ReadBytes(IOleDbCommand odc, int icol)
 {
     using (ArrayPtr prgch = MarshalEx.ArrayToNative(4000, typeof(byte)))
     {
         uint cbSpaceTaken;
         bool fIsNull;
         odc.GetColValue((uint)(icol + 1), prgch, prgch.Size, out cbSpaceTaken, out fIsNull, 0);
         if (fIsNull)
         {
             return(null);
         }
         return((byte[])MarshalEx.NativeToArray(prgch, (int)cbSpaceTaken, typeof(byte)));
     }
 }
示例#20
0
        /// <summary>
        /// Get an array of SelLevInfo structs from the given selection.
        /// </summary>
        /// <param name="vwsel"></param>
        /// <param name="cvsli"></param>
        /// <param name="ihvoRoot"></param>
        /// <param name="tagTextProp"></param>
        /// <param name="cpropPrevious"></param>
        /// <param name="ichAnchor"></param>
        /// <param name="ichEnd"></param>
        /// <param name="ws"></param>
        /// <param name="fAssocPrev"></param>
        /// <param name="ihvoEnd"></param>
        /// <param name="ttp"></param>
        /// <returns></returns>
        public static SelLevInfo[] AllTextSelInfo(IVwSelection vwsel, int cvsli,
                                                  out int ihvoRoot, out int tagTextProp, out int cpropPrevious, out int ichAnchor,
                                                  out int ichEnd, out int ws, out bool fAssocPrev, out int ihvoEnd, out ITsTextProps ttp)
        {
            Debug.Assert(vwsel != null);

            using (ArrayPtr rgvsliPtr = MarshalEx.ArrayToNative <SelLevInfo>(cvsli))
            {
                vwsel.AllTextSelInfo(out ihvoRoot, cvsli, rgvsliPtr,
                                     out tagTextProp, out cpropPrevious, out ichAnchor, out ichEnd,
                                     out ws, out fAssocPrev, out ihvoEnd, out ttp);
                return(MarshalEx.NativeToArray <SelLevInfo>(rgvsliPtr, cvsli));
            }
        }
示例#21
0
        public void WritingSystemsLists()
        {
            List <IWritingSystem> list = new List <IWritingSystem>();

            foreach (var x in Cache.LangProject.AllWritingSystems)
            {
                list.Add(x);
            }
            Assert.AreEqual(2, list.Count);

            ILgWritingSystemFactory factWs = Cache.ServiceLocator.GetInstance <ILgWritingSystemFactory>();

            Assert.LessOrEqual(list.Count, factWs.NumberOfWs, "factory list is at least as large as AllWritingSystems");
            Set <int> set = new Set <int>();

            using (ArrayPtr rgwsT = MarshalEx.ArrayToNative <int>(factWs.NumberOfWs))
            {
                factWs.GetWritingSystems(rgwsT, factWs.NumberOfWs);
                set.AddRange(MarshalEx.NativeToArray <int>(rgwsT, factWs.NumberOfWs));
            }
            int wsEn = factWs.GetWsFromStr("en");

            Assert.AreNotEqual(0, wsEn, "factory should contain English WS");
            int wsFr = factWs.GetWsFromStr("fr");

            Assert.AreNotEqual(0, wsFr, "factory should contain French WS");
            IWritingSystem eng = null;
            IWritingSystem frn = null;

            foreach (var x in list)
            {
                Assert.IsTrue(set.Contains(x.Handle), "AllWritingSystems should be a subset of the factory list");
                if (x.Handle == wsEn)
                {
                    eng = x;
                }
                else if (x.Handle == wsFr)
                {
                    frn = x;
                }
            }
            Assert.IsNotNull(eng, "AllWritingSystems should contain English");
            Assert.AreEqual("English", factWs.get_EngineOrNull(wsEn).LanguageName);
            Assert.AreEqual("English", eng.LanguageName);

            Assert.IsNotNull(frn, "AllWritingSystems should contain French");
            Assert.AreEqual("French", frn.LanguageName);
            Assert.AreEqual("French", factWs.get_Engine("fr").LanguageName);
        }
示例#22
0
        public void GetFieldIdsTest()
        {
            var flidSize = m_metaDataCache.FieldCount;

            int[] ids;
            var   testFlidSize = flidSize - 1;

            using (var flids = MarshalEx.ArrayToNative <int>(testFlidSize))
            {
                m_metaDataCache.GetFieldIds(testFlidSize, flids);
                ids = MarshalEx.NativeToArray <int>(flids, testFlidSize);
                Assert.AreEqual(testFlidSize, ids.Length, "Wrong size of fields returned.");
                foreach (var flid in ids)
                {
                    Assert.IsTrue(flid > 0, "Wrong flid value: " + flid);
                }
            }
            testFlidSize = flidSize;
            using (var flids = MarshalEx.ArrayToNative <int>(testFlidSize))
            {
                m_metaDataCache.GetFieldIds(testFlidSize, flids);
                ids = MarshalEx.NativeToArray <int>(flids, testFlidSize);
                Assert.AreEqual(testFlidSize, ids.Length, "Wrong size of fields returned.");
                foreach (var flid in ids)
                {
                    Assert.IsTrue(flid > 0, "Wrong flid value: " + flid);
                }
            }
            testFlidSize = flidSize + 1;
            using (var flids = MarshalEx.ArrayToNative <int>(testFlidSize))
            {
                m_metaDataCache.GetFieldIds(testFlidSize, flids);
                ids = MarshalEx.NativeToArray <int>(flids, testFlidSize);
                Assert.AreEqual(testFlidSize, ids.Length, "Wrong size of fields returned.");
                for (var iflid = 0; iflid < ids.Length; ++iflid)
                {
                    var flid = ids[iflid];
                    if (iflid < ids.Length - 1)
                    {
                        Assert.IsTrue(flid > 0, "Wrong flid value: " + flid);
                    }
                    else
                    {
                        Assert.AreEqual(0, flid, "Wrong value for flid beyond actual length.");
                    }
                }
            }
        }
        public void SimpleFiltering()
        {
            // Try all the variants of retrieving a vector property.
            var sensesOfHot = m_decorator.VecProp(m_hot.Hvo, LexEntryTags.kflidSenses);

            Assert.That(sensesOfHot.Length, Is.EqualTo(2), "one bad sense should be eliminated.");
            Assert.That(sensesOfHot[0], Is.EqualTo(m_hot.SensesOS[0].Hvo));
            Assert.That(sensesOfHot[1], Is.EqualTo(m_desirable.Hvo));

            Assert.That(m_decorator.get_VecSize(m_hot.Hvo, LexEntryTags.kflidSenses), Is.EqualTo(2));
            Assert.That(m_decorator.get_VecItem(m_hot.Hvo, LexEntryTags.kflidSenses, 1), Is.EqualTo(m_desirable.Hvo));

            // This test is perhaps redundant here: DictionaryPublicationDecorator does not have to do anything to get this behavior.
            using (ArrayPtr arrayPtr = MarshalEx.ArrayToNative <int>(2))
            {
                int chvo;
                m_decorator.VecProp(m_hot.Hvo, LexEntryTags.kflidSenses, 2, out chvo, arrayPtr);
                var values = MarshalEx.NativeToArray <int>(arrayPtr, 2);
                Assert.That(values[0], Is.EqualTo(m_hot.SensesOS[0].Hvo));
                Assert.That(values[1], Is.EqualTo(m_desirable.Hvo));
            }

            // This verifies both that examples are included in the bad objects, and that properties
            // that point at examples are automatically excluded.
            var hotTempExamples = m_decorator.VecProp(m_hotTemp.Hvo, LexSenseTags.kflidExamples);

            Assert.That(hotTempExamples.Length, Is.EqualTo(1));
            Assert.That(hotTempExamples[0], Is.EqualTo(m_goodHot.Hvo));

            // They should be filtered also from certain properties with CmObject signatures.
            var hotWaterComponents = m_decorator.VecProp(m_hotWaterComponents.Hvo, LexEntryRefTags.kflidComponentLexemes);

            Assert.That(hotWaterComponents.Length, Is.EqualTo(1));
            Assert.That(hotWaterComponents[0], Is.EqualTo(m_waterH2O.Hvo));
            // More cursory checks...there are many of these.
            Assert.That(m_decorator.VecProp(m_hotWaterComponents.Hvo, LexEntryRefTags.kflidPrimaryLexemes).Length, Is.EqualTo(1));
            // As well as checking that LexReference.Targets is filtered, this checks that we filter senses of excluded entries,
            // and that it really is possible for more than one thing to pass the filter.
            Assert.That(m_decorator.VecProp(m_blankSynonyms.Hvo, LexReferenceTags.kflidTargets).Length, Is.EqualTo(2));

            // They should be filtered from the top-level list of entries managed by the wrapped decorator
            var mainEntryList = m_decorator.VecProp(Cache.LangProject.LexDbOA.Hvo, ObjectListPublisher.OwningFlid);

            Assert.That(mainEntryList.Length,
                        Is.EqualTo(Cache.LangProject.LexDbOA.Entries.Where(
                                       le => le.DoNotPublishInRC.Count == 0 &&
                                       le.DoNotShowMainEntryInRC.Count == 0).Count()));
        }
示例#24
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Add something to the root vector
        /// </summary>
        /// <param name="toAdd">HVOs to add</param>
        /// ------------------------------------------------------------------------------------
        private void AddVecProp(int[] toAdd)
        {
            int cMax = 100;

            using (ArrayPtr arrayPtr = MarshalEx.ArrayToNative(cMax, typeof(int)))
            {
                int chvo;
                Cache.MainCacheAccessor.VecProp(kHvoRoot, DummyBasicViewVc.kflidTestDummy, cMax,
                                                out chvo, arrayPtr);
                int[] rghvo = new int[chvo + toAdd.Length];
                Array.Copy((int[])MarshalEx.NativeToArray(arrayPtr, chvo, typeof(int)), rghvo, chvo);
                Array.Copy(toAdd, 0, rghvo, chvo, toAdd.Length);
                Cache.VwCacheDaAccessor.CacheVecProp(kHvoRoot, DummyBasicViewVc.kflidTestDummy,
                                                     rghvo, rghvo.Length);
            }
        }
示例#25
0
        public void GetDirectSubclassesTest()
        {
            // Just use the count for all classes,
            // even though we know it will never be that high a number that can be returned.
            var countAllClasses = m_mdc.ClassCount;
            int countDirectSubclasses;

            //int[] clids = new int[countAllClasses];
            // Check PartOfSpeech.
            using (var clids = MarshalEx.ArrayToNative <int>(countAllClasses))
            {
                // Check PartOfSpeech.
                m_mdc.GetDirectSubclasses(5049, countAllClasses, out countDirectSubclasses, clids);
                Assert.AreEqual(0, countDirectSubclasses, "Wrong number of subclasses returned.");
            }

            using (var clids = MarshalEx.ArrayToNative <int>(countAllClasses))
            {
                // Check MoForm (all of its direct subclasses).
                m_mdc.GetDirectSubclasses(5035, countAllClasses, out countDirectSubclasses, clids);
                Assert.AreEqual(2, countDirectSubclasses, "Wrong number of subclasses returned.");
                var uIds = MarshalEx.NativeToArray <int>(clids, countAllClasses);
                for (var i = 0; i < uIds.Length; ++i)
                {
                    var clid = uIds[i];
                    if (i < 2)
                    {
                        Assert.IsTrue(((clid == 5028) || (clid == 5045)), "Clid should be 5028 or 5049 for direct subclasses of MoForm.");
                    }
                    else
                    {
                        Assert.AreEqual(0, clid, "Clid should be 0 from here on.");
                    }
                }
            }

            /* The method does not support getting some arbitrary subset of subclasses.
             * The array must contain at least that many spaces, if not more.
             * countDirectSubclasses = 0;
             * using (ArrayPtr clids = MarshalEx.ArrayToNative(1, typeof(int)))
             * {
             *      // Check MoForm (but only 1 of its subclasses).
             *      m_mdc.GetDirectSubclasses(5035, 1, out countDirectSubclasses, clids);
             *      Assert.AreEqual(1, countDirectSubclasses, "Wrong number of subclasses returned.");
             * }
             */
        }
示例#26
0
        /// <summary>
        /// Get a list of flids for the given class, and type.
        /// </summary>
        /// <param name="mdc"></param>
        /// <param name="clsid"></param>
        /// <param name="flidType"></param>
        /// <returns></returns>
        static public uint[] GetFieldsInClassOfType(IFwMetaDataCache mdc, uint clsid, FieldType flidType)
        {
            uint[] retval    = new uint[0];
            int    nflidType = (int)flidType;
            int    flidCount = mdc.GetFields(clsid, true, nflidType, 0, ArrayPtr.Null);

            if (flidCount > 0)
            {
                using (ArrayPtr rgflid = new ArrayPtr(flidCount * Marshal.SizeOf(typeof(uint))))
                {
                    int flidCount2 = mdc.GetFields(clsid, true, nflidType, flidCount, rgflid);
                    Debug.Assert(flidCount == flidCount2);
                    retval = (uint[])MarshalEx.NativeToArray(rgflid, flidCount, typeof(uint));
                }
            }
            return(retval);
        }
示例#27
0
        /// <summary>
        /// Get the array of SelLevInfo corresponding to one end point of a selection.
        /// </summary>
        /// <param name="vwselNew"></param>
        /// <param name="fEndPoint">True if we want the end of the selection. False if we want the anchor.</param>
        /// <returns></returns>
        protected static SelLevInfo[] GetOneEndPointOfSelection(IVwSelection vwselNew, bool fEndPoint)
        {
            // Get the info about the other end of the selection.
            int cvsli = vwselNew.CLevels(fEndPoint) - 1;

            SelLevInfo[] rgvsliEnd;
            using (ArrayPtr prgvsli = MarshalEx.ArrayToNative <SelLevInfo>(cvsli))
            {
                int          ihvoRoot, tagTextProp, cpropPrevious, ich, ws;
                bool         fAssocPrev;
                ITsTextProps ttpSelProps;
                vwselNew.AllSelEndInfo(fEndPoint, out ihvoRoot, cvsli, prgvsli,
                                       out tagTextProp, out cpropPrevious, out ich,
                                       out ws, out fAssocPrev, out ttpSelProps);
                rgvsliEnd = MarshalEx.NativeToArray <SelLevInfo>(prgvsli, cvsli);
            }
            return(rgvsliEnd);
        }
示例#28
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Print method
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public override void Print(PrintDocument pd)
        {
            CheckDisposed();

            bool fPrintSelection = (pd.PrinterSettings.PrintRange == PrintRange.Selection);

            int[] originalObjects = null;
            if (fPrintSelection)
            {
                IVwSelection     sel = RootBox.Selection;
                int              clev = sel.CLevels(true);
                int              hvoObj, tag, ihvoEnd, ihvoAnchor, cpropPrevious;
                IVwPropertyStore vps;
                sel.PropInfo(true, clev - 1, out hvoObj, out tag, out ihvoEnd, out cpropPrevious, out vps);
                clev = sel.CLevels(false);
                sel.PropInfo(false, clev - 1, out hvoObj, out tag, out ihvoAnchor, out cpropPrevious, out vps);
                ISilDataAccess sda      = m_fdoCache.MainCacheAccessor;
                int            chvoReal = sda.get_VecSize(m_hvoRoot, m_mainFlid);
                using (ArrayPtr arrayPtr = MarshalEx.ArrayToNative(chvoReal, typeof(int)))
                {
                    sda.VecProp(m_hvoRoot, m_mainFlid, chvoReal, out chvoReal, arrayPtr);
                    originalObjects = (int[])MarshalEx.NativeToArray(arrayPtr, chvoReal, typeof(int));
                }
                int   ihvoMin         = Math.Min(ihvoEnd, ihvoAnchor);
                int   ihvoLim         = Math.Max(ihvoEnd, ihvoAnchor) + 1;
                int[] selectedObjects = new int[ihvoLim - ihvoMin];
                for (int i = 0; i < selectedObjects.Length; i++)
                {
                    selectedObjects[i] = originalObjects[i + ihvoMin];
                }
                m_fdoCache.VwCacheDaAccessor.CacheVecProp(m_hvoRoot, m_mainFlid, selectedObjects, selectedObjects.Length);
            }
            try
            {
                base.Print(pd);
            }
            finally
            {
                if (fPrintSelection)
                {
                    m_fdoCache.VwCacheDaAccessor.CacheVecProp(m_hvoRoot, m_mainFlid, originalObjects, originalObjects.Length);
                }
            }
        }
示例#29
0
        public void GetClassIdsTest()
        {
            // Just use the count for all classes,
            // even though we know it will never be that high a number that can be returned.
            int[] ids;
            var   countAllClasses = m_metaDataCache.ClassCount;

            using (var clids = MarshalEx.ArrayToNative <int>(countAllClasses))
            {
                m_metaDataCache.GetClassIds(countAllClasses, clids);
                ids = MarshalEx.NativeToArray <int>(clids, countAllClasses);
                Assert.AreEqual(countAllClasses, ids.Length, "Wrong number of classes returned.");
            }
            countAllClasses = 2;
            using (var clids = MarshalEx.ArrayToNative <int>(countAllClasses))
            {
                // Check ClassL (all of its direct subclasses).
                m_metaDataCache.GetClassIds(countAllClasses, clids);
                ids = MarshalEx.NativeToArray <int>(clids, 2);
                Assert.AreEqual(countAllClasses, ids.Length, "Wrong number of classes returned.");
            }
        }
示例#30
0
        private void AddSubNodes(TreeNodeCollection parentNodeCollection, uint superClassClid)
        {
            int directSubclassCount;

            m_mdc.GetDirectSubclasses(superClassClid, 0, out directSubclassCount, null);
            uint[] uIds;
            using (ArrayPtr clids = MarshalEx.ArrayToNative(directSubclassCount, typeof(uint)))
            {
                m_mdc.GetDirectSubclasses(superClassClid, directSubclassCount, out directSubclassCount, clids);
                uIds = (uint[])MarshalEx.NativeToArray(clids, directSubclassCount, typeof(uint));
            }
            SortedList <string, uint> list = new SortedList <string, uint>(uIds.Length);

            foreach (uint subclassClid in uIds)
            {
                string classname = m_mdc.GetClassName(subclassClid);
                list.Add(classname, subclassClid);
            }
            foreach (KeyValuePair <string, uint> kvp in list)
            {
                AddNode(parentNodeCollection, kvp.Key, kvp.Value);
            }
        }