Example #1
0
 protected override void OnAccessorChanged(IAccessor accessor)
 {
     text.text  = accessor.FieldName;
     InvokeType = InvocationType.None;
     if (accessor is MethodAccessor)
     {
         del        = null;
         uEvent     = null;
         method     = ((MethodAccessor)accessor).Method;
         InvokeType = InvocationType.Method;
     }
     else if (accessor is FieldAccessor || accessor is PropertyAccessor || accessor is CustomPropertyAccessor_Base || accessor is CustomFunctionAccessor)
     {
         method = null;
         uEvent = null;
         del    = null;
         var value = accessor.FieldValue;
         if (value is Delegate)
         {
             del        = (Delegate)value;
             InvokeType = InvocationType.Delegate;
         }
         else if (value is UnityEvent)
         {
             uEvent     = (UnityEvent)value;
             InvokeType = InvocationType.UnityEvent;
         }
     }
     base.OnAccessorChanged(accessor);
 }
Example #2
0
        public bool TryGetNextInvocation(DateTime referenceTime,
                                         out InvocationType nextType, out DateTime nextTime)
        {
            var success = false;

            nextType = InvocationType.Undefined;
            // set to max. DateTime first to ease time comparisons later
            nextTime = DateTime.MaxValue;

            lock (_lock)
            {
                // detect invocation limit
                if (!HasInvocationsLeft)
                {
                    return(false);
                }

                // time limits
                // if expiration date reached and no intent to preserve possible left out invocations
                if (HasExpired(referenceTime) && (!GetPreserveDueInvocations()))
                {
                    return(false);
                }

                // determine possible next specified time
                success = TryGetNextSpecifiedTime(out nextTime);
                if (success)
                {
                    nextType = InvocationType.SpecifiedTime;
                }

                // detect interval and compare with possible previous specified time
                TimeSpan lastInterval;
                if (TryGetLastInterval(out lastInterval))
                {
                    DateTime nextIntervalTime;
                    if (!TryGetNextIntervalTime(out nextIntervalTime))
                    {
                        MakeLogError("TryGetLastInterval succeeded but TryGetNextIntervalTime failed in TimedFunction.TryIterateNextInvocation");
                    }

                    // only take intervals into account which would have been invocated in the meantime
                    if (nextIntervalTime <= GetEnd())
                    {
                        if (nextIntervalTime < nextTime)
                        {
                            nextTime = nextIntervalTime;
                            nextType = InvocationType.Interval;
                            success  = true;
                        }
                    }
                }
            }

            return(success);
        }
Example #3
0
 /// <summary>
 /// Creates a new instance of <see cref="InvocationSignature"/>.
 /// </summary>
 public InvocationSignature(
     MethodInfo method,
     MethodInfo targetMethod,
     Type declaringType,
     Type targetType,
     InvocationType invocationType)
 {
     Method         = method;
     TargetMethod   = targetMethod;
     DeclaringType  = declaringType;
     TargetType     = targetType;
     InvocationType = invocationType;
 }
        public async Task NoDiagnosticForRegexOptionsNonBacktracking(InvocationType invocationType)
        {
            string isMatchInvocation = invocationType == InvocationType.Constructor ? @".IsMatch("""")" : string.Empty;
            string test = @"using System.Text.RegularExpressions;

public class Program
{
    public static void Main(string[] args)
    {
        var isMatch = " + ConstructRegexInvocation(invocationType, "\"\"", "RegexOptions.IgnoreCase | RegexOptions.NonBacktracking") + isMatchInvocation + @";
    }
}";

            await VerifyCS.VerifyAnalyzerAsync(test);
        }
        public async Task NoDiagnosticsForNet60(InvocationType invocationType)
        {
            string isMatchInvocation = invocationType == InvocationType.Constructor ? @".IsMatch("""")" : string.Empty;
            string test = @"using System.Text;
using System.Text.RegularExpressions;

public class Program
{
    public static void Main(string[] args)
    {
        var isMatch = " + ConstructRegexInvocation(invocationType, pattern: "\"\"") + isMatchInvocation + @";
    }
}";

            await VerifyCS.VerifyAnalyzerAsync(test, ReferenceAssemblies.Net.Net60);
        }
