Пример #1
0
        private void DoUnpack(PackEngine.Engine engine, Common.CommandLine cmdLine)
        {
            string pathIn = cmdLine.GetValue <string>("/pathIn");

            if (string.IsNullOrEmpty(pathIn))
            {
                throw new ApplicationException("Input path is required");
            }

            string pathOut = cmdLine.GetValue <string>("/pathOut");

            if (string.IsNullOrEmpty(pathOut))
            {
                throw new ApplicationException("Output path is required");
            }

            PackEngine.PackageReader reader = engine.CreatePackageReader(pathIn);

            PackEngine.PackageInfo info = reader.GetInfo();
            if (info == null)
            {
                throw new ApplicationException("The package metadata is invalid");
            }

            pathOut = ReplacePackageInfoWildcards(pathOut, info);

            Console.WriteLine($"== Extracting package \"{info.Name}\".\r\n");

            reader.Extract(pathOut);
        }
Пример #2
0
        private void PrintPackage(PackEngine.PackageInfo package, int dupeCount = 0)
        {
            if (package == null)
            {
                return;
            }

            string dupeStr = dupeCount > 0 ? $" (+{dupeCount} older)" : string.Empty;

            Console.WriteLine($"{package.Name} {package.Version.ToString(4)}");
        }
Пример #3
0
        public PackEngine.PackageInfo WritePackage(Stream stream, out string storeFileName)
        {
            string tempStoreName = Path.Combine(TempDirName, Guid.NewGuid().ToString());

            using (Stream tempStream = WritePackage(tempStoreName))
                stream.CopyTo(tempStream);

            string tempStorePath  = Path.Combine(_storeRoot, tempStoreName);
            string finalStorePath = null;

            try
            {
                PackEngine.Engine        packEngine = new PackEngine.Engine();
                PackEngine.PackageReader reader     = packEngine.CreatePackageReader(tempStorePath);
                PackEngine.PackageInfo   info       = reader.GetInfo();
                if (info == null || !info.IsValid())
                {
                    throw new ApplicationException("Invalid package");
                }

                storeFileName  = MakeStoreFileName(info.Name, info.Version);
                finalStorePath = Path.Combine(_storeRoot, storeFileName);

                if (File.Exists(finalStorePath))
                {
                    File.Delete(finalStorePath);
                }

                (new FileInfo(finalStorePath)).Directory.Create();

                File.Move(tempStorePath, finalStorePath);

                return(info);
            }
            catch
            {
                if (finalStorePath != null && File.Exists(finalStorePath))
                {
                    File.Delete(finalStorePath);
                }

                storeFileName = null;

                return(null);
            }
            finally
            {
                if (File.Exists(tempStorePath))
                {
                    File.Delete(tempStorePath);
                }
            }
        }
Пример #4
0
        private void DoList(PackEngine.Engine engine, Common.CommandLine cmdLine)
        {
            string serverURI = cmdLine.GetValue <string>("/serverURI");

            if (string.IsNullOrEmpty(serverURI))
            {
                throw new ApplicationException("Server URI is required");
            }

            string name       = cmdLine.GetValue <string>("/name");
            string version    = cmdLine.GetValue <string>("/version");
            int    maxResults = cmdLine.GetValue <int>("/maxResults", -1);

            PackEngine.PackageManager packageManager = engine.CreatePackageManager(serverURI);

            List <PackEngine.PackageInfo> packages = packageManager.ListPackages(name, version, maxResults);

            PackEngine.PackageInfo first = null;
            int dupeCount = 0;

            foreach (PackEngine.PackageInfo package in packages)
            {
                if (first == null)
                {
                    first = package;
                }
                else if (first.Name == package.Name)
                {
                    ++dupeCount;
                }
                else
                {
                    PrintPackage(first, dupeCount);

                    first     = package;
                    dupeCount = 0;
                }
            }

            PrintPackage(first, dupeCount);
        }
Пример #5
0
        private void DoPack(PackEngine.Engine engine, Common.CommandLine cmdLine)
        {
            string pathIn = cmdLine.GetValue <string>("/pathIn");

            if (string.IsNullOrEmpty(pathIn))
            {
                throw new ApplicationException("Input path is required");
            }

            string pathOut = cmdLine.GetValue <string>("/pathOut");

            if (string.IsNullOrEmpty(pathOut))
            {
                throw new ApplicationException("Output path is required");
            }

            string  versionStr = cmdLine.GetValue <string>("/version", "1.0.0.0");
            Version version    = null;

            if (!Version.TryParse(versionStr, out version))
            {
                throw new ApplicationException($"Invalid version string \"{versionStr}\"");
            }

            PackEngine.PackageInfo info = new PackEngine.PackageInfo();
            info.Name    = cmdLine.GetValue <string>("/name", Path.GetFileNameWithoutExtension(pathOut));
            info.Version = version;

            pathIn  = ReplacePackageInfoWildcards(pathIn, info);
            pathOut = ReplacePackageInfoWildcards(pathOut, info);

            Console.WriteLine($"== Creating package \"{info.Name}\".\r\n");

            PackEngine.PackageWriter writer = engine.CreatePackageWriter(pathOut, info);
            writer.AddFolder(pathIn, string.Empty);
            writer.Save();
        }
Пример #6
0
        public bool AddPackage(Stream stream)
        {
            lock (_guard)
            {
                string storeFileName = null;

                try
                {
                    PackEngine.PackageInfo info = _store.WritePackage(stream, out storeFileName);
                    if (info == null || !info.IsValid() || string.IsNullOrEmpty(storeFileName))
                    {
                        throw new ApplicationException("Failed to handle the package");
                    }

                    if (_index.GetEntry(info.Name, info.Version.ToString()) != null)
                    {
                        return(false);
                    }

                    _index.AddEntry(new PackageIndex.Entry {
                        Info = info, StoreFileName = storeFileName
                    });
                }
                catch
                {
                    if (!string.IsNullOrEmpty(storeFileName))
                    {
                        _store.DeletePackage(storeFileName);
                    }

                    throw;
                }
            }

            return(true);
        }
Пример #7
0
 internal Entry()
 {
     Info = new PackEngine.PackageInfo();
 }
Пример #8
0
 private string ReplacePackageInfoWildcards(string str, PackEngine.PackageInfo info)
 {
     return(str.Replace("{PackageName}", info.Name).Replace("{PackageVersion}", info.Version.ToString()));
 }