Example #1
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <remarks>
        /// This Constructor is used for lazy load cases.
        /// The stored XML string (from the data store) is used to instantiate m_object.
        /// </remarks>
        internal CmObjectSurrogate(LcmCache cache, ICmObjectId objId, string classname, byte[] xmlData)
        {
            if (cache == null)
            {
                throw new ArgumentNullException("cache");
            }
            if (objId == null)
            {
                throw new ArgumentNullException("objId");
            }
            if (xmlData == null)
            {
                throw new ArgumentNullException("xmlData");
            }
            if (string.IsNullOrEmpty(classname))
            {
                throw new ArgumentNullException("classname");
            }

            m_cache     = cache;
            m_object    = null;
            RawXmlBytes = xmlData;
            m_guid      = objId is CmObjectIdWithHvo ? objId
                                : ((IServiceLocatorInternal)cache.ServiceLocator).IdentityMap.CreateObjectIdWithHvo(objId.Guid);
            SetClassName(classname);
        }
Example #2
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <remarks>
        /// This Constructor is used for porting from one BEP to another.
        /// It's faster than getting all the stuff from the xml string.
        /// </remarks>
        internal CmObjectSurrogate(LcmCache cache, ICmObjectSurrogate sourceSurrogate)
        {
            if (cache == null)
            {
                throw new ArgumentNullException("cache");
            }
            if (sourceSurrogate == null)
            {
                throw new ArgumentNullException("sourceSurrogate");
            }

            var surr = (CmObjectSurrogate)sourceSurrogate;

            m_cache  = cache;
            m_object = null;
            if (surr.RawXmlBytes != null)
            {
                RawXmlBytes = surr.RawXmlBytes;
            }
            else
            {
                Xml = sourceSurrogate.XML;
            }
            ICmObjectId objId = surr.Id;

            m_guid = objId is CmObjectIdWithHvo ? objId
                                : ((IServiceLocatorInternal)cache.ServiceLocator).IdentityMap.CreateObjectIdWithHvo(objId.Guid);
            SetClassName(surr.m_classname);
        }
        /// <summary>
        /// Get the ICmObjectSurrogate with the given Guid.
        /// </summary>
        /// <param name="guid"></param>
        /// <returns>The ICmObjectSurrogate with the given Guid.</returns>
        /// <exception cref="KeyNotFoundException">If the guid is not in the map</exception>
        internal ICmObjectOrSurrogate GetObjectOrSurrogate(ICmObjectId guid)
        {
            var result = m_IdentityMap[guid];

            if (result is CmObjectId)
            {
                throw new KeyNotFoundException("Key " + guid.Guid + " not found in identity map (actually just an ID is present)");
            }
            return(result);
        }
        /// <summary>
        /// Get the ICmObject with the given Guid.
        /// </summary>
        /// <param name="guid"></param>
        /// <returns>The ICmObject with the given Guid, or null, if not in Identity Map.</returns>
        internal ICmObject GetObject(ICmObjectId guid)
        {
            // This will ensure all Object info is in this map,
            // if it has to reconstitute it, it will call RegisterSurrogate,
            // which will make sure it is in all the correct places in this map.
            ICmObjectOrSurrogate objOrSurr;

            lock (SyncRoot)
                objOrSurr = GetObjectOrSurrogate(guid);
            return(objOrSurr.Object);
        }
 /// <summary>
 /// If the identity map for this ID contains a CmObject, return it.
 /// </summary>
 internal ICmObject GetObjectIfFluffed(ICmObjectId id)
 {
     lock (SyncRoot)
     {
         ICmObjectOrSurrogate result;
         if (m_IdentityMap.TryGetValue(id, out result) && result is ICmObject)
         {
             return((ICmObject)result);
         }
     }
     return(null);
 }
