Ejemplo n.º 1
0
        protected override void ProcessRecord()
        {
            CartridgeRepository repository = CartridgeRepository.Instance;

            foreach (string path in Directory.GetDirectories(NodeConfig.Values["CARTRIDGE_BASE_PATH"]))
            {
                try
                {
                    Manifest manifest = repository.Install(path);
                    Logger.Info("Installed cartridge ({0}, {1}, {2}, {3}) from {4}", manifest.CartridgeVendor, manifest.Name, manifest.Version, manifest.CartridgeVersion, path);
                }
                catch (Exception e)
                {
                    Logger.Warning("Failed to install cartridge from {0}. {1}", path, e.ToString());
                }
            }
        }
Ejemplo n.º 2
0
        public ReturnStatus Execute()
        {
            ReturnStatus returnStatus = new ReturnStatus();

            CartridgeRepository repository = CartridgeRepository.Instance;

            if (string.IsNullOrEmpty(Action))
            {
                returnStatus.Output   = "Usage: --action ACTION [--recursive] [--source directory] [--name NAME --version VERSION --cartridge_version VERSION]";
                returnStatus.ExitCode = 1;
                return(returnStatus);
            }

            try
            {
                switch (Action.ToLower())
                {
                case "install":
                {
                    string[] dirs = null;
                    if (Recursive)
                    {
                        Directory.GetDirectories(Source);
                    }
                    else
                    {
                        dirs = new string[] { Source };
                    }

                    bool success = true;

                    foreach (string dir in dirs)
                    {
                        try
                        {
                            repository.Install(dir);
                        }
                        catch (Exception e)
                        {
                            success = false;
                            Console.Error.WriteLine(string.Format("install failed for {0}: {1}", dir, e.Message));
                            if (D)
                            {
                                Console.Error.WriteLine(e.StackTrace);
                            }
                        }
                    }

                    if (success)
                    {
                        returnStatus.Output = "succeeded";
                    }
                    else
                    {
                        returnStatus.Output = "installation failed";
                    }

                    break;
                }

                case "erase":
                {
                    try
                    {
                        repository.Erase(Name, Version, CartridgeVersion);
                        returnStatus.Output = "succeeded";
                    }
                    catch (KeyNotFoundException e)
                    {
                        returnStatus.Output = "requested cartridge does not exist: " + e.ToString();
                    }
                    catch (Exception e)
                    {
                        returnStatus.Output = "Couldn't erase cartridge: " + e.ToString();
                    }

                    break;
                }

                case "list":
                {
                    if (D)
                    {
                        returnStatus.Output = repository.Inspect();
                    }
                    else
                    {
                        returnStatus.Output = repository.ToString();
                    }
                    break;
                }

                default:
                {
                    break;
                }
                }
                returnStatus.ExitCode = 0;
            }
            catch (Exception ex)
            {
                returnStatus.ExitCode = 1;
                returnStatus.Output   = ex.Message;
                if (D)
                {
                    Console.Error.WriteLine(ex.ToString());
                }
            }

            return(returnStatus);
        }