예제 #1
0
 /// <summary>Add a filename to the list.</summary>
 /// <param name="file">File metadata.</param>
 public void AddMruFile(ApsimFileMetadata file)
 {
     if (file.FileName.Length > 0) // Do we really need this check?
     {
         if (MruList.Count > 0)
         {
             int index = MruList.FindIndex(f => f.FileName == file.FileName);
             if (index < 0)
             {
                 // First time that filename has been added
                 if (MruList.Count >= FilesInHistory)
                 {
                     MruList.RemoveAt(MruList.Count - 1);  // Delete the last item
                 }
             }
             else
             {
                 // Item is in the history list => move to top
                 file = MruList[index];
                 MruList.RemoveAt(index);
             }
             MruList.Insert(0, file);
         }
         else
         {
             MruList.Add(file);
         }
     }
 }
예제 #2
0
        public void SetExpandedNodes(string fileName, TreeNode[] nodes)
        {
            ApsimFileMetadata file = GetMruFile(fileName);

            if (file == null)
            {
                file = new ApsimFileMetadata(fileName, nodes);
                AddMruFile(file);
            }
            else
            {
                file.ExpandedNodes = nodes;
            }
        }
예제 #3
0
        /// <summary>
        /// Upgrades to version 1. Changes MRUList from a list of
        /// strings to a list of type ApsimFileMetadata.
        /// </summary>
        /// <param name="rootNode"></param>
        private static void UpgradeToVersion1(XmlNode rootNode)
        {
            XmlNode mruList = rootNode["MruList"];

            for (int i = 0; i < mruList.ChildNodes.Count; i++)
            {
                XmlNode child = mruList.ChildNodes[i];

                // Create a new ApsimFileMetadata object containing the filename.
                ApsimFileMetadata file = new ApsimFileMetadata(child.InnerText);

                // Serialize the ApsimFileMetadata.
                string      xml = XmlUtilities.Serialise(file, false);
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(xml);

                // Import the serialized ApsimFileMetadata into this document,
                // replacing the existing string filename.
                XmlNode newChild = doc[typeof(ApsimFileMetadata).Name];
                newChild = mruList.OwnerDocument.ImportNode(newChild, true);
                mruList.ReplaceChild(newChild, child);
            }
        }