public override void InterpretContext(ArgumentContext context)
 {
     if (context.Arguments.Contains("-o"))
     {
         context.PatternDirectory.Add("bin");
     }
 }
 public void Interpret(ArgumentContext context)
 {
     foreach (var interpretter in _interpretters)
     {
         interpretter.InterpretContext(context);
     }
 }
 /// <summary>
 /// Ensures the given <see cref="IEnumerable{T}"/> is not empty
 /// </summary>
 /// <typeparam name="T">The <see cref="Type"/> of items in the IEnumerable</typeparam>
 /// <param name="argument">The context describing the value</param>
 /// <param name="message">An optional message to use when validation fails</param>
 /// <param name="paramName">An optional parameter name to use when validation fails</param>
 /// <returns>The given <see cref="IEnumerable{T}"/> if validation passes</returns>
 /// <exception cref="ArgumentException">If the <see cref="IEnumerable{T}"/> has no items</exception>
 /// <exception cref="ArgumentNullException">If <paramref name="argument.Value"/> is <c>null</c></exception>
 public static IEnumerable <T> IsNotempty <T>(this ArgumentContext <IEnumerable <T> > argument, string message = null, string paramName = null)
 {
     return(Ensure.Condition(
                argument.Value,
                a => a.Count() > 0,
                message ?? $"Exptected the IEnumerable of <{typeof(T).Name}> to have an item.",
                paramName));
 }
Exemple #4
0
 /// <summary>
 /// Ensures the given <see cref="string"/> value is not a whitespace
 /// </summary>
 /// <param name="argument">The context describing the value</param>
 /// <param name="message">An optional message to use when validation fails</param>
 /// <param name="paramName">An optional parameter name to use when validation fails</param>
 /// <returns>The given <see cref="string"/> if validation passes</returns>
 /// <exception cref="ArgumentException">If the given <see cref="string"/> is <c>null</c> or a whitespace</exception>
 /// <exception cref="ArgumentNullException">If <paramref name="argument.Value"/> is <c>null</c></exception>
 public static string IsNotNullOrWhiteSpace(this ArgumentContext <string> argument, string message = null, string paramName = null)
 {
     return(Ensure.Condition(
                argument.Value,
                a => !string.IsNullOrWhiteSpace(a),
                message ?? $"Expected <{argument}> to have length.",
                paramName));
 }
Exemple #5
0
 /// <summary>
 /// Ensures the given <see cref="object"/>'s type is assignable from <paramref name="type"/>
 /// </summary>
 /// <param name="argument">The context describing the value</param>
 /// <param name="type">The <see cref="Type"/> the object should be assignable from.</param>
 /// <param name="message">An optional message to use when validation fails</param>
 /// <param name="paramName">An optional parameter name to use when validation fails</param>
 /// <returns>The given <see cref="object"/> if validation passes</returns>
 /// <exception cref="ArgumentException">If the <see cref="object"/> is not assignable from <paramref name="type"/></exception>
 /// <exception cref="ArgumentNullException">If <paramref name="argument.Value"/> or <paramref name="type"/> is <c>null</c></exception>
 public static object IsAssignableFrom(this ArgumentContext <object> argument, Type type, string message = null, string paramName = null)
 {
     Ensure.NotNull(type, "Type");
     return(Ensure.Condition(
                argument.Value,
                a => a.GetType().GetTypeInfo().IsAssignableFrom(type.GetTypeInfo()),
                message ?? $"Exptected that <{argument.Value.GetType().Name}> is assignable from <{type.Name}>",
                paramName));
 }
 /// <summary>
 /// Ensures the given <see cref="IEnumerable{T}"/> contains <typeparamref name="T"/> <paramref name="value"/>
 /// </summary>
 /// <typeparam name="T">The <see cref="Type"/> of items in the IEnumerable</typeparam>
 /// <param name="argument">The context describing the value</param>
 /// <param name="value">The value to find in the collection</param>
 /// <param name="message">An optional message to use when validation fails</param>
 /// <param name="paramName">An optional parameter name to use when validation fails</param>
 /// <returns>The given <see cref="IEnumerable{T}"/> if validation passes</returns>
 /// <exception cref="ArgumentException">If the <see cref="IEnumerable{T}"/> does not contain <paramref name="value"/></exception>
 /// <exception cref="ArgumentNullException">If <paramref name="argument.Value"/> or <paramref name="value"/> is <c>null</c></exception>
 public static IEnumerable <T> Contains <T>(this ArgumentContext <IEnumerable <T> > argument, T value, string message = null, string paramName = null)
 {
     Ensure.NotNull(value, "Value");
     return(Ensure.Condition(
                argument.Value,
                a => a.Contains(value),
                message ?? $"Exptected the IEnumerable of <{typeof(T).Name}> to contain <{value}>",
                paramName));
 }
