internal AuthoredInstallEnvironment Clone() { AuthoredInstallEnvironment clone = componentEnvironment.ConfigureInlineComponent(cloneComponentDefinition) as AuthoredInstallEnvironment; clone.SourcePath = SourcePath; clone.DestinationPath = DestinationPath; clone.commandsToExecute = new List <ICommand>(commandsToExecute); clone.destinationFileLists = new Dictionary <string, List <InstallDestination> >(destinationFileLists); clone.sourceFileLists = new Dictionary <string, List <InstallSource> >(sourceFileLists); return(clone); }
private static object ConfigureComponentWithRequirements( IRequiresConfiguration requiredConfiguration, IComponentConfiguration configuration, IComponentDirectory componentDirectory) { // 3. fill in the other parameters from the component directory foreach (IRequirement req in requiredConfiguration.Requirements) { // Console.Out.WriteLine(">> Requirement: {0}", req.Name); if (configuration.Values.ContainsKey(req.Name)) { // Console.Out.WriteLine(" ... Contains Key"); req.SetValue(configuration.Values[req.Name].GetInstance(req.Type)); } else { if (req.Default != null) { // Console.Out.WriteLine(" ... Has Default"); // NEW CONFIGURED COMPONENT THAT IS req.SetValue( componentDirectory.ConfigureInlineComponent( new Instance( req.Default.GetInstance(req.Type)))); } else if (HasComponent(componentDirectory, req.Type)) { // Console.Out.WriteLine(" ... Setting By ICD"); req.SetValue(componentDirectory.GetInstanceByType(req.Type)); } else if (req.Hard) { throw new ComponentConfigurationException( null, String.Format("ComponentOS KERNEL PANIC! I have no value for: {0}", req.Name)); } } } if (requiredConfiguration.Instance is IComponentPostInitialization) { (requiredConfiguration.Instance as IComponentPostInitialization).PostComponentInit(componentDirectory); } return(requiredConfiguration.Instance); }
internal static AuthoredPackage LoadFromXML(XmlDocument doc, IComponentDirectory environment, string srcUrl) { /** let's load our stuff **/ XmlElement ipackageNode = doc["InstallPackage"] as XmlElement; if (new Version(ipackageNode.GetAttribute("xversion")) > expectedVersion) { throw new UnsupportedPackageFormatException("Expected xversion " + expectedVersion); } AuthoredPackage package = environment.ConfigureInlineComponent(authoredPackageProvider) as AuthoredPackage; package.name = ipackageNode.GetAttribute("name"); package.id = new Guid(ipackageNode.GetAttribute("id")); package.publisherName = ipackageNode.GetAttribute("publisher"); package.sourceLocation = srcUrl; // package.environment = new AuthoredInstallEnvironment(package); package.environment.LoadFromXML(doc); /** commands **/ if (ipackageNode["PreInstallCheck"] != null) { ImportCommands(ipackageNode["PreInstallCheck"], package.preInstallCheck, environment); } if (ipackageNode["Installation"] != null) { ImportCommands(ipackageNode["Installation"], package.installation, environment); } if (ipackageNode["PreUninstallCheck"] != null) { ImportCommands(ipackageNode["PreUninstallCheck"], package.preUninstallCheck, environment); } if (ipackageNode["Uninstallation"] != null) { ImportCommands(ipackageNode["Uninstallation"], package.uninstallation, environment); } return(package); }
public virtual object GetInstance( IComponentDirectory componentDirectory, object clientInstance, string requirementName, string requirementType) { ComponentDirectory = componentDirectory; { object instance = requiredConfiguration.Instance; if (instance != null) { return(instance); } } // 1. compute the best pre-initializer to use int currentScore = 0; int maxScore = Int32.MinValue; IRequiresConfiguration currentInitializer = null; foreach (IRequiresConfiguration initializer in requiredConfiguration.PreInitializers) { // Console.Out.WriteLine("Initializer..."); currentScore = 0; bool canUse = true; foreach (IRequirement req in initializer.Requirements) { if (req.Default == null) { /* find the value */ if (configuration.Values.ContainsKey(req.Name)) { currentScore++; } else if (HasComponent(componentDirectory, req.Type)) { currentScore++; } else if (req.Hard) { /* DEBUG: Console.Out.WriteLine("Missing Parameter: {0} {1}", req.Type, req.Name); */ if (req.Hard) { canUse = false; break; } } else { currentScore--; } } } if (canUse && (currentScore > maxScore)) { currentInitializer = initializer; maxScore = currentScore; } } // 1.1 give up if no pre-initializer can be used (because of unfulfillable hard requirements) if (currentInitializer == null) { throw new ComponentConfigurationException(this, "The component cannot be instantiated; No compatible pre-initializer exists"); } // 1.2 give up if after pre-initialization, the object cannot be used (because of unfulfillable hard requirements) foreach (IRequirement req in requiredConfiguration.Requirements) { if (req.Default == null && req.Hard) { /* if it's been solved through a pre-initializer */ bool found = false; foreach (IRequirement reqpre in currentInitializer.Requirements) { if (reqpre.Name == req.Name) { found = true; break; } } if (!found) { if (!req.ValueTypesOnly) { // query the ICD by type if (HasComponent(componentDirectory, req.Type)) { continue; } } throw new ComponentConfigurationException( this, String.Format( "The component cannot be instantiated; After pre-initialization, the {0} requirement is not satisfied", req.Name)); } } } // 2. fill in the pre-initializer foreach (IRequirement req in currentInitializer.Requirements) { // Console.Out.WriteLine(">> PreInitializer Requirement: {0}", req.Name); if (configuration.Values.ContainsKey(req.Name)) { // Console.Out.WriteLine(" ... Contains Key"); req.SetValue(configuration.Values[req.Name].GetInstance(req.Type)); } else { if (req.Default != null) { // Console.Out.WriteLine(" ... Has Default"); req.SetValue( componentDirectory.ConfigureInlineComponent( new Instance( req.Default.GetInstance(req.Type)))); } else if (HasComponent(componentDirectory, req.Type)) { // Console.Out.WriteLine(" ... Setting By ICD (type={0})", req.Type); req.SetValue(componentDirectory.GetInstanceByType(req.Type)); } else if (req.Hard) { throw new ComponentConfigurationException( this, String.Format("ComponentOS KERNEL PANIC! I have no value for: {0}", req.Name)); } } } requiredConfiguration.Preinitialize(currentInitializer); return(ConfigureComponentWithRequirements(requiredConfiguration, configuration, componentDirectory)); }
public override int Start(string verb, string[] arguments) { XmlDocument document = new XmlDocument(); XmlNode results = document.CreateElement("TestRunResults"); document.AppendChild(results); try { if (mode == TestRunMode.Classes) { foreach (string testSuite in arguments) { // Creates a test suite element. XmlNode testSuiteNode = document.CreateElement("TestSuite"); results.AppendChild(testSuiteNode); // The type. XmlAttribute attType = document.CreateAttribute("Type"); attType.Value = testSuite; testSuiteNode.Attributes.Append(attType); // We check for correctness. Type type = Type.GetType(testSuite); if (type == null || type.GetCustomAttributes(typeof(TestSuiteAttribute), true).Length == 0) { OutputError("Test suite {0} does not exist or is not a test suite (not [TestSuite] attribute)", testSuite); // We signal attribute. XmlAttribute att = document.CreateAttribute("Error"); att.Value = "Test suite does not exist or is not marked with TestSuiteAttribute"; testSuiteNode.Attributes.Append(att); continue; } // We now obtain an instance of test suite through configuration. object testSuiteInstance = componentDirectory.ConfigureInlineComponent( new ConfiguredComponent(type.FullName)); // We now call all tests. foreach (MethodInfo method in type.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)) { RunTest(method, document, testSuiteNode, testSuite, testSuiteInstance); } } } else if (mode == TestRunMode.Assemblies) { foreach (string asmName in arguments) { // Creates a test suite element. XmlNode assemblyNode = document.CreateElement("Assembly"); results.AppendChild(assemblyNode); // The type. XmlAttribute attFullName = document.CreateAttribute("FullName"); attFullName.Value = asmName; assemblyNode.Attributes.Append(attFullName); Assembly asm = Assembly.Load(new AssemblyName(asmName)); if (asm == null) { OutputError("Assembly {0} failed to load", asmName); // We signal attribute. XmlAttribute att = document.CreateAttribute("Error"); att.Value = "Assembly failed to load"; assemblyNode.Attributes.Append(att); continue; } // check all types that all TSd foreach (Type type in asm.GetTypes()) { if (type.GetCustomAttributes(typeof(TestSuiteAttribute), true).Length == 0) { continue; } // Creates a test suite element. XmlNode testSuiteNode = document.CreateElement("TestSuite"); assemblyNode.AppendChild(testSuiteNode); // The type. XmlAttribute attType = document.CreateAttribute("Type"); attType.Value = type.FullName; testSuiteNode.Attributes.Append(attType); // We now obtain an instance of test suite through configuration. object testSuiteInstance = componentDirectory.ConfigureInlineComponent( new ConfiguredComponent(type.FullName)); // We now call all tests. foreach (MethodInfo method in type.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)) { RunTest(method, document, testSuiteNode, type.FullName, testSuiteInstance); } } } } else { } } finally { // We serialize report. document.Save(console.Out); // to the node if (reportNode != null) { Node <object> node = this.database.Find <object>(reportNode); if (node == null) { OutputError("The report node path {0} does not exist, could not write the report", reportNode); } else { } } } return(0); }
private static void ImportCommands(XmlElement xmlElement, List <ICommand> list, IComponentDirectory componentEnvironment) { foreach (XmlNode node in xmlElement.ChildNodes) { if (!(node is XmlElement)) { continue; } XmlElement cmdElement = node as XmlElement; try { string asmName = "assembly"; string asm = "SharpMedia"; string nspName = "namespace"; string nsp = "SharpMedia.Components.Installation.Commands"; if (cmdElement.HasAttribute(asmName)) { asm = cmdElement.GetAttribute(asmName); } if (cmdElement.HasAttribute(nspName)) { nsp = cmdElement.GetAttribute(nspName); } /* fix the instance */ object instance = componentEnvironment.ConfigureInlineComponent( new ConfiguredComponent( String.Format("{0}.{1},{2}", nsp, cmdElement.Name, asm), new StandardConfiguration(cmdElement))); foreach (XmlAttribute attrib in cmdElement.Attributes) { if (attrib.Name == asmName || attrib.Name == nspName) { continue; } PropertyInfo pinfo = instance.GetType().GetProperty(attrib.Name); if (pinfo == null) { throw new Exception(String.Format("Command {0} does not support the {1} parameter", instance.GetType(), attrib.Name)); } if (!pinfo.PropertyType.IsArray) { pinfo.SetValue(instance, attrib.Value, null); } else { pinfo.SetValue(instance, attrib.Value.Split(','), null); } } list.Add(instance as ICommand); } catch (Exception e) { throw new UnsupportedPackageFormatException("Command " + cmdElement.Name + " did not read properly", e); } } }