Example #6
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <remarks>
        /// This Constructor is used for newly created CmObject cases.
        /// </remarks>
        internal CmObjectSurrogate(ICmObject obj)
        {
            if (obj == null)
            {
                throw new ArgumentNullException("obj");
            }

            m_guid   = obj.Id;
            m_object = obj;
            m_cache  = obj.Cache;
            if (m_cache == null)
            {
                throw new InvalidOperationException("'obj' has no LcmCache.");
            }
            SetClassName(obj.ClassName);
        }
 /// <summary>
 /// If we already know an HVO for this ID, answer it. Otherwise, assign a new one.
 /// Don't set up the association, because it will be established by assigning the HVO to
 /// a new (or restored) CmObject, and registering that.
 /// Assume we do NOT already have a CmObject for this ID; this method is reserved
 /// for use in the process of creating CmObjects.
 /// </summary>
 internal int GetOrAssignHvoFor(ICmObjectId id)
 {
     lock (SyncRoot)
     {
         ICmObjectOrSurrogate canonicalItem = m_IdentityMap[id];
         if (canonicalItem is CmObjectSurrogate)
         {
             ICmObjectId canonicalId = ((CmObjectSurrogate)canonicalItem).Id;
             if (canonicalId is CmObjectIdWithHvo)
             {
                 return(((CmObjectIdWithHvo)canonicalId).Hvo);
             }
         }
         Debug.Assert(!(canonicalItem is ICmObject));
         if (canonicalItem is CmObjectIdWithHvo)
         {
             return(((CmObjectIdWithHvo)canonicalItem).Hvo);
         }
         return(GetNextRealHvo());
     }
 }
Example #8
0
        /// <summary>
        /// Initialize from the data store (which uses byte arrays).
        /// </summary>
        internal void InitializeFromDataStore(LcmCache cache, ICmObjectId objId, string className, byte[] xmlData)
        {
            if (cache == null)
            {
                throw new ArgumentNullException("cache");
            }
            if (objId == null)
            {
                throw new ArgumentNullException("objId");
            }
            if (xmlData == null)
            {
                throw new ArgumentNullException("xmlData");
            }
            if (string.IsNullOrEmpty(className))
            {
                throw new ArgumentNullException("className");
            }

            lock (SyncRoot)
            {
                m_cache = cache;
                // Don't do this! If it's a new surrogate, the object is already null, and if not,
                // and we've already fluffed it, it's an invalid state for the object of the surrogate
                // to be null when it is fluffed.
                // m_object = null;
                // in fact, if we're re-creating a surrogate that got fluffed and garbage collected,
                // e.g., in Refreshing a surrogate to align it with another client,
                // we might be making a new object, yet the CmObject might already exist!
                m_object    = ((ICmObjectRepositoryInternal)m_cache.ServiceLocator.ObjectRepository).GetObjectIfFluffed(objId);
                RawXmlBytes = xmlData;
                m_guid      = objId is CmObjectIdWithHvo ? objId
                                        : ((IServiceLocatorInternal)cache.ServiceLocator).IdentityMap.CreateObjectIdWithHvo(objId.Guid);
                SetClassName(className);
            }
        }
Example #9
0
		/// <summary>
		/// Constructor.
		/// </summary>
		/// <remarks>
		/// This Constructor is used for porting from one BEP to another.
		/// It's faster than getting all the stuff from the xml string.
		/// </remarks>
		internal CmObjectSurrogate(FdoCache cache, ICmObjectSurrogate sourceSurrogate)
		{
			if (cache == null) throw new ArgumentNullException("cache");
			if (sourceSurrogate == null) throw new ArgumentNullException("sourceSurrogate");

			var surr = (CmObjectSurrogate) sourceSurrogate;
			m_cache = cache;
			m_object = null;
			if (surr.RawXmlBytes != null)
				RawXmlBytes = surr.RawXmlBytes;
			else
				Xml = sourceSurrogate.XML;
			ICmObjectId objId = surr.Id;
			m_guid = objId is CmObjectIdWithHvo ? objId
				: ((IServiceLocatorInternal)cache.ServiceLocator).IdentityMap.CreateObjectIdWithHvo(objId.Guid);
			SetClassName(surr.m_classname);
		}
