Exemplo n.º 1
0
        public PackageInfo GetInfo()
        {
            if (_info != null)
            {
                return(_info);
            }

            try
            {
                string json = null;

                using (ZipArchive archive = new ZipArchive(new FileStream(_path, FileMode.Open), ZipArchiveMode.Read))
                {
                    ZipArchiveEntry metadataEntry = archive.Entries.Where((ZipArchiveEntry e) => e.FullName == PackageInfo.FileName).First();

                    using (Stream stream = metadataEntry.Open())
                    {
                        using (StreamReader reader = new StreamReader(stream))
                        {
                            json = reader.ReadToEnd();
                        }
                    }
                }

                JavaScriptSerializer        serializer = new JavaScriptSerializer();
                Dictionary <string, object> root       = serializer.Deserialize <Dictionary <string, object> >(json);
                _info = PackageInfoSerializer.Deserialize(root);
            }
            catch (Exception)
            {
                return(null);
            }

            return(_info);
        }
Exemplo n.º 2
0
        private void SaveMetadata()
        {
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            string json = serializer.Serialize(PackageInfoSerializer.Serialize(_info));

            File.WriteAllText(Path.Combine(_tmpFolder, PackageInfo.FileName), json);
        }
Exemplo n.º 3
0
        public List <PackageInfo> ListPackages(string name = null, string version = null, int maxResults = -1)
        {
            string separator = null;
            string query     = "packages/list" + PackNameAndVersionQuery(name, version, ref separator);

            query += $"{separator}limit={maxResults}";

            string json = _client.DownloadString(_client.BaseAddress + query);

            JavaScriptSerializer        serializer = new JavaScriptSerializer();
            Dictionary <string, object> root       = serializer.Deserialize <Dictionary <string, object> >(json);

            return(PackageInfoSerializer.Deserialize(Common.JSON.GetJSONValue <ArrayList>(root, "packages", null)));
        }