Esempio n. 1
0
 public GhostDaDecorator(ISilDataAccessManaged domainDataByFlid, ITsString tss, int clidDst)
     : base(domainDataByFlid)
 {
     m_tss     = tss;
     m_clidDst = clidDst;
     SetOverrideMdc(new GhostMdc(MetaDataCache as IFwMetaDataCacheManaged));
 }
Esempio n. 2
0
 public InterestingTextsDecorator(ISilDataAccessManaged domainDataByFlid, XmlNode configurationNode,
                                  IFdoServiceLocator services)
     : base(domainDataByFlid)
 {
     SetOverrideMdc(new InterestingTextsMdc(base.MetaDataCache as IFwMetaDataCacheManaged));
     m_services = services;
 }
		public InterestingTextsDecorator(ISilDataAccessManaged domainDataByFlid, XmlNode configurationNode,
			IFdoServiceLocator services)
			: base(domainDataByFlid)
		{
			SetOverrideMdc(new InterestingTextsMdc(base.MetaDataCache as IFwMetaDataCacheManaged));
			m_services = services;
		}
Esempio n. 4
0
		public ConcDecorator(ISilDataAccessManaged domainDataByFlid, XmlNode configurationNode,
			IFdoServiceLocator services)
			: base(domainDataByFlid)
		{
			m_services = services;
			SetOverrideMdc(new ConcMdc(MetaDataCache as IFwMetaDataCacheManaged));
		}
Esempio n. 5
0
        /// <summary>
        /// Get a BsonValue and GUID for the object referenced by a Reference or Owning field.
        /// The GUID will be returned by adding it to a list passed in by reference, so that
        /// ReferenceCollection, OwningSequence, and similar fields will be easy to process.
        /// Note that we guarantee that a GUID will always be added to the list, even if this function
        /// returns null for the object's data. That way Select(hvo => GetCustomReferencedObject(hvo, flid, ref myGuidList))
        /// will always return the same number of items as the number of GUIDs in myGuidList.
        /// </summary>
        /// <returns>The custom referenced object's data converted to a BsonValue.</returns>
        /// <param name="hvo">Hvo of referenced object.</param>
        /// <param name="flid">Flid of referring field (required to get correct writing system for an StText).</param>
        /// <param name="listConverters">Dictionary of ConvertLcmToMongoOptionList instances, keyed by list code</param>
        /// <param name="referencedObjectGuids">List to which referenced object's GUID will be added.</param>
        private BsonValue GetCustomReferencedObject(int hvo, int flid,
                                                    IDictionary <string, ConvertLcmToMongoOptionList> listConverters,
                                                    ref List <Guid> referencedObjectGuids)
        {
            ISilDataAccessManaged data = (ISilDataAccessManaged)cache.DomainDataByFlid;

            if (hvo == 0 || !data.get_IsValidObject(hvo))
            {
                referencedObjectGuids.Add(Guid.Empty);
                return(null);
            }
            ICmObject referencedObject = cache.GetAtomicPropObject(hvo);

            if (referencedObject == null)
            {
                referencedObjectGuids.Add(Guid.Empty);
                return(null);
            }
            referencedObjectGuids.Add(referencedObject.Guid);
            if (referencedObject is IStText)
            {
                return(ConvertUtilities.GetCustomStTextValues((IStText)referencedObject, flid,
                                                              servLoc.WritingSystemManager, LcmMetaData, cache.DefaultUserWs));
            }
            else if (referencedObject is ICmPossibility)
            {
                //return GetCustomListValues((ICmPossibility)referencedObject, flid);
                string listCode = GetParentListCode(flid);
                return(new BsonString(listConverters[listCode].LfItemKeyString((ICmPossibility)referencedObject, _wsEn)));
            }
            else
            {
                return(null);
            }
        }
Esempio n. 6
0
 public ConcDecorator(ISilDataAccessManaged domainDataByFlid, XmlNode configurationNode,
                      IFdoServiceLocator services)
     : base(domainDataByFlid)
 {
     m_services = services;
     SetOverrideMdc(new ConcMdc(MetaDataCache as IFwMetaDataCacheManaged));
 }
Esempio n. 7
0
 public ComplexConcPatternSda(ISilDataAccessManaged domainDataByFlid, ComplexConcPatternNode root)
     : base(domainDataByFlid)
 {
     SetOverrideMdc(new ComplexConcordancePatternMdc((IFwMetaDataCacheManaged)domainDataByFlid.MetaDataCache));
     m_nodes    = new Dictionary <int, ComplexConcPatternNode>();
     m_root     = root;
     m_root.Sda = this;
 }
Esempio n. 8
0
        ///<summary>
        /// Decorate an ISilDataAccessManaged object with another layer limiting objects to print.
        ///</summary>
        ///<param name="oldSda"></param>
        ///<param name="rootHvo"></param>
        ///<param name="mainFlid"></param>
        ///<param name="selectedObjects"></param>
        ///<returns></returns>
        public static ISilDataAccessManaged CachePrintDecorator(ISilDataAccessManaged oldSda,
                                                                int rootHvo, int mainFlid, int[] selectedObjects)
        {
            var printDecorator = new ObjectListPublisher(oldSda, mainFlid);

            printDecorator.CacheVecProp(rootHvo, selectedObjects);
            return(printDecorator);
        }
Esempio n. 9
0
 private void InitXmlViewRootSpec(int hvoRoot, int flid, XmlNode xnSpec, ISilDataAccessManaged sda)
 {
     m_hvoRoot   = hvoRoot;
     m_mainFlid  = flid;
     m_sdaSource = sda;
     Debug.Assert(xnSpec != null, "Creating an XMLView with null spec");
     m_xnSpec = xnSpec;
 }
Esempio n. 10
0
 /// <summary>
 /// The main constructor.
 /// </summary>
 public XMLViewsDataCache(ISilDataAccessManaged domainDataByFlid, bool defaultSelected, Dictionary <int, int> selectedItems)
     : base(domainDataByFlid)
 {
     DefaultSelected = defaultSelected;
     m_selectedCache = selectedItems;
     SetOverrideMdc(new XmlViewsMdc(domainDataByFlid.MetaDataCache as IFwMetaDataCacheManaged));
     m_tagReversalEntriesBulkText = domainDataByFlid.MetaDataCache.GetFieldId("LexSense", "ReversalEntriesBulkText", false);
 }
 public PhonologicalFeaturePublisher(ISilDataAccessManaged domainDataByFlid, FdoCache cache)
     : base(domainDataByFlid, ListFlid)
 {
     m_cache        = cache;
     m_objProps     = new Dictionary <int, int>();
     m_unicodeProps = new Dictionary <int, string>();
     SetOverrideMdc(new PhonologicalFeatureMdc((IFwMetaDataCacheManaged)MetaDataCache));
 }
Esempio n. 12
0
		public ComplexConcPatternSda(ISilDataAccessManaged domainDataByFlid, ComplexConcPatternNode root)
			: base(domainDataByFlid)
		{
			SetOverrideMdc(new ComplexConcordancePatternMdc((IFwMetaDataCacheManaged) domainDataByFlid.MetaDataCache));
			m_nodes = new Dictionary<int, ComplexConcPatternNode>();
			m_root = root;
			m_root.Sda = this;
		}
		protected override BrowseViewer CreateBrowseViewer(XmlNode nodeSpec, int hvoRoot, int fakeFlid, FdoCache cache, Mediator mediator,
			ISortItemProvider sortItemProvider, ISilDataAccessManaged sda)
		{
			var viewer = new FdoUi.BrowseViewerPhonologicalFeatures(nodeSpec,
						 hvoRoot, fakeFlid,
						 cache, mediator, sortItemProvider, sda);
			return viewer;
		}
