Ejemplo n.º 1
0
        public static LfMultiText FromMultiITsString(ITsMultiString value, ILgWritingSystemFactory wsManager)
        {
            if (value == null || value.StringCount == 0)
            {
                return(null);
            }
            LfMultiText mt = new LfMultiText();

            for (int index = 0; index < value.StringCount; index++)
            {
                int       wsId;
                ITsString tss   = value.GetStringFromIndex(index, out wsId);
                string    wsStr = wsManager.GetStrFromWs(wsId);
                if (!string.IsNullOrEmpty(wsStr))
                {
                    string        valueStr = LfMerge.Core.DataConverters.ConvertLcmToMongoTsStrings.TextFromTsString(tss, wsManager);
                    LfStringField field    = LfStringField.FromString(valueStr);
                    if (field != null)
                    {
                        mt.Add(wsStr, field);
                    }
                }
                //MainClass.Logger.Warning("Adding multistring ws: {0}, str {1}", wsStr, valueStr);
            }
            return(mt);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Append to the PaMultiString the contents of the tsMultiString.
        /// For each writing system the contents will end up in a comma seperated list
        /// </summary>
        public static void Append(PaMultiString paMultiString, ITsMultiString tsMultiString, ILcmServiceLocator svcloc)
        {
            for (int i = 0; i < tsMultiString.StringCount; ++i)
            {
                int hvoWs;
                var tss = tsMultiString.GetStringFromIndex(i, out hvoWs);

                // hvoWs should *always* be found in AllWritingSystems.
                var ws = svcloc.WritingSystems.AllWritingSystems.SingleOrDefault(w => w.Handle == hvoWs);
                paMultiString.AddString(ws == null ? null : ws.Id, tss.Text);
            }
        }
Ejemplo n.º 3
0
        /// ------------------------------------------------------------------------------------
        private PaMultiString(ITsMultiString msa, ILcmServiceLocator svcloc)
        {
            Texts = new List <string>(msa.StringCount);
            WsIds = new List <string>(msa.StringCount);

            for (int i = 0; i < msa.StringCount; i++)
            {
                int       hvoWs;
                ITsString tss = msa.GetStringFromIndex(i, out hvoWs);
                Texts.Add(tss.Text);

                // hvoWs should *always* be found in AllWritingSystems.
                var ws = svcloc.WritingSystems.AllWritingSystems.SingleOrDefault(w => w.Handle == hvoWs);
                WsIds.Add(ws == null ? null : ws.Id);
            }
        }
Ejemplo n.º 4
0
		/// ------------------------------------------------------------------------------------
		private PaMultiString(ITsMultiString msa, IFdoServiceLocator svcloc)
		{
			Texts = new List<string>(msa.StringCount);
			WsIds = new List<string>(msa.StringCount);

			for (int i = 0; i < msa.StringCount; i++)
			{
				int hvoWs;
				ITsString tss = msa.GetStringFromIndex(i, out hvoWs);
				Texts.Add(tss.Text);

				// hvoWs should *always* be found in AllWritingSystems.
				var ws = svcloc.WritingSystems.AllWritingSystems.SingleOrDefault(w => w.Handle == hvoWs);
				WsIds.Add(ws == null ? null : ws.Id);
			}
		}
Ejemplo n.º 5
0
 private void PopulateSecondListView(ITsMultiString mainObject)
 {
     m_lvDetails.Clear();
     m_lvDetails.View           = View.Details;
     m_lvDetails.Sorting        = SortOrder.Ascending;
     m_lvDetails.SmallImageList = null;
     m_lvDetails.SuspendLayout();
     m_lvDetails.Columns.Add("WS", 50);
     m_lvDetails.Columns.Add("Text", 200);
     ListViewItem[] lvis = new ListViewItem[mainObject.StringCount];
     for (int i = 0; i < mainObject.StringCount; ++i)
     {
         int          ws;
         ITsString    tss         = mainObject.GetStringFromIndex(i, out ws);
         uint         wsLocalFlid = MetaDataCache.GetFieldId("LgWritingSystem", "ICULocale", false);
         string       wsLabel     = SilDataAccess.get_UnicodeProp(ws, (int)wsLocalFlid);
         ListViewItem lvi         = new ListViewItem(wsLabel);
         lvi.Tag = ws;
         lvi.SubItems.Add(tss.Text);
         lvis[i] = lvi;
     }
     m_lvDetails.Items.AddRange(lvis);
     m_lvDetails.ResumeLayout();
 }
Ejemplo n.º 6
0
        private void ExportCustomFields(TextWriter writer, IRnGenericRec record)
        {
            ISilDataAccessManaged sda = m_cache.DomainDataByFlid as ISilDataAccessManaged;

            Debug.Assert(sda != null);
            foreach (int flid in m_customFlids)
            {
                string             fieldName = m_mdc.GetFieldName(flid);
                bool               fHandled  = false;
                ITsString          tss;
                string             s;
                CellarPropertyType cpt = (CellarPropertyType)m_mdc.GetFieldType(flid);
                switch (cpt)
                {
                case CellarPropertyType.Boolean:
                    break;

                case CellarPropertyType.Integer:
                    break;

                case CellarPropertyType.Numeric:
                    break;

                case CellarPropertyType.Float:
                    break;

                case CellarPropertyType.Time:
                    break;

                case CellarPropertyType.Guid:
                    break;

                case CellarPropertyType.Image:
                case CellarPropertyType.Binary:
                    break;

                case CellarPropertyType.GenDate:
                    break;

                case CellarPropertyType.String:
                    tss = sda.get_StringProp(record.Hvo, flid);
                    if (tss != null && tss.Text != null)
                    {
                        ExportString(writer, tss, fieldName);
                    }
                    fHandled = true;
                    break;

                case CellarPropertyType.MultiString:
                case CellarPropertyType.MultiUnicode:
                    ITsMultiString tms = sda.get_MultiStringProp(record.Hvo, flid);
                    int            cch = 0;
                    for (int i = 0; i < tms.StringCount; ++i)
                    {
                        int ws;
                        tss  = tms.GetStringFromIndex(i, out ws);
                        cch += tss.Length;
                        if (cch > 0)
                        {
                            break;
                        }
                    }
                    if (cch > 0)
                    {
                        writer.WriteLine("<Field name=\"{0}\" type=\"MultiString\">", fieldName);
                        for (int i = 0; i < tms.StringCount; ++i)
                        {
                            int ws;
                            tss = tms.GetStringFromIndex(i, out ws);
                            if (tss != null && tss.Length > 0)
                            {
                                if (cpt == CellarPropertyType.MultiString)
                                {
                                    writer.WriteLine(TsStringUtils.GetXmlRep(tss,
                                                                             m_cache.WritingSystemFactory, ws, true));
                                }
                                else
                                {
                                    writer.WriteLine("<AUni ws=\"{0}\">{1}</AUni>",
                                                     m_cache.WritingSystemFactory.GetStrFromWs(ws),
                                                     XmlUtils.MakeSafeXml(tss.Text));
                                }
                            }
                        }
                        writer.WriteLine("</Field>");
                    }
                    fHandled = true;
                    break;

                case CellarPropertyType.Unicode:
                    break;

                case CellarPropertyType.ReferenceAtomic:
                case CellarPropertyType.ReferenceCollection:
                case CellarPropertyType.ReferenceSequence:
                {
                    int        destClid  = m_mdc.GetDstClsId(flid);
                    List <int> rghvoDest = new List <int>();
                    if (cpt == CellarPropertyType.ReferenceAtomic)
                    {
                        int hvo = sda.get_ObjectProp(record.Hvo, flid);
                        if (hvo != 0)
                        {
                            if (destClid == CmPossibilityTags.kClassId)
                            {
                                ICmPossibility poss = PossibilityRepository.GetObject(hvo);
                                ExportAtomicReference(writer, poss, fieldName, "CmPossibility");
                                fHandled = true;
                            }
                            else
                            {
                                rghvoDest.Add(hvo);
                            }
                        }
                        else
                        {
                            fHandled = true;
                        }
                    }
                    else
                    {
                        int[] hvos = sda.VecProp(record.Hvo, flid);
                        if (hvos.Length > 0)
                        {
                            if (destClid == CmPossibilityTags.kClassId)
                            {
                                List <ICmPossibility> collection = new List <ICmPossibility>();
                                foreach (int hvo in hvos)
                                {
                                    collection.Add(PossibilityRepository.GetObject(hvo));
                                }
                                ExportReferenceList(writer, collection, fieldName, "CmPossibility", cpt);
                                fHandled = true;
                            }
                            else
                            {
                                rghvoDest.AddRange(hvos);
                            }
                        }
                        else
                        {
                            fHandled = true;
                        }
                    }
                    if (rghvoDest.Count > 0)
                    {
                    }
                }
                break;

                case CellarPropertyType.OwningAtomic:
                case CellarPropertyType.OwningCollection:
                case CellarPropertyType.OwningSequence:
                {
                    int        destClid  = m_mdc.GetDstClsId(flid);
                    List <int> rghvoDest = new List <int>();
                    if (cpt == CellarPropertyType.OwningAtomic)
                    {
                        int hvo = sda.get_ObjectProp(record.Hvo, flid);
                        if (hvo != 0)
                        {
                            if (destClid == StTextTags.kClassId)
                            {
                                IStText text = StTextRepository.GetObject(hvo);
                                ExportStText(writer, text, fieldName);
                                fHandled = true;
                            }
                            else
                            {
                                rghvoDest.Add(hvo);
                            }
                        }
                        else
                        {
                            fHandled = true;
                        }
                    }
                    else
                    {
                    }
                }
                break;
                }
                if (!fHandled)
                {
                }
            }
        }
Ejemplo n.º 7
0
        private void PopulateListView(ListView listView, SelectedObject selObj)
        {
            SuspendLayout();

            // Get all fields from mdc.
            uint[] uflids;
            // First find out how many there are.
            int flidSize = MetaDataCache.GetFields(selObj.m_clid, true,
                                                   (int)CellarModuleDefns.kgrfcptAll, 0, null);

            // Now get them for real.
            using (ArrayPtr flids = MarshalEx.ArrayToNative(flidSize, typeof(uint)))
            {
                flidSize = MetaDataCache.GetFields(selObj.m_clid, true,
                                                   (int)CellarModuleDefns.kgrfcptAll, flidSize, flids);
                uflids = (uint[])MarshalEx.NativeToArray(flids, flidSize, typeof(uint));
            }
            List <ListViewItem> list = new List <ListViewItem>();

            foreach (uint flid in uflids)
            {
                if (flid > 0)
                {
                    string       classname;
                    string       fieldname = MetaDataCache.GetFieldName(flid);
                    ListViewItem lvi       = new ListViewItem(fieldname, 0);               // listView.Items.Add(fieldname);
                    list.Add(lvi);
                    lvi.Tag = flid;
                    // TODO: Show some kind of data in the second column of the lvi.
                    // For basic data types, just show the data, if it exists (NA, if not).
                    // Selecting a basic data type field, will clear the right panel.
                    // For objects, we need to distinguish between owning/reference and atomic/seq/coll:
                    // Just use the FDO 'standard' of OA, OS, OC, RA, RS, and RC, plus:
                    // atomic: Object class. Selection of the lvi will then show the object in the right pane.
                    // seq/coll: Maybe size of vector. Selection shows basic list of items in the vector in the right pane.
                    string data = "*N/A";
                    object obj  = SilDataAccess.get_Prop(selObj.m_hvo, (int)flid);
                    if (obj != null)
                    {
                        int flidType = MetaDataCache.GetFieldType(flid);
                        switch (flidType)
                        {
                        case (int)CellarModuleDefns.kcptOwningCollection:
                        case (int)CellarModuleDefns.kcptOwningSequence:
                        case (int)CellarModuleDefns.kcptReferenceSequence:
                        case (int)CellarModuleDefns.kcptReferenceCollection:
                            string pfx = String.Empty;
                            switch (flidType)
                            {
                            case (int)CellarModuleDefns.kcptOwningCollection:
                                pfx = "OC";
                                break;

                            case (int)CellarModuleDefns.kcptOwningSequence:
                                pfx = "OS";
                                break;

                            case (int)CellarModuleDefns.kcptReferenceSequence:
                                pfx = "RS";
                                break;

                            case (int)CellarModuleDefns.kcptReferenceCollection:
                                pfx = "RC";
                                break;
                            }
                            int        vecSize = m_cache.get_VecSize(selObj.m_hvo, (int)flid);
                            List <int> hvos    = (List <int>)m_cache.get_Prop(selObj.m_hvo, (int)flid);
                            data    = String.Format("{0}: {1} items", pfx, vecSize);
                            lvi.Tag = new SelectedVector(selObj.m_hvo, flid, hvos);
                            break;

                        case (int)CellarModuleDefns.kcptInteger:
                            if (flid == (int)CmObjectFields.kflidCmObject_Class)
                            {
                                classname = MetaDataCache.GetClassName(selObj.m_clid);
                                data      = String.Format("{0}: {1}", obj.ToString(), classname);
                            }
                            else
                            {
                                data = obj.ToString();
                            }
                            break;

                        case (int)CellarModuleDefns.kcptTime:
                            DateTime dt = new DateTime((long)obj);
                            data = dt.ToString();
                            break;

                        case (int)CellarModuleDefns.kcptOwningAtom:                                 // Fall through.
                        case (int)CellarModuleDefns.kcptReferenceAtom:
                            int objId = (int)obj;
                            int clid  = SilDataAccess.get_IntProp(objId, (int)CmObjectFields.kflidCmObject_Class);
                            classname = MetaDataCache.GetClassName((uint)clid);
                            data      = String.Format("{0}: a(n) {1}",
                                                      (flidType == (int)CellarModuleDefns.kcptOwningAtom) ? "OA" : "RA",
                                                      classname);
                            lvi.Tag = new SelectedObject(flid, objId, (uint)clid);
                            break;

                        case (int)CellarModuleDefns.kcptString:                                 // Fall through.
                        case (int)CellarModuleDefns.kcptBigString:
                            ITsString tssString = (ITsString)obj;
                            data = tssString.Text;
                            break;

                        case (int)CellarModuleDefns.kcptMultiUnicode:                                // Fall through.
                        case (int)CellarModuleDefns.kcptMultiBigUnicode:                             // Fall through.
                        case (int)CellarModuleDefns.kcptMultiString:                                 // Fall through.
                        case (int)CellarModuleDefns.kcptMultiBigString:
                            if (obj is ITsMultiString)
                            {
                                ITsMultiString tsms        = obj as ITsMultiString;
                                uint           wsLocalFlid = MetaDataCache.GetFieldId("LgWritingSystem", "ICULocale", false);
                                if (tsms.StringCount > 0)
                                {
                                    int       ws;
                                    ITsString tss     = tsms.GetStringFromIndex(0, out ws);
                                    string    wsLabel = SilDataAccess.get_UnicodeProp(ws, (int)wsLocalFlid);
                                    data = String.Format("{0}: {1}", wsLabel, tss.Text);
                                }
                                lvi.Tag = tsms;
                            }
                            break;

                        case (int)CellarModuleDefns.kcptUnicode:                                 // Fall through.
                        case (int)CellarModuleDefns.kcptBigUnicode:
                            data = (string)obj;
                            break;

                        default:
                            data = obj.ToString();
                            break;
                        }
                    }
                    lvi.SubItems.Add(data);
                }
            }
            listView.Items.AddRange(list.ToArray());
            listView.Sorting = SortOrder.Ascending;
            listView.Sort();
            ResumeLayout();
        }
Ejemplo n.º 8
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Handles the flids for basic data (bool, string, int, etc.)
        /// </summary>
        /// <param name="thisFlid">The object type flid.</param>
        /// <param name="flidType">The owning flid type.</param>
        /// <param name="hvoSrc">The hvo of the source object.</param>
        /// <param name="hvoNew">The hvo of the new object.</param>
        /// ------------------------------------------------------------------------------------
        private void HandleBasicOrStringFlid(int thisFlid, int flidType, int hvoSrc, int hvoNew)
        {
            // Basic and String properties are copied
            switch (flidType)
            {
            // Basic Properties follow

            case (int)CellarPropertyType.Binary:
                string flidName = m_mdc.GetFieldName(thisFlid);
                if (flidName == "Rules" || flidName == "StyleRules")
                {
                    CopyBinaryAsTextProps(thisFlid, hvoSrc, hvoNew);
                }
                else
                {
                    CopyBinaryAsBinary(thisFlid, hvoSrc, hvoNew);
                }
                break;

            case (int)CellarPropertyType.Boolean:
                // Copy boolean value
                m_sda.SetBoolean(hvoNew, thisFlid, m_sda.get_BooleanProp(hvoSrc, thisFlid));
                break;

            case (int)CellarPropertyType.Guid:
                // Copy guid value
                // These are currently used as the ID for an application, or a version number, or a Scripture Check ID)
                m_sda.SetGuid(hvoNew, thisFlid, m_sda.get_GuidProp(hvoSrc, thisFlid));
                break;

            case (int)CellarPropertyType.GenDate:                     // Fall through, since a GenDate is an int.
            case (int)CellarPropertyType.Integer:
                // Copy integer value
                m_sda.SetInt(hvoNew, thisFlid, m_sda.get_IntProp(hvoSrc, thisFlid));
                break;

            case (int)CellarPropertyType.Time:
                // Copy time value
                m_sda.SetTime(hvoNew, thisFlid, m_sda.get_TimeProp(hvoSrc, thisFlid));
                break;

            // String Properties follow

            case (int)CellarPropertyType.String:
                // Copy string value
                // Review: Please check these next three!
                m_sda.SetString(hvoNew, thisFlid, m_sda.get_StringProp(hvoSrc, thisFlid));
                break;

            case (int)CellarPropertyType.Unicode:
                // Copy Unicode string
                m_sda.set_UnicodeProp(hvoNew, thisFlid, m_sda.get_UnicodeProp(hvoSrc, thisFlid));
                break;

            case (int)CellarPropertyType.MultiString:                     // Fall through
            case (int)CellarPropertyType.MultiUnicode:
                ITsMultiString sMulti = m_sda.get_MultiStringProp(hvoSrc, thisFlid);
                for (int i = 0; i < sMulti.StringCount; i++)
                {
                    int       ws;
                    ITsString tss = sMulti.GetStringFromIndex(i, out ws);
                    m_sda.SetMultiStringAlt(hvoNew, thisFlid, ws, tss);
                }
                break;

            default:
                throw new FDOInvalidFieldTypeException(String.Format("CopyObject: Unsupported field type {0}.", flidType));
            }
        }
Ejemplo n.º 9
0
		private void PopulateSecondListView(ITsMultiString mainObject)
		{
			m_lvDetails.Clear();
			m_lvDetails.View = View.Details;
			m_lvDetails.Sorting = SortOrder.Ascending;
			m_lvDetails.SmallImageList = null;
			m_lvDetails.SuspendLayout();
			m_lvDetails.Columns.Add("WS", 50);
			m_lvDetails.Columns.Add("Text", 200);
			ListViewItem[] lvis = new ListViewItem[mainObject.StringCount];
			for (int i = 0; i < mainObject.StringCount; ++i)
			{
				int ws;
				ITsString tss = mainObject.GetStringFromIndex(i, out ws);
				uint wsLocalFlid = MetaDataCache.GetFieldId("LgWritingSystem", "ICULocale", false);
				string wsLabel = SilDataAccess.get_UnicodeProp(ws, (int)wsLocalFlid);
				ListViewItem lvi = new ListViewItem(wsLabel);
				lvi.Tag = ws;
				lvi.SubItems.Add(tss.Text);
				lvis[i] = lvi;
			}
			m_lvDetails.Items.AddRange(lvis);
			m_lvDetails.ResumeLayout();
		}