Example #10
0
		/// <summary>
		/// Constructor.
		/// </summary>
		/// <remarks>
		/// This Constructor is used for newly created CmObject cases.
		/// </remarks>
		internal CmObjectSurrogate(ICmObject obj)
		{
			if (obj == null) throw new ArgumentNullException("obj");

			m_guid = obj.Id;
			m_object = obj;
			m_cache = obj.Cache;
			if (m_cache == null)
				throw new InvalidOperationException("'obj' has no FdoCache.");
			SetClassName(obj.ClassName);
		}
 public IText GetObject(ICmObjectId id)
 {
     throw new NotImplementedException();
 }
Example #12
0
 /// <summary>
 /// Get the object with the given id.
 /// </summary>
 /// <exception cref="KeyNotFoundException">Thrown if the object does not exist.</exception>
 public T GetObject(ICmObjectId id)
 {
     return((T)m_dataReader.GetObject(id));
 }
Example #13
0
		/// <summary>
		/// Create a surrogate from the data store.
		/// This gets the full XML string of the object from the BEP.
		/// </summary>
		public ICmObjectSurrogate Create(ICmObjectId objId, string classname, byte[] xmlData)
		{
			return new CmObjectSurrogate(m_cache, objId, classname, xmlData);
		}
Example #14
0
		/// <summary>
		/// Initialize from the data store (which uses byte arrays).
		/// </summary>
		internal void InitializeFromDataStore(FdoCache cache, ICmObjectId objId, string className, byte[] xmlData)
		{
			if (cache == null)
				throw new ArgumentNullException("cache");
			if (objId == null)
				throw new ArgumentNullException("objId");
			if (xmlData == null)
				throw new ArgumentNullException("xmlData");
			if (string.IsNullOrEmpty(className))
				throw new ArgumentNullException("className");

			lock (SyncRoot)
			{
				m_cache = cache;
				// Don't do this! If it's a new surrogate, the object is already null, and if not,
				// and we've already fluffed it, it's an invalid state for the object of the surrogate
				// to be null when it is fluffed.
				// m_object = null;
				// in fact, if we're re-creating a surrogate that got fluffed and garbage collected,
				// e.g., in Refreshing a surrogate to align it with another client,
				// we might be making a new object, yet the CmObject might already exist!
				m_object = ((ICmObjectRepositoryInternal) m_cache.ServiceLocator.ObjectRepository).GetObjectIfFluffed(objId);
				RawXmlBytes = xmlData;
				m_guid = objId is CmObjectIdWithHvo ? objId
					: ((IServiceLocatorInternal)cache.ServiceLocator).IdentityMap.CreateObjectIdWithHvo(objId.Guid);
				SetClassName(className);
			}
		}
Example #15
0
		/// <summary>
		/// Constructor.
		/// </summary>
		/// <remarks>
		/// This Constructor is used for lazy load cases.
		/// The stored XML string (from the data store) is used to instantiate m_object.
		/// </remarks>
		internal CmObjectSurrogate(FdoCache cache, ICmObjectId objId, string classname, byte[] xmlData)
		{
			if (cache == null) throw new ArgumentNullException("cache");
			if (objId == null) throw new ArgumentNullException("objId");
			if (xmlData == null) throw new ArgumentNullException("xmlData");
			if (string.IsNullOrEmpty(classname)) throw new ArgumentNullException("classname");

			m_cache = cache;
			m_object = null;
			RawXmlBytes = xmlData;
			m_guid = objId is CmObjectIdWithHvo ? objId
				: ((IServiceLocatorInternal)cache.ServiceLocator).IdentityMap.CreateObjectIdWithHvo(objId.Guid);
			SetClassName(classname);
		}