Esempio n. 14
0
        protected override BrowseViewer CreateBrowseViewer(XmlNode nodeSpec, int hvoRoot, int fakeFlid, FdoCache cache, Mediator mediator,
					ISortItemProvider sortItemProvider, ISilDataAccessManaged sda)
        {
            var viewer = new BrowseActiveViewer(nodeSpec,
                         hvoRoot, fakeFlid,
                         cache, mediator, sortItemProvider, sda);
            viewer.CheckBoxActiveChanged += OnCheckBoxActiveChanged;
            return viewer;
        }
 public SdaDecorator(ISilDataAccessManaged domainDataByFlid, FdoCache cache, string displayNameProperty, string displayWs)
     : base(domainDataByFlid)
 {
     SetOverrideMdc(new MdcDecorator((IFwMetaDataCacheManaged)domainDataByFlid.MetaDataCache));
     m_strings           = new Dictionary <int, ITsString>();
     Cache               = cache;
     DisplayNameProperty = displayNameProperty;
     DisplayWs           = displayWs;
 }
Esempio n. 16
0
        private bool SameData(LayoutFinder otherLf)
        {
            if (otherLf.m_sda == m_sda)
            {
                return(true);
            }
            ISilDataAccessManaged first  = RootSdaOf(m_sda);
            ISilDataAccessManaged second = RootSdaOf(otherLf.m_sda);

            return(first == second && first != null);
        }
Esempio n. 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(ISilDataAccessManaged 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<int>(chvoReal))
			{
				BaseSda.VecProp(m_hvoRoot, m_mainFlid, chvoReal, out chvoReal, arrayPtr);
				m_validHvos = new Set<int>(MarshalEx.NativeToArray<int>(arrayPtr, chvoReal));
			}
		}
Esempio n. 18
0
        /// <summary>
        /// This method will return the list of items in this vector which are visible to the user, the base class version returns all items.
        /// </summary>
        protected virtual List <ICmObject> GetVisibleItemList()
        {
            ISilDataAccessManaged sda = m_rootb.DataAccess as ISilDataAccessManaged;
            var objRepo = Cache.ServiceLocator.ObjectRepository;

            if (sda != null)
            {
                return((from i in sda.VecProp(m_rootObj.Hvo, m_rootFlid)
                        where objRepo.GetObject(i) != null
                        select objRepo.GetObject(i)).ToList());
            }
            return(null);
        }
Esempio n. 19
0
        /// <summary>
        /// Make one that wraps the specified cache and passes items in the specified property of the specified root object.
        /// </summary>
        public FilterSdaDecorator(ISilDataAccessManaged 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 <int>(chvoReal))
            {
                BaseSda.VecProp(m_hvoRoot, m_mainFlid, chvoReal, out chvoReal, arrayPtr);
                m_validHvos = new Set <int>(MarshalEx.NativeToArray <int>(arrayPtr, chvoReal));
            }
        }
Esempio n. 20
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Initializes a new instance of the <see cref="XmlSeqView"/> class.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public XmlSeqView(FdoCache cache, int hvoRoot, int flid, XmlNode xnSpec, ISilDataAccessManaged sda, IApp app, ICmPossibility publication)
            : base(null)
        {
            m_app = app;
            var useSda        = sda;
            var decoratorSpec = XmlUtils.FindNode(xnSpec, "decoratorClass");

            if (decoratorSpec != null)
            {
                // For example, this may create a DictionaryPublicationDecorator.
                useSda = (ISilDataAccessManaged)DynamicLoader.CreateObject(decoratorSpec,
                                                                           new object[] { cache, sda, flid, publication });
            }
            InitXmlViewRootSpec(hvoRoot, flid, xnSpec, useSda);
        }
Esempio n. 21
0
		public LiftExporter(FdoCache cache)
		{
			m_cache = cache;
			m_mdc = cache.MetaDataCacheAccessor as IFwMetaDataCacheManaged;
			Debug.Assert(m_mdc != null);
			m_sda = m_cache.DomainDataByFlid as ISilDataAccessManaged;
			Debug.Assert(m_sda != null);
			m_repoCmPossibilityLists = m_cache.ServiceLocator.GetInstance<ICmPossibilityListRepository>();

			m_wsEn = cache.WritingSystemFactory.GetWsFromStr("en");
			if (m_wsEn == 0)
				m_wsEn = cache.DefaultUserWs;
			m_wsManager = cache.ServiceLocator.WritingSystemManager;
			m_wsBestAnalVern = (int)SpecialWritingSystemCodes.BestAnalysisOrVernacular;
		}
Esempio n. 22
0
		public override void FixtureSetup()
		{
			base.FixtureSetup();

			var servLoc = Cache.ServiceLocator;
			var mdc = servLoc.GetInstance<IFwMetaDataCacheManaged>();
			m_customCertifiedFlid = mdc.AddCustomField("WfiWordform", "Certified", CellarPropertyType.Boolean, 0);
			m_customITsStringFlid = mdc.AddCustomField("WfiWordform", "NewTsStringProp", CellarPropertyType.String, 0);
			m_customVernTsStringFlid = mdc.AddCustomField("WfiWordform", "NewVernStringProp", CellarPropertyType.String, 0, "helpId",
				WritingSystemServices.kwsVern, Guid.Empty);
			m_customMultiUnicodeFlid = mdc.AddCustomField("WfiWordform", "MultiUnicodeProp", CellarPropertyType.MultiUnicode, 0);
			m_customAtomicReferenceFlid = mdc.AddCustomField("WfiWordform", "NewAtomicRef", CellarPropertyType.ReferenceAtomic, CmPersonTags.kClassId);
			//m_customReferenceSequenceFlid = mdc.AddCustomField("WfiWordform", "NewRefSeq", CellarPropertyType.ReferenceSequence, CmPersonTags.kClassId);

			m_sda = servLoc.GetInstance<ISilDataAccessManaged>();
			m_possListFactory = servLoc.GetInstance<ICmPossibilityListFactory>();
			var lp = Cache.LanguageProject;
			NonUndoableUnitOfWorkHelper.Do(m_actionHandler, () =>
			{
				lp.PeopleOA = m_possListFactory.Create();
				var personFactory = servLoc.GetInstance<ICmPersonFactory>();
				var person1 = personFactory.Create();
				lp.PeopleOA.PossibilitiesOS.Add(person1);
				person1.DateOfBirth = new GenDate(GenDate.PrecisionType.Approximate, 1, 1, 3000, true);
				var person2 = personFactory.Create();
				lp.PeopleOA.PossibilitiesOS.Add(person2);

				lp.LocationsOA = m_possListFactory.Create();
				var location = servLoc.GetInstance<ICmLocationFactory>().Create();
				lp.LocationsOA.PossibilitiesOS.Add(location);
				lp.LocationsOA.IsSorted = true;

				person1.PlaceOfBirthRA = location;

				lp.EthnologueCode = "ZPI";

				lp.TranslatedScriptureOA = servLoc.GetInstance<IScriptureFactory>().Create();
			});
		}
