public virtual void FixtureSetup() { CheckDisposed(); string modelDir = DirectoryFinder.FwSourceDirectory; modelDir = modelDir.Substring(0, modelDir.LastIndexOf('\\')); modelDir = Path.Combine(modelDir, @"Output\XMI"); m_realDataCache = new RealDataCache(); m_realDataCache.MetaDataCache = MetaDataCache.CreateMetaDataCache(Path.Combine(modelDir, "xmi2cellar3.xml")); }
private void openToolStripMenuItem_Click(object sender, EventArgs e) { using (OpenFileDialog dlg = new OpenFileDialog()) { dlg.CheckFileExists = true; dlg.RestoreDirectory = true; dlg.Title = "Open Fieldworks Language Project"; dlg.ValidateNames = true; dlg.Multiselect = false; dlg.Filter = "Project files (*.xml)|*.xml"; if (dlg.ShowDialog(this) == DialogResult.OK) { Cursor = Cursors.WaitCursor; try { DateTime start = DateTime.Now; string modelDir = DirectoryFinder.FwSourceDirectory; modelDir = modelDir.Substring(0, modelDir.LastIndexOf('\\')); modelDir = Path.Combine(modelDir, @"Output\XMI"); string mdcPathname = Path.Combine(modelDir, "xmi2cellar3.xml"); using (RealCacheLoader loader = new RealCacheLoader()) { m_objects.Clear(); m_cache = loader.LoadCache(mdcPathname, dlg.FileName, m_objects); } DateTime end = DateTime.Now; TimeSpan span = new TimeSpan(end.Ticks - start.Ticks); string totalTime = String.Format("Minutes: {0}, Seconds: {1}, Millseconds: {2}", ((span.Hours * 60) + span.Minutes).ToString(), span.Seconds.ToString(), span.Milliseconds.ToString()); m_tstbLoadTime.Text = String.Format("Time to Load: {0}", totalTime); } finally { Cursor = Cursors.Default; } #if FlushMemory MemoryManagement.FlushMemory(); #endif uint mainClid = MetaDataCache.GetClassId("LangProject"); int mainHvo = 0; foreach (KeyValuePair<int, uint> kvp in m_objects) { //uint clid = (uint)m_cache.get_IntProp(kvp.Key, (int)CmObjectFields.kflidCmObject_Class); if (kvp.Value == mainClid) { mainHvo = kvp.Key; break; } } m_current = new SelectedObject(0, mainHvo, mainClid); PopulateMainListView(); } } }
public override void FixtureSetup() { base.FixtureSetup(); SetupTestModel(Resources.TextCacheModel_xml); m_sda = new RealDataCache(); m_sda.MetaDataCache = MetaDataCache.CreateMetaDataCache("TestModel.xml"); //m_cache.ParaContentsFlid = kflidParaContents; //m_cache.ParaPropertiesFlid = kflidParaProperties; //m_cache.TextParagraphsFlid = kflidTextParas; Debug.Assert(m_wsManager == null); m_wsManager = Cache.ServiceLocator.GetInstance<IWritingSystemManager>(); m_sda.WritingSystemFactory = m_wsManager; m_wsAnal = Cache.DefaultAnalWs; m_wsVern = Cache.DefaultVernWs; //IWritingSystem deWs; //m_wsManager.GetOrSet("de", out deWs); //m_wsDeu = deWs.Handle; //m_wsManager.UserWs = m_wsEng; //m_wsUser = m_wsManager.UserWs; m_tsf = TsStrFactoryClass.Create(); m_hvoLexDb = m_sda.MakeNewObject(kclsidLexDb, 0, -1, -1); kflidLexDb_Entries = m_sda.MetaDataCache.GetFieldId("LexDb", "Entries", false); kflidEntry_Form = m_sda.MetaDataCache.GetFieldId("Entry", "Form", false); kflidEntry_Summary = m_sda.MetaDataCache.GetFieldId("Entry", "Summary", false); m_hvoKick = m_sda.MakeNewObject(kclsidEntry, m_hvoLexDb, kflidLexDb_Entries, 0); m_sda.SetMultiStringAlt(m_hvoKick, kflidEntry_Form, m_wsVern, m_tsf.MakeString("kick", m_wsVern)); m_sda.SetString(m_hvoKick, kflidEntry_Summary, m_tsf.MakeString("strike with foot", m_wsAnal)); var keyAttrs = new Dictionary<string, string[]>(); keyAttrs["layout"] = new[] { "class", "type", "name", "choiceGuid" }; keyAttrs["group"] = new[] { "label" }; keyAttrs["part"] = new[] { "ref" }; var layoutInventory = new Inventory("*.fwlayout", "/LayoutInventory/*", keyAttrs, "test", "nowhere"); layoutInventory.LoadElements(Resources.Layouts_xml, 1); keyAttrs = new Dictionary<string, string[]>(); keyAttrs["part"] = new[] { "id" }; var partInventory = new Inventory("*Parts.xml", "/PartInventory/bin/*", keyAttrs, "test", "nowhere"); partInventory.LoadElements(Resources.Parts_xml, 1); m_layouts = new LayoutCache(m_sda.MetaDataCache, layoutInventory, partInventory); }
public virtual void FixtureSetup() { FileUtils.Manager.SetFileAdapter(new MockFileOS()); using (TextWriter fw = FileUtils.OpenFileForWrite("TestModel.xsd", Encoding.UTF8)) fw.Write(Properties.Resources.TestModel_xsd); using (TextWriter fw = FileUtils.OpenFileForWrite("TestModel.xml", Encoding.UTF8)) fw.Write(Properties.Resources.TestModel_xml); m_realDataCache = new RealDataCache { MetaDataCache = MetaDataCache.CreateMetaDataCache("TestModel.xml") }; }
/// <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> /// 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> private void Dispose(bool disposing) { //Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************"); // Must not be run more than once. if (m_isDisposed) return; if (disposing) { if (m_wsCache != null) m_wsCache.Clear(); if (m_delayedAtomicReferences != null) m_delayedAtomicReferences.Clear(); if (m_delayedVecterReferences != null) m_delayedVecterReferences.Clear(); if (m_cachedFlids != null) m_cachedFlids.Clear(); if (m_tsf != null) m_tsf.Dispose(); } // Dispose unmanaged resources here, whether disposing is true or false. if (m_itsf != null) { if (Marshal.IsComObject(m_itsf)) Marshal.ReleaseComObject(m_itsf); m_itsf = null; } m_tsf = null; m_metaDataCache = null; m_realDataCache = null; m_wsCache = null; m_delayedAtomicReferences = null; m_delayedVecterReferences = null; m_cachedFlids = null; m_isDisposed = true; }
/// ------------------------------------------------------------------------------------ /// <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) { //Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************"); // Must not be run more than once. if (m_isDisposed) return; if (disposing) { // Dispose managed resources here. if (m_realDataCache != null) m_realDataCache.Dispose(); } // Dispose unmanaged resources here, whether disposing is true or false. m_realDataCache = null; m_isDisposed = true; }
public UndoableRealDataCache() { m_cache = new RealDataCache(); }
public SimpleRootSiteDataProviderView(RealDataCache rdc) : base(rdc) { }
public SimpleRootSiteDataProvider_MultiStringView(RealDataCache rdc) : base(rdc) { // We don't actually want to show it, but we need to force the view to create the root // box and lay it out so that various test stuff can happen properly. Width = 300; Height = 307 - 25; }
protected SimpleRootSiteDataProviderViewBase(RealDataCache rdc) { Cache = rdc; VwCache = rdc; m_hvoRoot = Cache.MakeNewObject(kclsidOwnerless, 0, -1, -1); }
public RootSiteDataProvider_MultiStringView(RealDataCache rdc) : base(rdc) { }
/// <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; }
public override void FixtureTeardown() { FileUtils.Manager.Reset(); // GrowToWord causes a Char Property Engine to be created, and the test runner // fails if we don't shut the factory down. m_sda.Dispose(); m_sda = null; base.FixtureTeardown(); }