Example #16
0
 /// <summary>
 /// Create a surrogate from the data store.
 /// This gets the full XML string of the object from the BEP.
 /// </summary>
 public ICmObjectSurrogate Create(ICmObjectId objId, string classname, byte[] xmlData)
 {
     return(new CmObjectSurrogate(m_cache, objId, classname, xmlData));
 }
 public IdSurrogateWrapper(ICmObjectId id)
 {
     m_id = id;
 }
Example #18
0
 /// <summary>
 /// Get the specified object instance; short for getting ICmObjectRepository and asking it to GetObject.
 /// </summary>
 public ICmObject GetObject(ICmObjectId id)
 {
     return(GetInstance <ICmObjectRepository>().GetObject(id));
 }
Example #19
0
        public void ReconcileModifyingProperties()
        {
            var entry1 = MakeEntry("kick", "strike with foot");
            var sense1 = entry1.SensesOS[0];

            VerifyReconcilingAChange(
                () =>
            {
                SetString(sense1.Definition, Cache.DefaultAnalWs, "swing foot and make sharp contact with object");
                SetString(sense1.Definition, Cache.DefaultVernWs, "slam with nether appendage");
                SetString(sense1.Gloss, Cache.DefaultVernWs, "hit with foot");
            },
                "set multistring properties");
            VerifyReconcilingAChange(
                () => AddSense(entry1, "strike with boot"),
                "edit owing sequence");
            IText text = null;

            UndoableUnitOfWorkHelper.Do("undo make text", "redo make text", m_actionHandler,
                                        () =>
            {
                text = Cache.ServiceLocator.GetInstance <ITextFactory>().Create();
                //Cache.LangProject.TextsOC.Add(text);
            });
            IStText     stText = null;
            ICmObjectId id1    = null;

            VerifyReconcilingAChange(
                () =>
            {
                stText          = Cache.ServiceLocator.GetInstance <IStTextFactory>().Create();
                text.ContentsOA = stText;
                id1             = stText.Id;
            },
                "set owning atomic");
            stText = (IStText)Cache.ServiceLocator.GetObject(id1);
            ICmPossibility senseType = null;

            UndoableUnitOfWorkHelper.Do("undo make sense type", "redo make sense type", m_actionHandler,
                                        () =>
            {
                var senseTypesList = Cache.LangProject.LexDbOA.SenseTypesOA;
                if (senseTypesList == null)
                {
                    senseTypesList = Cache.ServiceLocator.GetInstance <ICmPossibilityListFactory>().Create();
                    Cache.LangProject.LexDbOA.SenseTypesOA = senseTypesList;
                }
                senseType = Cache.ServiceLocator.GetInstance <ICmPossibilityFactory>().Create();
                senseTypesList.PossibilitiesOS.Add(senseType);
            });
            VerifyReconcilingAChange(
                () => sense1.SenseTypeRA = senseType,
                "set ref atomic");
            ICmPossibilityList thesaurusItemsList = null;

            UndoableUnitOfWorkHelper.Do("undo make thes list", "redo make thes list", m_actionHandler,
                                        () =>
            {
                thesaurusItemsList = Cache.LangProject.ThesaurusRA;
                if (thesaurusItemsList == null)
                {
                    thesaurusItemsList            = Cache.ServiceLocator.GetInstance <ICmPossibilityListFactory>().Create();
                    Cache.LangProject.ThesaurusRA = thesaurusItemsList;
                }
            });
            ICmPossibility thesaurusItem1 = null;
            ICmPossibility thesaurusItem2 = null;
            ICmObjectId    id2            = null;

            VerifyReconcilingAChange(
                () =>
            {
                thesaurusItem1 = Cache.ServiceLocator.GetInstance <ICmPossibilityFactory>().Create();
                thesaurusItemsList.PossibilitiesOS.Add(thesaurusItem1);
                id1            = thesaurusItem1.Id;
                thesaurusItem2 = Cache.ServiceLocator.GetInstance <ICmPossibilityFactory>().Create();
                thesaurusItemsList.PossibilitiesOS.Add(thesaurusItem2);
                id2 = thesaurusItem2.Id;
            },
                "adding two items to an owning collection");
            // Verify undoes creating them, then creates new ones with the same IDs. We need the new valid objects.
            thesaurusItem1 = (ICmPossibility)Cache.ServiceLocator.GetObject(id1);
            thesaurusItem2 = (ICmPossibility)Cache.ServiceLocator.GetObject(id1);
            VerifyReconcilingAChange(
                () =>
            {
                sense1.ThesaurusItemsRC.Add(thesaurusItem1);
                sense1.ThesaurusItemsRC.Add(thesaurusItem2);
            },
                "adding two items to a reference collection");
            VerifyReconcilingAChange(
                () =>
            {
                entry1.MainEntriesOrSensesRS.Add(sense1);
            },
                "adding an item to a reference sequence");
            IStTxtPara para = null;

            UndoableUnitOfWorkHelper.Do("undo make para", "redo make para", m_actionHandler,
                                        () =>
            {
                para = Cache.ServiceLocator.GetInstance <IStTxtParaFactory>().Create();
                stText.ParagraphsOS.Add(para);
            });
            VerifyReconcilingAChange(
                () =>
            {
                SetParaContents(para, "Hello world");                                     // big string
                para.Label = Cache.TsStrFactory.MakeString("label", Cache.DefaultVernWs); // non-big string, just to be sure
            },
                "setting a simple string, previously empty");
            VerifyReconcilingAChange(
                () => SetParaContents(para, "Goodbye, world"),
                "setting a simple string, previously non-empty");
            VerifyReconcilingAChange(
                () => para.ParseIsCurrent = true,
                "setting a boolean");
            VerifyReconcilingAChange(
                () => thesaurusItem2.HelpId = "look for help here!",
                "setting a plain unicode string");
            VerifyReconcilingAChange(
                () => thesaurusItemsList.Depth = 17,
                "setting an integer");
            VerifyReconcilingAChange(
                () => thesaurusItemsList.ListVersion = Guid.NewGuid(),
                "setting a guid property");
            var propsBldr = TsPropsBldrClass.Create();

            propsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "red hot");
            var props = propsBldr.GetTextProps();

            VerifyReconcilingAChange(
                () => para.StyleRules = props,
                "setting a text props");
            IRnGenericRec genericRec = null;

            UndoableUnitOfWorkHelper.Do("undo make notebook record", "redo make notebook record", m_actionHandler,
                                        () =>
            {
                genericRec = Cache.ServiceLocator.GetInstance <IRnGenericRecFactory>().Create();
                Cache.LangProject.ResearchNotebookOA.RecordsOC.Add(genericRec);
            });
            VerifyReconcilingAChange(
                () => genericRec.DateOfEvent = new GenDate(GenDate.PrecisionType.Exact, 7, 23, 1908, true),
                "setting a generic date");
            IUserConfigAcct acct = null;

            UndoableUnitOfWorkHelper.Do("undo make user view", "redo", m_actionHandler,
                                        () =>
            {
                acct = Cache.ServiceLocator.GetInstance <IUserConfigAcctFactory>().Create();
                Cache.LanguageProject.UserAccountsOC.Add(acct);
            });
            VerifyReconcilingAChange(() => acct.Sid = new byte[] { 1, 2, 3 }, "setting a binary property");
        }