Esempio n. 23
0
 /// <summary>
 /// Create one. The SDA passed MAY be the DomainDataByFlid of the cache, but it is usually another
 /// decorator.
 /// </summary>
 public DictionaryPublicationDecorator(FdoCache cache, ISilDataAccessManaged domainDataByFlid, int mainFlid, ICmPossibility publication)
     : base(domainDataByFlid)
 {
     Cache                     = cache;
     m_entryRepo               = Cache.ServiceLocator.GetInstance <ILexEntryRepository>();
     m_lexRefRepo              = Cache.ServiceLocator.GetInstance <ILexReferenceRepository>();
     m_senseRepo               = Cache.ServiceLocator.GetInstance <ILexSenseRepository>();
     m_lerRepo                 = Cache.ServiceLocator.GetInstance <ILexEntryRefRepository>();
     m_LexDbEntriesFlid        = mainFlid;
     m_headwordFlid            = Cache.MetaDataCacheAccessor.GetFieldId2(LexEntryTags.kClassId, "HeadWord", false);
     m_mlHeadwordFlid          = Cache.MetaDataCacheAccessor.GetFieldId2(LexEntryTags.kClassId, "MLHeadWord", false);
     m_picsOfSensesFlid        = Cache.MetaDataCacheAccessor.GetFieldId2(LexEntryTags.kClassId, "PicturesOfSenses", false);
     m_senseOutlineFlid        = Cache.MetaDataCacheAccessor.GetFieldId2(LexSenseTags.kClassId, "LexSenseOutline", false);
     m_mlOwnerOutlineFlid      = Cache.MetaDataCacheAccessor.GetFieldId2(LexSenseTags.kClassId, "MLOwnerOutlineName", false);
     m_publishAsMinorEntryFlid = Cache.MetaDataCacheAccessor.GetFieldId2(LexEntryTags.kClassId, "PublishAsMinorEntry", false);
     m_headwordRefFlid         = Cache.MetaDataCacheAccessor.GetFieldId2(LexEntryTags.kClassId, "HeadWordRef", false);
     m_headwordReversalFlid    = Cache.MetaDataCacheAccessor.GetFieldId2(LexEntryTags.kClassId, "ReversalName", false);
     m_reversalNameFlid        = Cache.MetaDataCacheAccessor.GetFieldId2(LexSenseTags.kClassId, "ReversalName", false);
     Publication               = publication;
     BuildExcludedObjects();
     BuildFieldsToFilter();
     BuildHomographInfo();
 }
 /// <summary>
 /// Create one. The SDA passed MAY be the DomainDataByFlid of the cache, but it is usually another
 /// decorator.
 /// </summary>
 /// <param name="cache"></param>
 /// <param name="domainDataByFlid"></param>
 public DictionaryPublicationDecorator(FdoCache cache, ISilDataAccessManaged domainDataByFlid, int mainFlid, ICmPossibility publication)
     : base(domainDataByFlid)
 {
     Cache = cache;
     m_entryRepo = Cache.ServiceLocator.GetInstance<ILexEntryRepository>();
     m_lexRefRepo = Cache.ServiceLocator.GetInstance<ILexReferenceRepository>();
     m_senseRepo = Cache.ServiceLocator.GetInstance<ILexSenseRepository>();
     m_lerRepo = Cache.ServiceLocator.GetInstance<ILexEntryRefRepository>();
     m_LexDbEntriesFlid = mainFlid;
     m_headwordFlid = Cache.MetaDataCacheAccessor.GetFieldId2(LexEntryTags.kClassId, "HeadWord", false);
     m_mlHeadwordFlid = Cache.MetaDataCacheAccessor.GetFieldId2(LexEntryTags.kClassId, "MLHeadWord", false);
     m_picsOfSensesFlid = Cache.MetaDataCacheAccessor.GetFieldId2(LexEntryTags.kClassId, "PicturesOfSenses", false);
     m_senseOutlineFlid = Cache.MetaDataCacheAccessor.GetFieldId2(LexSenseTags.kClassId, "LexSenseOutline", false);
     m_mlOwnerOutlineFlid = Cache.MetaDataCacheAccessor.GetFieldId2(LexSenseTags.kClassId, "MLOwnerOutlineName", false);
     m_publishAsMinorEntryFlid = Cache.MetaDataCacheAccessor.GetFieldId2(LexEntryTags.kClassId, "PublishAsMinorEntry", false);
     m_doNotShowMainEntryInFlid = Cache.MetaDataCacheAccessor.GetFieldId2(LexEntryTags.kClassId, "DoNotShowMainEntryIn", false);
     m_headwordRefFlid = Cache.MetaDataCacheAccessor.GetFieldId2(LexEntryTags.kClassId, "HeadWordRef", false);
     m_headwordReversalFlid = Cache.MetaDataCacheAccessor.GetFieldId2(LexEntryTags.kClassId, "HeadWordReversal", false);
     m_reversalNameFlid = Cache.MetaDataCacheAccessor.GetFieldId2(LexSenseTags.kClassId, "ReversalName", false);
     Publication = publication;
     BuildExcludedObjects();
     BuildFieldsToFilter();
     BuildHomographInfo();
 }
 public FeatureConstraintPublisher(ISilDataAccessManaged domainDataByFlid)
     : base(domainDataByFlid, ListFlid)
 {
     m_unicodeProps = new Dictionary <int, string>();
     SetOverrideMdc(new FeatureConstraintMdc(MetaDataCache as IFwMetaDataCacheManaged));
 }
 public MockPublisher(ISilDataAccessManaged domainDataByFlid, int flid) : base(domainDataByFlid, flid)
 {
 }
 /// <summary>
 /// Make one. By default we filter to the main dictionary.
 /// </summary>
 /// <param name="cache"></param>
 public DictionaryPublicationDecorator(FdoCache cache, ISilDataAccessManaged domainDataByFlid, int mainFlid)
     : this(cache, domainDataByFlid, mainFlid, cache.LangProject.LexDbOA.PublicationTypesOA.PossibilitiesOS[0])
 {
 }
			public ReversalEntryDataAccess(ISilDataAccessManaged sda)
				: base(sda)
			{
			}
Esempio n. 29
0
        private List <IVwNotifyChange> m_notifees = new List <IVwNotifyChange>();       // the things we have to notify of PropChanges.

        /// <summary>
        /// Make one. By default we filter to the main dictionary.
        /// </summary>
        public DictionaryPublicationDecorator(FdoCache cache, ISilDataAccessManaged domainDataByFlid, int mainFlid)
            : this(cache, domainDataByFlid, mainFlid, cache.LangProject.LexDbOA.PublicationTypesOA.PossibilitiesOS[0])
        {
        }