Example #6
0
        public async Task NoDiagnosticsForLowerLanguageVersion(InvocationType invocationType)
        {
            string isMatchInvocation = invocationType == InvocationType.Constructor ? @".IsMatch("""")" : string.Empty;
            string test = @"using System.Text;
using System.Text.RegularExpressions;

public class Program
{
    public static void Main(string[] args)
    {
        var isMatch = " + ConstructRegexInvocation(invocationType, "\"\"") + isMatchInvocation + @";
    }
}";

            await VerifyCS.VerifyAnalyzerAsync(test, null, usePreviewLanguageVersion : false);
        }
        public async Task TopLevelStatements(InvocationType invocationType)
        {
            string isMatchInvocation = invocationType == InvocationType.Constructor ? @".IsMatch("""")" : string.Empty;
            string test      = @"using System.Text.RegularExpressions;
var isMatch = [|" + ConstructRegexInvocation(invocationType, pattern: "\"\"") + @"|]" + isMatchInvocation + ";";
            string fixedCode = @"using System.Text.RegularExpressions;
var isMatch = MyRegex().IsMatch("""");

partial class Program
{
    [GeneratedRegex("""")]
    private static partial Regex MyRegex();
}";

            await new VerifyCS.Test
            {
                TestCode  = test,
                FixedCode = fixedCode,
                TestState = { OutputKind = OutputKind.ConsoleApplication },
            }.RunAsync();
        }
        public async Task NoDiagnosticsForLowerLanguageVersion(InvocationType invocationType)
        {
            string isMatchInvocation = invocationType == InvocationType.Constructor ? @".IsMatch("""")" : string.Empty;
            string test = @"using System.Text;
using System.Text.RegularExpressions;

public class Program
{
    public static void Main(string[] args)
    {
        var isMatch = " + ConstructRegexInvocation(invocationType, "\"\"") + isMatchInvocation + @";
    }
}";

            await new VerifyCS.Test
            {
                TestCode        = test,
                FixedCode       = test,
                LanguageVersion = LanguageVersion.CSharp10,
            }.RunAsync();
        }
Example #9
0
        // general constructor
        public TimedFunction(DateTime[] specifiedTimes, TimeSpan[] intervals,
                             Tuple <DateTime, DateTime> startEnd)
        {
            _lock = new object();

            preserveDueInvocations = true;

            if (specifiedTimes != null)
            {
                hasSpecifiedTimes      = true;
                this.specifiedTimes    = specifiedTimes;
                lastSpecifiedTimeIndex = -1;
            }
            if (intervals != null)
            {
                hasIntervals      = true;
                this.intervals    = intervals;
                lastIntervalIndex = 0;
                lastIntervalTime  = DateTime.Now;
                lastIntervalIndex = -1;
            }
            if (startEnd != null)
            {
                hasStartEnd   = true;
                this.startEnd = startEnd;
            }

            // give first values for last and next invocation
            lastInvocationType = InvocationType.Undefined;
            var nextType = InvocationType.Undefined;
            var nextTime = DateTime.MinValue;

            if (TryGetNextInvocation(DateTime.MinValue, out nextType, out nextTime))
            {
                SetNextInvocationType(nextType);
            }
        }
Example #10
0
 protected void SetNextInvocationType(InvocationType value)
 {
     lock (_lock) { nextInvocationType = value; }
 }
Example #11
0
 protected void SetLastInvocationType(InvocationType value)
 {
     lock (_lock) { lastInvocationType = value; }
 }
 private static string ConstructRegexInvocation(InvocationType invocationType, string pattern, string?options = null)
 => invocationType switch
 {
Example #13
0
        protected void initialize()
        {
            matcher = new Matcher();
            matcher.Must().Match(source, regexInvocation, true, false).OrThrow($"Didn't understand invocation <[{source}]>");
            var assemblyName = matcher.FirstGroup;
            var alias        = matcher.SecondGroup;
            var sign         = matcher.ThirdGroup;
            var typeName     = matcher.FourthGroup;
            var dot          = matcher.FifthGroup;

            member = matcher.SixthGroup;
            var parameterSource  = matcher.SeventhGroup;
            var invocationMethod = matcher.EighthGroup;

            var assemblyPresent = assemblyName.IsNotEmpty();

            if (assemblyPresent)
            {
                Color(index, 1, Structures);
                Color(assemblyName.Length, Variables);
                Color(1, Structures);
                if (alias.IsNotEmpty())
                {
                    Color(alias.Length, Variables);
                    Color(sign.Length, Operators);
                }

                Color(typeName.Length, Variables);
            }
            else if (alias.IsNotEmpty())
            {
                Color(index, alias.Length, Variables);
                Color(sign.Length, Operators);
                Color(typeName.Length, Variables);
            }
            else
            {
                Color(index, typeName.Length, Variables);
            }

            Color(1, Structures);
            Color(member.Length, Messaging);
            Color(1, Structures);
            Color(parameterSource.Length, Variables);
            Color(1, Structures);
            Color(invocationMethod.Length, Operators);
            if (!assemblyPresent)
            {
                assemblyName = "mscorlib";
            }

            switch (member)
            {
            case "new":
                invocationType = New;
                bindingFlags   = new Bits32 <BindingFlags>(Public);
                break;

            default:
                invocationType = dot == "." ? InvocationType.Instance : InvocationType.Static;
                bindingFlags   = invocationType switch
                {
                    InvocationType.Instance => BindingFlags.Instance,
                    InvocationType.Static => BindingFlags.Static,
                    _ => bindingFlags
                };

                bindingFlags[Public] = true;
                switch (invocationMethod)
                {
                case "!":
                    bindingFlags[SetProperty] = true;
                    break;

                case "?":
                    bindingFlags[GetProperty] = true;
                    break;

                case ".!":
                    bindingFlags[SetField] = true;
                    break;

                case ".?":
                    bindingFlags[GetField] = true;
                    break;

                default:
                    bindingFlags[InvokeMethod] = true;
                    break;
                }

                break;
            }

            if (typeName.StartsWith("#"))
            {
                typeName = typeAliases.Find(typeName.Drop(1), _ => "");
            }

            if (alias.IsNotEmpty())
            {
                typeAliases[alias] = typeName;
            }

            typeName.Must().Not.BeNullOrEmpty().OrThrow(LOCATION, () => "Couldn't find type");
            var fullAssemblyName = typeToAssemblies[typeName];

            if (fullAssemblyName != null)
            {
                assemblyName = fullAssemblyName;
            }

            assembly = assemblies.Find(assemblyName, Assembly.Load);
            type     = assembly.GetType(typeName, false, true);
            type.Must().Not.BeNull().OrThrow(LOCATION, () => $"Didn't understand .NET type {typeName}");
            typeToAssemblies[typeName] = assemblyName;
            parameters = parameterSource.Split("/s* ',' /s*");
        }
Example #14
0
        public async Task <TOutput> Invoke <TInput, TOutput>(string functionName, TInput inputParam, InvocationType invocationType = null)
        {
            var lambdaConfig = new AmazonLambdaConfig()
            {
                RegionEndpoint = RegionEndpoint.GetBySystemName(AwsRegion)
            };
            var awsClient = new AmazonLambdaClient(AwsSecretAccessKeyId, AwsSecretAccessKey, lambdaConfig);

            var response = await awsClient.InvokeAsync(new InvokeRequest
            {
                FunctionName   = functionName,
                InvocationType = invocationType == null ? InvocationType.RequestResponse : invocationType,
                Payload        = JsonSerializer.Serialize(inputParam)
            });

            return(Deserialize <TOutput>(Encoding.Default.GetString(response.Payload.ToArray())));
        }
        private async UniTask <InvokeResponse> InvokeLambdaFunctionAsync(AmazonLambdaClient lambdaClient, string functionName, InvocationType invocationType, string payload = "")
        {
            var request = new InvokeRequest
            {
                FunctionName   = functionName,
                InvocationType = invocationType,
                Payload        = payload,
            };

            return(await lambdaClient.InvokeAsync(request));
        }
 public CustomProxy(InvocationType invocationType)
     : base(typeof(T))
 {
     this.invocations    = new List <string>();
     this.invocationType = invocationType;
 }
Example #17
0
        public OptimizedMethodInvokerTemplate(MethodBase method)
        {
            this.method = method;

            invocationType = ResolveInvocationType();
        }
Example #18
0
        void initialize()
        {
            matcher = new Matcher();
            matcher.RequiredMatch(source, $"^ ('|' /(-['|']+) '|')? (/({REGEX_VARIABLE}) /(/s* '=' /s*))? /('#'? [/w .]+) " +
                                  "/(['.:']) /(/w+) '(' /(-[')']*) ')' /('.'? ['!?'])? $", $"Didn't understand invocation <[{source}]>", true);
            matcher.Extract(0, out var assemblyName, out var alias, out var sign, out var typeName, out var dot, out member,
                            out var parameterSource, out var invocationMethod);
            var assemblyPresent = assemblyName.IsNotEmpty();

            if (assemblyPresent)
            {
                Color(index, 1, Structures);
                Color(assemblyName.Length, Variables);
                Color(1, Structures);
                if (alias.IsNotEmpty())
                {
                    Color(alias.Length, Variables);
                    Color(sign.Length, Operators);
                }
                Color(typeName.Length, Variables);
            }
            else if (alias.IsNotEmpty())
            {
                Color(index, alias.Length, Variables);
                Color(sign.Length, Operators);
                Color(typeName.Length, Variables);
            }
            else
            {
                Color(index, typeName.Length, Variables);
            }
            Color(1, Structures);
            Color(member.Length, Messaging);
            Color(1, Structures);
            Color(parameterSource.Length, Variables);
            Color(1, Structures);
            Color(invocationMethod.Length, Operators);
            if (!assemblyPresent)
            {
                assemblyName = "mscorlib";
            }
            switch (member)
            {
            case "new":
                invocationType = New;
                bindingFlags   = new Bits32 <BindingFlags>(Public);
                break;

            default:
                invocationType = dot == "." ? InvocationType.Instance : InvocationType.Static;
                switch (invocationType)
                {
                case InvocationType.Instance:
                    bindingFlags = BindingFlags.Instance;
                    break;

                case InvocationType.Static:
                    bindingFlags = BindingFlags.Static;
                    break;
                }
                bindingFlags[Public] = true;
                switch (invocationMethod)
                {
                case "!":
                    bindingFlags[SetProperty] = true;
                    break;

                case "?":
                    bindingFlags[GetProperty] = true;
                    break;

                case ".!":
                    bindingFlags[SetField] = true;
                    break;

                case ".?":
                    bindingFlags[GetField] = true;
                    break;

                default:
                    bindingFlags[InvokeMethod] = true;
                    break;
                }
                break;
            }
            if (typeName.StartsWith("#"))
            {
                typeName = typeAliases.Find(typeName.Skip(1), t => "");
            }
            if (alias.IsNotEmpty())
            {
                typeAliases[alias] = typeName;
            }
            Assert(typeName.IsNotEmpty(), LOCATION, "Couldn't find type");
            var fullAssemblyName = typeToAssemblies[typeName];

            if (fullAssemblyName != null)
            {
                assemblyName = fullAssemblyName;
            }
            assembly = assemblies.Find(assemblyName, Assembly.Load);
            type     = assembly.GetType(typeName, false, true);
            RejectNull(type, LOCATION, $"Didn't understand .NET type {typeName}");
            typeToAssemblies[typeName] = assemblyName;
            parameters = parameterSource.Split("/s* ',' /s*");
        }