示例#1
0
        public ECCAProject(string pathName)
        {
            if (File.Exists(pathName))
            {
                ECCAProject bufferProject = DeSerializeProject(pathName);

                ProjectInfo       = bufferProject.ProjectInfo;
                ElementCollection = bufferProject.ElementCollection;
                BeamCollection    = bufferProject.BeamCollection;
                FileLocation      = bufferProject.FileLocation;
            }
            else
            {
                ProjectInfo       = new ECCAPojectInfo();
                ElementCollection = new ECCAElementCollection();
                BeamCollection    = new ECCABeamCollection();
                FileLocation      = "";
                //A new File will be saved to requested path:

                DialogResult var = MessageBox.Show("A projectfile could not be found, Shall I attempt to create one ?", "Warning", MessageBoxButtons.YesNo);
                if (var == DialogResult.Yes)
                {
                    bool saveallok = SerializeProject(pathName);
                    if (saveallok == true)
                    {
                        MessageBox.Show("A new project file was created");
                    }
                }
            }
        }
示例#2
0
        public ECCAProject DeSerializeProject(string projectPath)
        {
            ECCAProject newProject = new ECCAProject();

            //Reatemp
            try
            {
                if (File.Exists(projectPath))
                {
                    AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);


                    IFormatter formatter = new BinaryFormatter();
                    Stream     stream    = new FileStream(projectPath, FileMode.Open);
                    newProject = (ECCAProject)formatter.Deserialize(stream);
                    stream.Close();
                }
                else
                {
                    MessageBox.Show("Project path cannot be found, a new file can be created");
                }

                //This is the only location a project path can be defined
                newProject.FileLocation = projectPath;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            return(newProject);
        }