Esempio n. 30
0
 /// <summary>
 /// Make one, wrapping some other ISilDataAccessManged (typically the main DomainDataByFlid).
 /// </summary>
 /// <param name="domainDataByFlid">The domainDataByFlid.</param>
 /// <param name="flid">The flid.</param>
 public ObjectListPublisher(ISilDataAccessManaged domainDataByFlid, int flid)
     : base(domainDataByFlid)
 {
     SetOverrideMdc(new ObjectListPublisherMdc(MetaDataCache as IFwMetaDataCacheManaged, this));
     m_flid = flid;
 }
		/// <summary>
		/// Constructor.
		/// </summary>
		/// <param name="domainDataByFlid">The FDO DomainDataByFlid implementation,
		/// which is used to get the basic FDO data.</param>
		/// <remarks>
		/// The hvo values are true 'handles' in that they are valid for one session,
		/// but may not be the same integer for another session for the 'same' object.
		/// Therefore, one should not use them for multi-session identity.
		/// CmObject identity can only be guaranteed by using their Guids (or using '==' in code).
		/// </remarks>
		protected DomainDataByFlidDecoratorBase(ISilDataAccessManaged domainDataByFlid)
		{
			if (domainDataByFlid == null) throw new ArgumentNullException("domainDataByFlid");

			m_domainDataByFlid = domainDataByFlid;
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Initializes a new instance of the <see cref="T:BrowseViewer"/> class.
		/// The sortItemProvider is typically the RecordList that impelements sorting and
		/// filtering of the items we are displaying.
		/// The data access passed typically is a decorator for the one in the cache, adding
		/// the sorted, filtered list of objects accessed as property fakeFlid of hvoRoot.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		public BrowseViewerPhonologicalFeatures(XmlNode nodeSpec, int hvoRoot, int fakeFlid,
			FdoCache cache, Mediator mediator, ISortItemProvider sortItemProvider, ISilDataAccessManaged sda)
			: base(nodeSpec, hvoRoot, fakeFlid, cache, mediator, sortItemProvider, sda)
		{ }
Esempio n. 33
0
		/// <summary>
		/// Simpler constructor supplies default args
		/// </summary>
		internal XMLViewsDataCache(ISilDataAccessManaged domainDataByFlid, XmlNode nodeSpec)
			: this(domainDataByFlid, XmlUtils.GetOptionalBooleanAttributeValue(nodeSpec, "defaultChecked", true),
			new Dictionary<int, int>())
		{
		}
Esempio n. 34
0
		public ShowSpaceDecorator(ISilDataAccessManaged sda) : base(sda)
		{}