Exemple #7
0
 /// <summary>
 /// Ensures the given <see cref="string"/> value matches the <see cref="Regex"/> <paramref name="pattern"/>
 /// </summary>
 /// <param name="argument">The context describing the value</param>
 /// <param name="pattern"></param>
 /// <param name="message">An optional message to use when validation fails</param>
 /// <param name="paramName">An optional parameter name to use when validation fails</param>
 /// <returns>The given <see cref="string"/> if validation passes</returns>
 /// <exception cref="ArgumentException">If the given <see cref="string"/> does not match <paramref name="pattern"/> </exception>
 /// <exception cref="ArgumentNullException">If <paramref name="argument.Value"/> or <paramref name="pattern"/> is <c>null</c></exception>
 public static string IsMatch(this ArgumentContext <string> argument, string pattern, string message = null, string paramName = null)
 {
     Ensure.NotNull(pattern, "Pattern");
     return(Ensure.Condition(
                argument.Value,
                a => Regex.IsMatch(a, pattern),
                message ?? $"Expected <{argument}> to match <{pattern}>",
                paramName));
 }
Exemple #8
0
 /// <summary>
 /// Ensures the given <see cref="string"/> value contains <paramref name="value"/>
 /// </summary>
 /// <param name="argument">The context describing the value</param>
 /// <param name="value"></param>
 /// <param name="message">An optional message to use when validation fails</param>
 /// <param name="paramName">An optional parameter name to use when validation fails</param>
 /// <returns>The given <see cref="string"/> if validation passes</returns>
 /// <exception cref="ArgumentException">If the given <see cref="string"/> does not contain <paramref name="value"/></exception>
 /// <exception cref="ArgumentNullException">If <paramref name="argument.Value"/> or <paramref name="value"/> is <c>null</c></exception>
 public static string Contains(this ArgumentContext <string> argument, string value, string message = null, string paramName = null)
 {
     Ensure.NotNull(value, "Value");
     return(Ensure.Condition(
                argument.Value,
                a => a.Contains(value),
                message ?? $"Expected <{argument}> to contain <{value}>",
                paramName));
 }
