Beispiel #1
0
        /// <summary>
        /// reads the manual from specific file and return list<string>
        /// </summary>
        /// <returns></returns>

        //public List<string> GettingManual()
        //{
        //    FileStream fs = new FileStream("Manual.txt", FileMode.Open, FileAccess.Read);
        //    StreamReader sr = new StreamReader(fs);
        //    List<string> manual = new List<string>();
        //    string s = sr.ReadLine();
        //    while (s != null)
        //    {
        //        manual.Add(s);
        //        s = sr.ReadLine();
        //    }
        //    sr.Dispose();
        //    fs.Dispose();
        //    return manual;
        //}
        /// <summary>
        ///  save the project to a file as a binary format.
        /// user will give the filepath and the object that need to save as two paramaters.
        /// </summary>
        /// <returns></returns>
        public void SaveToFile(string filepath, PipelineGround p)
        {
            BinaryFormatter bf = new BinaryFormatter();
            FileStream      fs = new FileStream(filepath, FileMode.OpenOrCreate, FileAccess.Write);

            fs.SetLength(0);
            bf.Serialize(fs, p);
            fs.Dispose();
        }
Beispiel #2
0
        private void OpenFile()
        {
            if (changes)
            {
                DialogResult result = MessageBox.Show("Do you want to save the previous work?", "save?", MessageBoxButtons.YesNo);
                if (result == DialogResult.Yes)
                {
                    if (path == "")
                    {
                        SaveToFile();
                    }
                    else
                    {
                        fh.SaveToFile(path, pg);
                    }
                }
            }

            string         filename = "";
            OpenFileDialog newfile  = new OpenFileDialog();

            newfile.DefaultExt = ".np";             // Default file extension
            newfile.Filter     = "Flie (.np)|*.np"; // Filter files by extension
            DialogResult dr = newfile.ShowDialog();

            if (dr == DialogResult.OK)
            {
                path = filename = newfile.FileName;
                ClearNumericBox();
                Reset();
                pg = fh.LoadFromFile(filename);
                if (pg == null)
                {
                    pg = new PipelineGround();
                }

                pbPipeline.Invalidate();
                changes   = false;
                this.Text = filename;
            }
        }
Beispiel #3
0
        /// <summary>
        ///  reads a project and load  from a file.
        /// if the file selected is not a valid file, then return null.
        /// otherwise read the file and return the object with type of "pipeground".
        /// </summary>
        /// <param name="filepath"></param>
        /// <returns>the object created above (pipeground object mani)</returns>
        /// </summary>
        /// <returns></returns>
        public PipelineGround LoadFromFile(string filepath)
        {
            try
            {
                BinaryFormatter bf = new BinaryFormatter();
                FileStream      fs = new FileStream(filepath, FileMode.Open, FileAccess.Read);
                if (fs.Length == 0)
                {
                    pg = null;
                }
                else
                {
                    pg = (PipelineGround)bf.Deserialize(fs);
                }
                fs.Dispose();
                return(pg);
            }
            catch (Exception)
            {
                MessageBox.Show("Not a valid file!");

                return(null);
            }
        }
Beispiel #4
0
        /// <summary>
        /// constructor of specific class
        /// </summary>

        public FileHelper()
        {
            pg = new PipelineGround();
        }