private Task ProcessContainerIndex(HttpContext context, int packageIndex)
        {
            string[] allVersions = MasterData.Use(packageIndex, (packages, _, _packageIndex) =>
            {
                return(packages[_packageIndex].Versions
                       .Select(x => x.Version.ToString())
                       .ToArray());
            });

            string json = JsonConvert.SerializeObject(new { versions = allVersions }, Formatting.None);

            context.Response.StatusCode  = 200;
            context.Response.ContentType = "application/json";
            return(context.Response.WriteAsync(json, Encoding.UTF8));
        }
        private async Task ProcessContainerVersion(HttpContext context, int packageIndex, Version version)
        {
            lock (Globals.ConsoleLock)
                Console.WriteLine($"ProcessContainerVersion [version: {version}]");

            byte[] content = MasterData.Use(packageIndex, version, (packages, contentFacade, _packageIndex, _version) =>
            {
                VersionInfo[] versions = packages[_packageIndex].Versions;

                for (int i = 0; i < versions.Length; i++)
                {
                    if (versions[i].Version == _version)
                    {
                        byte[] result;
                        if (contentFacade.TryGetValue(versions[i].ContentId, out result))
                        {
                            return(result);
                        }
                    }
                }

                return(null);
            });

            if (content != null)
            {
                context.Response.StatusCode  = 200;
                context.Response.ContentType = "application/octet-stream";
                await context.Response.Body.WriteAsync(content, 0, content.Length);

                return;
            }

            context.Response.StatusCode = 404;
            lock (Globals.ConsoleLock)
                Console.WriteLine($"ContainerVersion: return {context.Response.StatusCode}");
        }
Example #3
0
        private async Task ProcessDownload(HttpContext context, string downloadPath)
        {
            byte[] content = MasterData.Use(downloadPath, (packageInfo, contentFacade, _downloadPath) =>
            {
                byte[] _content;
                if (contentFacade.TryGetValue(_downloadPath.TrimStart(Characters.UrlPathSeparator), out _content))
                {
                    return(_content);
                }
                return(null);
            });

            if (content == null)
            {
                context.Response.StatusCode = 404;
                lock (Globals.ConsoleLock)
                    Console.WriteLine($"Download: return {context.Response.StatusCode}");
                return;
            }

            context.Response.StatusCode  = 200;
            context.Response.ContentType = "application/octet-stream";
            await context.Response.Body.WriteAsync(content, 0, content.Length);
        }
Example #4
0
        private async Task FindPackage(HttpContext context)
        {
            var strings = context.Request.Query["id"];

            if (strings.Count == 0)
            {
                context.Response.StatusCode = 400;
                lock (Globals.ConsoleLock)
                    Console.WriteLine($"Find: return {context.Response.StatusCode}");
                return;
            }

            var id = strings[0].Trim(Characters.SingleQuote);

            if (id.Length == 0)
            {
                context.Response.StatusCode = 400;
                lock (Globals.ConsoleLock)
                    Console.WriteLine($"Find: return {context.Response.StatusCode}");
                return;
            }

            VersionInfo[] versions = MasterData.Use(id, (packages, _, _id) =>
            {
                foreach (var packageInfo in packages)
                {
                    if (string.Equals(packageInfo.Id, _id, StringComparison.OrdinalIgnoreCase))
                    {
                        return(packageInfo.Versions);
                    }
                }
                return(null);
            });

            if (versions == null)
            {
                versions = Globals.EmptyVersionInfoArray;
            }
            else
            {
                lock (Globals.ConsoleLock)
                {
                    Console.WriteLine();
                    Console.WriteLine("--- Find -------------------------------------");
                    foreach (var v in versions)
                    {
                        Console.WriteLine($"{id} - {v.Version}");
                    }
                    Console.WriteLine("----------------------------------------------");
                    Console.WriteLine();
                }
            }

            var doc = new XElement(
                XmlElements.feed,
                new XAttribute(XmlElements.baze, XmlNamespaces.baze),
                new XAttribute(XmlElements.m, XmlNamespaces.m),
                new XAttribute(XmlElements.d, XmlNamespaces.d),
                new XAttribute(XmlElements.georss, XmlNamespaces.georss),
                new XAttribute(XmlElements.gml, XmlNamespaces.gml),
                new XElement(XmlElements.m_count, versions.Length.ToString()),
                versions.Select(x =>
                                new XElement(
                                    XmlElements.entry,
                                    new XElement(XmlElements.id, $"{context.Request.Scheme}://{context.Request.Host}{Segment}/Packages(Id='{id}',Version='{x.Version}')"),
                                    new XElement(
                                        XmlElements.content,
                                        new XAttribute("type", "application/zip"),
                                        new XAttribute("src", $"{context.Request.Scheme}://{context.Request.Host}{Segment}/download/{x.ContentId}")
                                        ),
                                    new XElement(
                                        XmlElements.m_properties,
                                        new XElement(XmlElements.d_id, id),
                                        new XElement(XmlElements.d_version, x.Version)
                                        )
                                    )
                                )
                );

            versions = null;

            var bytes = Encoding.UTF8.GetBytes(doc.ToString(SaveOptions.DisableFormatting));

            context.Response.StatusCode  = 200;
            context.Response.ContentType = "application/xml";
            await context.Response.Body.WriteAsync(bytes, 0, bytes.Length);
        }
Example #5
0
 private Task ProcessSearch(HttpContext context)
 {
     return(MasterData.Use(context, ProcessSearchSafe));
 }