protected virtual void MakeRootInternal() { // Setting this result too low can result in moving a cursor from an editable field // to a non-editable field (e.g. with Control-Right and Control-Left cursor // commands). Normally we could set this to only a few (e.g. 4). but in // Interlinearizer we may want to jump from one sentence annotation to the next over // several read-only paragraphs contained in a word bundle. Make sure that // procedures that use this limit do not move the cursor from an editable to a // non-editable field. m_rootb.MaxParasToScan = 2000; EnsureVc(); // We want to get notified when anything changes. m_sda = m_cache.MainCacheAccessor; m_sda.AddNotification(this); m_vc.ShowMorphBundles = m_propertyTable.GetBoolProperty("ShowMorphBundles", true); m_vc.LineChoices = LineChoices; m_vc.ShowDefaultSense = true; m_rootb.DataAccess = m_cache.MainCacheAccessor; m_rootb.SetRootObject(m_hvoRoot, m_vc, InterlinVc.kfragStText, m_styleSheet); m_objRepo = m_cache.ServiceLocator.GetInstance <ICmObjectRepository>(); }
/// <summary>Constructor.</summary> public SingleLexReference(ICmObject lexRef, int hvoCrossRef) { m_lexRef = lexRef as ILexReference; m_hvoCrossRef = hvoCrossRef; m_cache = lexRef.Cache; m_cmObjectRepository = m_cache.ServiceLocator.GetInstance <ICmObjectRepository>(); }
protected InterlinearExporter(FdoCache cache, XmlWriter writer, ICmObject objRoot, InterlinLineChoices lineChoices, InterlinVc vc) : base(null, cache.MainCacheAccessor, objRoot.Hvo) { m_cache = cache; m_writer = writer; m_flidStTextTitle = m_cache.MetaDataCacheAccessor.GetFieldId("StText", "Title", false); m_flidStTextSource = m_cache.MetaDataCacheAccessor.GetFieldId("StText", "Source", false); m_vc = vc; SetTextTitleAndMetadata(objRoot as IStText); // Get morphtype information that we need later. (plus stuff we don't...) See LT-8288. IMoMorphType mmtStem; IMoMorphType mmtPrefix; IMoMorphType mmtSuffix; IMoMorphType mmtInfix; IMoMorphType mmtBoundStem; IMoMorphType mmtSimulfix; IMoMorphType mmtSuprafix; m_cache.ServiceLocator.GetInstance <IMoMorphTypeRepository>().GetMajorMorphTypes( out mmtStem, out mmtPrefix, out mmtSuffix, out mmtInfix, out mmtBoundStem, out m_mmtProclitic, out m_mmtEnclitic, out mmtSimulfix, out mmtSuprafix); m_wsManager = m_cache.ServiceLocator.WritingSystemManager; m_repoObj = m_cache.ServiceLocator.GetInstance <ICmObjectRepository>(); }
/// <summary> /// Executes in two distinct scenarios. /// /// 1. If disposing is true, the method has been called directly /// or indirectly by a user's code via the Dispose method. /// Both managed and unmanaged resources can be disposed. /// /// 2. If disposing is false, the method has been called by the /// runtime from inside the finalizer and you should not reference (access) /// other managed objects, as they already have been garbage collected. /// Only unmanaged resources can be disposed. /// </summary> /// <param name="disposing"></param> /// <remarks> /// If any exceptions are thrown, that is fine. /// If the method is being done in a finalizer, it will be ignored. /// If it is thrown by client code calling Dispose, /// it needs to be handled by fixing the bug. /// /// If subclasses override this method, they should call the base implementation. /// </remarks> protected virtual void Dispose(bool disposing) { System.Diagnostics.Debug.WriteLineIf(!disposing, "****** Missing Dispose() call for " + GetType().Name + ". ****** "); // Must not be run more than once. if (m_isDisposed) { return; } if (disposing) { // Dispose managed resources here. if (m_FdoToSda != null) { m_FdoToSda.Clear(); } if (m_SdaToFdo != null) { m_SdaToFdo.Clear(); } } // Dispose unmanaged resources here, whether disposing is true or false. Marshal.ReleaseComObject(m_sda); m_sda = null; m_cache = null; m_FdoToSda = null; m_SdaToFdo = null; m_coRepository = null; m_isDisposed = true; }
/// <summary> /// Write a collection of IManyOneSortItems in a form that can be reconstituted by ReadItems. /// </summary> public static void WriteItems(ArrayList items, StreamWriter output, ICmObjectRepository repo) { foreach (IManyOnePathSortItem item in items) { output.WriteLine(item.PersistData(repo)); } output.Flush(); }
/// <summary> /// Build a collection of IManyOneSortItems from data written by WriteItems. /// </summary> public static ArrayList ReadItems(StreamReader input, ICmObjectRepository repo, out string versionStamp) { versionStamp = null; // default. try { if (!input.EndOfStream && input.Peek() == '<') { // Get a version stamp and check it out. var line = input.ReadLine(); if (!line.StartsWith("<version>") || !line.EndsWith("</version>")) { return(null); // cache is no good at all! } versionStamp = line.Substring("<version>".Length, line.Length - "<version></version>".Length); } var result = new ArrayList(); while (!input.EndOfStream) { result.Add(new LazyManyOnePathSortItem(input.ReadLine(), repo)); } return(result); } // If we find a guid we don't recognize as a valid object, the actual data is somehow // not consistent with what we saved, so discard the saved information. catch (InvalidObjectGuidException) { return(null); } // Likewise, if anything goes wrong with reading the file, we'll just rebuild the index. catch (IOException) { return(null); } // Also if the file has been corrupted somehow with invalid Base64 data, we'll rebuild // the index. See FWR-1110. catch (FormatException) { return(null); } // This occurs if an input line has an even number of chunks (semi-colon-separated). LT-11240. // This again indicates the file is corrupt and we will just rebuild the index. catch (IndexOutOfRangeException) { return(null); } // If the string representing a GUID that we read from the file doesn't produce // a byte array exactly 8 bytes long, we get this (FWR-2890). Similar to FormatException, // if the file is corrupt we'll just rebuild the index. // Review JohnT: is this a case where we should just catch all exceptions? But then // if someone introduces a defect the program may just slow down without our ever // realizing why. catch (ArgumentException) { return(null); } }
private ICmObjectOrId ParseGuidRep(ICmObjectRepository repo, string chunk) { var result = repo.GetObjectOrIdWithHvoFromGuid(new Guid(Convert.FromBase64String(chunk))); if (result == null) { throw new InvalidObjectGuidException(); } return(result); }
/// <summary> /// Constructor /// </summary> internal LoadingServices(IDataSetup dataSetup, ICmObjectIdFactory objIdFactory, IFwMetaDataCacheManaged mdcManaged, ILgWritingSystemFactory wsf, IUnitOfWorkService uowService, ICmObjectSurrogateRepository surrRepository, ICmObjectRepository cmObjRepository) { m_dataSetup = dataSetup; m_objIdFactory = objIdFactory; m_mdcManaged = mdcManaged; m_wsf = wsf; m_uowService = uowService; m_surrRepository = surrRepository; m_cmObjRepository = cmObjRepository; }
internal string LinkRef(int hvo) { ICmObjectRepository repo = m_cache.ServiceLocator.GetInstance <ICmObjectRepository>(); if (!repo.IsValidObjectId(hvo)) { return(null); } Guid guid = repo.GetObject(hvo).Guid; FwLinkArgs link = new FwLinkArgs("lexiconEdit", guid); return(link.ToString()); }
/// <summary> /// The method object's constructor. /// </summary> /// <param name="vc">The view constructor</param> /// <param name="vwenv">The view environment</param> /// <param name="hvo">A handle on the root object</param> /// <param name="flid">The field ID</param> /// <param name="frag">A code identifying the current part of the display</param> public XmlVcDisplayVec(XmlVc vc, IVwEnv vwenv, int hvo, int flid, int frag) { m_viewConstructor = vc; m_vwEnv = vwenv; m_hvo = hvo; m_flid = flid; m_frag = frag; m_cache = m_viewConstructor.Cache; m_sda = m_viewConstructor.DataAccess; if (vwenv.DataAccess != null) m_sda = vwenv.DataAccess; m_objRepo = m_cache.ServiceLocator.GetInstance<ICmObjectRepository>(); m_stringTable = m_viewConstructor.StringTbl; }
/// <summary> /// Write a collection of IManyOneSortItems in a form that can be reconstituted by ReadItems. /// </summary> public static void WriteItems(ArrayList items, StreamWriter output, ICmObjectRepository repo, string versionStamp) { // Make an XML-like header if we include a version stamp. The rest of the file is not XML-ish, but let's start // identifying the header information clearly, in case we have reason to add any more types. if (versionStamp != null) { output.WriteLine("<version>" + versionStamp + "</version>"); } foreach (IManyOnePathSortItem item in items) { output.WriteLine(item.PersistData(repo)); } output.Flush(); }
/// <summary> /// The method object's constructor. /// </summary> /// <param name="vc">The view constructor</param> /// <param name="vwenv">The view environment</param> /// <param name="hvo">A handle on the root object</param> /// <param name="flid">The field ID</param> /// <param name="frag">A code identifying the current part of the display</param> public XmlVcDisplayVec(XmlVc vc, IVwEnv vwenv, int hvo, int flid, int frag) { m_viewConstructor = vc; m_vwEnv = vwenv; m_hvo = hvo; m_flid = flid; m_frag = frag; m_cache = m_viewConstructor.Cache; m_sda = m_viewConstructor.DataAccess; if (vwenv.DataAccess != null) { m_sda = vwenv.DataAccess; } m_objRepo = m_cache.ServiceLocator.GetInstance <ICmObjectRepository>(); }
/// <summary> /// Determine whether this UOW can safely Redo. /// Higher-level methods are responsible for determining whether this UOW conflicts with /// those in other stacks. This method is mainly focused on whether referential integrity will be broken. /// </summary> /// <returns></returns> internal bool CanRedo(ICmObjectRepository objRepo) { var newGuids = new HashSet <Guid>(from id in m_newObjects select id.Guid); foreach (var item in m_changes) { if (!item.IsRedoable) { return(false); } var change = item as FdoStateChangeBase; if (change == null) { continue; // assume other changes are redoable if they think they are } if (change.CreatesProblemReferenceOnRedo(objRepo, newGuids)) { return(false); } } // Now verify that none of the objects which this action deletes will leave a dangling // reference if deleted (except references which the action already deletes itself). // (We don't need to check objects created by this UOW; they won't get re-created by undoing it.) if (m_deletedObjects.Count == 0) { return(true); } var delObjects = new HashSet <ICmObject>( from obj in m_deletedObjects where !newGuids.Contains(obj.Guid) select objRepo.GetObject(obj)); int externalIncomingRefs = delObjects.Sum(obj => ((ICmObjectInternal)obj).IncomingRefsNotFrom(delObjects)); if (externalIncomingRefs == 0) { return(true); } // OK, there are potential problem references after we redo the change...will redoing it fix them? var oldGuids = new HashSet <Guid>(from obj in m_deletedObjects select obj.Guid); foreach (var item in m_changes) { var change = item as FdoStateChangeBase; if (change != null) { externalIncomingRefs -= change.CountDeletedRefsToOnRedo(oldGuids); } } return(externalIncomingRefs == 0); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Creates a new owned object /// </summary> /// <typeparam name="TObj">The type of object</typeparam> /// <param name="srcRepository">The repository that holds the object.</param> /// <param name="srcObj">The object (used to create a new object of the same type).</param> /// <returns>The created object</returns> /// ------------------------------------------------------------------------------------ private TObj CreateOwnedObj <TObj>(ICmObjectRepository srcRepository, TObj srcObj) where TObj : ICmObject { if (srcObj.Owner == null) { throw new ArgumentException("Can't create Owned Copy of unowned original!", "srcObj"); } int owningFlidType = m_mdc.GetFieldType(srcObj.OwningFlid); // Determine appropriate owner of copy // If source's owner has also been copied, we want to add this copy to the copy! // If a delegate has not been set, use the source's owner as the copy's owner. ICmObject copied; if (!m_sourceToCopyMap.TryGetValue(srcObj.Owner.Hvo, out copied)) { copied = (m_topLevelOwnerFunct == kAddToSourceOwner) ? srcObj.Owner : null; } Debug.Assert(copied != null, "Non top-level objects should have their owner already copied"); int ord; switch (owningFlidType) { case (int)CellarPropertyType.OwningAtomic: ord = -2; break; case (int)CellarPropertyType.OwningCollection: ord = -1; break; case (int)CellarPropertyType.OwningSequence: // put copy at end of sequence until told otherwise ord = m_sda.get_VecSize(copied.Hvo, srcObj.OwningFlid); break; default: throw new NotImplementedException("Unsupported owningFlidType."); } int newHvo = m_sda.MakeNewObject(srcObj.ClassID, copied.Hvo, srcObj.OwningFlid, ord); return((TObj)srcRepository.GetObject(newHvo)); }
/// A representation that can be used to create an equivalent LazyManyOnePathSortItem later. /// Keep consistent with the ManyOnePathSortItem PersistData (and our constructor). /// </summary> public string PersistData(ICmObjectRepository repo) { StringBuilder builder = new StringBuilder(); builder.Append(PersistGuid(m_item)); if (PathLength > 0) { for (int i = 0; i < m_pathObjects.Length; i++) { builder.Append(";"); builder.Append(m_pathFlids[i]); builder.Append(";"); builder.Append(PersistGuid(m_pathObjects[i])); } } return(builder.ToString()); }
public LazyManyOnePathSortItem(string persistInfo, ICmObjectRepository repo) { m_repo = repo; var chunks = persistInfo.Split(';'); m_item = ParseGuidRep(repo, chunks[0]); if (chunks.Length > 1) { var pathLen = chunks.Length / 2; m_pathObjects = new ICmObjectOrId[pathLen]; m_pathFlids = new int[pathLen]; for (int i = 0; i < pathLen; i++) { m_pathFlids[i] = int.Parse(chunks[i * 2 + 1]); m_pathObjects[i] = ParseGuidRep(repo, chunks[i * 2 + 2]); } } }
/// <summary> /// Constructor. Called by service locator factory (by reflection). /// </summary> /// <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> internal DomainDataByFlid(ICmObjectRepository cmObjectRepository, IStTextRepository stTxtRepository, IFwMetaDataCacheManaged mdc, ISilDataAccessHelperInternal uowService, ITsStrFactory tsf, ILgWritingSystemFactory wsf) { if (cmObjectRepository == null) throw new ArgumentNullException("cmObjectRepository"); if (stTxtRepository == null) throw new ArgumentNullException("stTxtRepository"); if (mdc == null) throw new ArgumentNullException("mdc"); if (uowService == null) throw new ArgumentNullException("uowService"); if (tsf == null) throw new ArgumentNullException("tsf"); if (wsf == null) throw new ArgumentNullException("wsf"); m_cmObjectRepository = cmObjectRepository; m_stTxtRepository = stTxtRepository; m_mdc = mdc; m_uowService = uowService; m_tsf = tsf; m_wsf = wsf; }
private void DisplayCurrentRoot() { if (m_currentRoot > 0) { m_xrev.DatTree.Visible = true; ICmObjectRepository repo = m_cache.ServiceLocator.GetInstance <ICmObjectRepository>(); ICmObject root; // JohnT: I don't know why this is done at all. Therefore I made a minimal change rather than removing it // altogether. If someone knows why it sometimes needs doing, please comment. Or if you know why it once did // and it no longer applies, please remove it. I added the test that the Clerk is not aleady looking // at this object to suppress switching back to the raw text pane when clicking on the Info pane of an empty text. // (FWR-3180) if (repo.TryGetObject(m_currentRoot, out root) && root is IStText && m_xrev.Clerk.CurrentObjectHvo != m_currentRoot) { m_xrev.Clerk.JumpToRecord(m_currentRoot); } } else if (m_currentRoot == 0) { m_xrev.DatTree.Visible = false; } }
/// <summary> /// Determine whether this UOW can safely Undo. /// Higher-level methods are responsible for determining whether this UOW conflicts with /// those in other stacks. This method is mainly focused on whether referential integrity will be broken. /// </summary> internal bool CanUndo(ICmObjectRepository objRepo) { var deletedGuids = new HashSet <Guid>(from obj in m_deletedObjects select obj.Guid); if (m_changes.OfType <FdoStateChangeBase>().Any(change => change.CreatesProblemReferenceOnUndo(objRepo, deletedGuids))) { return(false); } // Now verify that none of the new objects which this action creates will leave a dangling // reference if deleted. if (m_newObjects.Count == 0) { return(true); } // If any of the new objects is has already been deleted, we don't have to worry about leaving refs to it! var newObjects = new HashSet <ICmObject>(from id in m_newObjects where objRepo.IsValidObjectId(id.Guid) select objRepo.GetObject(id)); int externalIncomingRefs = newObjects.Sum(obj => ((ICmObjectInternal)obj).IncomingRefsNotFrom(newObjects)); if (externalIncomingRefs == 0) { return(true); } // OK, there are problem references AFTER the change...will undoing it fix them? var newGuids = new HashSet <Guid>(from id in m_newObjects select id.Guid); foreach (var item in m_changes) { var change = item as FdoStateChangeBase; if (change != null) { externalIncomingRefs -= change.CountDeletedRefsToOnUndo(newGuids); } } return(externalIncomingRefs == 0); }
public LazyManyOnePathSortItem(string persistInfo, ICmObjectRepository repo) { m_repo = repo; var chunks = persistInfo.Split(';'); m_item = ParseGuidRep(repo, chunks[0]); if (chunks.Length > 1) { var pathLen = chunks.Length/2; m_pathObjects = new ICmObjectOrId[pathLen]; m_pathFlids = new int[pathLen]; for (int i = 0; i < pathLen; i++) { m_pathFlids[i] = int.Parse(chunks[i*2 + 1]); m_pathObjects[i] = ParseGuidRep(repo, chunks[i * 2 + 2]); } } }
public ICmObject GetObject(ICmObjectRepository repo) { throw new NotImplementedException(); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initializes a new instance of the <see cref="TeEditingHelper"/> class. /// </summary> /// <param name="callbacks">The callbacks.</param> /// <param name="cache">The cache.</param> /// <param name="filterInstance">The filter instance.</param> /// <param name="viewType">Type of the view.</param> /// <param name="app">The app.</param> /// ------------------------------------------------------------------------------------ public TeEditingHelper(IEditingCallbacks callbacks, FdoCache cache, int filterInstance, TeViewType viewType, IApp app) : base(cache, callbacks) { if (m_cache == null) throw new ArgumentNullException("cache"); m_scr = m_cache.LangProject.TranslatedScriptureOA; m_app = app; IFdoServiceLocator servloc = m_cache.ServiceLocator; m_repoStText = servloc.GetInstance<IStTextRepository>(); m_repoScrTxtPara = servloc.GetInstance<IScrTxtParaRepository>(); m_repoScrBook = servloc.GetInstance<IScrBookRepository>(); m_repoScrSection = servloc.GetInstance<IScrSectionRepository>(); m_repoScrFootnote = servloc.GetInstance<IScrFootnoteRepository>(); m_repoCmTrans = servloc.GetInstance<ICmTranslationRepository>(); m_wsContainer = servloc.WritingSystems; m_repoCmObject = servloc.GetInstance<ICmObjectRepository>(); m_repoSegment = servloc.GetInstance<ISegmentRepository>(); m_viewType = viewType; m_filterInstance = filterInstance; PasteFixTssEvent += RemoveHardFormatting; }
protected virtual void MakeRootInternal() { m_rootb = VwRootBoxClass.Create(); m_rootb.SetSite(this); // Setting this result too low can result in moving a cursor from an editable field // to a non-editable field (e.g. with Control-Right and Control-Left cursor // commands). Normally we could set this to only a few (e.g. 4). but in // Interlinearizer we may want to jump from one sentence annotation to the next over // several read-only paragraphs contained in a word bundle. Make sure that // procedures that use this limit do not move the cursor from an editable to a // non-editable field. m_rootb.MaxParasToScan = 2000; EnsureVc(); // We want to get notified when anything changes. m_sda = m_fdoCache.MainCacheAccessor; m_sda.AddNotification(this); m_vc.ShowMorphBundles = m_mediator.PropertyTable.GetBoolProperty("ShowMorphBundles", true); m_vc.LineChoices = LineChoices; m_vc.ShowDefaultSense = true; m_rootb.DataAccess = m_fdoCache.MainCacheAccessor; m_rootb.SetRootObject(m_hvoRoot, m_vc, InterlinVc.kfragStText, m_styleSheet); m_objRepo = m_fdoCache.ServiceLocator.GetInstance<ICmObjectRepository>(); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initializes a new instance of the <see cref="InterlinVc"/> class. /// </summary> /// <remarks>We use the default analysis writing system as the default, even though /// this view displays data in multiple writing systems. It's pretty arbitrary in this /// case, but we need a valid WS because if we get an ORC, we have to create a Ts String /// using some writing system.</remarks> /// <param name="cache">The cache.</param> /// ------------------------------------------------------------------------------------ public InterlinVc(FdoCache cache) : base(cache.DefaultAnalWs) { Cache = cache; m_wsManager = m_cache.ServiceLocator.WritingSystemManager; m_segRepository = m_cache.ServiceLocator.GetInstance<ISegmentRepository>(); m_coRepository = m_cache.ServiceLocator.GetInstance<ICmObjectRepository>(); m_wmbRepository = m_cache.ServiceLocator.GetInstance<IWfiMorphBundleRepository>(); m_analRepository = m_cache.ServiceLocator.GetInstance<IWfiAnalysisRepository>(); StTxtParaRepository = m_cache.ServiceLocator.GetInstance<IStTxtParaRepository>(); m_wsAnalysis = cache.DefaultAnalWs; m_wsUi = cache.LanguageWritingSystemFactoryAccessor.UserWs; Decorator = new InterlinViewDataCache(m_cache); PreferredVernWs = cache.DefaultVernWs; m_selfFlid = m_cache.MetaDataCacheAccessor.GetFieldId2(CmObjectTags.kClassId, "Self", false); m_tssMissingGloss = m_tsf.MakeString(ITextStrings.ksStars, m_wsAnalysis); m_tssMissingGlossPrepend = m_tsf.MakeString(ITextStrings.ksStars + MorphServices.kDefaultSeparatorLexEntryInflTypeGlossAffix, m_wsAnalysis); m_tssMissingGlossAppend = m_tsf.MakeString(MorphServices.kDefaultSeparatorLexEntryInflTypeGlossAffix + ITextStrings.ksStars, m_wsAnalysis); m_tssMissingSense = m_tssMissingGloss; m_tssMissingMsa = m_tssMissingGloss; m_tssMissingAnalysisPos = m_tssMissingGloss; m_tssEmptyAnalysis = m_tsf.MakeString("", m_wsAnalysis); m_WsList = new WsListManager(m_cache); m_tssEmptyPara = m_tsf.MakeString(ITextStrings.ksEmptyPara, m_wsAnalysis); m_tssSpace = m_tsf.MakeString(" ", m_wsAnalysis); m_msaVc = new MoMorphSynAnalysisUi.MsaVc(m_cache); m_vernWss = WritingSystemServices.GetAllWritingSystems(m_cache, "all vernacular", null, 0, 0); // This usually gets overridden, but ensures default behavior if not. m_lineChoices = InterlinLineChoices.DefaultChoices(m_cache.LangProject, WritingSystemServices.kwsVernInParagraph, WritingSystemServices.kwsAnal); // This used to be a constant but was made variables with dummy virtual handlers so that // ClearInfoAbout can clear them out. // load guesses ktagSegmentForms = SegmentTags.kflidAnalyses; GetSegmentLevelTags(cache); LangProjectHvo = m_cache.LangProject.Hvo; }
public bool OkToMove(int hvoDstOwner, int flidDst, int ihvoDstStart, ObjectDragInfo odi) { CheckDisposed(); FDO.FdoCache cache = Slice.ContainingDataTree.Cache; ICmObjectRepository repo = cache.ServiceLocator.GetInstance <ICmObjectRepository>(); if (flidDst == odi.FlidSrc) { // Verify that it is not a no-operation. if (hvoDstOwner == odi.HvoSrcOwner) { // Same property of same object. If it's a collection, disable. CellarPropertyType fieldType = (CellarPropertyType)cache.DomainDataByFlid.MetaDataCache.GetFieldType((int)flidDst); // We can't drag it to the position it's already at; that's no change. We also can't drag it // to the position one greater: that amounts to trying to place it after itself, which (after // removing it from before itself) amounts to a no-operation. if (fieldType == CellarPropertyType.OwningSequence && ihvoDstStart != odi.IhvoSrcStart && ihvoDstStart != odi.IhvoSrcStart + 1) { // It's a sequence and the target and source positions are different, so we can do it. return(true); } } else { // Different objects; need to verify no circular ownership involved. for (int ihvo = odi.IhvoSrcStart; ihvo <= odi.IhvoSrcEnd; ihvo++) { int hvo = cache.DomainDataByFlid.get_VecItem(odi.HvoSrcOwner, odi.FlidSrc, ihvo); // See if hvoDstOwner is owned by hvo ICmObject obj2 = repo.GetObject(hvoDstOwner); // loop from hvo2 to root owner of hvo2. If hvo2 or any of its owners is hvo, // we have a problem. while (obj2 != null) { if (hvo == obj2.Hvo) { return(false); // circular ownership, can't drop. } obj2 = obj2.Owner; } } return(true); } } else { // Different property, check signature. IFwMetaDataCache mdc = cache.DomainDataByFlid.MetaDataCache; int luclid = mdc.GetDstClsId((int)flidDst); for (int ihvo = odi.IhvoSrcStart; ihvo <= odi.IhvoSrcEnd; ihvo++) { int hvo = cache.DomainDataByFlid.get_VecItem(odi.HvoSrcOwner, odi.FlidSrc, ihvo); int cls = repo.GetObject(hvo).ClassID; while (cls != 0 && cls != luclid) { cls = mdc.GetBaseClsId(cls); } if (cls == 0) { return(false); // wrong signature, can't drop. } } // All sigs OK, allow drop. return(true); } // If none of those cases is OK, can't do it. return(false); }
/// <summary> /// Write a collection of IManyOneSortItems in a form that can be reconstituted by ReadItems. /// </summary> public static void WriteItems(ArrayList items, StreamWriter output, ICmObjectRepository repo, string versionStamp) { // Make an XML-like header if we include a version stamp. The rest of the file is not XML-ish, but let's start // identifying the header information clearly, in case we have reason to add any more types. if (versionStamp != null) output.WriteLine("<version>" + versionStamp + "</version>"); foreach (IManyOnePathSortItem item in items) output.WriteLine(item.PersistData(repo)); output.Flush(); }
public ICmObject GetObject(ICmObjectRepository repo) { return(repo.GetObject(this)); }
protected InterlinearExporter(FdoCache cache, XmlWriter writer, ICmObject objRoot, InterlinLineChoices lineChoices, InterlinVc vc) : base(null, cache.MainCacheAccessor, objRoot.Hvo) { m_cache = cache; m_writer = writer; m_flidStTextTitle = m_cache.MetaDataCacheAccessor.GetFieldId("StText", "Title", false); m_flidStTextSource = m_cache.MetaDataCacheAccessor.GetFieldId("StText", "Source", false); m_vc = vc; SetTextTitleAndMetadata(objRoot as IStText); // Get morphtype information that we need later. (plus stuff we don't...) See LT-8288. IMoMorphType mmtStem; IMoMorphType mmtPrefix; IMoMorphType mmtSuffix; IMoMorphType mmtInfix; IMoMorphType mmtBoundStem; IMoMorphType mmtSimulfix; IMoMorphType mmtSuprafix; m_cache.ServiceLocator.GetInstance<IMoMorphTypeRepository>().GetMajorMorphTypes( out mmtStem, out mmtPrefix, out mmtSuffix, out mmtInfix, out mmtBoundStem, out m_mmtProclitic, out m_mmtEnclitic, out mmtSimulfix, out mmtSuprafix); m_wsManager = m_cache.ServiceLocator.WritingSystemManager; m_repoObj = m_cache.ServiceLocator.GetInstance<ICmObjectRepository>(); }
/// ----------------------------------------------------------------------------------- /// <summary> /// Initializes a new instance of the <see cref="XDumper"/> class. /// </summary> /// ----------------------------------------------------------------------------------- public XDumper(FdoCache cache) { m_cache = cache; m_mdc = m_cache.ServiceLocator.GetInstance<IFwMetaDataCacheManaged>(); m_cmObjectRepository = m_cache.ServiceLocator.GetInstance<ICmObjectRepository>(); m_wsManager = m_cache.ServiceLocator.WritingSystemManager; m_wsContainer = m_cache.ServiceLocator.WritingSystems; }
private ICmObjectOrId ParseGuidRep(ICmObjectRepository repo, string chunk) { var result = repo.GetObjectOrIdWithHvoFromGuid(new Guid(Convert.FromBase64String(chunk))); if (result == null) throw new InvalidObjectGuidException(); return result; }
/// <summary> /// Build a collection of IManyOneSortItems from data written by WriteItems. /// </summary> public static ArrayList ReadItems(StreamReader input, ICmObjectRepository repo, out string versionStamp) { versionStamp = null; // default. try { if (!input.EndOfStream && input.Peek() == '<') { // Get a version stamp and check it out. var line = input.ReadLine(); if (!line.StartsWith("<version>") || !line.EndsWith("</version>")) return null; // cache is no good at all! versionStamp = line.Substring("<version>".Length, line.Length - "<version></version>".Length); } var result = new ArrayList(); while (!input.EndOfStream) result.Add(new LazyManyOnePathSortItem(input.ReadLine(), repo)); return result; } // If we find a guid we don't recognize as a valid object, the actual data is somehow // not consistent with what we saved, so discard the saved information. catch (InvalidObjectGuidException) { return null; } // Likewise, if anything goes wrong with reading the file, we'll just rebuild the index. catch (IOException) { return null; } // Also if the file has been corrupted somehow with invalid Base64 data, we'll rebuild // the index. See FWR-1110. catch (FormatException) { return null; } // This occurs if an input line has an even number of chunks (semi-colon-separated). LT-11240. // This again indicates the file is corrupt and we will just rebuild the index. catch (IndexOutOfRangeException) { return null; } // If the string representing a GUID that we read from the file doesn't produce // a byte array exactly 8 bytes long, we get this (FWR-2890). Similar to FormatException, // if the file is corrupt we'll just rebuild the index. // Review JohnT: is this a case where we should just catch all exceptions? But then // if someone introduces a defect the program may just slow down without our ever // realizing why. catch(ArgumentException) { return null; } }
/// <summary> /// /// </summary> /// <param name="hvo"></param> /// <param name="tag"></param> /// <param name="ivMin"></param> /// <param name="cvIns"></param> /// <param name="cvDel"></param> public void PropChanged(int hvo, int tag, int ivMin, int cvIns, int cvDel) { if (tag == MainTag) { // something has changed in the list we're displaying. make sure // our checkboxes are up to date, before we process OnPaint if (Vc != null && Vc.HasSelectColumn) { // there can be a circular dependency between checked items in a browse viewer // and the record list managing that list. // The record list can depend upon BulkEdit settings for loading its list // (e.g. ListItemsClass), so the bulk edit bar must load before the RecordList. // But, the BrowseViewer and BulkEditBar (Delete tab) also needs to know when // RecordList has been loaded, so that they can manage checkbox behavior for // the actual items being displayed. if (m_bv != null) m_bv.UpdateCheckedItems(); } if (SelectedObject != m_hvoOldSel) { // The selected object has changed even though the index didn't, e.g., because we // changed the sorting of the list while leaving the selected index fixed. // We need to fire the notification saying it changed, anyway. // (But don't update m_hvoOldSelection; FireSelectionChanged must find the old one to register a change.) m_mediator.IdleQueue.Add(IdleQueuePriority.Medium, FireSelectionChanged); } } else if (RootBox != null && hvo > 0 && SelectedObject > 0) { // Check whether the changed object is either the selected object or owned // by the selected object. If so, do a fake PropChanged that causes the whole // row to be regenerated. This ensures updating of virtual properties of the // object in other columns (e.g., when user opinion of this object changes, // the count of approved analyses should change). // This might become unnecessary if we can find a better way to generate // PropChanged when virtuals change. // See FWR-661. if (m_repo == null) m_repo = this.Cache.ServiceLocator.GetInstance<ICmObjectRepository>(); ICmObject objSel; if (!m_repo.TryGetObject(SelectedObject, out objSel)) return; ICmObject obj; if (!m_repo.TryGetObject(hvo, out obj)) return; if (obj == objSel || obj.OwnerOfClass(objSel.ClassID) == objSel) { // Reconstruct the current row (by pretending to replace the object), // preserving the selection if any (otherwise, the selection disappears // after each letter typed in a browse view...FWR-690). m_mediator.IdleQueue.Add(IdleQueuePriority.Medium, UpdateSelectedRow); } } }
internal override void Init(Mediator mediator, XmlNode node) { base.Init(mediator, node); m_objRepo = m_cache.ServiceLocator.GetInstance<ICmObjectRepository>(); m_possRepo = m_cache.ServiceLocator.GetInstance<ICmPossibilityRepository>(); }
internal override void Init(Mediator mediator, PropertyTable propertyTable, XmlNode node) { base.Init(mediator, propertyTable, node); m_objRepo = m_cache.ServiceLocator.GetInstance <ICmObjectRepository>(); m_possRepo = m_cache.ServiceLocator.GetInstance <ICmPossibilityRepository>(); }
/// A representation that can be used to create an equivalent LazyManyOnePathSortItem later. /// Keep consistent with the ManyOnePathSortItem PersistData (and our constructor). /// </summary> public string PersistData(ICmObjectRepository repo) { StringBuilder builder = new StringBuilder(); builder.Append(PersistGuid(m_item)); if (PathLength > 0) { for (int i = 0; i < m_pathObjects.Length; i++) { builder.Append(";"); builder.Append(m_pathFlids[i]); builder.Append(";"); builder.Append(PersistGuid(m_pathObjects[i])); } } return builder.ToString(); }
public ICmObject GetObject(ICmObjectRepository repo) { return repo.GetObject(this); }
/// <summary> /// Constructor /// </summary> internal LoadingServices(IDataSetup dataSetup, ICmObjectIdFactory objIdFactory, IFwMetaDataCacheManaged mdcManaged, ILgWritingSystemFactory wsf, ITsStrFactory tsf, IUnitOfWorkService uowService, ICmObjectSurrogateRepository surrRepository, ICmObjectRepository cmObjRepository) { m_dataSetup = dataSetup; m_objIdFactory = objIdFactory; m_mdcManaged = mdcManaged; m_wsf = wsf; m_tsf = tsf; m_uowService = uowService; m_surrRepository = surrRepository; m_cmObjRepository = cmObjRepository; }