示例#1
0
        public virtual void Initialize(IJob package = null)
        {
            if (State == TaskState.Init)
            {
                Job = package;
                CheckoutParameters();

                State = TaskState.Pending;
                if (null != Requirements && 0 != Requirements.Length)
                {
                    if (null == package)
                    {
                        throw new Exception("cannot resolve requirements without");
                    }
                    foreach (var requirement in Requirements)
                    {
                        if (requirement.StartsWith("@"))
                        {
                            var groupName = requirement.Substring(1);
                            foreach (var module in package.Tasks.Values)
                            {
                                if (module.Group == groupName)
                                {
                                    if (!RequiredModules.Contains(module))
                                    {
                                        RequiredModules.Add(module);
                                    }
                                }
                            }
                        }
                        else
                        {
                            if (package.Tasks.ContainsKey(requirement))
                            {
                                if (!RequiredModules.Contains(package.Tasks[requirement]))
                                {
                                    RequiredModules.Add(package.Tasks[requirement]);
                                }
                            }
                            else
                            {
                                throw new Exception("cannot resolve dependency from " + Name + " to " + requirement);
                            }
                        }
                    }
                }
            }
        }
示例#2
0
        //    public string Copyright { get; set; }
        //    public object Tags { get; set; }
        //    public string ReleaseNotes { get; set; }
        //    public object RequiredScripts { get; set; }
        //    public object ExternalScriptDependencies { get; set; }
        //    public object LicenseUri { get; set; }
        //    public object ProjectUri { get; set; }
        //    public object IconUri { get; set; }
        //    public object DefinedCommands { get; set; }
        //    public object DefinedFunctions { get; set; }
        //    public object DefinedWorkflows { get; set; }

        public PSScriptInfo(Hashtable definition)
        {
            this.RequiredModules            = new List <RequiredModuleSpecs>();
            this.ExternalModuleDependencies = new string[0];

            foreach (var dk in definition.Keys)
            {
                if (definition[dk] != null)
                {
                    if ("Name".Equals(dk.ToString(), StringComparison.OrdinalIgnoreCase))
                    {
                        Name = LanguagePrimitives.ConvertTo <string>(definition[dk]);
                    }
                    else if ("Version".Equals(dk.ToString(), StringComparison.OrdinalIgnoreCase))
                    {
                        Version = LanguagePrimitives.ConvertTo <Version>(definition[dk]);
                    }
                    else if ("Guid".Equals(dk.ToString(), StringComparison.OrdinalIgnoreCase))
                    {
                        Guid = LanguagePrimitives.ConvertTo <Guid?>(definition[dk]);
                    }
                    else if ("Path".Equals(dk.ToString(), StringComparison.OrdinalIgnoreCase))
                    {
                        Path = LanguagePrimitives.ConvertTo <string>(definition[dk]);
                    }
                    else if ("ScriptBase".Equals(dk.ToString(), StringComparison.OrdinalIgnoreCase))
                    {
                        ScriptBase = LanguagePrimitives.ConvertTo <string>(definition[dk]);
                    }
                    else if ("Description".Equals(dk.ToString(), StringComparison.OrdinalIgnoreCase))
                    {
                        Description = LanguagePrimitives.ConvertTo <string>(definition[dk]);
                    }
                    else if ("Author".Equals(dk.ToString(), StringComparison.OrdinalIgnoreCase))
                    {
                        Author = LanguagePrimitives.ConvertTo <string>(definition[dk]);
                    }
                    else if ("CompanyName".Equals(dk.ToString(), StringComparison.OrdinalIgnoreCase))
                    {
                        CompanyName = LanguagePrimitives.ConvertTo <string>(definition[dk]);
                    }
                    else if ("RequiredModules".Equals(dk.ToString(), StringComparison.OrdinalIgnoreCase))
                    {
                        var reqM = LanguagePrimitives.ConvertTo <Microsoft.PowerShell.Commands.ModuleSpecification[]>(definition[dk]);
                        foreach (var item in reqM)
                        {
                            RequiredModules.Add(new RequiredModuleSpecs(item, null));
                        }
                    }
                    else if ("ExternalModuleDependencies".Equals(dk.ToString(), StringComparison.OrdinalIgnoreCase))
                    {
                        ExternalModuleDependencies = LanguagePrimitives.ConvertTo <string[]>(definition[dk]);
                    }
                    else if ("PrivateData".Equals(dk.ToString(), StringComparison.OrdinalIgnoreCase))
                    {
                        PrivateData = LanguagePrimitives.ConvertTo <string>(definition[dk]);
                    }
                }
            }

            if (String.IsNullOrEmpty(this.Name))
            {
                throw new ArgumentException("Name cannot be blank.");
            }
            if (String.IsNullOrEmpty(this.Path))
            {
                throw new ArgumentException("Path cannot be blank.");
            }
            if (String.IsNullOrEmpty(this.ScriptBase))
            {
                throw new ArgumentException("ScriptBase cannot be blank.");
            }
        }