示例#1
0
        private EvaluationResult HasMount(Context context, ModuleLiteral env, EvaluationStackFrame args)
        {
            var engine = context.FrontEndHost.Engine;
            var name   = Convert.ToString(args[0].Value, CultureInfo.InvariantCulture);

            GetProvenance(context, out AbsolutePath path, out LineInfo lineInfo);

            var result = engine.TryGetMount(name, "Script", AmbientTypes.ScriptModuleId, out IMount mount);

            switch (result)
            {
            case TryGetMountResult.Success:
                return(EvaluationResult.True);

            case TryGetMountResult.NameNullOrEmpty:
                throw TryGetMountException.MountNameNullOrEmpty(env, new ErrorContext(pos: 1), lineInfo);

            case TryGetMountResult.NameNotFound:
                return(EvaluationResult.False);

            default:
                Contract.Assume(false, "Unexpected TryGetMountResult");
                return(EvaluationResult.Undefined);
            }
        }
示例#2
0
        private EvaluationResult GetMount(Context context, ModuleLiteral env, EvaluationStackFrame args)
        {
            var engine = context.FrontEndHost.Engine;
            var name   = Convert.ToString(args[0].Value, CultureInfo.InvariantCulture);

            GetProvenance(context, out AbsolutePath path, out LineInfo lineInfo);

            var result = engine.TryGetMount(name, "Script", AmbientTypes.ScriptModuleId, out IMount mount);

            switch (result)
            {
            case TryGetMountResult.Success:
                return
                    (EvaluationResult.Create(ObjectLiteral.Create(
                                                 new Binding(MountNameObject, mount.Name, location: lineInfo),
                                                 new Binding(MountPathObject, mount.Path, location: lineInfo))));

            case TryGetMountResult.NameNullOrEmpty:
                throw TryGetMountException.MountNameNullOrEmpty(env, new ErrorContext(pos: 1), lineInfo);

            case TryGetMountResult.NameNotFound:
                // Check for case mismatch.
                var mountNames = engine.GetMountNames("Script", BuildXL.Utilities.ModuleId.Invalid);
                foreach (var mountName in mountNames)
                {
                    if (string.Equals(name, mountName, StringComparison.OrdinalIgnoreCase))
                    {
                        throw TryGetMountException.MountNameCaseMismatch(env, name, mountName, new ErrorContext(pos: 1), lineInfo);
                    }
                }

                throw TryGetMountException.MountNameNotFound(env, name, mountNames, new ErrorContext(pos: 1), lineInfo);

            default:
                Contract.Assume(false, "Unexpected TryGetMountResult");
                return(EvaluationResult.Undefined);
            }
        }