Example #20
0
        public void ReconcileCollectionChanges()
        {
            int         entryCount = Cache.LangProject.LexDbOA.Entries.Count();
            var         destroy    = MakeEntry("destroy", "wipe out");
            var         destroyId  = destroy.Id;
            var         remove     = MakeEntry("remove", "get rid of");
            var         removeId   = remove.Id;
            ILexEntry   right      = null;
            ICmObjectId rightId    = null;
            ILexEntry   kick       = null;
            List <ICmObjectSurrogate> newbiesClockwise;
            List <ICmObjectSurrogate> dirtballsClockwise;
            List <ICmObjectId>        gonersClockwise;

            GetEffectsOfChange(() =>
            {
                right = MakeEntry("right", "correct");
                destroy.Delete();
            },
                               () => rightId = right.Id,
                               out newbiesClockwise, out dirtballsClockwise, out gonersClockwise);
            UndoableUnitOfWorkHelper.Do("undo", "redo", m_actionHandler,
                                        () =>
            {
                kick = MakeEntry("kick", "strike with foot");
                remove.Delete();
            });
            var uowService = Cache.ServiceLocator.GetInstance <IUnitOfWorkService>();
            var reconciler = ((UnitOfWorkService)uowService).Reconciler(newbiesClockwise, dirtballsClockwise, gonersClockwise);
            var notifiee   = new Notifiee();

            Cache.DomainDataByFlid.AddNotification(notifiee);
            Assert.That(reconciler.OkToReconcileChanges(), Is.True);
            reconciler.ReconcileForeignChanges();             // In effect the other client added 'right' and deleted 'destroy'.

            Assert.IsTrue(Cache.LangProject.LexDbOA.Entries.Contains(kick));
            right = (ILexEntry)Cache.ServiceLocator.GetObject(rightId);             // will throw if it doesn't exist.
            Assert.IsTrue(Cache.LangProject.LexDbOA.Entries.Contains(right));
            Assert.IsFalse(Cache.LangProject.LexDbOA.Entries.Contains(remove));
            Assert.IsFalse(Cache.ServiceLocator.ObjectRepository.IsValidObjectId(destroyId.Guid));
            // One way to be sure 'destroy' really got destroyed.
            Assert.That(Cache.LangProject.LexDbOA.Entries.Count(), Is.EqualTo(entryCount + 2));

            // See if we got PropChanged notifications on 'Entries'
            int flidEntries = Cache.MetaDataCache.GetFieldId2(LexDbTags.kClassId, "Entries", false);

            notifiee.CheckChangesWeaker(
                new[] { new ChangeInformationTest(Cache.LangProject.LexDbOA.Hvo, flidEntries, 0, entryCount + 2, entryCount + 2) },
                "missing Entries propcount");

            // adding kick; right should still be there. Remove should come back, Destroy still be gone.
            m_actionHandler.Undo();
            Assert.IsFalse(Cache.LangProject.LexDbOA.Entries.Contains(kick));
            Assert.IsTrue(Cache.LangProject.LexDbOA.Entries.Contains(right));
            Assert.IsTrue(Cache.LangProject.LexDbOA.Entries.Contains(remove));
            Assert.That(Cache.LangProject.LexDbOA.Entries.Count(), Is.EqualTo(entryCount + 2));

            m_actionHandler.Redo();             // restore kick, re-delete Remove.
            Assert.IsTrue(Cache.LangProject.LexDbOA.Entries.Contains(kick));
            Assert.IsTrue(Cache.LangProject.LexDbOA.Entries.Contains(right));
            Assert.IsFalse(Cache.LangProject.LexDbOA.Entries.Contains(remove));
            Assert.That(Cache.LangProject.LexDbOA.Entries.Count(), Is.EqualTo(entryCount + 2));
        }
 /// <summary>
 /// Get the ICmObjectSurrogate for the given CmObjectId.
 /// </summary>
 internal ICmObjectSurrogate GetSurrogate(ICmObjectId id)
 {
     lock (SyncRoot)
         return((ICmObjectSurrogate)GetObjectOrSurrogate(id));
 }