Exemple #9
0
 /// <summary>
 /// Ensures the given <see cref="string"/> value is <paramref name="length"/> long.
 /// </summary>
 /// <param name="argument">The context describing the value</param>
 /// <param name="length"></param>
 /// <param name="message">An optional message to use when validation fails</param>
 /// <param name="paramName">An optional parameter name to use when validation fails</param>
 /// <returns>The given <see cref="string"/> if validation passes</returns>
 /// <exception cref="ArgumentException">If the given <see cref="string"/> length differs from <paramref name="length"/></exception>
 /// <exception cref="ArgumentNullException">If <paramref name="argument.Value"/> or <paramref name="length"/> is <c>null</c></exception>
 public static string Length(this ArgumentContext <string> argument, int length, string message = null, string paramName = null)
 {
     Ensure.NotNull(length, "Length");
     return(Ensure.Condition(
                argument.Value,
                a => a.Length.Equals(length),
                message ?? $"Expected length of <{argument}> is <{length}>.",
                paramName));
 }
 /// <summary>
 /// Ensures the given <see cref="IEnumerable{T}"/> has <paramref name="count"/> amount of items
 /// </summary>
 /// <typeparam name="T">The <see cref="Type"/> of items in the IEnumerable</typeparam>
 /// <param name="argument">The context describing the value</param>
 /// <param name="count">The amount of items expected in the <see cref="IEnumerable{T}"/></param>
 /// <param name="message">An optional message to use when validation fails</param>
 /// <param name="paramName">An optional parameter name to use when validation fails</param>
 /// <returns>The given <see cref="IEnumerable{T}"/> if validation passes</returns>
 /// <exception cref="ArgumentException">If the amount of items in the <see cref="IEnumerable{T}"/> differs from <paramref name="count"/></exception>
 /// <exception cref="ArgumentNullException">If <paramref name="argument.Value"/> or <paramref name="count"/> is <c>null</c></exception>
 public static IEnumerable <T> CountIs <T>(this ArgumentContext <IEnumerable <T> > argument, int count, string message = null, string paramName = null)
 {
     Ensure.NotNull(count, "Count");
     return(Ensure.Condition(
                argument.Value,
                a => a.Count().Equals(count),
                message ?? $"Exptected the IEnumerable of <{typeof(T).Name}> to have <{count}> items, it has <{argument.Value.Count()}>",
                paramName));
 }
Exemple #11
0
 /// <summary>
 /// Ensures the given <see cref="object"/> value equals <paramref name="value"/>
 /// </summary>
 /// <param name="argument">The context describing the value</param>
 /// <param name="value">The value to compare with <paramref name="argument.Value"/></param>
 /// <param name="message">An optional message to use when validation fails</param>
 /// <param name="paramName">An optional parameter name to use when validation fails</param>
 /// <returns>The given <see cref="object"/> if validation passes</returns>
 /// <exception cref="ArgumentException">If the <see cref="object"/> does not contain <paramref name="value"/></exception>
 /// <exception cref="ArgumentNullException">If <paramref name="argument.Value"/> or <paramref name="value"/> is <c>null</c></exception>
 public static object Equals(this ArgumentContext <object> argument, object value, string message = null, string paramName = null)
 {
     Ensure.NotNull(value, "Value");
     return(Ensure.Condition(
                argument.Value,
                a => a.Equals(value),
                message ?? $"Expected <{argument.Value}> to be equal to <{value}>",
                paramName));
 }
Exemple #12
0
        /// <summary>
        /// Ensures the given <see cref="string"/> value is an <see cref="int"/>
        /// </summary>
        /// <param name="argument">The context describing the value</param>
        /// <param name="message">An optional message to use when validation fails</param>
        /// <param name="paramName">An optional parameter name to use when validation fails</param>
        /// <returns>The given <see cref="string"/> if validation passes</returns>
        /// <exception cref="ArgumentException">If the given <see cref="string"/> is not a number</exception>
        /// <exception cref="ArgumentNullException">If <paramref name="argument.Value"/> is <c>null</c></exception>
        public static string IsNumber(this ArgumentContext <string> argument, string message = null, string paramName = null)
        {
            int result;

            return(Ensure.Condition(
                       argument.Value,
                       a => int.TryParse(a, out result),
                       $"Expected <{argument}> to be a number.",
                       paramName));
        }
Exemple #13
0
        static void Main(string[] args)
        {
            var ctx = new ArgumentContext(args);

            Func <string, bool> act = shema => { return(true); };

            Database.GenerateFile(ctx, act);

            string directory = new FileInfo(ctx.Filename).Directory.FullName;
        }
