Example #1
0
        public void ReadLayout(Control f)
        {
            MemoryStream s = SaveLoadLayout.LoadFormDB(f.Name);

            if (s == null)
            {
                return;
            }
            StreamReader sr        = new StreamReader(s);
            string       cleandown = sr.ReadToEnd();

            cleandown = "<DOCUMENT_ELEMENT>" + cleandown + "</DOCUMENT_ELEMENT>";

            XmlDocument doc = new XmlDocument();

            doc.LoadXml(cleandown);

            foreach (XmlNode node in doc.DocumentElement.ChildNodes)
            {
                if (node.Name.Equals("Object"))
                {
                    ReadObject(node, f);
                }
            }
        }
Example #2
0
        /// <summary>
        /// This method is used to parse the given file.  Before calling this
        /// method the host member variable must be setup.  This method will
        /// create a data set, read the data set from the XML stored in the
        /// file, and then walk through the data set and create components
        /// stored within it.  The data set is stored in the persistedData
        /// member variable upon return.
        ///
        /// This method never throws exceptions.  It will set the successful
        /// ref parameter to false when there are catastrophic errors it can't
        /// resolve (like being unable to parse the XML).  All error exceptions
        /// are added to the errors array list, including minor errors.
        /// </summary>
        private string ReadFile(string fileName, ArrayList errors, out XmlDocument document)
        {
            string baseClass = null;

            // Anything unexpected is a fatal error.
            //
            try
            {
                // The main form and items in the component tray will be at the
                // same level, so we have to create a higher super-root in order
                // to construct our XmlDocument.

                MemoryStream s         = SaveLoadLayout.LoadFormDB(FormName);
                StreamReader sr        = new StreamReader(s);
                string       cleandown = sr.ReadToEnd();

                cleandown = "<DOCUMENT_ELEMENT>" + cleandown + "</DOCUMENT_ELEMENT>";

                XmlDocument doc = new XmlDocument();

                doc.LoadXml(cleandown);
                doc.Save("c:\\aa.xml");
                // Now, walk through the document's elements.
                //
                foreach (XmlNode node in doc.DocumentElement.ChildNodes)
                {
                    if (baseClass == null)
                    {
                        baseClass = node.Attributes["name"].Value;
                    }

                    if (node.Name.Equals("Object"))
                    {
                        ReadObject(node, errors);
                    }
                    else
                    {
                        errors.Add(string.Format("Node type {0} is not allowed here.", node.Name));
                    }
                }

                document = doc;
            }
            catch (Exception ex)
            {
                document = null;
                MessageBox.Show(ex.Message, "´íÎó");
            }
            return(baseClass);
        }
Example #3
0
        /// <summary>
        /// Opens an Xml file and loads it up using BasicHostLoader (inherits from
        /// BasicDesignerLoader)
        /// </summary>
        public HostControl GetNewHost(string sClass, string formName)
        {
            HostSurface   hostSurface = (HostSurface)this.CreateDesignSurface(this.ServiceContainer);
            IDesignerHost host        = (IDesignerHost)hostSurface.GetService(typeof(IDesignerHost));

            BasicHostLoader basicHostLoader = null;

            if (SaveLoadLayout.TestFormat(formName) == false)
            {
                basicHostLoader = new BasicHostLoader(GetType(sClass, formName), formName);
            }
            else
            {
                basicHostLoader = new BasicHostLoader(formName);
            }
            hostSurface.BeginLoad(basicHostLoader);
            hostSurface.Loader = basicHostLoader;
            hostSurface.Initialize();
            return(new HostControl(hostSurface));
        }
Example #4
0
        /// <summary>
        /// Save the current state of the loader. If the user loaded the file
        /// or saved once before, then he doesn't need to select a file again.
        /// Unless this is being called as a result of "Save As..." being clicked,
        /// in which case forceFilePrompt will be true.
        /// </summary>
        public void Save(bool forceFilePrompt)
        {
            try
            {
                Flush();


                // Write out our xmlDocument to a file.
                StringWriter  sw  = new StringWriter();
                XmlTextWriter xtw = new XmlTextWriter(sw);

                xtw.Formatting = Formatting.Indented;
                xmlDocument.WriteTo(xtw);

                // Get rid of our artificial super-root before we save out
                // the XML.
                //
                string cleanup = sw.ToString().Replace("<DOCUMENT_ELEMENT>", "");

                cleanup = cleanup.Replace("</DOCUMENT_ELEMENT>", "");
                xtw.Close();
                MemoryStream s    = new MemoryStream();
                StreamWriter file = new StreamWriter(s);

                file.Write(cleanup);

                file.Close();
                SaveLoadLayout.SaveToDB(FormName, s);
                unsaved = false;
            }

            catch (Exception ex)
            {
                MessageBox.Show("Error during save: " + ex.ToString());
            }
        }
Example #5
0
        /// <summary>
        /// Save the current state of the loader. If the user loaded the file
        /// or saved once before, then he doesn't need to select a file again.
        /// Unless this is being called as a result of "Save As..." being clicked,
        /// in which case forceFilePrompt will be true.
        /// </summary>
        public void Save(bool forceFilePrompt)
        {
            try
            {
                Flush();

                // Write out our xmlDocument to a file.
                StringWriter  sw  = new StringWriter();
                XmlTextWriter xtw = new XmlTextWriter(sw);

                xtw.Formatting = Formatting.Indented;
                xmlDocument.WriteTo(xtw);

                // Get rid of our artificial super-root before we save out
                // the XML.
                //
                string cleanup = sw.ToString().Replace("<DOCUMENT_ELEMENT>", "");

                cleanup = cleanup.Replace("</DOCUMENT_ELEMENT>", "");
                xtw.Close();

                MemoryStream s    = new MemoryStream();
                StreamWriter file = new StreamWriter(s);

                file.Write(cleanup);
                file.Close();
                SaveLoadLayout.SaveToDB(FormName, s);
                //int filterIndex = 3;

                //if ((fileName == null) || forceFilePrompt)
                //{
                //    SaveFileDialog dlg = new SaveFileDialog();

                //    dlg.DefaultExt = "xml";
                //    dlg.Filter = "XML Files|*.xml";
                //    if (dlg.ShowDialog() == DialogResult.OK)
                //    {
                //        fileName = dlg.FileName;
                //        filterIndex = dlg.FilterIndex;
                //    }
                //}

                //if (fileName != null)
                //{
                //    switch (filterIndex)
                //    {
                //        case 1 :
                //            {
                //                // Write out our xmlDocument to a file.
                //                StringWriter sw = new StringWriter();
                //                XmlTextWriter xtw = new XmlTextWriter(sw);

                //                xtw.Formatting = Formatting.Indented;
                //                xmlDocument.WriteTo(xtw);

                //                // Get rid of our artificial super-root before we save out
                //                // the XML.
                //                //
                //                string cleanup = sw.ToString().Replace("<DOCUMENT_ELEMENT>", "");

                //                cleanup = cleanup.Replace("</DOCUMENT_ELEMENT>", "");
                //                xtw.Close();

                //                StreamWriter file = new StreamWriter(fileName);

                //                file.Write(cleanup);
                //                file.Close();
                //            }
                //            break;
                //    }
                unsaved = false;
                //}
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error during save: " + ex.ToString());
            }
        }