示例#1
0
        /// <summary>
        /// Call this method to persist the current layout to disk.
        /// </summary>
        public string SaveLayout()
        {
            if (DockManager.IsLoaded)
            {
                // Save pads
                List<string> padNamesList = new List<string>();
                foreach (IPad pad in Pads)
                {
                    // We have to save all the pad names that have ever been
                    // shown even if they're hidden now or else the layout
                    // manager won't remember where they are when shown again.
                    padNamesList.Add(pad.Name);
                }

                string padNames = String.Join(",", padNamesList.ToArray());

                // Save documents
                DocumentList docNamesList = new DocumentList();
                foreach (IDocument doc in Documents)
                {
                    docNamesList.AddItem(
                        new DocumentItem(doc.Name, doc.Memento)
                        );
                }

                XmlSerializer s = new XmlSerializer(typeof(DocumentList));
                StringWriter sw = new StringWriter();
                s.Serialize(sw, docNamesList);
                string docNames = sw.ToString();
                sw.Close();

                // Save layout
                StringWriter swLayout = new StringWriter();
                DockManager.SaveLayout(swLayout);
                string layout = swLayout.ToString();
                swLayout.Close();

                // encode it to base 64 so we don't have to worry about control codes
                byte[] encbuf;

                encbuf = System.Text.Encoding.Unicode.GetBytes(padNames);
                string padNamesEncoded = Convert.ToBase64String(encbuf);

                encbuf = System.Text.Encoding.Unicode.GetBytes(docNames);
                string docNamesEncoded = Convert.ToBase64String(encbuf);

                encbuf = System.Text.Encoding.Unicode.GetBytes(layout);
                string layoutEncoded = Convert.ToBase64String(encbuf);

                // "The base-64 digits in ascending order from zero are the uppercase
                // characters "A" to "Z", the lowercase characters "a" to "z",
                // the numerals "0" to "9", and the symbols "+" and "/".
                // The valueless character, "=", is used for trailing padding."
                return padNamesEncoded + "." + docNamesEncoded + "." + layoutEncoded;
            }
            else
            {
                throw new InvalidOperationException("The DockManager isn't loaded yet.");
            }
        }