Esempio n. 35
0
 public SdaDecorator(ISilDataAccessManaged domainDataByFlid)
     : base(domainDataByFlid)
 {
     SetOverrideMdc(new MdcDecorator((IFwMetaDataCacheManaged)domainDataByFlid.MetaDataCache));
 }
        /// <summary>
        /// Set custom field data for one field (specified by owner HVO and field ID).
        /// </summary>
        /// <returns><c>true</c>, if custom field data was set, <c>false</c> otherwise (e.g., if value hadn't changed,
        /// or value was null, or field type was one not implemented in LCM, such as CellarPropertyType.Float).</returns>
        /// <param name="hvo">HVO of object whose field we're setting.</param>
        /// <param name="flid">Field ID of custom field to set.</param>
        /// <param name="value">Field's new value (as returned by GetCustomFieldData).</param>
        /// <param name="guidOrGuids">GUID or guids associated with new value (as returned by GetCustomFieldData).
        /// May be null or BsonNull.Value if no GUIDs associated with this value.</param>
        public bool SetCustomFieldData(int hvo, int flid, BsonValue value, BsonValue guidOrGuids)
        {
            if ((value == null) || (value == BsonNull.Value) ||
                ((value.BsonType == BsonType.Array) && (value.AsBsonArray.Count == 0)))
            {
                return(false);
            }
            List <Guid> fieldGuids = new List <Guid>();

            if (guidOrGuids == null || guidOrGuids == BsonNull.Value)
            {
                // Leave fieldGuids as an empty list
            }
            else
            {
                if (guidOrGuids is BsonArray)
                {
                    fieldGuids.AddRange(guidOrGuids.AsBsonArray.Select(bsonValue => ParseGuidOrDefault(bsonValue.AsString)));
                }
                else
                {
                    fieldGuids.Add(ParseGuidOrDefault(guidOrGuids.AsString));
                }
            }
            ISilDataAccessManaged data      = (ISilDataAccessManaged)cache.DomainDataByFlid;
            CellarPropertyType    fieldType = (CellarPropertyType)lcmMetaData.GetFieldType(flid);
            string fieldName = lcmMetaData.GetFieldNameOrNull(flid);

//			logger.Debug("Custom field named {0} has type {1}", fieldName, fieldType.ToString());
            if (fieldName == null)
            {
                return(false);
            }

            // Valid field types in LCM are GenDate, Integer, String, OwningAtomic, ReferenceAtomic, and ReferenceCollection, so that's all we implement.
            switch (fieldType)
            {
            case CellarPropertyType.GenDate:
            {
                var    valueAsMultiText = BsonSerializer.Deserialize <LfMultiText>(value.AsBsonDocument);
                string valueAsString    = valueAsMultiText.BestString(new string[] { MagicStrings.LanguageCodeForGenDateFields });
                if (string.IsNullOrEmpty(valueAsString))
                {
                    return(false);
                }
                GenDate valueAsGenDate;
                if (GenDate.TryParse(valueAsString, out valueAsGenDate))
                {
                    GenDate oldValue = data.get_GenDateProp(hvo, flid);
                    if (oldValue == valueAsGenDate)
                    {
                        return(false);
                    }
                    else
                    {
                        data.SetGenDate(hvo, flid, valueAsGenDate);
                        return(true);
                    }
                }
                return(false);
            }

            case CellarPropertyType.Integer:
            {
                var    valueAsMultiText = BsonSerializer.Deserialize <LfMultiText>(value.AsBsonDocument);
                string valueAsString    = valueAsMultiText.BestString(new string[] { MagicStrings.LanguageCodeForIntFields });
                if (string.IsNullOrEmpty(valueAsString))
                {
                    return(false);
                }
                int valueAsInt;
                if (int.TryParse(valueAsString, out valueAsInt))
                {
                    int oldValue = data.get_IntProp(hvo, flid);
                    if (oldValue == valueAsInt)
                    {
                        return(false);
                    }
                    else
                    {
                        data.SetInt(hvo, flid, valueAsInt);
                        return(true);
                    }
                }
                return(false);
            }

            case CellarPropertyType.OwningAtomic:
            {
                // Custom field is a MultiparagraphText, which is an IStText object in LCM
                IStTextRepository textRepo = servLoc.GetInstance <IStTextRepository>();
                Guid    fieldGuid          = fieldGuids.FirstOrDefault();
                IStText text;
                if (!textRepo.TryGetObject(fieldGuid, out text))
                {
                    int currentFieldContentsHvo = data.get_ObjectProp(hvo, flid);
                    if (currentFieldContentsHvo != LcmCache.kNullHvo)
                    {
                        text = (IStText)cache.GetAtomicPropObject(currentFieldContentsHvo);
                    }
                    else
                    {
                        // NOTE: I don't like the "magic" -2 number below, but LCM doesn't seem to have an enum for this. 2015-11 RM
                        int newStTextHvo = data.MakeNewObject(cache.GetDestinationClass(flid), hvo, flid, -2);
                        text = (IStText)cache.GetAtomicPropObject(newStTextHvo);
                    }
                }
                // Shortcut: if text contents haven't changed, we don't want to change anything at all
                BsonValue currentLcmTextContents = ConvertUtilities.GetCustomStTextValues(text, flid,
                                                                                          servLoc.WritingSystemManager, lcmMetaData, cache.DefaultUserWs);
                if ((currentLcmTextContents == BsonNull.Value || currentLcmTextContents == null) &&
                    (value == BsonNull.Value || value == null))
                {
                    return(false);
                }
                if (currentLcmTextContents != null && currentLcmTextContents.Equals(value))
                {
                    // No changes needed.
                    return(false);
                }
                // BsonDocument passed in contains "paragraphs". ParseCustomStTextValuesFromBson wants only a "value" element
                // inside the doc, so we'll need to construct a new doc for the StTextValues.
                BsonDocument     doc       = value.AsBsonDocument;
                LfMultiParagraph multiPara = BsonSerializer.Deserialize <LfMultiParagraph>(doc);
                // Now we have another way to check for "old value and new value were the same": if the LCM multiparagraph was empty,
                // GetCustomStTextValues will have returned null -- so if this multiPara has no paragraphs, that's also an unchanged situation
                if ((multiPara.Paragraphs == null || multiPara.Paragraphs.Count <= 0) &&
                    (currentLcmTextContents == BsonNull.Value || currentLcmTextContents == null))
                {
                    return(false);
                }
                int wsId;
                if (multiPara.InputSystem == null)
                {
                    wsId = lcmMetaData.GetFieldWs(flid);
                }
                else
                {
                    wsId = servLoc.WritingSystemFactory.GetWsFromStr(multiPara.InputSystem);
                }
                ConvertUtilities.SetCustomStTextValues(text, multiPara.Paragraphs, wsId);

                return(true);
            }

            case CellarPropertyType.ReferenceAtomic:
                if (fieldGuids.FirstOrDefault() != Guid.Empty)
                {
                    int referencedHvo = data.get_ObjFromGuid(fieldGuids.FirstOrDefault());
                    int oldHvo        = data.get_ObjectProp(hvo, flid);
                    if (referencedHvo == oldHvo)
                    {
                        return(false);
                    }
                    else
                    {
                        data.SetObjProp(hvo, flid, referencedHvo);
                        // TODO: What if the value of the referenced object has changed in LanguageForge? (E.g., change that possibility's text from "foo" to "bar")
                        // Need to implement that scenario.
                        return(true);
                    }
                }
                else
                {
                    // It's a reference to an ICmPossibility instance: create a new entry in appropriate PossibilityList
                    LfStringField valueAsLfStringField = BsonSerializer.Deserialize <LfStringField>(value.AsBsonDocument);
                    string        nameHierarchy        = valueAsLfStringField.Value;
                    if (nameHierarchy == null)
                    {
                        return(false);
                    }
                    int fieldWs = lcmMetaData.GetFieldWs(flid);
                    // Oddly, this can return 0 for some custom fields. TODO: Find out why: that seems like it would be an error.
                    if (fieldWs == 0)
                    {
                        fieldWs = cache.DefaultUserWs;                         // TODO: Investigate, because this should probably be wsEn instead so that we can create correct keys.
                    }
                    if (fieldWs < 0)
                    {
                        // FindOrCreatePossibility has a bug where it doesn't handle "magic" writing systems (e.g., -1 for default analysis, etc) and
                        // throws an exception instead. So we need to get a real ws here.
                        fieldWs = WritingSystemServices.ActualWs(cache, fieldWs, hvo, flid);
                    }
                    ICmPossibilityList parentList = GetParentListForField(flid);
                    ICmPossibility     newPoss    = parentList.FindOrCreatePossibility(nameHierarchy, fieldWs);

                    int oldHvo = data.get_ObjectProp(hvo, flid);
                    if (newPoss.Hvo == oldHvo)
                    {
                        return(false);
                    }
                    else
                    {
                        data.SetObjProp(hvo, flid, newPoss.Hvo);
                        return(true);
                    }
                }

            case CellarPropertyType.ReferenceCollection:
            case CellarPropertyType.ReferenceSequence:
            {
                if (value == null || value == BsonNull.Value)
                {
                    // Can't write null to a collection or sequence in LCM; it's forbidden. So data.SetObjProp(hvo, flid, LcmCache.kNullHvo) will not work.
                    // Instead, we delete all items from the existing collection or sequence, and thus store an empty coll/seq in LCM.
                    int oldSize = data.get_VecSize(hvo, flid);
                    if (oldSize == 0)
                    {
                        // It was already empty, so leave it unchanged so we don't cause unnecessary changes in the .fwdata XML (and unnecessary Mercurial commits).
                        return(false);
                    }
                    else
                    {
                        data.Replace(hvo, flid, 0, oldSize, null, 0);                                 // This is how you set an empty array
                        return(true);
                    }
                }
                int fieldWs = lcmMetaData.GetFieldWs(flid);
                // TODO: Investigate why this is sometimes coming back as 0 instead of as a real writing system ID
                if (fieldWs == 0)
                {
                    fieldWs = cache.DefaultUserWs;
                }
                ICmPossibilityList parentList = GetParentListForField(flid);

                LfStringArrayField valueAsStringArray = BsonSerializer.Deserialize <LfStringArrayField>(value.AsBsonDocument);

                // Step 1: Get ICmPossibility instances from the string keys that LF gave us

                // First go through all the GUIDs we have and match them up to the keys. If they match up,
                // then remove the keys from the list. Any remaining keys get looked up with FindOrCreatePossibility(), so now we
                // have a complete set of GUIDs (or ICmPossibility objects, which works out to the same thing).

                // TODO: This is all kind of ugly, and WAY too long for one screen. I could put it in its own function,
                // but there's really no real gain from that, as it simply moves the logic even further away from where
                // it needs to be. There's not really a *good* way to achieve simplicity with this code design, unfortunately.
                // The only thing that would be close to simple would be to call some functions from the LcmToMongo option list
                // converters, and that's pulling in code from the "wrong" direction, which has its own ugliness. Ugh.

                HashSet <string> keysFromLF = new HashSet <string>(valueAsStringArray.Values);
                var fieldObjs = new List <ICmPossibility>();
                foreach (Guid guid in fieldGuids)
                {
                    ICmPossibility poss;
                    string         key = "";
                    if (guid != default(Guid))
                    {
                        poss = servLoc.GetInstance <ICmPossibilityRepository>().GetObject(guid);
                        if (poss == null)
                        {
                            // TODO: Decide what to do with possibilities deleted from LCM
                            key = "";
                        }
                        else
                        {
                            if (poss.Abbreviation == null)
                            {
                                key = "";
                            }
                            else
                            {
                                ITsString keyTss = poss.Abbreviation.get_String(wsEn);
                                key = keyTss == null ? "" : keyTss.Text ?? "";
                            }
                            fieldObjs.Add(poss);
                        }
                    }
                    keysFromLF.Remove(key);
                    // Ignoring return value (HashSet.Remove returns false if the key wasn't present), because false could mean one of two things:
                    // 1. The CmPossibility had its English abbreviation changed in LCM, but LF doesn't know this yet.
                    //    If this is the case, the LF key won't match, but the GUID will still match. So we might end up creating
                    //    duplicate entries below with the FindOrCreatePossibility. TODO: Need to verify that LCM->LF possibility lists
                    //    get updated correctly if renames happen! (... Or use the OptionList converters, that's what they were for.)
                    // 2. The CmPossibility was just created in LF and isn't in LCM yet. In which case we should have been using the
                    //    OptionList converters, which would hopefully have handled creating the ICmPossibility instane in LCM.
                    // Either way, we can't really use that fact later, since we can't be certain if the possibility was renamed or created.
                }
                // Any remaining keysFromLF strings did not have corresponding GUIDs in Mongo.
                // This is most likely because they were added by LF, which doesn't write to the customFieldGuids field.
                // So we assume they exist in FW, and just look them up.
                foreach (string key in keysFromLF)
                {
                    ICmPossibility poss = parentList.FindOrCreatePossibility(key, wsEn);
                    // TODO: If this is a new possibility, then we need to populate it with ALL the corresponding data from LF,
                    // which we don't necessarily have at this point. Need to make that a separate step in the Send/Receive: converting option lists first.
                    fieldObjs.Add(poss);
                }
                // logger.Debug("Custom field {0} for CmObject {1}: BSON list was [{2}] and customFieldGuids was [{3}]. This was translated to keysFromLF = [{4}] and fieldObjs = [{5}]",
                //  fieldName,
                //  hvo,
                //  String.Join(", ", valueAsStringArray.Values),
                //  String.Join(", ", fieldGuids.Select(g => g.ToString())),
                //  String.Join(", ", keysFromLF.AsEnumerable()),
                //  String.Join(", ", fieldObjs.Select(poss => poss.AbbrAndName))
                // );
                // Step 2: Remove any objects from the "old" list that weren't in the "new" list
                // We have to look them up by HVO because that's the only public API available in LCM
                // Following logic inspired by XmlImportData.CopyCustomFieldData in FieldWorks source
                int[] oldHvosArray = data.VecProp(hvo, flid);
                int[] newHvosArray = fieldObjs.Select(poss => poss.Hvo).ToArray();
                // Shortcut check
                if (oldHvosArray.SequenceEqual(newHvosArray))
                {
                    // Nothing to do, so return now so that we don't cause unnecessary changes and commits in Mercurial
                    return(false);
                }
                HashSet <int> newHvos      = new HashSet <int>(newHvosArray);
                HashSet <int> combinedHvos = new HashSet <int>();
                // Loop backwards so deleting items won't mess up indices of subsequent deletions
                for (int idx = oldHvosArray.Length - 1; idx >= 0; idx--)
                {
                    int oldHvo = oldHvosArray[idx];
                    if (newHvos.Contains(oldHvo))
                    {
                        combinedHvos.Add(oldHvo);
                    }
                    else
                    {
                        data.Replace(hvo, flid, idx, idx + 1, null, 0);                                 // Important to pass *both* null *and* 0 here to remove items
                    }
                }

                // Step 3: Add any objects from the "new" list that weren't in the "old" list
                foreach (int newHvo in newHvosArray)
                {
                    if (combinedHvos.Contains(newHvo))
                    {
                        continue;
                    }
                    // This item was added in the new list
                    data.Replace(hvo, flid, combinedHvos.Count, combinedHvos.Count, new int[] { newHvo }, 1);
                    combinedHvos.Add(newHvo);
                }
                return(true);
            }

            case CellarPropertyType.String:
            {
                var    valueAsMultiText          = BsonSerializer.Deserialize <LfMultiText>(value.AsBsonDocument);
                int    wsIdForField              = lcmMetaData.GetFieldWs(flid);
                string wsStrForField             = servLoc.WritingSystemFactory.GetStrFromWs(wsIdForField);
                KeyValuePair <string, string> kv = valueAsMultiText.BestStringAndWs(new string[] { wsStrForField });
                string foundWs   = kv.Key ?? string.Empty;
                string foundData = kv.Value ?? string.Empty;
                int    foundWsId = servLoc.WritingSystemFactory.GetWsFromStr(foundWs);
                if (foundWsId == 0)
                {
                    return(false);                            // Skip any unidentified writing systems
                }
                ITsString oldValue = data.get_StringProp(hvo, flid);
                ITsString newValue = ConvertMongoToLcmTsStrings.SpanStrToTsString(foundData, foundWsId, servLoc.WritingSystemFactory);
                if (oldValue != null && TsStringUtils.GetDiffsInTsStrings(oldValue, newValue) == null)                         // GetDiffsInTsStrings() returns null when there are no changes
                {
                    return(false);
                }
                else
                {
                    data.SetString(hvo, flid, newValue);
                    return(true);
                }
            }

            default:
                return(false);
                // TODO: Maybe issue a proper warning (or error) log message for "field type not recognized"?
            }
        }