Example #22
0
        private void SetBasics()
        {
#if FirstByLINQXML // 20.112/20.289 (s)
            var element = XElement.Parse(m_xml);
            m_guid      = new Guid(element.Attribute("guid").Value);
            m_classname = element.Attribute("class").Value;
#endif
#if FirstByStringManipulation // 3.795/3.902 (s)
            var startIdx = m_xml.IndexOf("guid=");
            var endIdx   = m_xml.IndexOf("\"", startIdx + 7);
            m_guid = new Guid(m_xml.Substring(startIdx + 6, endIdx - 6 - startIdx));

            startIdx    = m_xml.IndexOf("class=");
            endIdx      = m_xml.IndexOf("\"", startIdx + 8);
            m_classname = m_xml.Substring(startIdx + 7, endIdx - 7 - startIdx);
#endif
#if SecondByStringManipulation // 3.407/3.518 (s) // Seems to be the fastest, to date.
            var startIdx = RawXmlBytes.IndexOfSubArray(GuidEquals) + GuidEquals.Length;
            m_guid = ((IServiceLocatorInternal)m_cache.ServiceLocator).IdentityMap.CreateObjectIdWithHvo(GuidFromByteSubArray(RawXmlBytes, startIdx));

            startIdx = RawXmlBytes.IndexOfSubArray(ClassEquals) + ClassEquals.Length;
            var endIdx = Array.IndexOf(RawXmlBytes, QuoteChar, startIdx + 1);
            SetClassName(Encoding.UTF8.GetString(RawXmlBytes, startIdx, endIdx - startIdx));
#endif
#if ThirdByStringManipulation // 4.371/4.479 (s)
            var haveGuid  = false;
            var haveClass = false;
            var xmlLength = m_xml.Length;
            for (var i = 0; i < xmlLength; i++)
            {
                var currentChar = m_xml[i];
                switch (currentChar)
                {
                case 'g':
                    m_guid   = new Guid(m_xml.Substring(i + 6, 36));
                    i       += 42;
                    haveGuid = true;
                    break;

                case 'c':
                    i += 7;
                    for (var j = i; j < xmlLength; ++j)
                    {
                        if (m_xml[j] != '"')
                        {
                            continue;
                        }
                        m_classname = m_xml.Substring(i, j - i);
                        haveClass   = true;
                        i           = j;
                        break;
                    }
                    break;
                }
                if (haveGuid && haveClass)
                {
                    break;
                }
            }
#endif
#if FourthByStringManipulation // 4.318/4.434 (s)
            var xmlLength = m_xml.Length;
            var mtGuid    = Guid.Empty;
            for (var i = 0; i < xmlLength; i++)
            {
                switch (m_xml[i])
                {
                case 'g':
                    m_guid = new Guid(m_xml.Substring(i + 6, 36));
                    if (m_classname != null)
                    {
                        return;
                    }
                    i += 42;
                    break;

                case 'c':
                    i += 7;
                    for (var j = i; j < xmlLength; ++j)
                    {
                        if (m_xml[j] != '"')
                        {
                            continue;
                        }
                        m_classname = m_xml.Substring(i, j - i);
                        if (m_guid != mtGuid)
                        {
                            return;
                        }
                        i = j;
                        break;
                    }
                    break;
                }
            }
#endif
        }