Exemple #14
0
        public override void InterpretContext(ArgumentContext context)
        {
            var path = context.Arguments
                       .Where(a => a.StartsWith("-p"))
                       .FirstOrDefault();

            if (!string.IsNullOrEmpty(path))
            {
                context.DirectoryPath = path.Substring(3);
            }
        }
 public override void InterpretContext(ArgumentContext context)
 {
     if (context.Arguments.Contains("-?"))
     {
         var builder = new StringBuilder();
         builder.Append($"Help to clean up your .net repository by removing some working folder:{Environment.NewLine}");
         foreach (var interpret in Interpretter.Instance.Interpretters)
         {
             builder.Append($"{interpret.GetHelpMessage()}{Environment.NewLine}");
         }
         context.HelpMessage = builder.ToString();
     }
 }
Exemple #16
0
        public override async Task ProvideArgumentAsync(ArgumentContext context)
        {
            if (context.PreviousValue is not null)
            {
                return;
            }

            var semanticModel = await context.Document.GetRequiredSemanticModelAsync(context.CancellationToken).ConfigureAwait(false);

            var symbols = semanticModel.LookupSymbols(context.Position, name: context.Parameter.Name);

            foreach (var symbol in symbols)
            {
                if (SymbolEqualityComparer.Default.Equals(context.Parameter.Type, symbol.GetSymbolType()))
                {
                    context.DefaultValue = context.Parameter.Name;
                    return;
                }
            }
        }
        public void TestMethod1()
        {
            Func <string, bool> act = shema => { return(true); };
            string file             = Path.Combine(Path.GetTempPath(), Path.GetTempFileName());

            var ctx = new ArgumentContext()
            {
                Source      = "DEV_V",
                Login       = "******",
                Pwd         = "GUEST",
                Filename    = file,
                ExcludeCode = false,
                Name        = "DEV",
                OwnerFilter = "*",
            };

            var db1 = Database.GenerateFile(ctx, act);

            var db2 = OracleDatabase.ReadFile(file);

            // C:\Users\g.beard\AppData\Local\Temp\tmp8C5D.tmp
        }
Exemple #18
0
        public override Task ProvideArgumentAsync(ArgumentContext context)
        {
            if (context.PreviousValue is not null)
            {
                // This argument provider does not attempt to replace arguments already in code.
                return(Task.CompletedTask);
            }

            if (context.Parameter.RefKind != RefKind.Out)
            {
                // This argument provider only considers 'out' parameters.
                return(Task.CompletedTask);
            }

            // Since tihs provider runs after ContextVariableArgumentProvider, we know there is no suitable target in
            // the current context. Instead, offer to declare a new variable.
            var name = context.Parameter.Name;

            if (SyntaxFacts.GetKeywordKind(name) != SyntaxKind.None ||
                SyntaxFacts.GetContextualKeywordKind(name) != SyntaxKind.None)
            {
                name = "@" + name;
            }

            var syntax = SyntaxFactory.Argument(
                nameColon: null,
                refKindKeyword: SyntaxFactory.Token(SyntaxKind.OutKeyword),
                SyntaxFactory.DeclarationExpression(
                    type: SyntaxFactory.IdentifierName("var"),
                    designation: SyntaxFactory.SingleVariableDesignation(SyntaxFactory.Identifier(
                                                                             SyntaxFactory.TriviaList(),
                                                                             contextualKind: SyntaxKind.None,
                                                                             text: name,
                                                                             valueText: context.Parameter.Name,
                                                                             SyntaxFactory.TriviaList()))));

            context.DefaultValue = syntax.NormalizeWhitespace().ToFullString();
            return(Task.CompletedTask);
        }