Esempio n. 37
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Make the root box.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		public override void MakeRoot()
		{
			CheckDisposed();

			if (m_fdoCache == null || DesignMode)
				return;

			m_rootb = VwRootBoxClass.Create();
			m_rootb.SetSite(this);
			// Only change it if it is null or different.
			// Otherwise, it does an uneeded disposal/creation of the layout cache.
			if (m_xbvvc.Cache == null || m_xbvvc.Cache != m_fdoCache)
				m_xbvvc.Cache = m_fdoCache;
			SetSelectedRowHighlighting();
			this.ReadOnlyView = this.ReadOnlySelect;

			// This is where the 'Decorator' SDA is added.
			// This SDA can handle fake stuff, if the SDA overrides are all implemented properly.
			m_sda = m_bv.SpecialCache;
			m_rootb.DataAccess = m_sda;

			RootObjectHvo = m_hvoRoot;
			base.MakeRoot();
			m_bv.SpecialCache.AddNotification(this);
			m_dxdLayoutWidth = kForceLayout; // Don't try to draw until we get OnSize and do layout.
			// Filter bar uses info from our VC and can't fininish init until we make it.
			if (m_bv.FilterBar != null)
				m_bv.FilterBar.MakeItems();
			// Simulate a column drag to get the columns resized.
			// No good, we can't do this until we've had one layout call.
			//m_bv.ColumnDragged();
			//TODO:
			//ptmw->RegisterRootBox(qrootb);
			if (RootSiteEditingHelper != null)
			{
				RootSiteEditingHelper.PasteFixTssEvent -= new FwPasteFixTssEventHandler(OnPasteFixTssEvent);
				RootSiteEditingHelper.PasteFixTssEvent += new FwPasteFixTssEventHandler(OnPasteFixTssEvent);
			}
		}
Esempio n. 38
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Inits the specified node spec.
		/// </summary>
		/// <param name="nodeSpec">The node spec.</param>
		/// <param name="hvoRoot">The hvo root.</param>
		/// <param name="fakeFlid">The fake flid.</param>
		/// <param name="cache">The cache.</param>
		/// <param name="mediator">The mediator.</param>
		/// <param name="bv">The bv. Also used to set SortItemProvider</param>
		/// ------------------------------------------------------------------------------------
		public virtual void Init(XmlNode nodeSpec, int hvoRoot, int fakeFlid,
			FdoCache cache, Mediator mediator, BrowseViewer bv)
		{
			CheckDisposed();

			Debug.Assert((m_selectedIndex == -1), "Cannot set the index to less than zero before initializing.");
			Debug.Assert(m_nodeSpec == null || m_nodeSpec == nodeSpec, "XmlBrowseViewBase.Init: Mismatched configuration parameters.");

			m_hvoRoot = hvoRoot;
			m_fakeFlid = fakeFlid;
			if (m_nodeSpec == null)
				m_nodeSpec = nodeSpec;
			m_bv = bv;
			StringTbl = mediator.StringTbl;
			m_mediator = mediator;
			m_fdoCache = cache;
			m_sda = m_bv.SpecialCache;
			// This is usually done in MakeRoot, but we need it to exist right from the start
			// because right after we make this window we use info from the VC to help make
			// the column headers.
			if (bv != null)
				m_sortItemProvider = bv.SortItemProvider;
			m_xbvvc = Vc;
			string sDefaultCursor = XmlUtils.GetOptionalAttributeValue(nodeSpec,
				"defaultCursor", null);
			// Set a default cursor for a ReadOnly view, if none is given.
			if (sDefaultCursor == null && ReadOnlySelect)
				sDefaultCursor = "Arrow";
			if (sDefaultCursor != null)
			{
				switch (sDefaultCursor)
				{
					case "IBeam":
						EditingHelper.DefaultCursor = Cursors.IBeam;
						break;
					case "Hand":
						EditingHelper.DefaultCursor = Cursors.Hand;
						break;
					case "Arrow":
						EditingHelper.DefaultCursor = Cursors.Arrow;
						break;
					case "Cross":
						EditingHelper.DefaultCursor = Cursors.Cross;
						break;
				}
			}
		}
