Пример #1
0
        private bool AddModule(Packages.Package pkg, IModule module)
        {
            if (pkg.Modules.Any(m => m.Name.Equals(module.Name, StringComparison.OrdinalIgnoreCase)))
            {
                base.Out.Warning.WriteLine(string.Format("A module with the name '{0}' has already been added. The module will not be added.", module.Name));
            }
            else if (pkg.Modules.Any(m => m.ModuleType == module.GetType().FullName))
            {
                base.Out.Warning.WriteLine(string.Format("A module of type '{0}' has already been added. The module will not be added.", module.GetType()));
            }
            else
            {
                if (base.Host.Modules.Any(m => m.Name.Equals(module.Name, StringComparison.OrdinalIgnoreCase)))
                {
                    base.Out.Warning.WriteLine(string.Format("A module with the name '{0}' is already installed. The package may not laod correctly now that this module is added.", module.Name));
                }
                else if (base.Host.Modules.Any(m => m.GetType() == module.GetType()))
                {
                    base.Out.Warning.WriteLine(string.Format("A module of type '{0}' is already installed. The package may not load correctly now that this module is added.", module.GetType()));
                }

                pkg.Modules.Add(new PackageModule()
                {
                    Assembly   = Assembly,
                    ModuleType = module.GetType().FullName,
                    Name       = module.Name
                });

                return(true);
            }

            return(false);
        }
        public override void Invoke(CommandInvocationContext context)
        {
            if (PackageLogic.Instance.PackagesCollection.Packages
                .Exists(e => e.Name.Equals(Name, StringComparison.OrdinalIgnoreCase)))
            {
                base.Out.Warning.WriteLine(string.Format("The package name '{0}' is already being used by another package", Name));
            }
            else
            {
                var newPkg = new Packages.Package()
                {
                    Name = Name
                };

                PackageLogic.Instance.PackagesCollection.Packages.Add(newPkg);
                PackageLogic.Instance.Save();

                base.Out.Object.Write(TableRecords.CreatePackageRecordList(newPkg));
            }
        }