Example #1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Creates a Person object by deserializing the specified file. The file can be just
        /// the name of the file, without the path, or the full path specification. If that
        /// fails, null is returned or, when there's an exception, it is thrown.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public static Person Load(SpongeProject prj, string pathName)
        {
            var fileName = Path.GetFileName(pathName);
            var folder   = fileName;

            if (folder.EndsWith("." + Sponge.PersonFileExtension))
            {
                folder = fileName.Remove(folder.Length - (Sponge.PersonFileExtension.Length + 1));
            }
            else
            {
                fileName += ("." + Sponge.PersonFileExtension);
            }

            folder   = Path.Combine(prj.PeopleFolder, folder);
            fileName = Path.Combine(folder, fileName);

            Exception e;
            var       person = XmlSerializationHelper.DeserializeFromFile <Person>(fileName, out e);

            if (e != null)
            {
                var msg = ExceptionHelper.GetAllExceptionMessages(e);
                Utils.MsgBox(msg);
            }

            person.Project = prj;
            return(person);
        }
Example #2
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Creates a Sponge project with the specified name.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public static SpongeProject Create(string prjName)
        {
            var prj = new SpongeProject();

            prj.Initialize(prjName, null);
            return(prj);
        }
Example #3
0
        public void Load()
        {
            VerifyProject(_prj, kTestPrjName);

            _prj = SpongeProject.Load(_prj.FullFilePath);
            VerifyProject(_prj, kTestPrjName);
        }
Example #4
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Creates a session object by deserializing the specified file. The file can be just
        /// the name of the file, without the path, or the full path specification. If that
        /// fails, null is returned or, when there's an exception, it is thrown.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public static Session Load(SpongeProject prj, string pathName)
        {
            string errorMsg;
            var    session = Load(prj, pathName, out errorMsg);

            if (errorMsg == null)
            {
                return(session);
            }

            ErrorReport.NotifyUserOfProblem("Could not load session \"{0}\". {1}", pathName, errorMsg);
            return(null);
        }
Example #5
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Creates a session object by deserializing the specified file. The file can be just
        /// the name of the file, without the path, or the full path specification. If that
        /// fails, null is returned or, when there's an exception, it is thrown.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public static Session Load(SpongeProject prj, string pathName, out string errorMsg)
        {
            errorMsg = null;

            var fileName = Path.GetFileName(pathName);
            var folder   = fileName;

            if (folder.EndsWith("." + Sponge.SessionFileExtension))
            {
                folder = fileName.Remove(folder.Length - (Sponge.SessionFileExtension.Length + 1));
            }
            else
            {
                fileName += ("." + Sponge.SessionFileExtension);
            }

            folder = Path.Combine(prj.SessionsFolder, folder);
            var path = Path.Combine(folder, fileName);

            if (!File.Exists(path))
            {
                errorMsg = string.Format("The session file at \"{0}\" is missing.", path);
                return(null);
            }

            Exception e;
            var       session = XmlSerializationHelper.DeserializeFromFile <Session>(path, out e);

            if (e != null)
            {
                errorMsg = ExceptionHelper.GetAllExceptionMessages(e);
                return(null);
            }

            if (session == null)            //jh: I've noticed that DeserializeFromFile likes to return null, with no error.
            {
                errorMsg = "Cause unknown";
                return(null);
            }

            session.Project = prj;
            session.Id      = Path.GetFileNameWithoutExtension(fileName);
            return(session);
        }
Example #6
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Verifies the existence of the specified project.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private static void VerifyProject(SpongeProject prj, string expectedPrjName)
        {
            Assert.IsNotNull(prj);
            var expectedPath = Path.Combine(SpongeProject.ProjectsFolder, expectedPrjName);

            Assert.AreEqual(expectedPath, prj.Folder);
            Assert.IsTrue(Directory.Exists(prj.Folder));

            expectedPath = Path.Combine(prj.Folder, "People");
            Assert.AreEqual(expectedPath, prj.PeopleFolder);
            Assert.IsTrue(Directory.Exists(prj.PeopleFolder));

            expectedPath = Path.Combine(prj.Folder, "Sessions");
            Assert.AreEqual(expectedPath, prj.SessionsFolder);
            Assert.IsTrue(Directory.Exists(prj.SessionsFolder));

            expectedPath = Path.Combine(prj.Folder, kTestPrjFileName);
            Assert.AreEqual(expectedPath, prj.FullFilePath);
            Assert.IsTrue(File.Exists(prj.FullFilePath));
        }
Example #7
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Initializes a new instance of the <see cref="Person"/> class.
 /// </summary>
 /// ------------------------------------------------------------------------------------
 private Person(SpongeProject prj, string personName)
 {
     Project  = prj;
     FullName = personName;
 }
Example #8
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Creates a Person object for the specified person's full name.
 /// </summary>
 /// ------------------------------------------------------------------------------------
 public static Person CreateFromName(SpongeProject prj, string personName)
 {
     return(new Person(prj, personName));
 }
Example #9
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Creates a session having the specified name and for the specified project.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public static Session Create(SpongeProject prj, string name)
        {
            var session = new Session(prj, name);

            return(session);
        }
Example #10
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Initializes a new instance of the <see cref="Session"/> class.
 /// </summary>
 /// ------------------------------------------------------------------------------------
 private Session(SpongeProject prj, string id)
 {
     Project = prj;
     Id      = id;
 }