Esempio n. 39
0
        protected override BrowseViewer CreateBrowseViewer(XmlNode nodeSpec, int hvoRoot, int fakeFlid, LcmCache cache,
                                                           Mediator mediator, PropertyTable propertyTable,
                                                           ISortItemProvider sortItemProvider, ISilDataAccessManaged sda)
        {
            var viewer = new BrowseActiveViewer(nodeSpec,
                                                hvoRoot, fakeFlid,
                                                cache, mediator, propertyTable, sortItemProvider, sda);

            viewer.CheckBoxActiveChanged += OnCheckBoxActiveChanged;
            return(viewer);
        }
Esempio n. 40
0
		/// <summary>
		/// The main constructor.
		/// </summary>
		public XMLViewsDataCache(ISilDataAccessManaged domainDataByFlid, bool defaultSelected, Dictionary<int, int> selectedItems)
			: base(domainDataByFlid)
		{
			DefaultSelected = defaultSelected;
			m_selectedCache = selectedItems;
			SetOverrideMdc(new XmlViewsMdc(domainDataByFlid.MetaDataCache as IFwMetaDataCacheManaged));
			m_tagReversalEntriesBulkText = domainDataByFlid.MetaDataCache.GetFieldId("LexSense", "ReversalEntriesBulkText", false);
		}
Esempio n. 41
0
		/// <summary>
		/// Make one, wrapping some other ISilDataAccessManged (typically the main DomainDataByFlid).
		/// </summary>
		/// <param name="domainDataByFlid">The domainDataByFlid.</param>
		/// <param name="flid">The flid.</param>
		public ObjectListPublisher(ISilDataAccessManaged domainDataByFlid, int flid)
			: base(domainDataByFlid)
		{
			SetOverrideMdc(new ObjectListPublisherMdc(MetaDataCache as IFwMetaDataCacheManaged, this));
			m_flid = flid;
		}
Esempio n. 42
0
 public ShowSpaceDecorator(ISilDataAccessManaged sda) : base(sda)
 {
 }
Esempio n. 43
0
        /// <summary>
        /// Gets the data for one custom field, and any relevant GUIDs.
        /// </summary>
        /// <param name="hvo">Hvo of object we're getting the field for.</param>
        /// <param name="flid">Flid for this field.</param>
        /// <param name="fieldSourceType">Either "entry", "senses" or "examples". Could also be "allomorphs", eventually.</param>
        /// <param name="bsonForThisField">Output of a BsonDocument with the following structure: <br />
        /// { fieldName: { "value": BsonValue, "guid": "some-guid-as-a-string" } } <br />
        /// -OR- <br />
        /// { fieldName: { "value": BsonValue, "guid": ["guid1", "guid2", "guid3"] } } <br />
        /// The format of the fieldName key will be "customField_FOO_field_name_with_underscores",
        /// where FOO is one of "entry", "senses", or "examples". <br />
        /// The type of the "guid" value (array or string) will determine whether there is a single GUID,
        /// or a list of GUIDs that happens to contain only one entry.
        /// If there is no "guid" key, that field has no need for a GUID. (E.g., a number).
        /// </param>
        /// <param name="listConverters">Dictionary of ConvertLcmToMongoOptionList instances, keyed by list code</param>
        private BsonDocument GetCustomFieldData(int hvo, int flid, string fieldSourceType,
                                                IDictionary <string, ConvertLcmToMongoOptionList> listConverters)
        {
            BsonValue             fieldValue   = null;
            BsonValue             fieldGuid    = null; // Might be a single value, might be a list (as a BsonArray)
            ISilDataAccessManaged data         = (ISilDataAccessManaged)cache.DomainDataByFlid;
            CellarPropertyType    LcmFieldType = (CellarPropertyType)LcmMetaData.GetFieldType(flid);
            var dataGuids = new List <Guid>();

            // Valid field types in Lcm are GenDate, Integer, String, OwningAtomic, ReferenceAtomic, and ReferenceCollection, so that's all we implement.
            switch (LcmFieldType)
            {
            case CellarPropertyType.GenDate:
                GenDate genDate    = data.get_GenDateProp(hvo, flid);
                string  genDateStr = genDate.ToLongString();
                // LF wants single-string fields in the format { "ws": { "value": "contents" } }
                fieldValue = String.IsNullOrEmpty(genDateStr) ? null :
                             LfMultiText.FromSingleStringMapping(
                    MagicStrings.LanguageCodeForGenDateFields, genDateStr).AsBsonDocument();
                break;
            // When parsing, will use GenDate.TryParse(str, out genDate)

            case CellarPropertyType.Integer:
                fieldValue = new BsonInt32(data.get_IntProp(hvo, flid));
                if (fieldValue.AsInt32 == default(Int32))
                {
                    fieldValue = null;                     // Suppress int fields with 0 in them, to save Mongo DB space
                }
                else
                {
                    // LF wants single-string fields in the format { "ws": { "value": "contents" } }
                    fieldValue = LfMultiText.FromSingleStringMapping(
                        MagicStrings.LanguageCodeForIntFields, fieldValue.AsInt32.ToString()).AsBsonDocument();
                }
                break;

            case CellarPropertyType.OwningAtomic:
            case CellarPropertyType.ReferenceAtomic:
                int ownedHvo = data.get_ObjectProp(hvo, flid);
                fieldValue = GetCustomReferencedObject(ownedHvo, flid, listConverters, ref dataGuids);
                if (fieldValue != null && LcmFieldType == CellarPropertyType.ReferenceAtomic)
                {
                    // Single CmPossiblity reference - LF expects format like { "value": "key of possibility" }
                    fieldValue = new BsonDocument("value", fieldValue);
                }
                fieldGuid = new BsonString(dataGuids.FirstOrDefault().ToString());
                break;

            case CellarPropertyType.MultiUnicode:
                ITsMultiString tss = data.get_MultiStringProp(hvo, flid);
                if (tss != null && tss.StringCount > 0)
                {
                    fieldValue = LfMultiText.FromMultiITsString(tss, servLoc.WritingSystemManager).AsBsonDocument();
                }
                break;

            case CellarPropertyType.OwningCollection:
            case CellarPropertyType.OwningSequence:
            case CellarPropertyType.ReferenceCollection:
            case CellarPropertyType.ReferenceSequence:
                int[] listHvos    = data.VecProp(hvo, flid);
                var   innerValues = new BsonArray(listHvos.Select(listHvo => GetCustomReferencedObject(listHvo, flid, listConverters, ref dataGuids)).Where(x => x != null));
                if (innerValues.Count == 0)
                {
                    fieldValue = null;
                }
                else
                {
                    fieldValue = new BsonDocument("values", innerValues);
                    fieldGuid  = new BsonArray(dataGuids.Select(guid => guid.ToString()));
                }
                break;

            case CellarPropertyType.String:
                ITsString iTsValue = data.get_StringProp(hvo, flid);
                if (iTsValue == null || String.IsNullOrEmpty(iTsValue.Text))
                {
                    fieldValue = null;
                }
                else
                {
                    fieldValue = LfMultiText.FromSingleITsString(iTsValue, servLoc.WritingSystemManager).AsBsonDocument();
                }
                break;

            default:
                fieldValue = null;
                if (logger != null)
                {
                    logger.Warning("Lcm CellarPropertyType.{0} not recognized for LF custom field", LcmFieldType.ToString());
                }
                break;
            }

            if (fieldValue == null)
            {
                return(null);
            }
            else
            {
                var result = new BsonDocument();
                result.Add("value", fieldValue ?? BsonNull.Value);                 // BsonValues aren't allowed to have C# nulls; they have their own null representation
                if (fieldGuid is BsonArray)
                {
                    result.Add("guid", fieldGuid, ((BsonArray)fieldGuid).Count > 0);
                }
                else
                {
                    result.Add("guid", fieldGuid, fieldGuid != null);
                }
                return(result);
            }
        }
