private int getWsFromId(string id)
        {
            // special case, the only few we support so far (and only for a few fields).
            if (id == "best analysis")
            {
                return(WritingSystemServices.kwsFirstAnal);               //LangProject.kwsFirstAnal;
            }
            else if (id == "vern in para")
            {
                return(WritingSystemServices.kwsVernInParagraph);
            }
            Debug.Assert(!XmlViewsUtils.GetWsRequiresObject(id), "Writing system is magic.  These should never be used in the Interlinear area.");

            int ws = -50;

            try
            {
                if (!XmlViewsUtils.GetWsRequiresObject(id))
                {
                    // Try to convert the ws parameter into an int.  Sometimes the parameter
                    // cannot be interpreted without an object, such as when the ws is a magic
                    // string that will change the actual ws depending on the contents of the
                    // object.  In these cases, we give -50 as a known constant to check for.
                    // This can possibly throw an exception, so we'll enclose it in a try block.
                    ws = WritingSystemServices.InterpretWsLabel(m_cache, id, null, 0, 0, null);
                }
            }
            catch
            {
                Debug.Assert(ws != -50, "InterpretWsLabel was not able to interpret the Ws Label.  The most likely cause for this is that a magic ws was passed in.");
            }
            return(ws);
        }
Exemplo n.º 2
0
        private int GetRealWsFromSpec(InterlinLineSpec spec)
        {
            if (!spec.IsMagicWritingSystem)
            {
                return(spec.WritingSystem);
            }
            // special case, the only few we support so far (and only for a few fields).
            if (spec.WritingSystem == WritingSystemServices.kwsFirstAnal)
            {
                return(Cache.LangProject.DefaultAnalysisWritingSystem.Handle);
            }
            if (spec.WritingSystem == WritingSystemServices.kwsVernInParagraph)
            {
                return(Cache.LangProject.DefaultVernacularWritingSystem.Handle);                // REVIEW (Hasso) 2018.01: this is frequently the case, but not always
            }
            int ws = -50;

            try
            {
                ws = WritingSystemServices.InterpretWsLabel(Cache, spec.WsLabel(Cache).Text, null, 0, 0, null);
            }
            catch
            {
                Debug.Assert(ws != -50, "InterpretWsLabel was not able to interpret the Ws Label.  The most likely cause for this is that a magic ws was passed in.");
            }
            return(ws);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Calls the sort method.
        /// </summary>
        /// <param name="cmo">The object.</param>
        /// <param name="sortedFromEnd">if set to <c>true</c> [sorted from end].</param>
        /// <returns></returns>
        private string[] CallSortMethod(ICmObject cmo, bool sortedFromEnd)
        {
            Type typeCmo = cmo.GetType();

            try
            {
                MethodInfo mi = typeCmo.GetMethod(m_sMethodName);
                if (mi == null)
                {
                    return(null);
                }

                object obj;
                if (mi.GetParameters().Length == 2)
                {
                    // Enhance JohnT: possibly we should seek to evaluate this every time, in case it is a magic WS like
                    // "best vernacular". But interpreting those requires a flid, and we don't have one; indeed, the
                    // method may retrieve information from several. So we may as well just accept that the fancy ones
                    // won't work.
                    if (m_ws == 0 && WritingSystemName != null)
                    {
                        m_ws = WritingSystemServices.InterpretWsLabel(m_cache, WritingSystemName, null, 0, 0, null);
                    }
                    obj = mi.Invoke(cmo, new object[] { sortedFromEnd, m_ws });
                }
                else
                {
                    obj = mi.Invoke(cmo, new object[] { sortedFromEnd });
                }
                if (obj is string)
                {
                    return new [] { (string)obj }
                }
                ;
                // otherwise assume it already is a string array.
                return((string[])obj);
            }
            catch (Exception)
            {
                return(null);
            }
        }