Exemple #19
0
        public override async Task ProvideArgumentAsync(ArgumentContext context)
        {
            await base.ProvideArgumentAsync(context).ConfigureAwait(false);

            if (context.DefaultValue is not null)
            {
                switch (context.Parameter.RefKind)
                {
                case RefKind.Ref:
                    context.DefaultValue = "ref " + context.DefaultValue;
                    break;

                case RefKind.Out:
                    context.DefaultValue = "out " + context.DefaultValue;
                    break;

                case RefKind.In:
                case RefKind.None:
                default:
                    break;
                }
            }
        }
        private PropertyContextSurface ChangeProperty(INakedObject nakedObject, string propertyName, ArgumentContext argument) {
            ValidateConcurrency(nakedObject, argument.Digest);
            PropertyContext context = CanChangeProperty(nakedObject, propertyName, argument.Value);
            if (string.IsNullOrEmpty(context.Reason)) {
                var spec = context.Target.Spec as IObjectSpec;
                Trace.Assert(spec != null);

                IEnumerable<PropertyContext> existingValues = spec.Properties.Where(p => p.Id != context.Id).
                    Select(p => new {p, no = p.GetNakedObject(context.Target)}).
                    Select(ao => new PropertyContext {
                        Property = ao.p,
                        ProposedNakedObject = ao.no,
                        ProposedValue = ao.no == null ? null : ao.no.Object,
                        Target = context.Target
                    }
                    ).Union(new[] {context});

                var objectContext = new ObjectContext(context.Target) {VisibleProperties = existingValues.ToArray()};

                if (ConsentHandler(CrossValidate(objectContext), objectContext, Cause.Other)) {
                    if (!argument.ValidateOnly) {
                        SetProperty(context);
                    }
                }
                else {
                    context.Reason = objectContext.Reason;
                    context.ErrorCause = objectContext.ErrorCause;
                }
            }
            context.Mutated = true; // mark as changed even if property not actually changed to stop self rep
            return context.ToPropertyContextSurface(this, framework);
        }
 public PropertyContextSurface DeleteProperty(LinkObjectId objectId, string propertyName, ArgumentContext argument) {
     return MapErrors(() => ChangeProperty(GetObjectAsNakedObject(objectId), propertyName, argument));
 }
Exemple #22
0
 public override object VisitArgument([NotNull] ArgumentContext context) => new Argument(null, Visit(context.children[0]).ToString());
Exemple #23
0
 public override Task ProvideArgumentAsync(ArgumentContext context)
 {
     if (context.PreviousValue is { })
Exemple #24
0
 /// <summary>
 /// Ensures the given <see cref="object"/> value is not <c>null</c>
 /// </summary>
 /// <param name="argument">The context describing the value</param>
 /// <param name="message">An optional message to use when validation fails</param>
 /// <param name="paramName">An optional parameter name to use when validation fails</param>
 /// <returns>The given <see cref="object"/> if validation passes</returns>
 /// <exception cref="ArgumentNullException">If <paramref name="argument.Value"/> is <c>null</c></exception>
 public static object NotNull(this ArgumentContext <object> argument, string message = null, string paramName = null)
 {
     return(Ensure.NotNull(argument.Value, message, paramName));
 }
 public abstract void InterpretContext(ArgumentContext context);
	public ArgumentContext argument() {
		ArgumentContext _localctx = new ArgumentContext(Context, State);
		EnterRule(_localctx, 150, RULE_argument);
		int _la;
		try {
			State = 1019;
			switch ( Interpreter.AdaptivePredict(TokenStream,143,Context) ) {
			case 1:
				EnterOuterAlt(_localctx, 1);
				{
				State = 1011; test();
				State = 1013;
				_la = TokenStream.La(1);
				if (_la==FOR) {
					{
					State = 1012; comp_for();
					}
				}

				}
				break;
			case 2:
				EnterOuterAlt(_localctx, 2);
				{
				State = 1015; test();
				State = 1016; Match(ASSIGN);
				State = 1017; test();
				}
				break;
			}
		}
		catch (RecognitionException re) {
			_localctx.exception = re;
			ErrorHandler.ReportError(this, re);
			ErrorHandler.Recover(this, re);
		}
		finally {
			ExitRule();
		}
		return _localctx;
	}
 public override Task ProvideArgumentAsync(ArgumentContext context)
 => Task.CompletedTask;