Esempio n. 1
0
        private List <Alteration> GetAlterations(Objects.Version version)
        {
            List <Objects.Version> parents = Query <Objects.Version>(
                @"WITH RECURSIVE
                  ancestors(rowid, ID, Author, Message, Published, Branch, Parent, Timestamp, Snapshot, AlterationList) AS (
                      SELECT rowid, * FROM Version WHERE Version.ID = ?
                      UNION ALL
                      SELECT Version.rowid, Version.* FROM ancestors, Version
                      WHERE ancestors.Parent = Version.ID AND ancestors.Snapshot IS NULL
                  )
                  SELECT * FROM ancestors;", version.ID);

            return(GetAlterationsInternal(parents));
            //List<Objects.Version> parents = new List<Objects.Version>();
            //Objects.Version snapshotVersion = version;
            //while (true)
            //{
            //    parents.Add(snapshotVersion);
            //    if (snapshotVersion.Snapshot.HasValue)
            //        break;
            //    else
            //    {
            //        snapshotVersion = Get<Objects.Version>(snapshotVersion.Parent);
            //    }
            //}
            //return GetAlterationsInternal(parents);
        }
Esempio n. 2
0
        public List <Record> GetRecords(Objects.Version version, bool testFailure = false)
        {
            List <Record>     baseList;
            List <Alteration> alterations;

            return(GetRecords(version, out baseList, out alterations, testFailure));
        }
Esempio n. 3
0
 public VersionVM(Version version, Area area)
 {
     m_Version                = version;
     m_Area                   = area;
     CopyInfoCommand          = new DelegateCommand(CopyInfo);
     GeneratePatchFileCommand = new DelegateCommand(GeneratePatchFile);
     CreateReviewCommand      = new DelegateCommand(CreateReview);
 }
Esempio n. 4
0
        public IHttpContext Annotation(IHttpContext context)
        {
            try
            {
                Printer.PrintMessage($"Rest Begin {context.Request.Url} #{context.Request.Id}");
                string versionString      = context.Request.PathParameters["p0"];
                string keyString          = context.Request.PathParameters["p1"];
                bool   getAnnotationId    = context.Request.PathParameters.Count == 3;
                string annotationIdString = getAnnotationId ? context.Request.PathParameters["p2"] : null;

                using (Area ws = Area.Load(Info, true, true))
                {
                    Version ver = ws.GetPartialVersion(versionString);

                    if (ver != null)
                    {
                        bool       ignoreCase = true;
                        Annotation annotation = null;
                        if (getAnnotationId)
                        {
                            annotation = ws.GetAllAnnotations(ver.ID, keyString, ignoreCase).FirstOrDefault(a => a.ID.ToString().StartsWith(annotationIdString.ToLowerInvariant()));
                        }
                        else
                        {
                            annotation = ws.GetAnnotation(ver.ID, keyString, ignoreCase);
                        }

                        if (annotation != null)
                        {
                            SendResponse(context, ws.GetAnnotationAsString(annotation));
                        }
                        else
                        {
                            SendResponse(context, Grapevine.Shared.HttpStatusCode.NoContent);   // 204 - everything is fine, you get nothing
                        }
                    }
                    else
                    {
                        SendResponse(context, Grapevine.Shared.HttpStatusCode.NotFound);    // 404 - everything is terrible, you are a monster
                    }
                }

                return(context);
            }
            catch (Exception e)
            {
                Printer.PrintMessage($"Rest Exception #{context.Request.Id} {e}");

                return(context);
            }
            finally
            {
                Printer.PrintMessage($"Rest Query Retired #{context.Request.Id}");
            }
        }
Esempio n. 5
0
        private BuildStatus GetBuildStatus(Version version, Version buildVersion)
        {
            if (m_PreviousLog == null)
            {
                // No previous log - starting from scratch
                if (buildVersion != null && version.Branch != buildVersion.Branch)
                {
                    return(BuildStatus.Pending);
                }
                else
                {
                    return(Program.Options.Status);
                }
            }

            // Newer than specified version and on the same branch, must be pending
            if (buildVersion != null && version.Branch == buildVersion.Branch && version.Timestamp > buildVersion.Timestamp)
            {
                return(BuildStatus.Pending);
            }

            // Check for an existing entry for this version
            LogEntry oldEntry = m_PreviousLog.LogEntries.FirstOrDefault(x => x.ID == version.ID);

            if (oldEntry != null)
            {
                // Version previously passed or failed.
                if (oldEntry.Status == BuildStatus.Passed || oldEntry.Status == BuildStatus.Failed)
                {
                    return(oldEntry.Status);
                }

                // Once it's building, it can only go to pass or fail
                if (oldEntry.Status == BuildStatus.Building && Program.Options.Status != BuildStatus.Passed && Program.Options.Status != BuildStatus.Failed)
                {
                    return(oldEntry.Status);
                }

                // Don't change entries on a different branch
                if (buildVersion != null && version.Branch != buildVersion.Branch)
                {
                    return(oldEntry.Status);
                }
            }

            // Newer than specified version and on different branch, but no previous version, must be pending
            if (buildVersion != null && version.Timestamp > buildVersion.Timestamp)
            {
                return(BuildStatus.Pending);
            }

            // Everything else gets the passed in status
            return(Program.Options.Status);
        }
Esempio n. 6
0
        public IHttpContext Annotations(IHttpContext context)
        {
            try
            {
                Printer.PrintMessage($"Rest Begin {context.Request.Url} #{context.Request.Id}");
                RestAnnotationDictionary restAnnotationList = new RestAnnotationDictionary();

                string versionString = context.Request.PathParameters["p0"]; // the group from PathInfo in RestRouteAttribute

                List <Objects.Annotation> annotations = new List <Objects.Annotation>();
                using (Area ws = Area.Load(Info, true, true))
                {
                    Version ver = ws.GetPartialVersion(versionString);

                    if (ver != null)
                    {
                        bool activeOnly = true;
                        annotations.AddRange(ws.GetAnnotationsForVersion(ver.ID, activeOnly));
                        for (int i = 0; i < annotations.Count; i++)
                        {
                            var key = annotations[i].Key;
                            if (!restAnnotationList.annotations.ContainsKey(key))
                            {
                                restAnnotationList.annotations.Add(key, new List <RestAnnotationEntry>());
                            }
                            restAnnotationList.annotations[key].Add(new RestAnnotationEntry
                            {
                                author = annotations[i].Author,
                                id     = annotations[i].ID.ToString(),
                                time   = annotations[i].Timestamp.ToProperTimeStamp()
                            });
                        }
                    }

                    SendResponse(context, JsonConvert.SerializeObject(restAnnotationList));
                }

                return(context);
            }
            catch (Exception e)
            {
                Printer.PrintMessage($"Rest Exception #{context.Request.Id} {e}");

                return(context);
            }
            finally
            {
                Printer.PrintMessage($"Rest Query Retired #{context.Request.Id}");
            }
        }
Esempio n. 7
0
        public AlterationVM(Alteration alteration, Area area, Version version)
        {
            _alteration = alteration;
            _area = area;
            _version = version;

            if (_alteration.PriorRecord.HasValue)
                _priorRecord = _area.GetRecord(_alteration.PriorRecord.Value);
            if (_alteration.NewRecord.HasValue)
                _newRecord = _area.GetRecord(_alteration.NewRecord.Value);

            DiffWithPreviousCommand = new DelegateCommand(DiffWithPrevious, CanDiffWithPrevious);
            DiffWithCurrentCommand = new DelegateCommand(DiffWithCurrent, CanDiffWithCurrent);
            LogCommand = new DelegateCommand(Log);
            SaveVersionAsCommand = new DelegateCommand(SaveVersionAs, CanSaveVersionAs);
        }
Esempio n. 8
0
 public static RestVersion FromVersion(Area ws, Version version)
 {
     if (version == null)
     {
         return(null);
     }
     return(new RestVersion()
     {
         author = version.Author,
         id = version.ID.ToString(),
         message = version.Message,
         parent = version.Parent.HasValue ? version.Parent.Value.ToString() : string.Empty,
         branch = ws.Branches.Where(x => x.ID == version.Branch).First().Name,
         timestamp = version.Timestamp.ToProperTimeStamp(),
         tags = ws.GetTagsForVersion(version.ID)
     });
 }
Esempio n. 9
0
        public void Update()
        {
            foreach (Branch branch in m_Branches)
            {
                Version version = null;
                try
                {
                    version = m_Area.GetBranchHeadVersion(branch);
                }
                catch
                {
                    version = null;
                }
                if (version != null)
                {
                    m_Versions.AddRange(m_Area.GetLogicalHistory(version, false, false, false, m_Limit));
                }
            }

            m_Versions = m_Versions.OrderByDescending(o => o.Timestamp).ToList();
        }
Esempio n. 10
0
        public AlterationVM(Alteration alteration, Area area, Version version)
        {
            _alteration = alteration;
            _area       = area;
            _version    = version;

            if (_alteration.PriorRecord.HasValue)
            {
                _priorRecord = _area.GetRecord(_alteration.PriorRecord.Value);
            }
            if (_alteration.NewRecord.HasValue)
            {
                _newRecord = _area.GetRecord(_alteration.NewRecord.Value);
            }

            DiffWithPreviousCommand = new DelegateCommand(DiffWithPrevious, CanDiffWithPrevious);
            DiffWithCurrentCommand  = new DelegateCommand(DiffWithCurrent, CanDiffWithCurrent);
            LogCommand            = new DelegateCommand(Log);
            SaveVersionAsCommand  = new DelegateCommand(SaveVersionAs, CanSaveVersionAs);
            OpenInExplorerCommand = new DelegateCommand(OpenInExplorer);
        }
Esempio n. 11
0
        public void Serialize()
        {
            LogEntries.Clear();

            Version buildVersion = null;
            Guid    buildVersionID;

            if (Guid.TryParse(Program.Options.BuildVersionID, out buildVersionID))
            {
                buildVersion = m_Area.GetVersion(buildVersionID);
            }

            IEnumerable <Version> versions = (m_Limit.HasValue && m_Limit.Value > 0) ? m_Versions.Take(m_Limit.Value) : m_Versions;

            foreach (Version version in versions)
            {
                LogEntries.Add(new LogEntry(
                                   m_Area.GetBranch(version.Branch).Name,
                                   version.Revision,
                                   version.ID,
                                   version.Author,
                                   ToJavascriptTimestamp(version.Timestamp),
                                   version.Message,
                                   m_Area.GetTagsForVersion(version.ID),
                                   GetBuildStatus(version, buildVersion)));
            }

            try
            {
                XmlSerializer seralizer = new XmlSerializer(typeof(Log));
                using (StreamWriter writer = new StreamWriter(m_Destination))
                {
                    seralizer.Serialize(writer, this);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(String.Format("Failed to write file {0}\n{1}", m_Destination, ex.Message));
            }
        }
Esempio n. 12
0
        public List <Record> GetCachedRecords(Objects.Version version, bool testFailure = false)
        {
            List <Record> results;

            if (LocalDatabase.GetCachedRecords(version.ID, out results))
            {
                return(results);
            }
            results = GetRecords(version, testFailure);
            try
            {
                if (!testFailure)
                {
                    LocalDatabase.CacheRecords(version.ID, results);
                }
            }
            catch (InvalidOperationException)
            {
                // ignore
            }
            return(results);
        }
Esempio n. 13
0
        public List <Objects.Version> GetHistory(Objects.Version version, int?limit = null)
        {
            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();
            //List<Objects.Version> result = new List<Objects.Version>();
            //result.Add(version);
            //var results = Query<Objects.Version>(
            //    @"WITH RECURSIVE
            //        ancestors(n) AS (
            //            VALUES(?)
            //            UNION
            //            SELECT Parent FROM ancestors, Version
            //            WHERE ancestors.n = Version.ID
            //        )
            //        SELECT Version.* FROM Version INNER JOIN ancestors ON ancestors.n = Version.ID;", version.Parent);
            //result.AddRange(results);
            var result = Query <Objects.Version>(string.Format(
                                                     @"WITH RECURSIVE
                  ancestors(rowid, ID, Author, Message, Published, Branch, Parent, Timestamp, Snapshot, AlterationList) AS (
                      SELECT rowid, * FROM Version WHERE Version.ID = ?
                      UNION ALL
                      SELECT Version.rowid, Version.* FROM ancestors, Version
                      WHERE ancestors.Parent = Version.ID
                      {0}
                  )
                  SELECT * FROM ancestors;", limit.HasValue ? "LIMIT " + limit.Value.ToString() : ""), version.ID);

            // Naive version
            // var ver = version;
            // while (ver != null)
            // {
            //     result.Add(ver);
            //     ver = Find<Objects.Version>(ver.Parent);
            // }
            sw.Stop();
            Printer.PrintDiagnostics("History determined in {0} ms", sw.ElapsedMilliseconds);
            return(result);
        }
Esempio n. 14
0
 public List <Objects.Version> GetDirectChildren(Objects.Version version)
 {
     return(Query <Objects.Version>("SELECT * FROM Version WHERE Parent = ?", version.ID));
 }
Esempio n. 15
0
        private void Log()
        {
            Version headVersion = m_AreaVM.Area.GetBranchHeadVersion(m_Branch);

            LogDialog.Show(headVersion, m_AreaVM.Area);
        }
Esempio n. 16
0
        private BuildStatus GetBuildStatus(Version version, Version buildVersion)
        {
            if (m_PreviousLog == null)
            {
                // No previous log - starting from scratch
                if (buildVersion != null && version.Branch != buildVersion.Branch)
                    return BuildStatus.Pending;
                else
                    return Program.Options.Status;
            }

            // Newer than specified version and on the same branch, must be pending
            if (buildVersion != null && version.Branch == buildVersion.Branch && version.Timestamp > buildVersion.Timestamp)
                return BuildStatus.Pending;

            // Check for an existing entry for this version
            LogEntry oldEntry = m_PreviousLog.LogEntries.FirstOrDefault(x => x.ID == version.ID);
            if (oldEntry != null)
            {
                // Version previously passed or failed.
                if (oldEntry.Status == BuildStatus.Passed || oldEntry.Status == BuildStatus.Failed)
                    return oldEntry.Status;
                
                // Once it's building, it can only go to pass or fail
                if (oldEntry.Status == BuildStatus.Building && Program.Options.Status != BuildStatus.Passed && Program.Options.Status != BuildStatus.Failed)
                    return oldEntry.Status;

                // Don't change entries on a different branch
                if (buildVersion != null && version.Branch != buildVersion.Branch)
                    return oldEntry.Status;
            }

            // Newer than specified version and on different branch, but no previous version, must be pending
            if (buildVersion != null && version.Timestamp > buildVersion.Timestamp)
                return BuildStatus.Pending;

            // Everything else gets the passed in status
            return Program.Options.Status;
        }
Esempio n. 17
0
 public VersionVM(Version version, Area area)
 {
     _version = version;
     _area = area;
 }
Esempio n. 18
0
        public List <Record> GetRecords(Objects.Version version, out List <Record> baseList, out List <Alteration> alterations, bool testFailure = false)
        {
            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();
            Printer.PrintDiagnostics("Getting records for version {0}.", version.ID);
            long?snapshotID = null;
            bool readtrans  = false;

            try
            {
                BeginTransaction();
                readtrans = true;
            }
            catch (InvalidOperationException)
            {
                // not an issue
            }
            List <Objects.Version> parents = new List <Objects.Version>();

            Objects.Version snapshotVersion = version;
            while (!snapshotID.HasValue)
            {
                parents.Add(snapshotVersion);
                if (snapshotVersion.Snapshot.HasValue)
                {
                    snapshotID = snapshotVersion.Snapshot;
                }
                else
                {
                    if (!snapshotVersion.Parent.HasValue)
                    {
                        break;
                    }
                    snapshotVersion = Get <Objects.Version>(snapshotVersion.Parent);
                }
            }
            if (!snapshotID.HasValue)
            {
                Printer.PrintDiagnostics(" - No snapshot.");
                baseList = new List <Record>();
            }
            else
            {
                Printer.PrintDiagnostics(" - Last snapshot version: {0}", snapshotVersion.ID);
                var sslist = Query <RecordRef>("SELECT * FROM RecordRef WHERE RecordRef.SnapshotID = ?", snapshotID.Value).Select(x => x.RecordID).ToList();
                CacheRecords(sslist);
                baseList = sslist.Select(x => GetCachedRecord(x)).ToList();
                Printer.PrintDiagnostics(" - Snapshot {0} has {1} records.", snapshotID, baseList.Count);
            }
            alterations = GetAlterationsInternal(parents);
            if (readtrans)
            {
                Commit();
            }
            Printer.PrintDiagnostics(" - Target has {0} alterations.", alterations.Count);
            List <Record> finalList = null;

            try
            {
                finalList = Consolidate(baseList, alterations, null);
            }
            catch
            {
                if (testFailure)
                {
                    throw;
                }
                Printer.PrintError("Error during database operation. Deleting cached snapshots.");
                BeginExclusive(true);
                RunConsistencyCheck();
                Commit();
                Printer.PrintError("Please retry this operation.");
                throw;
            }
            Printer.PrintDiagnostics("Record list resolved in {0} ticks.", sw.ElapsedTicks);
            if (testFailure)
            {
                return(finalList);
            }
            if (baseList.Count < alterations.Count || (alterations.Count > 4096 && parents.Count > 128))
            {
                Printer.PrintDiagnostics(" - Attempting to build new snapshot ({0} records in base list, {1} alterations over {2} revisions)", baseList.Count, alterations.Count, parents.Count);
                try
                {
                    BeginTransaction();
                    try
                    {
                        Objects.Snapshot snapshot = new Snapshot();
                        this.InsertSafe(snapshot);
                        foreach (var z in finalList)
                        {
                            Objects.RecordRef rref = new RecordRef();
                            rref.RecordID   = z.Id;
                            rref.SnapshotID = snapshot.Id;
                            this.InsertSafe(rref);
                        }
                        version.Snapshot = snapshot.Id;
                        this.UpdateSafe(version);
                        Commit();
                    }
                    catch
                    {
                        Rollback();
                    }
                }
                catch
                {
                    // Already in a transaction
                    Objects.Snapshot snapshot = new Snapshot();
                    this.InsertSafe(snapshot);
                    foreach (var z in finalList)
                    {
                        Objects.RecordRef rref = new RecordRef();
                        rref.RecordID   = z.Id;
                        rref.SnapshotID = snapshot.Id;
                        this.InsertSafe(rref);
                    }
                    version.Snapshot = snapshot.Id;
                    this.UpdateSafe(version);
                }
            }
            return(finalList);
        }
Esempio n. 19
0
 public List <Alteration> GetAlterationsForVersion(Objects.Version version)
 {
     return(Query <Alteration>("SELECT * from Alteration WHERE Owner = ?", version.AlterationList));
 }
Esempio n. 20
0
 public GraphNode(Version version, string label, Color color)
 {
     Version = version;
     Label   = label;
     Color   = color;
 }