Example #23
0
		private void SetBasics()
		{
#if FirstByLINQXML // 20.112/20.289 (s)
			var element = XElement.Parse(m_xml);
			m_guid = new Guid(element.Attribute("guid").Value);
			m_classname = element.Attribute("class").Value;
#endif
#if FirstByStringManipulation // 3.795/3.902 (s)
			var startIdx = m_xml.IndexOf("guid=");
			var endIdx = m_xml.IndexOf("\"", startIdx + 7);
			m_guid = new Guid(m_xml.Substring(startIdx + 6, endIdx - 6 - startIdx));

			startIdx = m_xml.IndexOf("class=");
			endIdx = m_xml.IndexOf("\"", startIdx + 8);
			m_classname = m_xml.Substring(startIdx + 7, endIdx - 7 - startIdx);
#endif
#if SecondByStringManipulation // 3.407/3.518 (s) // Seems to be the fastest, to date.
			var startIdx = RawXmlBytes.IndexOfSubArray(GuidEquals) + GuidEquals.Length;
			m_guid = ((IServiceLocatorInternal)m_cache.ServiceLocator).IdentityMap.CreateObjectIdWithHvo(GuidFromByteSubArray(RawXmlBytes, startIdx));

			startIdx = RawXmlBytes.IndexOfSubArray(ClassEquals) + ClassEquals.Length;
			var endIdx = Array.IndexOf(RawXmlBytes, QuoteChar, startIdx + 1);
			SetClassName(Encoding.UTF8.GetString(RawXmlBytes, startIdx, endIdx - startIdx));
#endif
#if ThirdByStringManipulation // 4.371/4.479 (s)
			var haveGuid = false;
			var haveClass = false;
			var xmlLength = m_xml.Length;
			for (var i = 0; i < xmlLength; i++)
			{
				var currentChar = m_xml[i];
				switch (currentChar)
				{
					case 'g':
						m_guid = new Guid(m_xml.Substring(i + 6, 36));
						i += 42;
						haveGuid = true;
						break;
					case 'c':
						i += 7;
						for (var j = i; j < xmlLength; ++j)
						{
							if (m_xml[j] != '"') continue;
							m_classname = m_xml.Substring(i, j - i);
							haveClass = true;
							i = j;
							break;
						}
						break;
				}
				if (haveGuid && haveClass)
					break;
			}
#endif
#if FourthByStringManipulation // 4.318/4.434 (s)
			var xmlLength = m_xml.Length;
			var mtGuid = Guid.Empty;
			for (var i = 0; i < xmlLength; i++)
			{
				switch (m_xml[i])
				{
					case 'g':
						m_guid = new Guid(m_xml.Substring(i + 6, 36));
						if (m_classname != null) return;
						i += 42;
						break;
					case 'c':
						i += 7;
						for (var j = i; j < xmlLength; ++j)
						{
							if (m_xml[j] != '"') continue;
							m_classname = m_xml.Substring(i, j - i);
							if (m_guid != mtGuid) return;
							i = j;
							break;
						}
						break;
				}
			}
#endif
		}
