/// <summary> /// The load routine for the static data file collection /// </summary> /// <param name="PopulateNodeTrees"></param> /// <returns></returns> public bool Load(int populateDepth = 0) { // Loads the static data and builds the trees representing the data files if (!DataDirectoryInfo.Exists) { return(false); } else { foreach (FileInfo dataFile in DataDirectoryInfo.GetFiles(targetFileExtension)) { // Create a new Json_File_UI and populate the path. Json_File_UI tempJsonFile = new Json_File_UI(this, dataFile, populateDepth); // Add the file to the Data Dictionary DataDictionary.Add(dataFile.Name, tempJsonFile); //if (tempJsonFile.IsLoaded) // && !LoadError) { if (tempJsonFile.RootNode == null) { throw new NullReferenceException ("Json_FileCollection.Load: tempJsonFile.RootNode was null."); } else { RootNode.Nodes.Insert(0, tempJsonFile.RootNode); } } } return(true); } }
/// <summary> /// Handles closing of this collection of files, and de-allocation of it's objects /// </summary> /// <returns></returns> public bool Close() { if (IsDirty) { return(false); // indicates a problem and can't close } else { // Not dirty, OK to close everything IsLoaded = false; bool subFileCloseSuccess = true; if (DataDictionary != null) { foreach (KeyValuePair <string, Json_File_UI> keyValuePair in DataDictionary) { Json_File_UI jsonBaseFile = keyValuePair.Value; if (jsonBaseFile != null) { bool resultOk = jsonBaseFile.Close(); if (!resultOk) { subFileCloseSuccess = false; } else { jsonBaseFile = null; // remove the jsonBaseFile from the list //DataDictionary.Remove(keyValuePair.Key); } } } } else { DataDictionary = null; } DataDirectoryInfo = null; RootNode = null; return(subFileCloseSuccess); } }