/// <summary> /// Create a RealDataCache object, and laod it with metadata and real data. /// </summary> /// <param name="metadataPathname"></param> /// <param name="realDataPathname"></param> /// <param name="objects"></param> /// <returns></returns> public RealDataCache LoadCache(string metadataPathname, string realDataPathname, Dictionary<int, uint> objects) { CheckDisposed(); m_realDataCache = new RealDataCache(); m_realDataCache.CheckWithMDC = false; try { #if DEBUG //Process objectBrowser = Process.GetCurrentProcess(); //long memory = objectBrowser.PrivateMemorySize64; //Debug.WriteLine(String.Format("Memory used (start load): {0}.", memory.ToString())); DateTime start = DateTime.Now; #endif m_metaDataCache = new MetaDataCache(); m_metaDataCache.InitXml(metadataPathname, true); m_realDataCache.MetaDataCache = m_metaDataCache; #if DEBUG DateTime end = DateTime.Now; TimeSpan span = new TimeSpan(end.Ticks - start.Ticks); string totalTime = String.Format("Hours: {0}, Minutes: {1}, Seconds: {2}, Millseconds: {3}", span.Hours.ToString(), span.Minutes.ToString(), span.Seconds.ToString(), span.Milliseconds.ToString()); Debug.WriteLine("Time to load MDC: " + totalTime); start = end; //memory = objectBrowser.PrivateMemorySize64; //Debug.WriteLine(String.Format("Memory used (loaded MDC load): {0}.", memory.ToString())); #endif XmlDocument doc = new XmlDocument(); doc.Load(realDataPathname); #if DEBUG end = DateTime.Now; span = new TimeSpan(end.Ticks - start.Ticks); totalTime = String.Format("Hours: {0}, Minutes: {1}, Seconds: {2}, Millseconds: {3}", span.Hours.ToString(), span.Minutes.ToString(), span.Seconds.ToString(), span.Milliseconds.ToString()); Debug.WriteLine("Time to load XML: " + totalTime); start = end; //memory = objectBrowser.PrivateMemorySize64; //Debug.WriteLine(String.Format("Memory used (loaded data XML): {0}.", memory.ToString())); #endif // Load Writing Systems first. int ord = 0; int hvo; uint clid = 0; { XmlNodeList wsNodes = doc.DocumentElement.SelectNodes("LgWritingSystem"); uint flid = m_metaDataCache.GetFieldId("LgWritingSystem", "ICULocale", false); // We need a full list of ints and strings for Wses, // before we can load string data, // so cache the barebones first. foreach (XmlNode wsNode in wsNodes) { hvo = BootstrapWs(wsNode, flid, out clid, objects); } foreach (XmlNode wsNode in wsNodes) { string uid = wsNode.Attributes["id"].Value.Substring(1); hvo = m_realDataCache.get_ObjFromGuid(new Guid(uid)); LoadObject(wsNode, hvo, clid, objects); } } // Now load other ownerless objects, except LangProject and Wses. foreach (XmlNode otherOwnerlessNode in doc.DocumentElement.ChildNodes) { if (otherOwnerlessNode.Name != "LangProject" && otherOwnerlessNode.Name != "LgWritingSystem") { hvo = LoadCmObjectProperties(otherOwnerlessNode, 0, 0, ord, out clid, objects); LoadObject(otherOwnerlessNode, hvo, clid, objects); } } // Now load LangProject XmlNode langProjectNode = doc.DocumentElement.SelectSingleNode("LangProject"); hvo = LoadCmObjectProperties(langProjectNode, 0, 0, ord, out clid, objects); LoadObject(langProjectNode, hvo, clid, objects); // Set references // Set atomic references foreach (KeyValuePair<HvoFlidKey, XmlNode> kvp in m_delayedAtomicReferences) { string uid = kvp.Value.Attributes["target"].Value.Substring(1); try { int hvoTarget = m_realDataCache.get_ObjFromGuid(new Guid(uid)); m_realDataCache.CacheObjProp(kvp.Key.Hvo, (int)kvp.Key.Flid, hvoTarget); } catch { // Invalid reference. Just clear the cache in case there is a save. m_realDataCache.SetObjProp(kvp.Key.Hvo, (int)kvp.Key.Flid, 0); } } //// Remove all items from m_delayedAtomicReferences that are in handledRefs. //// Theory has it that m_delayedAtomicReferences should then be empty. m_delayedAtomicReferences.Clear(); // Set vector (col or seq) references. foreach (KeyValuePair<HvoFlidKey, List<XmlNode>> kvp in m_delayedVecterReferences) { List<int> hvos = new List<int>(); foreach (XmlNode obj in kvp.Value) { string uid = obj.Attributes["target"].Value.Substring(1); try { int ownedHvo = m_realDataCache.get_ObjFromGuid(new Guid(uid)); hvos.Add(ownedHvo); } catch { // Invalid reference. Just remove the bogus hvo. // Since the id is added after the exception, it is effectively 'removed'. Debug.WriteLine("Bogus Id found."); } } m_realDataCache.CacheVecProp(kvp.Key.Hvo, (int)kvp.Key.Flid, hvos.ToArray(), hvos.Count); } m_delayedVecterReferences.Clear(); #if DEBUG end = DateTime.Now; span = new TimeSpan(end.Ticks - start.Ticks); totalTime = String.Format("Hours: {0}, Minutes: {1}, Seconds: {2}, Millseconds: {3}", span.Hours.ToString(), span.Minutes.ToString(), span.Seconds.ToString(), span.Milliseconds.ToString()); Debug.WriteLine("Time to load main Cache: " + totalTime); start = end; Debug.WriteLine(String.Format("Number of objects cached: {0}", (m_realDataCache.NextHvo - 1).ToString())); //memory = objectBrowser..PrivateMemorySize64; //Debug.WriteLine(String.Format("Memory used (cache loaded): {0}.", memory.ToString())); #endif } finally { m_realDataCache.CheckWithMDC = true; } return m_realDataCache; }
/// <summary> /// Create a RealDataCache object, and laod it with metadata and real data. /// </summary> /// <param name="metadataPathname"></param> /// <param name="realDataPathname"></param> /// <param name="objects"></param> /// <returns></returns> public ISilDataAccess LoadCache(string metadataPathname, string realDataPathname, Dictionary<int, int> objects) { CheckDisposed(); m_realDataCache = new RealDataCache {CheckWithMDC = false}; try { #if DEBUG //Process objectBrowser = Process.GetCurrentProcess(); //long memory = objectBrowser.PrivateMemorySize64; //Debug.WriteLine(String.Format("Memory used (start load): {0}.", memory.ToString())); DateTime start = DateTime.Now; #endif m_metaDataCache = new MetaDataCache(); m_metaDataCache.InitXml(metadataPathname, true); m_realDataCache.MetaDataCache = m_metaDataCache; #if DEBUG var end = DateTime.Now; var span = new TimeSpan(end.Ticks - start.Ticks); var totalTime = String.Format("Hours: {0}, Minutes: {1}, Seconds: {2}, Millseconds: {3}", span.Hours, span.Minutes, span.Seconds, span.Milliseconds); Debug.WriteLine("Time to load MDC: " + totalTime); start = end; //memory = objectBrowser.PrivateMemorySize64; //Debug.WriteLine(String.Format("Memory used (loaded MDC load): {0}.", memory.ToString())); #endif var doc = new XmlDocument(); doc.Load(realDataPathname); #if DEBUG end = DateTime.Now; span = new TimeSpan(end.Ticks - start.Ticks); totalTime = String.Format("Hours: {0}, Minutes: {1}, Seconds: {2}, Millseconds: {3}", span.Hours, span.Minutes, span.Seconds, span.Milliseconds); Debug.WriteLine("Time to load XML: " + totalTime); start = end; //memory = objectBrowser.PrivateMemorySize64; //Debug.WriteLine(String.Format("Memory used (loaded data XML): {0}.", memory.ToString())); #endif int hvo, clid = 0; const int ord = 0; // First load all objects as if they were ownerless, except top-level objects. foreach (XmlNode ownedNode in doc.DocumentElement.ChildNodes) { if (ownedNode.Attributes.GetNamedItem("owner").Value == "none") continue; hvo = LoadCmObjectProperties(ownedNode, 0, 0, ord, out clid, objects); LoadObject(ownedNode, hvo, clid, objects); } // Now load all owned objects //XmlNode langProjectNode = doc.DocumentElement.SelectSingleNode("LangProject"); //hvo = LoadCmObjectProperties(langProjectNode, 0, 0, ord, out clid, objects); //LoadObject(langProjectNode, hvo, clid, objects); foreach (XmlNode unownedNode in doc.DocumentElement.ChildNodes) { if (unownedNode.Attributes.GetNamedItem("owner").Value == "none") { hvo = LoadCmObjectProperties(unownedNode, 0, 0, ord, out clid, objects); LoadObject(unownedNode, hvo, clid, objects); } } // Set references // Set atomic references foreach (var kvp in m_delayedAtomicReferences) { var id = kvp.Value.Attributes["target"].Value.Substring(1); try { var hvoTarget = m_realDataCache.get_ObjFromGuid(new Guid(id)); m_realDataCache.CacheObjProp(kvp.Key.Hvo, kvp.Key.Flid, hvoTarget); } catch { // Invalid reference. Just clear the cache in case there is a save. m_realDataCache.SetObjProp(kvp.Key.Hvo, kvp.Key.Flid, 0); } } //// Remove all items from m_delayedAtomicReferences that are in handledRefs. //// Theory has it that m_delayedAtomicReferences should then be empty. m_delayedAtomicReferences.Clear(); // Set vector (col or seq) references. foreach (var kvp in m_delayedVecterReferences) { var hvos = new List<int>(); foreach (XmlNode obj in kvp.Value) { var id = obj.Attributes["target"].Value.Substring(1); try { var ownedHvo = m_realDataCache.get_ObjFromGuid(new Guid(id)); hvos.Add(ownedHvo); } catch { // Invalid reference. Just remove the bogus hvo. // Since the id is added after the exception, it is effectively 'removed'. Debug.WriteLine("Bogus Id found."); } } m_realDataCache.CacheVecProp(kvp.Key.Hvo, kvp.Key.Flid, hvos.ToArray(), hvos.Count); } m_delayedVecterReferences.Clear(); #if DEBUG end = DateTime.Now; span = new TimeSpan(end.Ticks - start.Ticks); totalTime = String.Format("Hours: {0}, Minutes: {1}, Seconds: {2}, Millseconds: {3}", span.Hours, span.Minutes, span.Seconds, span.Milliseconds); Debug.WriteLine("Time to load main Cache: " + totalTime); Debug.WriteLine(String.Format("Number of objects cached: {0}", (m_realDataCache.NextHvo - 1))); //memory = objectBrowser..PrivateMemorySize64; //Debug.WriteLine(String.Format("Memory used (cache loaded): {0}.", memory.ToString())); #endif } finally { m_realDataCache.CheckWithMDC = true; } return m_realDataCache; }