Example #24
0
		void VerifyChanges(ICmObject[] expectedNewbies, ICmObject[] expectedDirtballs,
			ICmObjectId[] expectedGoners, IUnitOfWorkService m_uowService)
		{
			var newbies = new HashSet<ICmObjectId>();
			var dirtballs = new HashSet<ICmObjectOrSurrogate>(new ObjectSurrogateEquater());
			var goners = new HashSet<ICmObjectId>();
			m_uowService.GatherChanges(newbies, dirtballs, goners);
			var setNewbies = new HashSet<ICmObjectId>(from obj in expectedNewbies select obj.Id);
			Assert.That(newbies.Except(setNewbies), Is.Empty, "some unexpected newbies were found");
			Assert.That(setNewbies.Except(newbies), Is.Empty, "some expected newbies were not found");
			var setDirtballs = new HashSet<ICmObjectOrSurrogate>(expectedDirtballs.Cast<ICmObjectOrSurrogate>());
			Assert.That(dirtballs.Except(setDirtballs), Is.Empty, "some unexpected dirtballs were found");
			Assert.That(setDirtballs.Except(dirtballs), Is.Empty, "some expected dirtballs were not found");
			var setGoners = new HashSet<ICmObjectId>(expectedGoners);
			Assert.That(goners.Except(setGoners), Is.Empty, "some unexpected goners were found");
			Assert.That(setGoners.Except(goners), Is.Empty, "some expected goners were not found");
		}
 /// <summary>
 /// Get the specified object instance; short for getting ICmObjectRepository and asking it to GetObject.
 /// </summary>
 public ICmObject GetObject(ICmObjectId id)
 {
     return(m_baseServiceLocator.GetInstance <ICmObjectRepository>().GetObject(id));
 }