コード例 #1
0
ファイル: XWorkstation.cs プロジェクト: fairyfingers/CKli
 public EnvVar(XElementReader r, bool valueRequired)
 {
     Name  = r.HandleRequiredAttribute <string>("Name");
     Value = valueRequired
                 ? r.HandleRequiredAttribute <string>("Value")
                 : r.HandleOptionalAttribute <string>("Value", null);
 }
コード例 #2
0
        public XTypedObject CreateInstance(IActivityMonitor monitor, XElement e, IServiceProvider baseProvider = null, Type type = null)
        {
            using (monitor.OpenDebug($"Creating XTypedObject from root {e.ToStringPath()}."))
            {
                if (e == null)
                {
                    throw new ArgumentNullException(nameof(e));
                }
                if (monitor == null)
                {
                    throw new ArgumentNullException(nameof(monitor));
                }
                if (_typeRegister.Count == 0)
                {
                    AutoRegisterFromLoadedAssemblies(monitor);
                }

                e.Changing += PreventAnyChangesToXElement;
                var eReader = new XElementReader(monitor, e, new HashSet <XObject>());

                if (type == null)
                {
                    type = GetMappping(eReader);
                }
                var rootConfig = new XTypedObject.Initializer(this, eReader, baseProvider);
                var root       = (XTypedObject)baseProvider.SimpleObjectCreate(monitor, type, rootConfig);
                var result     = root != null && CreateChildren(root, rootConfig) ? root : null;
                if (result != null)
                {
                    eReader.WarnUnhandledAttributes();
                }
                return(result);
            }
        }
コード例 #3
0
        public Type GetMappping(XElementReader r)
        {
            var t = GetNameMappping(r.Element.Name);

            if (t == null)
            {
                r.WarnUnhandledElements();
            }
            else
            {
                r.Handle(r.Element);
            }
            return(t);
        }
コード例 #4
0
ファイル: NPMProjectSpec.cs プロジェクト: fairyfingers/CKli
 internal NPMProjectSpec(XElementReader r)
 {
     IsPrivate    = r.HandleOptionalAttribute(nameof(IsPrivate), false);
     Folder       = new NormalizedPath(r.HandleRequiredAttribute <string>(nameof(Folder))).With(NormalizedPathRootKind.None);
     PackageName  = HandlePackageName(r.HandleOptionalAttribute(nameof(PackageName), ""));
     OutputFolder = r.HandleRequiredAttribute <string>(nameof(OutputFolder));
     if (Folder.IsRooted)
     {
         throw new InvalidDataException("Path cannot be rooted.");
     }
     if (OutputFolder.IsRooted)
     {
         throw new InvalidDataException("Path cannot be rooted.");
     }
 }
コード例 #5
0
ファイル: XWorkstation.cs プロジェクト: fairyfingers/CKli
        void HandleScriptElement(XElementReader r)
        {
            var p = r.HandleOptionalAttribute("Platform", (PlatformID)0);

            if (p != (PlatformID)0 && p != Environment.OSVersion.Platform)
            {
                r.Monitor.Info($"Skipping one script since Platform is '{p}' (current is '{Environment.OSVersion.Platform}').");
            }
            else
            {
                var w = new NormalizedPath(r.HandleOptionalAttribute("WorkingDir", String.Empty));
                if (w.IsRooted)
                {
                    r.ThrowXmlException($"WorkingDir attribute must be a relative path: '{w}' is rooted.");
                }
                w = _fileSystem.Root.Combine(w).ResolveDots(_fileSystem.Root.Parts.Count);
                var    t = r.HandleOptionalAttribute("Type", ScriptType.PS1);
                var    a = r.HandleOptionalAttribute("Arguments", String.Empty);
                var    c = r.HandleOptionalAttribute("ContinueOnNonZeroExitCode", false);
                string script;
                var    url = r.HandleOptionalAttribute <string>("Url", null);
                if (url != null)
                {
                    script = $@"
$Script = Invoke-WebRequest '{url}'
$ScriptBlock = [Scriptblock]::Create($Script.Content)
Invoke-Command -ScriptBlock $ScriptBlock";
                    if (a.Length > 0)
                    {
                        script += $" -ArgumentList ($args + @('{a}'))";
                    }
                    a = String.Empty;
                    if (!String.IsNullOrEmpty(r.Element.Value))
                    {
                        r.ThrowXmlException("Script element must be empty when Url attribute is used.");
                    }
                }
                else
                {
                    script = r.Element.Value;
                }
                _scripts.Add(new ScriptLine(script, t, p, w, a, c));
            }
        }
コード例 #6
0
ファイル: SimpleCredentials.cs プロジェクト: CK-Build/CKli
        /// <summary>
        /// Initializes a new <see cref="SimpleCredentials"/> from its xml representation
        /// that must have a UserName attribute and Password or PasswordSecretKeyName (but not both).
        /// </summary>
        /// <param name="r">The xml element reader.</param>
        public SimpleCredentials(XElementReader r)
        {
            UserName = r.HandleRequiredAttribute <string>("UserName");
            var  p    = r.HandleOptionalAttribute <string>("Password", null);
            var  k    = r.HandleOptionalAttribute <string>("PasswordSecretKeyName", null);
            bool hasP = !String.IsNullOrEmpty(p);
            bool hasK = !String.IsNullOrEmpty(k);

            if (hasP && hasK)
            {
                throw new ArgumentException($"Credential element '{r.Element}' can not specify both Password and PasswordSecretKeyName attributes.");
            }
            if (hasP || hasK)
            {
                PasswordOrSecretKeyName = hasP ? p : k;
                IsSecretKeyName         = hasK;
            }
            r.WarnUnhandled();
        }
コード例 #7
0
 internal AngularWorkspaceSpec(XElementReader r)
 {
     Path         = r.HandleRequiredAttribute <NormalizedPath>(nameof(Path));
     OutputFolder = r.HandleRequiredAttribute <NormalizedPath>(nameof(OutputFolder));
 }