Esempio n. 44
0
		public TransduceMethod(FdoCache cache, ISilDataAccessManaged sda, FieldReadWriter dstAccessor, XmlNode spec, FieldReadWriter srcAccessor,
			ECInterfaces.IEncConverter converter, ITsString tssSep, NonEmptyTargetOptions options)
			: base(cache, sda, dstAccessor, spec)
		{
			m_srcAccessor = srcAccessor;
			m_converter = converter;
			m_tssSep = tssSep;
			m_options = options;
		}
Esempio n. 45
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)
                {
                }
            }
        }
Esempio n. 46
0
		public DoItMethod(FdoCache cache, ISilDataAccessManaged sda, FieldReadWriter accessor, XmlNode spec)
		{
			m_cache = cache;
			m_accessor = accessor;
			m_sda = sda;
			m_nodeSpec = spec;

			m_sEditIf = XmlUtils.GetOptionalAttributeValue(spec, "editif");
			if (!String.IsNullOrEmpty(m_sEditIf))
			{
				if (m_sEditIf[0] == '!')
				{
					m_fEditIfNot = true;
					m_sEditIf = m_sEditIf.Substring(1);
				}
				string sWs = StringServices.GetWsSpecWithoutPrefix(spec);
				if (sWs != null)
					m_wsEditIf = XmlViewsUtils.GetWsFromString(sWs, m_cache);
			}
		}
Esempio n. 47
0
 /// <summary>
 /// Simpler constructor supplies default args
 /// </summary>
 internal XMLViewsDataCache(ISilDataAccessManaged domainDataByFlid, XmlNode nodeSpec)
     : this(domainDataByFlid, XmlUtils.GetOptionalBooleanAttributeValue(nodeSpec, "defaultChecked", true),
            new Dictionary <int, int>())
 {
 }
Esempio n. 48
0
			public GhostDaDecorator(ISilDataAccessManaged domainDataByFlid, ITsString tss, int clidDst)
				: base(domainDataByFlid)
			{
				m_tss = tss;
				m_clidDst = clidDst;
				SetOverrideMdc(new GhostMdc(MetaDataCache as IFwMetaDataCacheManaged));
			}
Esempio n. 49
0
		public ClearMethod(FdoCache cache, ISilDataAccessManaged sda, FieldReadWriter accessor, XmlNode spec)
			: base(cache, sda, accessor, spec)
		{
			ITsStrFactory tsf = TsStrFactoryClass.Create();
			m_newValue = tsf.MakeString("", accessor.WritingSystem);
		}
Esempio n. 50
0
 public PhonologicalFeaturePublisher(ISilDataAccessManaged domainDataByFlid)
     : base(domainDataByFlid, ListFlid)
 {
     m_objProps = new Dictionary <int, int>();
     SetOverrideMdc(new PhonologicalFeatureMdc(MetaDataCache as IFwMetaDataCacheManaged));
 }
Esempio n. 51
0
		public BulkCopyMethod(FdoCache cache, ISilDataAccessManaged sda, FieldReadWriter dstAccessor,
			XmlNode spec, FieldReadWriter srcAccessor, ITsString tssSep, NonEmptyTargetOptions options)
			: base(cache, sda, dstAccessor, spec)
		{
			m_srcAccessor = srcAccessor;
			m_tssSep = tssSep;
			m_options = options;
		}
		public MockPublisher(ISilDataAccessManaged domainDataByFlid, int flid) : base(domainDataByFlid, flid)
		{
		}
Esempio n. 53
0
		public ReplaceWithMethod(FdoCache cache, ISilDataAccessManaged sda, FieldReadWriter accessor, XmlNode spec, IVwPattern pattern, ITsString replacement)
			: base(cache, sda, accessor, spec)
		{
			m_pattern = pattern;
			m_replacement = replacement;
			m_pattern.ReplaceWith = m_replacement;
			m_textSourceInit = VwStringTextSourceClass.Create();
			m_ts = m_textSourceInit as IVwTextSource;
		}
Esempio n. 54
0
		public override void FixtureTeardown()
		{
			m_sda = null;
			m_possListFactory = null;

			base.FixtureTeardown();
		}
Esempio n. 55
0
		public RespellingSda(ISilDataAccessManaged domainDataByFlid, XmlNode configurationNode,
			IFdoServiceLocator services)
			: base(domainDataByFlid, configurationNode, services)
		{
			SetOverrideMdc(new RespellingMdc(MetaDataCache as IFwMetaDataCacheManaged));
		}
Esempio n. 56
0
		public DeleteCustomList(FdoCache cache)
		{
			m_cache = cache;
			m_ddbf = (ISilDataAccessManaged)m_cache.DomainDataByFlid;
		}
		public FakeDecorator(ISilDataAccessManaged domainDataByFlid) : base(domainDataByFlid)
		{
			m_mdc = new FakeMdc((IFwMetaDataCacheManaged)domainDataByFlid.MetaDataCache);
		}
 public FakeDecorator(ISilDataAccessManaged domainDataByFlid) : base(domainDataByFlid)
 {
     m_mdc = new FakeMdc((IFwMetaDataCacheManaged)domainDataByFlid.MetaDataCache);
 }
 public DeleteCustomList(FdoCache cache)
 {
     m_cache = cache;
     m_ddbf  = (ISilDataAccessManaged)m_cache.DomainDataByFlid;
 }
Esempio n. 60
0
 protected virtual BrowseViewer CreateBrowseViewer(XmlNode nodeSpec, int hvoRoot, int fakeFlid, LcmCache cache,
                                                   Mediator mediator, PropertyTable propertyTable,
                                                   ISortItemProvider sortItemProvider, ISilDataAccessManaged sda)
 {
     return(new BrowseViewer(nodeSpec,
                             hvoRoot, fakeFlid,
                             cache, mediator, propertyTable, sortItemProvider, sda));
 }