internal async Task PersistRefTest()
 {
     TreeNode tr = new TreeNode.Builder(new List<TreeTreeReference>(0), new List<TreeBlobReference>(0));
     await trrepo.PersistTree(tr.ID, new IVO.Definition.Containers.ImmutableContainer<TreeID, TreeNode>(trx => trx.ID, tr));
     Commit cm = new Commit.Builder(new List<CommitID>(0), tr.ID, "James S. Dunne", DateTimeOffset.Now, "Initial commit.");
     await cmrepo.PersistCommit(cm);
     Ref rf = new Ref.Builder((RefName)"v1.0", cm.ID);
     await rfrepo.PersistRef(rf);
 }
        public static Errorable<Ref.Builder> FromJSON(this RefRequest rfm)
        {
            // Do conversions on the strings and detect any errors:
            var maybecommitid = CommitID.TryParse(rfm.commitid ?? String.Empty);
            if (maybecommitid.HasErrors) return maybecommitid.Errors;

            Ref.Builder rf = new Ref.Builder(
                pName:      (RefName)rfm.name,
                pCommitID:  maybecommitid.Value
            );
            return rf;
        }
        internal async Task GetRefByNameTest()
        {
            TreeNode tr = new TreeNode.Builder(new List<TreeTreeReference>(0), new List<TreeBlobReference>(0));
            await trrepo.PersistTree(tr.ID, new IVO.Definition.Containers.ImmutableContainer<TreeID, TreeNode>(trx => trx.ID, tr));
            Commit cm = new Commit.Builder(new List<CommitID>(0), tr.ID, "James S. Dunne", DateTimeOffset.Now, "Initial commit.");
            await cmrepo.PersistCommit(cm);
            Ref rf = new Ref.Builder((RefName)"v1.0", cm.ID);
            await rfrepo.PersistRef(rf);

            var errf = await rfrepo.GetRefByName((RefName)"v1.0");
            Assert.IsFalse(errf.HasErrors);
            Ref rrf = errf.Value;
            Assert.IsNotNull(rrf);
            Assert.AreEqual(rf.Name.ToString(), rrf.Name.ToString());
            Assert.AreEqual(rf.CommitID, rrf.CommitID);
        }
示例#4
0
        public async Task<ActionResult> Create(Errorable<RefName> erefName, CommitRequest cmj)
        {
            if (erefName.HasErrors) return ErrorJson(erefName);
            if (cmj == null) return Json(new { success = false });

            // First get the ref and its CommitID, if it exists:
            Ref rf;
            var erf = await cms.rfrepo.GetRefByName(erefName.Value);
            if (erf.HasErrors)
            {
                // Skip the RefNameDoesNotExistError error (should only be one - using All() makes sure that any other errors will fall out):
                if (!erf.Errors.All(err => err is RefNameDoesNotExistError))
                    return ErrorJson(erf);
                rf = null;
            }
            else rf = erf.Value;

            // Map from the JSON CommitModel:
            var ecb = cmj.FromJSON();
            if (ecb.HasErrors) return ErrorJson(ecb);

            Commit.Builder cb = ecb.Value;
            
            // Add the ref's CommitID as the parent, if the ref exists:
            if ((rf != null) && (cb.Parents.Count == 0))
            {
                cb.Parents.Add(rf.CommitID);
            }

            // Persist the commit:
            var epcm = await cms.cmrepo.PersistCommit(cb);
            if (epcm.HasErrors) return ErrorJson(epcm);

            Commit pcm = epcm.Value;

            // Persist the ref with this new CommitID:
            Ref.Builder rfb = new Ref.Builder(erefName.Value, pcm.ID);
            erf = await cms.rfrepo.PersistRef(rfb);
            if (erf.HasErrors) return ErrorJson(erf);

            rf = erf.Value;

            // Return the commit model as JSON again:
            return Json(new { @ref = rf.ToJSON(), commit = pcm.ToJSON() }, JsonRequestBehavior.AllowGet);
        }