Exemplo n.º 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);
        }
Exemplo n.º 2
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);
                }
            }
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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();
        }
Exemplo n.º 5
0
        private void RunInternal(Common.CommandLine cmdLine)
        {
            if (cmdLine.GetValue <bool>("/help") || cmdLine.IsEmpty)
            {
                Usage();
                return;
            }

            string prevDirPath = null;

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

            if (!string.IsNullOrEmpty(rootPath))
            {
                prevDirPath = Directory.GetCurrentDirectory();
                Directory.SetCurrentDirectory(rootPath);
            }

            string verb = null;

            try
            {
                PackEngine.Engine engine = new PackEngine.Engine();

                verb = cmdLine.GetValue <string>("/verb", "Build");
                if (verb == "Pack")
                {
                    DoPack(engine, cmdLine);
                }
                else if (verb == "Unpack")
                {
                    DoUnpack(engine, cmdLine);
                }
                else if (verb == "List")
                {
                    DoList(engine, cmdLine);
                }
                else if (verb == "Upload")
                {
                    DoUpload(engine, cmdLine);
                }
                else if (verb == "Download")
                {
                    DoDownload(engine, cmdLine);
                }
                else if (verb == "Delete")
                {
                    DoDelete(engine, cmdLine);
                }
                else
                {
                    throw new ApplicationException("Invalid verb specified");
                }
            }
            finally
            {
                if (!string.IsNullOrEmpty(prevDirPath))
                {
                    Directory.SetCurrentDirectory(prevDirPath);
                }
            }

            if (verb != "List")
            {
                Console.WriteLine("\r\n== Package operation completed successfully.");
            }
        }
Exemplo n.º 6
0
 private void DoDelete(PackEngine.Engine engine, Common.CommandLine cmdLine)
 {
     // ...
 }
Exemplo n.º 7
0
 private void DoDownload(PackEngine.Engine engine, Common.CommandLine cmdLine)
 {
     // ...
 }