Ejemplo n.º 1
0
        public IHttpContext TagJournal(IHttpContext context)
        {
            try
            {
                Printer.PrintMessage($"Rest Begin {context.Request.Url} #{context.Request.Id}");
                int maxResults = 0;
                int startAt    = 0;
                if (!int.TryParse(context.Request.QueryString["maxResults"], out maxResults))
                {
                    maxResults = 50;
                }
                if (!int.TryParse(context.Request.QueryString["startAt"], out startAt))
                {
                    startAt = 0;
                }

                RestTagJournalList restTagJournalList = new RestTagJournalList()
                {
                    maxResults = maxResults, startAt = startAt
                };

                using (Area ws = Area.Load(Info, true, true))
                {
                    if (ws != null)
                    {
                        var tagJournalList = ws.GetTagJournalTimeOrder().Skip(startAt).Take(maxResults + 1).ToList();
                        restTagJournalList.isLast = tagJournalList.Count <= maxResults;
                        if (!restTagJournalList.isLast)
                        {
                            tagJournalList.RemoveAt(tagJournalList.Count - 1);
                        }
                        restTagJournalList.total = tagJournalList.Count;
                        foreach (var tagJournalEntry in tagJournalList)
                        {
                            var restVersion = RestVersion.FromVersion(ws, ws.GetVersion(tagJournalEntry.Version));
                            // Some versions may not have replicated, soz.
                            if (restVersion == null)
                            {
                                continue;
                            }
                            restTagJournalList.tagjournals.Add(new RestTagJournalEntry()
                            {
                                version  = restVersion,
                                removing = tagJournalEntry.Removing,
                                value    = tagJournalEntry.Value,
                                time     = tagJournalEntry.Time.ToProperTimeStamp(),
                            });
                        }
                    }

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

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

                return(context);
            }
            finally
            {
                Printer.PrintMessage($"Rest Query Retired #{context.Request.Id}");
            }
        }
Ejemplo n.º 2
0
        public IHttpContext Versions(IHttpContext context)
        {
            try
            {
                Printer.PrintMessage($"Rest Begin {context.Request.Url} #{context.Request.Id}");
                int maxResults = 0;
                int startAt    = 0;
                if (!int.TryParse(context.Request.QueryString["maxResults"], out maxResults))
                {
                    maxResults = 50;
                }
                if (!int.TryParse(context.Request.QueryString["startAt"], out startAt))
                {
                    startAt = 0;
                }
                string filterByBranchName = context.Request.QueryString["branch"] ?? string.Empty;

                RestVersionList restVersionList = new RestVersionList()
                {
                    maxResults = maxResults, startAt = startAt
                };

                using (Area ws = Area.Load(Info, true, true))
                {
                    if (ws != null)
                    {
                        Branch branch    = null;
                        bool   noResults = false;
                        if (!string.IsNullOrWhiteSpace(filterByBranchName))
                        {
                            branch    = ws.Branches.Where(x => x.Name == filterByBranchName).FirstOrDefault();
                            noResults = branch == null;
                        }

                        if (!noResults)
                        {
                            // ws.GetVersions should be in date descending order
                            // Getting one extra so we can see if we have got all entries
                            var versions = ws.GetVersions(branch, maxResults + startAt + 1).Skip(startAt).ToList();
                            restVersionList.isLast = versions.Count <= maxResults;
                            if (!restVersionList.isLast)
                            {
                                versions.RemoveAt(versions.Count - 1);
                            }
                            restVersionList.total = versions.Count;
                            foreach (var version in versions)
                            {
                                restVersionList.versions.Add(RestVersion.FromVersion(ws, version));
                            }
                        }
                    }

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

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

                return(context);
            }
            finally
            {
                Printer.PrintMessage($"Rest Query Retired #{context.Request.Id}");
            }
        }